index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <template>
  2. <view class="container">
  3. <template v-if="Data.is_sell != 1">
  4. <div class="qtmd mar_b20" v-if="goodsInfo.shipping_method == 2">
  5. <view class="order_list flex_r flex_ac flex_jb">
  6. <view class="list_name">发货方式</view>
  7. <view class="list_con flex_r flex_jb">
  8. <div class="select_tab" @click="onprom(0)" :class="{st_active:prom_type===0}">快递邮寄</div>
  9. <div class="select_tab" @click="onprom(1)" :class="{st_active:prom_type===1}">到店自提</div>
  10. </view>
  11. </view>
  12. </div>
  13. <div class="qtmd mar_b20" v-else>
  14. <view class="order_list flex_r flex_ac flex_jb">
  15. <view class="list_name">发货方式</view>
  16. <view class="list_con flex_r flex_jb">
  17. <div class="list_con" v-if="prom_type==0">快递邮寄</div>
  18. <div class="list_con" v-else>到店自提</div>
  19. </view>
  20. </view>
  21. </div>
  22. </template>
  23. <!-- 收货地址 -->
  24. <view class="address mar_b20" v-if="Data.is_sell != 1 && prom_type != 1">
  25. <block v-if="DefaultAddress.name" >
  26. <view class="add_head flex_r flex_ac flex_jb">
  27. <view class="user_info flex_r flex_ac">
  28. <view class="user_name">{{ DefaultAddress.name }}</view>
  29. <view class="user_phone">{{ DefaultAddress.mobile }}</view>
  30. </view>
  31. <view class="set_address flex_r flex_ac" @tap="chooseWXaddress">
  32. <image
  33. class="set_img"
  34. src="/static/img/setAddress.png"
  35. mode=""
  36. ></image>
  37. <view class="set_text">修改</view>
  38. </view>
  39. </view>
  40. <view class="add_name mar_t20">{{ DefaultAddress.province + ' ' + DefaultAddress.city + ' ' + DefaultAddress.area + ' ' + DefaultAddress.street + ' ' + DefaultAddress.address }}</view>
  41. </block>
  42. <block v-else>
  43. <view class="add_address flex_c flex_ac flex_jc" @tap="chooseWXaddress('add')">
  44. <image class="add_icon" src="/static/img/add.png" mode=""></image>
  45. <view class="add_text">添加收货地址</view>
  46. </view>
  47. </block>
  48. </view>
  49. <!-- 收货地址-end -->
  50. <!-- 商品信息 -->
  51. <view class="goods_info mar_b20">
  52. <view class="info_type">{{ modularName }}</view>
  53. <view class="goods flex_r">
  54. <image class="goods_img" :src="goodsInfo.original_img" mode=""></image>
  55. <view class="goods_con flex_c flex_jc flex_jb">
  56. <view class="goods_name ellipsis2">{{ goodsInfo.goods_name }}</view>
  57. <view class="goods_msg" v-if="Data.type == 2"
  58. >{{ goodsInfo.trade_price }}元+{{ goodsInfo.trade_num }}批发券+{{
  59. goodsInfo.treasure_price
  60. }}茶宝</view
  61. >
  62. <view class="goods_msg" v-else>{{ goodsInfo.cost_price }}</view>
  63. <view class="goods_num">x {{ Data.num }}</view>
  64. </view>
  65. </view>
  66. </view>
  67. <!-- 商品信息-end -->
  68. <!-- 订单信息 -->
  69. <view class="order">
  70. <view class="order_list flex_r flex_ac flex_jb">
  71. <view class="list_name">数量</view>
  72. <view class="list_con">{{ Data.num }}</view>
  73. </view>
  74. <view class="order_list flex_r flex_ac flex_jb" v-if="Data.is_sell != 1 && prom_type != 1">
  75. <view class="flex_r flex_ac">
  76. <view class="list_name">运费</view>
  77. <view class="list_con p_color">({{ freight }}元/每套)</view>
  78. </view>
  79. <view class="list_con">¥{{ $h.Mul(freight, Data.num) }}</view>
  80. </view>
  81. <view
  82. class="order_list flex_r flex_ac flex_jb"
  83. v-if="Data.type == 2 || Data.type == 5"
  84. >
  85. <view class="flex_r flex_ac">
  86. <view class="list_name">茶宝</view>
  87. <view class="list_con p_color">(可用{{ userinfo.cha_bao }})</view>
  88. </view>
  89. <view class="list_con" v-if="Data.type != 5"
  90. >{{ goodsInfo.treasure_price * Data.num }} 茶宝</view
  91. >
  92. <view class="list_con" v-else
  93. >{{ $h.Mul(goodsInfo.cha_bao, Data.num) }} 茶宝</view
  94. >
  95. </view>
  96. <view class="order_list flex_r flex_ac flex_jb" v-if="Data.type == 2">
  97. <view class="flex_r flex_ac">
  98. <view class="list_name">批发券</view>
  99. <view class="list_con p_color">(可用{{ userinfo.integral }})</view>
  100. </view>
  101. <view class="list_con"
  102. >{{ $h.Mul(goodsInfo.trade_num, Data.num) }} 批发券</view
  103. >
  104. </view>
  105. <view class="order_list flex_r flex_ac flex_jb" v-if="Data.type != 5">
  106. <view class="list_name">商品金额</view>
  107. <view class="list_con"
  108. >¥{{
  109. $h.Mul(
  110. Data.type == 2 ? goodsInfo.trade_price : goodsInfo.cost_price,
  111. Data.num
  112. ) || 0
  113. }}</view
  114. >
  115. </view>
  116. <view
  117. class="order_list flex_r flex_ac flex_jb"
  118. v-if="['1','2','3'].includes(Data.type)"
  119. >
  120. <view class="list_name">可用余额</view>
  121. <view class="list_con p_color">¥{{ userinfo.user_money }}</view>
  122. </view>
  123. </view>
  124. <!-- 订单信息-end -->
  125. <!-- 底部操作栏 -->
  126. <view class="bar flex_r flex_ac flex_jb">
  127. <view class="bar_info flex_r flex_ac"
  128. >待支付<text>¥{{ obligation }}</text></view
  129. >
  130. <view class="pay_btn flex_r flex_ac flex_jc" @tap="payment"
  131. >立即支付</view
  132. >
  133. </view>
  134. <!-- 底部操作栏-end -->
  135. <!-- 收货地址弹窗 -->
  136. <userAddress ref="userAddress" @addressConfirm="loadDa" />
  137. </view>
  138. </template>
  139. <script>
  140. let page = 1;
  141. let app = getApp();
  142. var appEv = app.$vm.$options;
  143. import { post } from "@/request/api.js";
  144. import { ToPayOpre } from "@/utils/reqTools.js";
  145. let toPayOpre = new ToPayOpre();
  146. import userAddress from "pages/xghc-addrress/userAddress";
  147. export default {
  148. data() {
  149. return {
  150. Data: {},
  151. goodsInfo: "", // 商品信息
  152. modularName: "", // 商品类型
  153. DefaultAddress: {}, // 用户默认地址
  154. // basicsInfo: "", // 订单信息
  155. freight: 0, //运费
  156. userinfo: {},
  157. obligation: 0, //待支付
  158. prom_type: 0,
  159. };
  160. },
  161. components: {
  162. userAddress,
  163. },
  164. onLoad(e) {
  165. this.Data = e;
  166. this.getuserInfo();
  167. this.loadAddress();
  168. this.loadData(e);
  169. // this.userinfo = uni.getStorageSync("userinfo");
  170. // 1零售 2批发 3精品 4今日值买
  171. this.modularName = this.tidyTpye(e.type);
  172. },
  173. mounted() {
  174. // this.$refs.popup.open('top');
  175. },
  176. methods: {
  177. onprom(va){
  178. this.prom_type = va
  179. this.loadData(this.Data);
  180. },
  181. loadData(da) {
  182. post("goods/goodsDetail", da).then((res) => {
  183. if (res.code === 0) {
  184. this.goodsInfo = res.data.data;
  185. if(this.goodsInfo.shipping_method != 2) this.prom_type = this.goodsInfo.shipping_method
  186. post("goods/freight", { type: da.type, id: da.id }).then((res) => {
  187. if (res.code === 0) this.freight = res.data.freight;
  188. // 计算待支付
  189. let p = this.Data.type == 2 ? this.goodsInfo.trade_price : this.goodsInfo.cost_price; //商品单价
  190. let y = (this.Data.is_sell == 1 || this.prom_type == 1) ? 0 : this.freight; // 运费单价 寄卖、自提 运费为0
  191. let ps = this.$h.Mul(p,this.Data.num); //商品总价
  192. let ys = this.$h.Mul(y,this.Data.num) //运费总价
  193. let a = this.$h.Add(ps, ys); //商品总价加运费
  194. let b = this.$h.Sub(a,this.userinfo.user_money); //待支付金额
  195. let b1 = this.$h.Sub(ps,this.userinfo.user_money); //待支付金额 零售&批发 运费必须现金支付
  196. if (["4", "5", "6"].includes(this.Data.type)) this.obligation = a;
  197. else if (["1", "2"].includes(this.Data.type)) this.obligation = b1 > 0 ? this.$h.Add(b1, ys) : ys;
  198. else this.obligation = b > 0 ? b : 0;
  199. });
  200. }
  201. });
  202. },
  203. // 获取用户地址
  204. loadAddress() {
  205. post("user/addressList").then((res) => {
  206. if (res.code === 0) {
  207. let da = res.data.data;
  208. if(da.length){
  209. for (const i of da) {
  210. if (i.status == 1) {
  211. this.DefaultAddress = i;
  212. break;
  213. } else this.DefaultAddress = da[0];
  214. }
  215. }
  216. console.log('this.DefaultAddress',this.DefaultAddress);
  217. // #ifdef  MP-WEIXIN
  218. // if (!da.length && this.Data.is_sell != 1) this.getwexinAddress();
  219. // #endif
  220. }
  221. });
  222. },
  223. //获取微信的收货地址
  224. getwexinAddress() {
  225. let that = this
  226. uni.chooseAddress({
  227. success(res) {
  228. console.log(res);
  229. if (res.errMsg == "chooseAddress:ok") {
  230. let data = {
  231. province: res.provinceName,
  232. city: res.cityName,
  233. area: res.countyName,
  234. street: res.streetName,
  235. address: res.detailInfo,
  236. mobile: res.telNumber,
  237. name: res.userName,
  238. is_default: 0,
  239. };
  240. post("user/addAddress", data).then((res) => {
  241. if (res.code === 0) {
  242. appEv.errTips(res.msg);
  243. that.loadAddress();
  244. }
  245. });
  246. }
  247. },
  248. });
  249. },
  250. chooseWXaddress(va) {
  251. let a = va != "add" ? this.DefaultAddress.id : "add";
  252. this.$refs.userAddress.open(a);
  253. },
  254. // 支付
  255. payment() {
  256. let type = "H5";
  257. // #ifdef  H5
  258. type = "H5";
  259. // #endif
  260. // #ifdef  APP
  261. type = "app";
  262. // #endif
  263. // #ifdef  MP-WEIXIN
  264. type = "jsapi";
  265. // #endif
  266. // if (!this.DefaultAddress.id) {
  267. // appEv.errTips("请选择地址");
  268. // return;
  269. // }
  270. let that = this
  271. if (that.obligation == 0) {
  272. uni.showModal({
  273. title: "温馨提示",
  274. content: "你将使用余额支付该订单",
  275. showCancel: true,
  276. confirmText: "确认",
  277. confirmColor: "#f02f2f",
  278. success(res) {
  279. if (res.confirm) {
  280. post("goods/submitOrder", {
  281. ...that.Data,
  282. address_id: that.DefaultAddress.id || '',
  283. regional_code: that.DefaultAddress.regional_code || '',
  284. trade_type: type,
  285. prom_type: that.prom_type,
  286. price: that.goodsInfo.cost_price,
  287. }).then((res) => {
  288. if (res.code === 0) {
  289. if (res.data.length !== 0) {
  290. toPayOpre.toPay(res.data, (rea) => {
  291. if (!rea) {
  292. // 支付成功
  293. appEv.errTips("支付成功");
  294. if (that.Data.type == 2 && that.Data.is_sell == 1) {
  295. setTimeout(() => {
  296. that.goto("/pages/account/consignment");
  297. }, 1500);
  298. } else {
  299. setTimeout(() => {
  300. that.goto("/pages/szw-order-list/index");
  301. }, 1500);
  302. }
  303. } else {
  304. // 支付失败
  305. appEv.errTips("支付已取消");
  306. }
  307. });
  308. } else {
  309. appEv.errTips("支付成功");
  310. setTimeout(() => {
  311. if (that.Data.is_sell != 1)
  312. that.goto("/pages/szw-order-list/index");
  313. else that.goto("/pages/account/consignment");
  314. }, 1500);
  315. }
  316. } else {
  317. that.loadData(that.Data);
  318. }
  319. });
  320. }
  321. },
  322. });
  323. } else {
  324. post("goods/submitOrder", {
  325. ...that.Data,
  326. address_id: that.DefaultAddress.id || '',
  327. regional_code: that.DefaultAddress.regional_code || '',
  328. trade_type: type,
  329. prom_type: that.prom_type,
  330. price: that.goodsInfo.cost_price,
  331. }).then((res) => {
  332. if (res.code === 0) {
  333. if (res.data.length !== 0) {
  334. toPayOpre.toPay(res.data, (rea) => {
  335. if (!rea) {
  336. // 支付成功
  337. appEv.errTips("支付成功");
  338. if (that.Data.type == 2 && that.Data.is_sell == 1) {
  339. setTimeout(() => {
  340. that.goto("/pages/account/consignment");
  341. }, 1500);
  342. } else {
  343. setTimeout(() => {
  344. that.goto("/pages/szw-order-list/index");
  345. }, 1500);
  346. }
  347. } else {
  348. // 支付失败
  349. appEv.errTips("支付已取消");
  350. }
  351. });
  352. } else {
  353. appEv.errTips("支付成功");
  354. setTimeout(() => {
  355. if (that.Data.is_sell != 1)
  356. that.goto("/pages/szw-order-list/index");
  357. else that.goto("/pages/account/consignment");
  358. }, 1500);
  359. }
  360. } else {
  361. that.loadData(that.Data);
  362. }
  363. });
  364. }
  365. },
  366. loadDa(da) {
  367. this.DefaultAddress = da;
  368. },
  369. // 获取userinfo
  370. async getuserInfo() {
  371. let res = await post("/user/userinfo")
  372. if (res.code === 0) {
  373. uni.setStorageSync("userinfo", res.data.data);
  374. this.userinfo = res.data.data;
  375. }
  376. },
  377. },
  378. };
  379. </script>
  380. <style lang="scss">
  381. // 页面配置
  382. page {
  383. background: #f5f5f5;
  384. }
  385. .container {
  386. padding: 20rpx;
  387. box-sizing: border-box;
  388. }
  389. // 页面配置-end
  390. // 收货地址
  391. .user_phone {
  392. font-size: 26rpx;
  393. color: #222;
  394. }
  395. .set_text {
  396. font-size: 24rpx;
  397. color: #868686;
  398. }
  399. .set_img {
  400. width: 24rpx;
  401. height: 24rpx;
  402. margin-right: 9rpx;
  403. }
  404. .add_address {
  405. width: 100%;
  406. overflow: hidden;
  407. height: 109rpx;
  408. }
  409. .add_icon {
  410. width: 60rpx;
  411. height: 60rpx;
  412. margin-bottom: 12rpx;
  413. }
  414. .user_name {
  415. font-size: 32rpx;
  416. color: #000;
  417. margin-right: 46rpx;
  418. }
  419. .add_name {
  420. // width: 448rpx;
  421. // overflow: hidden;
  422. font-size: 24rpx;
  423. color: #868686;
  424. }
  425. .add_text {
  426. font-size: 24rpx;
  427. color: #868686;
  428. font-family: "SourceHanSansCN-Normal";
  429. }
  430. .address {
  431. width: 100%;
  432. overflow: hidden;
  433. padding: 28rpx;
  434. box-sizing: border-box;
  435. background: #fff;
  436. border-radius: 12rpx;
  437. }
  438. // 收货地址-end
  439. // 商品信息
  440. .goods:nth-last-child(1) {
  441. margin-bottom: 0;
  442. }
  443. .goods_num {
  444. // text-align: right;
  445. font-size: 26rpx;
  446. color: #989898;
  447. position: absolute;
  448. bottom: 0;
  449. right: 0;
  450. }
  451. .goods_con {
  452. width: calc(100% - 202rpx - 36rpx);
  453. min-height: 187rpx;
  454. position: relative;
  455. // overflow: hidden;
  456. }
  457. .goods {
  458. width: 100%;
  459. overflow: hidden;
  460. margin-bottom: 20rpx;
  461. align-items: initial;
  462. }
  463. .goods_img {
  464. width: 202rpx;
  465. height: 187rpx;
  466. margin-right: 36rpx;
  467. border-radius: 12rpx;
  468. }
  469. .goods_name {
  470. font-size: 34rpx;
  471. color: #1b1b1b;
  472. font-family: "SourceHanSansCN-Bold";
  473. font-weight: bold;
  474. }
  475. .goods_msg {
  476. overflow: hidden;
  477. font-size: 26rpx;
  478. color: #18bb88;
  479. font-family: "SourceHanSansCN-Medium";
  480. font-weight: 500;
  481. }
  482. .info_type {
  483. font-size: 30rpx;
  484. color: #353535;
  485. font-family: "SourceHanSansCN-Bold";
  486. font-weight: bold;
  487. margin-bottom: 43rpx;
  488. }
  489. .goods_info {
  490. width: 100%;
  491. overflow: hidden;
  492. padding: 28rpx;
  493. background: #fff;
  494. border-radius: 12rpx;
  495. box-sizing: border-box;
  496. }
  497. // 商品信息-end
  498. // 订单信息
  499. .list_name {
  500. width: 112rpx;
  501. text-align-last: justify;
  502. font-size: 26rpx;
  503. color: rgba(0, 0, 0, 0.8);
  504. font-family: SourceHanSansCN-Medium;
  505. font-weight: 700;
  506. }
  507. .order_list:nth-last-child(1) {
  508. margin-bottom: 0;
  509. }
  510. .order_list {
  511. width: 100%;
  512. overflow: hidden;
  513. margin-bottom: 30rpx;
  514. }
  515. .list_con {
  516. font-size: 24rpx;
  517. color: #000;
  518. font-family: "SourceHanSansCN-Medium";
  519. font-weight: bold;
  520. line-height: 1;
  521. }
  522. .order {
  523. width: 100%;
  524. overflow: hidden;
  525. padding: 28rpx;
  526. box-sizing: border-box;
  527. background: #fff;
  528. border-radius: 12rpx;
  529. }
  530. .list_name text {
  531. font-size: 26rpx;
  532. color: rgba(0, 0, 0, 0.8);
  533. font-family: "SourceHanSansCN-Medium";
  534. font-weight: bold;
  535. line-height: 1;
  536. }
  537. .p_color {
  538. color: #ff6d44;
  539. }
  540. // 订单信息-end
  541. // 底部操作栏
  542. .bar_info {
  543. font-size: 24rpx;
  544. color: #000;
  545. font-family: "SourceHanSansCN-Medium";
  546. font-weight: bold;
  547. }
  548. .bar_info text {
  549. font-size: 30rpx;
  550. color: #ff6d44;
  551. font-family: "SourceHanSansCN-Medium";
  552. font-weight: bold;
  553. }
  554. .pay_btn {
  555. width: 187rpx;
  556. height: 72rpx;
  557. font-size: 30rpx;
  558. font-family: "SourceHanSansCN-Medium";
  559. font-weight: bold;
  560. background: #2db48a;
  561. border-radius: 36rpx;
  562. color: #fff;
  563. }
  564. .bar {
  565. width: 100%;
  566. overflow: hidden;
  567. position: fixed;
  568. bottom: 0;
  569. left: 0;
  570. background: #fff;
  571. box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.15);
  572. padding: 14rpx 30rpx;
  573. box-sizing: border-box;
  574. }
  575. // 底部操作栏-end
  576. .qtmd{
  577. width: 100%;
  578. padding: 28rpx;
  579. box-sizing: border-box;
  580. background: #fff;
  581. border-radius: 12rpx;
  582. .select_tab{
  583. margin-left: 30rpx;
  584. font-size: 28rpx;
  585. &:first-child{
  586. margin-left: 0;
  587. }
  588. &::before{
  589. content: "";
  590. display: inline-block;
  591. width: 32rpx;
  592. height: 32rpx;
  593. background-image: url("~@/static/img/weixuanzhong_icon.png");
  594. background-size: 100% 100%;
  595. vertical-align: middle;
  596. margin-right: 6rpx;
  597. }
  598. }
  599. .st_active{
  600. &::before{
  601. background-image: url("~@/static/img/xuanzhong_icon.png");
  602. }
  603. }
  604. }
  605. </style>