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