order.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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" @tap="toChoose">
  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 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="list_2_1">
  31. <view class="l">
  32. <image class="image" :src="tag.file&&tag.file.length>0?tag.file[0].url:''"
  33. mode=""></image>
  34. </view>
  35. <view class="c">
  36. <view class="name">
  37. {{tag.goods_name}}
  38. </view>
  39. <view class="Spec">
  40. 规格:{{tag.goodsSpec_name}}
  41. </view>
  42. </view>
  43. <view class="r">
  44. <view class="price">
  45. ¥{{tag.price}}
  46. </view>
  47. <view class="num">
  48. ×{{tag.num}}
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="list_3">
  54. <view class="other">
  55. <view class="other_1">配送方式</view>
  56. <view class="other_2"><text class="iconfont icon-duihao"></text>快递配送</view>
  57. </view>
  58. <view class="other">
  59. <view class="other_1">运费</view>
  60. <view class="other_2" v-if="!item.freight_total==0">¥{{item.freight_total}}
  61. </view>
  62. <view class="other_2" v-else>包邮</view>
  63. </view>
  64. <view class="other">
  65. <view class="other_1">订单备注</view>
  66. <view class="other_3">
  67. <input type="text" v-model="item.remarks" placeholder="选填,可填写您与卖家达成一致的要求" />
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. <view class="other" v-for="(item,index) in total_detail" :key="index">
  73. <view class="other_1">{{item.zh}}</view>
  74. <view class="other_2">¥{{item.money}}</view>
  75. </view>
  76. </view>
  77. </view>
  78. </scroll-view>
  79. </view>
  80. <view class="two">
  81. <view class="two_1">
  82. <view>实付金额:</view>
  83. <view>¥{{goods_total}}</view>
  84. </view>
  85. <view class="two_2">
  86. <text @tap="toSubmit">提交订单</text>
  87. </view>
  88. </view>
  89. </view>
  90. </mobile-frame>
  91. </template>
  92. <script>
  93. export default {
  94. data() {
  95. return {
  96. // 设备平台信息
  97. system: {},
  98. user: {},
  99. key: '',
  100. address: {},
  101. orderList: [],
  102. shop: [],
  103. goods_total: 0,
  104. // 金额明细
  105. total_detail: [],
  106. // 收货地址
  107. addressList: [],
  108. total: 0,
  109. page: 0,
  110. skip: 0,
  111. limit: 10,
  112. };
  113. },
  114. onLoad: function(e) {
  115. const that = this;
  116. uni.$on("id", async (id) => {
  117. let arr = await that.$api(`/address/${id}`, `GET`)
  118. if (arr.errcode == '0') {
  119. that.$set(that, `address`, arr.data)
  120. }
  121. })
  122. that.$set(that, `key`, e.key || '');
  123. that.watchLogin()
  124. },
  125. methods: {
  126. // 监听用户是否登录
  127. watchLogin() {
  128. const that = this;
  129. uni.getStorage({
  130. key: 'token',
  131. success: function(res) {
  132. let user = that.$jwt(res.data);
  133. that.$set(that, `user`, user);
  134. // 设备平台信息
  135. let config = that.$config;
  136. that.$set(that, `system`, config.system);
  137. that.search()
  138. },
  139. fail: function(err) {
  140. uni.navigateTo({
  141. url: `/pages/login/index`
  142. })
  143. }
  144. })
  145. },
  146. // 查询列表
  147. async search() {
  148. const that = this;
  149. let user = that.user;
  150. const res = await that.$api(`/address`, 'GET', {
  151. customer: user._id
  152. })
  153. if (res.errcode == '0') {
  154. that.$set(that, `addressList`, res.data.reverse());
  155. }
  156. const arr = await that.$api(`/order/toMakeOrder`, 'POST', {
  157. key: that.key
  158. })
  159. if (arr.errcode == '0') {
  160. // 地址
  161. that.$set(that, `address`, arr.data.address);
  162. // 订单
  163. that.$set(that, `orderList`, arr.data.goodsData);
  164. // 总价
  165. that.$set(that, `total_detail`, arr.data.orderTotal);
  166. that.computedTotal();
  167. }
  168. },
  169. // 选择收货地址
  170. toChoose() {
  171. const that = this;
  172. if (that.address?._id) {
  173. uni.navigateTo({
  174. url: `/pagesMy/address/index?type=${"shopping"}&id=${that.address._id}`
  175. })
  176. } else {
  177. uni.navigateTo({
  178. url: `/pagesMy/address/index?type=${"shopping"}`
  179. })
  180. }
  181. },
  182. // 提交订单
  183. async toSubmit() {
  184. const that = this;
  185. let system = that.system;
  186. if (that.address) {
  187. let obj = {
  188. address: that.address,
  189. goods: that.orderList,
  190. total_detail: that.total_detail,
  191. coupon: that.coupon,
  192. type: that.type,
  193. inviter: that.inviter,
  194. plus_goods: that.plus_goods
  195. }
  196. if (that.group_id) obj.group = that.group_id;
  197. // 创建订单
  198. let p1 = await that.$api(`/order`, 'POST', obj);
  199. if (p1.errcode == '0') {
  200. if (system.uniPlatform == "mp-weixin") {
  201. // 微信支付
  202. uni.showLoading({
  203. title: '加载中'
  204. })
  205. // 支付信息
  206. let p2 = await that.$api('/pay/toPayOrder', 'POST', {
  207. order_id: p1.data,
  208. type: '0'
  209. })
  210. if (p2.errcode == '0' && p2.data.paySign) {
  211. uni.requestPayment({
  212. "provider": "wxpay",
  213. ...p2.data,
  214. success: async function(res) {
  215. // 获取团信息
  216. let p3 = await that.$api('/group/getGroup', 'GET', {
  217. order_id: p1.data,
  218. })
  219. if (p3.errcode == '0') {
  220. uni.hideLoading();
  221. if (p3.data) {
  222. uni.reLaunch({
  223. url: `/pagesHome/group/share?id=${p3.data}`
  224. })
  225. } else {
  226. uni.reLaunch({
  227. url: `/pagesMy/order/index?status=${'1'}`
  228. })
  229. }
  230. } else {
  231. uni.showToast({
  232. title: p3.errmsg,
  233. icon: 'none'
  234. })
  235. }
  236. },
  237. fail: function(err) {
  238. uni.showToast({
  239. title: `支付失败`,
  240. icon: 'none'
  241. })
  242. uni.hideLoading();
  243. uni.reLaunch({
  244. url: `/pagesMy/order/index?status=${'0'}`
  245. })
  246. }
  247. })
  248. } else {
  249. uni.showToast({
  250. title: p2.errmsg,
  251. icon: 'none'
  252. })
  253. }
  254. } else if (system.uniPlatform == "app") {
  255. uni.requestPayment({
  256. provider: 'alipay',
  257. orderInfo: 'orderInfo',
  258. success: function(res) {
  259. console.log('success:' + JSON.stringify(res));
  260. },
  261. fail: function(err) {
  262. console.log('fail:' + JSON.stringify(err));
  263. }
  264. });
  265. } else {
  266. uni.showToast({
  267. title: `平台不支持支付`,
  268. icon: 'none'
  269. })
  270. }
  271. } else {
  272. uni.showToast({
  273. title: p1.errmsg,
  274. icon: 'none'
  275. })
  276. }
  277. } else {
  278. uni.showToast({
  279. title: `没有收货地址`,
  280. icon: 'none'
  281. })
  282. }
  283. },
  284. // 计算优惠券
  285. async computedTotal() {
  286. const total_detail = this.total_detail;
  287. let total = 0;
  288. for (let val of total_detail) total = this.$plus(total, val.money)
  289. if (total >= 0) {
  290. this.$set(this, `goods_total`, total);
  291. } else {
  292. uni.showToast({
  293. title: `实付金额不能为负数 不能使用该优惠劵`,
  294. icon: 'none'
  295. })
  296. }
  297. }
  298. }
  299. }
  300. </script>
  301. <style lang="scss">
  302. .main {
  303. display: flex;
  304. flex-direction: column;
  305. width: 100vw;
  306. height: 100vh;
  307. .one {
  308. position: relative;
  309. flex-grow: 1;
  310. background-color: var(--f1Color);
  311. .one_1 {
  312. display: flex;
  313. justify-content: space-between;
  314. align-items: center;
  315. width: 100vw;
  316. padding: 2vw;
  317. border-bottom: 1vw dashed var(--fcColor);
  318. .address {
  319. flex-grow: 1;
  320. margin: 0 0 0 2vw;
  321. font-size: var(--font14Size);
  322. color: var(--f85Color);
  323. }
  324. .iconfont {
  325. font-size: var(--font20Szie);
  326. }
  327. .other {
  328. width: 82vw;
  329. padding: 0 2vw;
  330. .name {
  331. font-size: var(--font16Size);
  332. }
  333. .other_1 {
  334. font-size: var(--font14Size);
  335. color: var(--f85Color);
  336. text {
  337. margin: 0 1vw 0 0;
  338. }
  339. }
  340. }
  341. }
  342. .one_2 {
  343. .list {
  344. width: 100vw;
  345. margin: 2vw 0;
  346. .list_1 {
  347. padding: 2vw;
  348. background-color: var(--mainColor);
  349. border-bottom: 0.1vw solid var(--fcColor);
  350. text {
  351. padding: 0 0 0 1vw;
  352. }
  353. }
  354. .list_2 {
  355. padding: 2vw;
  356. background-color: var(--mainColor);
  357. .list_2_1 {
  358. display: flex;
  359. .l {
  360. width: 20vw;
  361. .image {
  362. width: 100%;
  363. height: 20vw;
  364. border-radius: 5px;
  365. }
  366. }
  367. .c {
  368. width: 60vw;
  369. padding: 0 2vw;
  370. .Spec {
  371. font-size: var(--font12Size);
  372. color: var(--f85Color);
  373. }
  374. }
  375. .r {
  376. width: 15vw;
  377. text-align: right;
  378. }
  379. }
  380. .list_2_2 {
  381. padding: 0 1vw 1vw 0;
  382. font-size: var(--font14Size);
  383. }
  384. .list_2_3 {
  385. display: flex;
  386. justify-content: space-between;
  387. border: 1px solid var(--fcColor);
  388. border-radius: 5px;
  389. margin: 0 0 1vw 0;
  390. padding: 1vw;
  391. .left {
  392. .name {
  393. font-size: 14px;
  394. }
  395. .Spec {
  396. font-size: var(--font12Size);
  397. color: var(--f85Color);
  398. }
  399. }
  400. }
  401. }
  402. .list_3 {
  403. width: 96vw;
  404. padding: 2vw;
  405. background-color: var(--mainColor);
  406. .other {
  407. display: flex;
  408. justify-content: space-between;
  409. border-bottom: 0.1vw solid var(--fcColor);
  410. margin: 0 0 2vw 0;
  411. padding: 2vw 0;
  412. .other_1 {
  413. font-size: var(--font16Size);
  414. color: var(--f85Color);
  415. }
  416. .other_3 {
  417. flex-grow: 1;
  418. margin: 0 0 0 2vw;
  419. font-size: var(--font12Size);
  420. }
  421. text {
  422. padding: 0 1vw 0 0;
  423. font-size: var(--font20Szie);
  424. }
  425. }
  426. }
  427. }
  428. .other {
  429. display: flex;
  430. justify-content: space-between;
  431. background-color: var(--mainColor);
  432. border-bottom: 0.1vw solid var(--fcColor);
  433. width: 96vw;
  434. padding: 2vw;
  435. .other_1 {
  436. font-size: var(--font16Size);
  437. color: var(--f85Color);
  438. }
  439. .other_3 {
  440. flex-grow: 1;
  441. margin: 0 0 0 2vw;
  442. font-size: var(--font12Size);
  443. }
  444. .other_4 {
  445. color: var(--fFB1Color);
  446. }
  447. text {
  448. padding: 0 1vw 0 0;
  449. font-size: var(--font20Szie);
  450. }
  451. }
  452. }
  453. }
  454. .two {
  455. display: flex;
  456. justify-content: space-between;
  457. border-top: 0.1vw solid var(--fcColor);
  458. .two_1 {
  459. display: flex;
  460. align-items: center;
  461. padding: 0 2vw;
  462. font-size: var(--font16Size);
  463. view:last-child {
  464. margin: 0 0 0 2vw;
  465. color: var(--ff0Color);
  466. font-weight: bold;
  467. }
  468. }
  469. .two_2 {
  470. padding: 3vw 4vw;
  471. color: var(--mainColor);
  472. font-size: var(--font16Size);
  473. background-color: var(--ff0Color);
  474. }
  475. }
  476. }
  477. .scroll-view {
  478. position: absolute;
  479. top: 0;
  480. left: 0;
  481. right: 0;
  482. bottom: 0;
  483. .list-scroll-view {
  484. display: flex;
  485. flex-direction: row;
  486. flex-wrap: wrap;
  487. }
  488. }
  489. .popup {
  490. display: flex;
  491. flex-direction: column;
  492. height: 100vw;
  493. overflow-x: hidden;
  494. background-color: var(--f5Color);
  495. padding: 2vw;
  496. .list {
  497. .one {
  498. display: flex;
  499. justify-content: space-between;
  500. margin: 2vw 0 0 0;
  501. padding: 2vw;
  502. background-color: var(--mainColor);
  503. .name {
  504. font-size: var(--font16Size);
  505. }
  506. .address {
  507. font-size: var(--font14Size);
  508. }
  509. .iconfont {
  510. line-height: 15vw;
  511. font-size: var(--font20Szie);
  512. }
  513. }
  514. .two {
  515. display: flex;
  516. justify-content: space-between;
  517. border-top: 0.1vw solid var(--fcColor);
  518. padding: 2vw;
  519. background-color: var(--mainColor);
  520. font-size: var(--font14Size);
  521. .text {
  522. margin: 0 2vw 0 0;
  523. border: 0.1vw solid var(--fFB1Color);
  524. padding: 1vw;
  525. font-size: var(--font12Size);
  526. border-radius: 2vw;
  527. color: var(--fFB1Color);
  528. }
  529. }
  530. }
  531. }
  532. </style>