order.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view">
  6. <view class="list-scroll-view">
  7. <view class="one_1">
  8. <text class="localicon iconfont icon-dingweixiao"></text>
  9. <view class="other" v-if="address._id">
  10. <view class="name">
  11. <text>{{address.name}},</text>{{address.phone}}
  12. </view>
  13. <view class="other_1">
  14. <text>{{address.province}}</text><text>{{address.city}}</text>
  15. <text>{{address.area}}</text><text>{{address.address}}</text>
  16. </view>
  17. </view>
  18. <view class="address" v-else><text>请选择一个收货地址</text></view>
  19. <text @click="toChoose" class="iconfont icon-jiantouyou"></text>
  20. </view>
  21. <view class="one_2">
  22. <view class="list" v-for="(item,index) in orderList" :key="index">
  23. <view class="list_1">
  24. <view class="l">
  25. <text class="iconfont icon-shangdian"></text>
  26. <text>{{item.shop_name}}</text>
  27. </view>
  28. </view>
  29. <view class="list_2" v-for="(tag,index) in item.goods" :key="index">
  30. <view class="l">
  31. <image class="image" :src="tag.file&&tag.file.length>0?tag.file[0].url:''"
  32. mode=""></image>
  33. </view>
  34. <view class="c">
  35. <view class="name">
  36. {{tag.goods_name}}
  37. </view>
  38. <view class="Spec">
  39. 规格:{{tag.goodsSpec_name}}
  40. </view>
  41. </view>
  42. <view class="r">
  43. <view class="price">
  44. ¥{{tag.money}}
  45. </view>
  46. <view class="num">
  47. ×{{tag.num}}
  48. </view>
  49. </view>
  50. </view>
  51. <view class="list_3">
  52. <view class="other">
  53. <view class="other_1">配送方式</view>
  54. <view class="other_2"><text class="iconfont icon-duihao"></text>快递配送</view>
  55. </view>
  56. <view class="other">
  57. <view class="other_1">运费</view>
  58. <view class="other_2" v-if="!item.freight_total==0">¥{{item.freight_total}}
  59. </view>
  60. <view class="other_2" v-else>包邮</view>
  61. </view>
  62. <view class="other">
  63. <view class="other_1">优惠劵</view>
  64. <view class="other_2" @click="toCoupon" v-if="couponList.length">
  65. {{coupon_name||'请选择优惠劵'}}</view>
  66. <view class="other_2" v-else>暂无优惠劵使用</view>
  67. </view>
  68. <view class="other">
  69. <view class="other_1">订单备注</view>
  70. <view class="other_3">
  71. <input type="text" v-model="item.remarks" placeholder="选填,可填写您与卖家达成一致的要求" />
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </scroll-view>
  79. </view>
  80. <view class="two">
  81. <view class="two_1">
  82. <view>实付金额:</view>
  83. <view>¥{{goods_total}}</view>
  84. </view>
  85. <view class="two_2">
  86. <text @click="toSubmit">提交订单</text>
  87. </view>
  88. </view>
  89. </view>
  90. <uni-popup ref="popup" background-color="#fff" type="bottom">
  91. <view class="content" v-if="type=='0'" v-for="(item,index) in addressList" :key="index">
  92. <view class="one">
  93. <view class="one_1">
  94. <view class="name">
  95. <text>{{item.name}},</text>{{item.phone}}
  96. </view>
  97. <view class="address">
  98. <text>{{item.province}}</text><text>{{item.city}}</text>
  99. <text>{{item.area}}</text><text>{{item.address}}</text>
  100. </view>
  101. </view>
  102. <text class="iconfont icon-jiantouyou"></text>
  103. </view>
  104. <view class="two">
  105. <view class="two_1">
  106. <checkbox-group @change="toCheckbox">
  107. <label>
  108. <checkbox :value="item._id" :checked="item.checked" style="transform:scale(0.7)" />选择地址
  109. </label>
  110. </checkbox-group>
  111. </view>
  112. <view class="two_2">
  113. <text class="text" v-if="item.is_default=='1'">默认</text>
  114. <text @click="toDel(item)" class="iconfont icon-del"></text>
  115. </view>
  116. </view>
  117. </view>
  118. <view class="content" v-else>
  119. <discount :couponList="couponList" @toDiscount="toDiscount"></discount>
  120. </view>
  121. </uni-popup>
  122. </mobile-frame>
  123. </template>
  124. <script>
  125. import discount from '@/components/discount/index.vue';
  126. export default {
  127. components: {
  128. discount
  129. },
  130. data() {
  131. return {
  132. user: {},
  133. key: '',
  134. address: {},
  135. orderList: [],
  136. shop: [],
  137. goods_total: 0,
  138. // 金额明细
  139. total_detail: {},
  140. // 收货地址
  141. addressList: [],
  142. // 优惠劵
  143. couponList: [],
  144. coupon: [],
  145. // 优惠劵名称
  146. coupon_name: '',
  147. type: '',
  148. };
  149. },
  150. onLoad: async function(e) {
  151. const that = this;
  152. that.$set(that, `key`, e.key || '');
  153. that.watchLogin()
  154. },
  155. methods: {
  156. // 使用优惠劵
  157. toDiscount(e) {
  158. const that = this;
  159. that.$set(that, 'coupon_name', e.coupon.name)
  160. that.coupon.push(e._id)
  161. that.$refs.popup.close();
  162. },
  163. // 选择收货地址
  164. toChoose() {
  165. const that = this;
  166. if (that.addressList.length > 0) {
  167. that.$set(that, 'type', '0')
  168. that.$refs.popup.open();
  169. } else {
  170. uni.showToast({
  171. title: `暂无收货地址`,
  172. icon: 'none'
  173. })
  174. }
  175. },
  176. // 选择优惠劵
  177. toCoupon() {
  178. const that = this;
  179. that.$set(that, 'type', '1')
  180. that.$set(that, 'coupon', [])
  181. that.$refs.popup.open();
  182. },
  183. // 是否选中
  184. toCheckbox(e) {
  185. const that = this;
  186. var addressList = that.addressList;
  187. var values = e.detail.value;
  188. for (var i = 0, lenI = addressList.length; i < lenI; ++i) {
  189. const item = addressList[i]
  190. if (values.includes(item._id)) {
  191. that.$set(item, 'checked', true)
  192. that.$set(that, `address`, item);
  193. } else {
  194. that.$set(item, 'checked', false)
  195. }
  196. }
  197. that.$refs.popup.close();
  198. },
  199. // 删除收货地址
  200. toDel(e) {
  201. const that = this;
  202. uni.showModal({
  203. title: '提示',
  204. content: '确定删除该地址吗?',
  205. success: async function(res) {
  206. if (res.confirm) {
  207. const arr = await that.$api(`/address/${e._id}`, 'DELETE');
  208. if (arr.errcode == '0') {
  209. uni.showToast({
  210. title: '删除信息成功',
  211. icon: 'none'
  212. })
  213. that.search();
  214. } else {
  215. uni.showToast({
  216. title: arr.errmsg,
  217. icon: 'none'
  218. })
  219. }
  220. }
  221. }
  222. });
  223. },
  224. // 提交订单
  225. async toSubmit() {
  226. const that = this;
  227. if (that.address) {
  228. let data = {
  229. address: that.address,
  230. goods: that.orderList,
  231. total_detail: that.total_detail,
  232. coupon: that.coupon
  233. }
  234. const arr = await that.$api(`/order`, 'POST', data)
  235. console.log(arr)
  236. if (arr.errcode == '0') {
  237. uni.getStorage({
  238. key: 'system',
  239. success: async function(res) {
  240. // 微信小程序支付
  241. if (res.data.uniPlatform == "mp-weixin") {
  242. const res = await that.$api('/pay/toPayOrder', 'POST', {
  243. order_id: arr.data,
  244. type: '0'
  245. })
  246. uni.requestPayment({
  247. "provider": "wxpay",
  248. ...res.data,
  249. success(res) {
  250. uni.reLaunch({
  251. url: `/pagesMy/order/index?status=${'1'}`
  252. })
  253. },
  254. fail(e) {
  255. console.log('in fail');
  256. console.log(e)
  257. }
  258. })
  259. } else if (res.data.uniPlatform == "app") {
  260. // app支付
  261. uni.requestPayment({
  262. provider: 'alipay',
  263. orderInfo: 'orderInfo', //微信、支付宝订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
  264. success: function(res) {
  265. console.log('success:' + JSON.stringify(res));
  266. },
  267. fail: function(err) {
  268. console.log('fail:' + JSON.stringify(err));
  269. }
  270. });
  271. } else {
  272. uni.showToast({
  273. title: `平台不支持支付`,
  274. icon: 'none'
  275. })
  276. }
  277. },
  278. fail: function(err) {}
  279. })
  280. } else {
  281. uni.showToast({
  282. title: arr.data.msg,
  283. icon: 'none'
  284. })
  285. }
  286. } else {
  287. uni.showToast({
  288. title: `没有收货地址`,
  289. icon: 'none'
  290. })
  291. }
  292. },
  293. // 监听用户是否登录
  294. watchLogin() {
  295. const that = this;
  296. uni.getStorage({
  297. key: 'token',
  298. success: function(res) {
  299. let user = that.$jwt(res.data);
  300. that.$set(that, `user`, user);
  301. that.search()
  302. },
  303. fail: function(err) {
  304. uni.reLaunch({
  305. url: `/pages/login/index`
  306. })
  307. }
  308. })
  309. },
  310. // 查询列表
  311. async search() {
  312. const that = this;
  313. let user = that.user;
  314. const res = await that.$api(`/address`, 'GET', {
  315. customer: user._id
  316. })
  317. if (res.errcode == '0') {
  318. that.$set(that, `addressList`, res.data);
  319. }
  320. const arr = await that.$api(`/order/toMakeOrder`, 'POST', {
  321. key: that.key
  322. })
  323. if (arr.errcode == '0') {
  324. that.$set(that, `address`, arr.data.address);
  325. that.$set(that, `orderList`, arr.data.goodsData);
  326. that.$set(that, `total_detail`, arr.data.orderTotal);
  327. var total = arr.data.orderTotal.freight_total + arr.data.orderTotal.goods_total
  328. that.$set(that, `goods_total`, total);
  329. that.$set(that, `couponList`, arr.data.couponList);
  330. }
  331. },
  332. }
  333. }
  334. </script>
  335. <style lang="scss">
  336. .main {
  337. display: flex;
  338. flex-direction: column;
  339. width: 100vw;
  340. height: 100vh;
  341. .one {
  342. position: relative;
  343. flex-grow: 1;
  344. background-color: var(--f1Color);
  345. .one_1 {
  346. display: flex;
  347. justify-content: space-between;
  348. align-items: center;
  349. width: 100vw;
  350. padding: 2vw;
  351. border-bottom: 1vw dashed var(--fcColor);
  352. .address {
  353. flex-grow: 1;
  354. margin: 0 0 0 2vw;
  355. font-size: var(--font14Size);
  356. color: var(--f85Color);
  357. }
  358. .iconfont {
  359. font-size: var(--font20Szie);
  360. }
  361. .other {
  362. width: 82vw;
  363. padding: 0 2vw;
  364. .name {
  365. font-size: var(--font16Size);
  366. }
  367. .other_1 {
  368. font-size: var(--font14Size);
  369. color: var(--f85Color);
  370. text {
  371. margin: 0 1vw 0 0;
  372. }
  373. }
  374. }
  375. }
  376. .one_2 {
  377. margin: 2vw 0 0 0;
  378. .list {
  379. width: 100vw;
  380. margin: 2vw 0;
  381. .list_1 {
  382. padding: 2vw;
  383. background-color: var(--mainColor);
  384. border-bottom: 0.1vw solid var(--fcColor);
  385. text {
  386. padding: 0 0 0 1vw;
  387. }
  388. }
  389. .list_2 {
  390. padding: 2vw;
  391. display: flex;
  392. background-color: var(--mainColor);
  393. .l {
  394. width: 20vw;
  395. .image {
  396. width: 100%;
  397. height: 20vw;
  398. border-radius: 5px;
  399. }
  400. }
  401. .c {
  402. width: 60vw;
  403. padding: 0 2vw;
  404. .Spec {
  405. font-size: var(--font12Size);
  406. color: var(--f85Color);
  407. }
  408. }
  409. .r {
  410. width: 15vw;
  411. text-align: right;
  412. }
  413. }
  414. .list_3 {
  415. width: 96vw;
  416. padding: 2vw;
  417. background-color: var(--mainColor);
  418. .other {
  419. display: flex;
  420. justify-content: space-between;
  421. border-bottom: 0.1vw solid var(--fcColor);
  422. margin: 0 0 2vw 0;
  423. padding: 2vw 0;
  424. .other_1 {
  425. font-size: var(--font16Size);
  426. color: var(--f85Color);
  427. }
  428. .other_3 {
  429. flex-grow: 1;
  430. margin: 0 0 0 2vw;
  431. font-size: var(--font12Size);
  432. }
  433. text {
  434. padding: 0 1vw 0 0;
  435. font-size: var(--font20Szie);
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. .two {
  443. display: flex;
  444. justify-content: space-between;
  445. border-top: 0.1vw solid var(--fcColor);
  446. .two_1 {
  447. display: flex;
  448. align-items: center;
  449. padding: 0 2vw;
  450. font-size: var(--font16Size);
  451. view:last-child {
  452. margin: 0 0 0 2vw;
  453. color: var(--ff0Color);
  454. font-weight: bold;
  455. }
  456. }
  457. .two_2 {
  458. padding: 3vw 4vw;
  459. color: var(--mainColor);
  460. font-size: var(--font16Size);
  461. background-color: var(--ff0Color);
  462. }
  463. }
  464. }
  465. .scroll-view {
  466. position: absolute;
  467. top: 0;
  468. left: 0;
  469. right: 0;
  470. bottom: 0;
  471. .list-scroll-view {
  472. display: flex;
  473. flex-direction: row;
  474. flex-wrap: wrap;
  475. }
  476. }
  477. .content {
  478. display: flex;
  479. flex-direction: column;
  480. max-height: 100vw;
  481. min-height: 100vw;
  482. background-color: var(--f5Color);
  483. .one {
  484. display: flex;
  485. justify-content: space-between;
  486. margin: 2vw 0 0 0;
  487. padding: 2vw;
  488. background-color: var(--mainColor);
  489. .name {
  490. font-size: var(--font16Size);
  491. }
  492. .address {
  493. font-size: var(--font14Size);
  494. }
  495. .iconfont {
  496. line-height: 15vw;
  497. font-size: var(--font20Szie);
  498. }
  499. }
  500. .two {
  501. display: flex;
  502. justify-content: space-between;
  503. border-top: 0.1vw solid var(--fcColor);
  504. padding: 2vw;
  505. background-color: var(--mainColor);
  506. font-size: var(--font14Size);
  507. .text {
  508. margin: 0 2vw 0 0;
  509. border: 0.1vw solid var(--fFB1Color);
  510. padding: 1vw;
  511. font-size: var(--font12Size);
  512. border-radius: 2vw;
  513. color: var(--fFB1Color);
  514. }
  515. }
  516. }
  517. </style>