order.vue 12 KB

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