order.vue 14 KB

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