order.vue 12 KB

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