order.vue 13 KB

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