index.vue 15 KB

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