order.vue 13 KB

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