order.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. coupon_name: '',
  146. type: '',
  147. };
  148. },
  149. onLoad: async function(e) {
  150. const that = this;
  151. that.$set(that, `key`, e.key || '');
  152. that.watchLogin()
  153. },
  154. methods: {
  155. // 使用优惠劵
  156. toDiscount(e) {
  157. const that = this;
  158. that.$set(that, 'coupon_name', e.coupon.name)
  159. that.coupon.push(e._id)
  160. that.$refs.popup.close();
  161. },
  162. // 选择收货地址
  163. toChoose() {
  164. const that = this;
  165. if (that.addressList.length > 0) {
  166. that.$set(that, 'type', '0')
  167. that.$refs.popup.open();
  168. } else {
  169. uni.showToast({
  170. title: `暂无收货地址`,
  171. icon: 'none'
  172. })
  173. }
  174. },
  175. // 选择优惠劵
  176. toCoupon() {
  177. const that = this;
  178. that.$set(that, 'type', '1')
  179. that.$set(that, 'coupon', [])
  180. that.$refs.popup.open();
  181. },
  182. // 是否选中
  183. toCheckbox(e) {
  184. const that = this;
  185. var addressList = that.addressList;
  186. var values = e.detail.value;
  187. for (var i = 0, lenI = addressList.length; i < lenI; ++i) {
  188. const item = addressList[i]
  189. if (values.includes(item._id)) {
  190. that.$set(item, 'checked', true)
  191. that.$set(that, `address`, item);
  192. } else {
  193. that.$set(item, 'checked', false)
  194. }
  195. }
  196. that.$refs.popup.close();
  197. },
  198. // 删除收货地址
  199. toDel(e) {
  200. const that = this;
  201. uni.showModal({
  202. title: '提示',
  203. content: '确定删除该地址吗?',
  204. success: async function(res) {
  205. if (res.confirm) {
  206. const arr = await that.$api(`/address/${e._id}`, 'DELETE');
  207. if (arr.errcode == '0') {
  208. uni.showToast({
  209. title: '删除信息成功',
  210. icon: 'none'
  211. })
  212. that.search();
  213. } else {
  214. uni.showToast({
  215. title: arr.errmsg,
  216. icon: 'none'
  217. })
  218. }
  219. }
  220. }
  221. });
  222. },
  223. // 提交订单
  224. async toSubmit() {
  225. const that = this;
  226. if (that.address) {
  227. let data = {
  228. address: that.address,
  229. goods: that.orderList,
  230. total_detail: that.total_detail,
  231. coupon: that.coupon
  232. }
  233. const arr = await that.$api(`/order`, 'POST', data)
  234. console.log(arr)
  235. if (arr.errcode == '0') {
  236. uni.getStorage({
  237. key: 'system',
  238. success: async function(res) {
  239. // 微信小程序支付
  240. if (res.data.uniPlatform == "mp-weixin") {
  241. const res = await that.$api('/pay/toPayOrder', 'POST', {
  242. order_id: arr.data,
  243. type: '0'
  244. })
  245. uni.requestPayment({
  246. "provider": "wxpay",
  247. ...res.data,
  248. success(res) {
  249. uni.reLaunch({
  250. url: `/pagesMy/order/index?status=${'1'}`
  251. })
  252. },
  253. fail(e) {
  254. console.log('in fail');
  255. console.log(e)
  256. }
  257. })
  258. } else if (res.data.uniPlatform == "app") {
  259. // app支付
  260. uni.requestPayment({
  261. provider: 'alipay',
  262. orderInfo: 'orderInfo', //微信、支付宝订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
  263. success: function(res) {
  264. console.log('success:' + JSON.stringify(res));
  265. },
  266. fail: function(err) {
  267. console.log('fail:' + JSON.stringify(err));
  268. }
  269. });
  270. } else {
  271. uni.showToast({
  272. title: `平台不支持支付`,
  273. icon: 'none'
  274. })
  275. }
  276. },
  277. fail: function(err) {}
  278. })
  279. } else {
  280. uni.showToast({
  281. title: arr.data.msg,
  282. icon: 'none'
  283. })
  284. }
  285. } else {
  286. uni.showToast({
  287. title: `没有收货地址`,
  288. icon: 'none'
  289. })
  290. }
  291. },
  292. // 监听用户是否登录
  293. watchLogin() {
  294. const that = this;
  295. uni.getStorage({
  296. key: 'token',
  297. success: function(res) {
  298. let user = that.$jwt(res.data);
  299. that.$set(that, `user`, user);
  300. that.search()
  301. },
  302. fail: function(err) {
  303. uni.reLaunch({
  304. url: `/pages/login/index`
  305. })
  306. }
  307. })
  308. },
  309. // 查询列表
  310. async search() {
  311. const that = this;
  312. let user = that.user;
  313. const res = await that.$api(`/address`, 'GET', {
  314. customer: user._id
  315. })
  316. if (res.errcode == '0') {
  317. that.$set(that, `addressList`, res.data);
  318. }
  319. const arr = await that.$api(`/order/toMakeOrder`, 'POST', {
  320. key: that.key
  321. })
  322. if (arr.errcode == '0') {
  323. that.$set(that, `address`, arr.data.address);
  324. that.$set(that, `orderList`, arr.data.goodsData);
  325. that.$set(that, `total_detail`, arr.data.orderTotal);
  326. var total = arr.data.orderTotal.freight_total + arr.data.orderTotal.goods_total
  327. that.$set(that, `goods_total`, total);
  328. that.$set(that, `couponList`, arr.data.couponList);
  329. }
  330. },
  331. }
  332. }
  333. </script>
  334. <style lang="scss">
  335. .main {
  336. display: flex;
  337. flex-direction: column;
  338. width: 100vw;
  339. height: 100vh;
  340. .one {
  341. position: relative;
  342. flex-grow: 1;
  343. background-color: var(--f1Color);
  344. .one_1 {
  345. display: flex;
  346. justify-content: space-between;
  347. align-items: center;
  348. width: 100vw;
  349. padding: 2vw;
  350. border-bottom: 1vw dashed var(--fcColor);
  351. .address {
  352. flex-grow: 1;
  353. margin: 0 0 0 2vw;
  354. font-size: var(--font14Size);
  355. color: var(--f85Color);
  356. }
  357. .iconfont {
  358. font-size: var(--font20Szie);
  359. }
  360. .other {
  361. width: 82vw;
  362. padding: 0 2vw;
  363. .name {
  364. font-size: var(--font16Size);
  365. }
  366. .other_1 {
  367. font-size: var(--font14Size);
  368. color: var(--f85Color);
  369. text {
  370. margin: 0 1vw 0 0;
  371. }
  372. }
  373. }
  374. }
  375. .one_2 {
  376. margin: 2vw 0 0 0;
  377. .list {
  378. width: 100vw;
  379. margin: 2vw 0;
  380. .list_1 {
  381. padding: 2vw;
  382. background-color: var(--mainColor);
  383. border-bottom: 0.1vw solid var(--fcColor);
  384. text {
  385. padding: 0 0 0 1vw;
  386. }
  387. }
  388. .list_2 {
  389. padding: 2vw;
  390. display: flex;
  391. background-color: var(--mainColor);
  392. .l {
  393. width: 20vw;
  394. .image {
  395. width: 100%;
  396. height: 20vw;
  397. border-radius: 5px;
  398. }
  399. }
  400. .c {
  401. width: 60vw;
  402. padding: 0 2vw;
  403. .Spec {
  404. font-size: var(--font12Size);
  405. color: var(--f85Color);
  406. }
  407. }
  408. .r {
  409. width: 15vw;
  410. text-align: right;
  411. }
  412. }
  413. .list_3 {
  414. width: 96vw;
  415. padding: 2vw;
  416. background-color: var(--mainColor);
  417. .other {
  418. display: flex;
  419. justify-content: space-between;
  420. border-bottom: 0.1vw solid var(--fcColor);
  421. margin: 0 0 2vw 0;
  422. padding: 2vw 0;
  423. .other_1 {
  424. font-size: var(--font16Size);
  425. color: var(--f85Color);
  426. }
  427. .other_3 {
  428. flex-grow: 1;
  429. margin: 0 0 0 2vw;
  430. font-size: var(--font12Size);
  431. }
  432. text {
  433. padding: 0 1vw 0 0;
  434. font-size: var(--font20Szie);
  435. }
  436. }
  437. }
  438. }
  439. }
  440. }
  441. .two {
  442. display: flex;
  443. justify-content: space-between;
  444. border-top: 0.1vw solid var(--fcColor);
  445. .two_1 {
  446. display: flex;
  447. align-items: center;
  448. padding: 0 2vw;
  449. font-size: var(--font16Size);
  450. view:last-child {
  451. margin: 0 0 0 2vw;
  452. color: var(--ff0Color);
  453. font-weight: bold;
  454. }
  455. }
  456. .two_2 {
  457. padding: 3vw 4vw;
  458. color: var(--mainColor);
  459. font-size: var(--font16Size);
  460. background-color: var(--ff0Color);
  461. }
  462. }
  463. }
  464. .scroll-view {
  465. position: absolute;
  466. top: 0;
  467. left: 0;
  468. right: 0;
  469. bottom: 0;
  470. .list-scroll-view {
  471. display: flex;
  472. flex-direction: row;
  473. flex-wrap: wrap;
  474. }
  475. }
  476. .content {
  477. display: flex;
  478. flex-direction: column;
  479. max-height: 100vw;
  480. min-height: 100vw;
  481. background-color: var(--f5Color);
  482. .one {
  483. display: flex;
  484. justify-content: space-between;
  485. margin: 2vw 0 0 0;
  486. padding: 2vw;
  487. background-color: var(--mainColor);
  488. .name {
  489. font-size: var(--font16Size);
  490. }
  491. .address {
  492. font-size: var(--font14Size);
  493. }
  494. .iconfont {
  495. line-height: 15vw;
  496. font-size: var(--font20Szie);
  497. }
  498. }
  499. .two {
  500. display: flex;
  501. justify-content: space-between;
  502. border-top: 0.1vw solid var(--fcColor);
  503. padding: 2vw;
  504. background-color: var(--mainColor);
  505. font-size: var(--font14Size);
  506. .text {
  507. margin: 0 2vw 0 0;
  508. border: 0.1vw solid var(--fFB1Color);
  509. padding: 1vw;
  510. font-size: var(--font12Size);
  511. border-radius: 2vw;
  512. color: var(--fFB1Color);
  513. }
  514. }
  515. }
  516. </style>