order.vue 13 KB

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