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. if (arr.errcode == '0') {
  240. uni.getStorage({
  241. key: 'system',
  242. success: async function(res) {
  243. // 微信小程序支付
  244. if (res.data.uniPlatform == "mp-weixin") {
  245. const res = await that.$api('/pay/toPayOrder', 'POST', {
  246. order_id: arr.data,
  247. type: '0'
  248. })
  249. uni.requestPayment({
  250. "provider": "wxpay",
  251. ...res.data,
  252. success(res) {
  253. uni.reLaunch({
  254. url: `/pagesMy/order/index?status=${'1'}`
  255. })
  256. },
  257. fail(e) {
  258. console.log('in fail');
  259. console.log(e)
  260. }
  261. })
  262. } else if (res.data.uniPlatform == "app") {
  263. // app支付
  264. uni.requestPayment({
  265. provider: 'alipay',
  266. orderInfo: 'orderInfo', //微信、支付宝订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
  267. success: function(res) {
  268. console.log('success:' + JSON.stringify(res));
  269. },
  270. fail: function(err) {
  271. console.log('fail:' + JSON.stringify(err));
  272. }
  273. });
  274. } else {
  275. uni.showToast({
  276. title: `平台不支持支付`,
  277. icon: 'none'
  278. })
  279. }
  280. },
  281. fail: function(err) {}
  282. })
  283. } else {
  284. uni.showToast({
  285. title: arr.data.msg,
  286. icon: 'none'
  287. })
  288. }
  289. } else {
  290. uni.showToast({
  291. title: `没有收货地址`,
  292. icon: 'none'
  293. })
  294. }
  295. },
  296. // 监听用户是否登录
  297. watchLogin() {
  298. const that = this;
  299. uni.getStorage({
  300. key: 'token',
  301. success: function(res) {
  302. let user = that.$jwt(res.data);
  303. that.$set(that, `user`, user);
  304. that.search()
  305. },
  306. fail: function(err) {
  307. uni.reLaunch({
  308. url: `/pages/login/index`
  309. })
  310. }
  311. })
  312. },
  313. // 查询列表
  314. async search() {
  315. const that = this;
  316. let user = that.user;
  317. const res = await that.$api(`/address`, 'GET', {
  318. customer: user._id
  319. })
  320. if (res.errcode == '0') {
  321. that.$set(that, `addressList`, res.data);
  322. }
  323. const arr = await that.$api(`/order/toMakeOrder`, 'POST', {
  324. key: that.key
  325. })
  326. if (arr.errcode == '0') {
  327. that.$set(that, `address`, arr.data.address);
  328. that.$set(that, `orderList`, arr.data.goodsData);
  329. that.$set(that, `total_detail`, arr.data.orderTotal);
  330. var total = arr.data.orderTotal.freight_total + arr.data.orderTotal.goods_total
  331. that.$set(that, `goods_total`, total);
  332. that.$set(that, `couponList`, arr.data.couponList);
  333. }
  334. },
  335. }
  336. }
  337. </script>
  338. <style lang="scss">
  339. .main {
  340. display: flex;
  341. flex-direction: column;
  342. width: 100vw;
  343. height: 100vh;
  344. .one {
  345. position: relative;
  346. flex-grow: 1;
  347. background-color: var(--f1Color);
  348. .one_1 {
  349. display: flex;
  350. justify-content: space-between;
  351. align-items: center;
  352. width: 100vw;
  353. padding: 2vw;
  354. border-bottom: 1vw dashed var(--fcColor);
  355. .address {
  356. flex-grow: 1;
  357. margin: 0 0 0 2vw;
  358. font-size: var(--font14Size);
  359. color: var(--f85Color);
  360. }
  361. .iconfont {
  362. font-size: var(--font20Szie);
  363. }
  364. .other {
  365. width: 82vw;
  366. padding: 0 2vw;
  367. .name {
  368. font-size: var(--font16Size);
  369. }
  370. .other_1 {
  371. font-size: var(--font14Size);
  372. color: var(--f85Color);
  373. text {
  374. margin: 0 1vw 0 0;
  375. }
  376. }
  377. }
  378. }
  379. .one_2 {
  380. margin: 2vw 0 0 0;
  381. .list {
  382. width: 100vw;
  383. margin: 2vw 0;
  384. .list_1 {
  385. padding: 2vw;
  386. background-color: var(--mainColor);
  387. border-bottom: 0.1vw solid var(--fcColor);
  388. text {
  389. padding: 0 0 0 1vw;
  390. }
  391. }
  392. .list_2 {
  393. padding: 2vw;
  394. display: flex;
  395. background-color: var(--mainColor);
  396. .l {
  397. width: 20vw;
  398. .image {
  399. width: 100%;
  400. height: 20vw;
  401. border-radius: 5px;
  402. }
  403. }
  404. .c {
  405. width: 60vw;
  406. padding: 0 2vw;
  407. .Spec {
  408. font-size: var(--font12Size);
  409. color: var(--f85Color);
  410. }
  411. }
  412. .r {
  413. width: 15vw;
  414. text-align: right;
  415. }
  416. }
  417. .list_3 {
  418. width: 96vw;
  419. padding: 2vw;
  420. background-color: var(--mainColor);
  421. .other {
  422. display: flex;
  423. justify-content: space-between;
  424. border-bottom: 0.1vw solid var(--fcColor);
  425. margin: 0 0 2vw 0;
  426. padding: 2vw 0;
  427. .other_1 {
  428. font-size: var(--font16Size);
  429. color: var(--f85Color);
  430. }
  431. .other_3 {
  432. flex-grow: 1;
  433. margin: 0 0 0 2vw;
  434. font-size: var(--font12Size);
  435. }
  436. text {
  437. padding: 0 1vw 0 0;
  438. font-size: var(--font20Szie);
  439. }
  440. }
  441. }
  442. }
  443. }
  444. }
  445. .two {
  446. display: flex;
  447. justify-content: space-between;
  448. border-top: 0.1vw solid var(--fcColor);
  449. .two_1 {
  450. display: flex;
  451. align-items: center;
  452. padding: 0 2vw;
  453. font-size: var(--font16Size);
  454. view:last-child {
  455. margin: 0 0 0 2vw;
  456. color: var(--ff0Color);
  457. font-weight: bold;
  458. }
  459. }
  460. .two_2 {
  461. padding: 3vw 4vw;
  462. color: var(--mainColor);
  463. font-size: var(--font16Size);
  464. background-color: var(--ff0Color);
  465. }
  466. }
  467. }
  468. .scroll-view {
  469. position: absolute;
  470. top: 0;
  471. left: 0;
  472. right: 0;
  473. bottom: 0;
  474. .list-scroll-view {
  475. display: flex;
  476. flex-direction: row;
  477. flex-wrap: wrap;
  478. }
  479. }
  480. .content {
  481. display: flex;
  482. flex-direction: column;
  483. max-height: 100vw;
  484. min-height: 100vw;
  485. overflow-y: auto;
  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>