order.vue 13 KB

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