order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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') {
  157. that.$set(that, `addressList`, res.data.reverse());
  158. }
  159. const arr = await that.$api(`/groupOrder/toOrderPage`, 'POST', {
  160. key: that.key
  161. }, 'group')
  162. if (arr.errcode == '0') {
  163. // 地址
  164. that.$set(that, `address`, arr.data.address);
  165. // 订单
  166. that.$set(that, `info`, arr.data);
  167. // 总价
  168. that.$set(that, `total_detail`, arr.data.total_detail);
  169. that.computedTotal();
  170. }
  171. },
  172. // 选择收货地址
  173. toChoose() {
  174. const that = this;
  175. if (that.address?._id) {
  176. uni.navigateTo({
  177. url: `/pagesMy/address/index?type=${"shopping"}&id=${that.address._id}`
  178. })
  179. } else {
  180. uni.navigateTo({
  181. url: `/pagesMy/address/index?type=${"shopping"}`
  182. })
  183. }
  184. },
  185. // 提交订单
  186. async toSubmit() {
  187. const that = this;
  188. let system = that.system;
  189. if (that.address) {
  190. let obj = {
  191. address: that.address,
  192. shop: that.info.shop._id,
  193. goods: that.info.goods._id,
  194. goodsSpec: that.info.goodsSpec._id,
  195. num: that.info.num,
  196. group: that.info.group,
  197. remarks: that.remarks
  198. }
  199. // 创建订单
  200. let p1 = await that.$api(`/groupOrder`, 'POST', obj, 'group');
  201. if (p1.errcode == '0') {
  202. if (system.uniPlatform == "mp-weixin") {
  203. // 微信支付
  204. uni.showLoading({
  205. title: '加载中'
  206. })
  207. // 支付信息
  208. let p2 = await that.$api('/orderDeal/pay', 'POST', {
  209. order_id: p1.data,
  210. }, 'group')
  211. if (p2.errcode == '0' && p2.data.paySign) {
  212. uni.requestPayment({
  213. "provider": "wxpay",
  214. ...p2.data,
  215. success: async function(res) {
  216. console.log(res);
  217. uni.reLaunch({
  218. url: `/pagesMy/dough/index`
  219. })
  220. },
  221. fail: function(err) {
  222. console.log(err);
  223. uni.showToast({
  224. title: `支付失败`,
  225. icon: 'none'
  226. })
  227. uni.hideLoading();
  228. uni.reLaunch({
  229. url: `/pagesMy/dough/index`
  230. })
  231. }
  232. })
  233. } else {
  234. uni.showToast({
  235. title: p2.errmsg,
  236. icon: 'none'
  237. })
  238. }
  239. } else if (system.uniPlatform == "app") {
  240. uni.requestPayment({
  241. provider: 'alipay',
  242. orderInfo: 'orderInfo',
  243. success: function(res) {
  244. console.log('success:' + JSON.stringify(res));
  245. },
  246. fail: function(err) {
  247. console.log('fail:' + JSON.stringify(err));
  248. }
  249. });
  250. } else {
  251. uni.showToast({
  252. title: `平台不支持支付`,
  253. icon: 'none'
  254. })
  255. }
  256. } else {
  257. uni.showToast({
  258. title: p1.errmsg,
  259. icon: 'none'
  260. })
  261. }
  262. } else {
  263. uni.showToast({
  264. title: `没有收货地址`,
  265. icon: 'none'
  266. })
  267. }
  268. },
  269. // 计算优惠券
  270. async computedTotal() {
  271. const total_detail = this.total_detail;
  272. let total = 0;
  273. for (let val of total_detail) total = this.$plus(total, val.money)
  274. if (total >= 0) {
  275. this.$set(this, `goods_total`, total);
  276. } else {
  277. uni.showToast({
  278. title: `实付金额不能为负数 不能使用该优惠劵`,
  279. icon: 'none'
  280. })
  281. }
  282. }
  283. }
  284. }
  285. </script>
  286. <style lang="scss">
  287. .main {
  288. display: flex;
  289. flex-direction: column;
  290. width: 100vw;
  291. height: 100vh;
  292. .one {
  293. position: relative;
  294. flex-grow: 1;
  295. background-color: var(--f1Color);
  296. .one_1 {
  297. display: flex;
  298. justify-content: space-between;
  299. align-items: center;
  300. width: 100vw;
  301. padding: 2vw;
  302. border-bottom: 1vw dashed var(--fcColor);
  303. .address {
  304. flex-grow: 1;
  305. margin: 0 0 0 2vw;
  306. font-size: var(--font14Size);
  307. color: var(--f85Color);
  308. }
  309. .iconfont {
  310. font-size: var(--font20Szie);
  311. }
  312. .other {
  313. width: 82vw;
  314. padding: 0 2vw;
  315. .name {
  316. font-size: var(--font16Size);
  317. }
  318. .other_1 {
  319. font-size: var(--font14Size);
  320. color: var(--f85Color);
  321. text {
  322. margin: 0 1vw 0 0;
  323. }
  324. }
  325. }
  326. }
  327. .one_2 {
  328. .list {
  329. width: 100vw;
  330. margin: 2vw 0;
  331. .list_1 {
  332. padding: 2vw;
  333. background-color: var(--mainColor);
  334. border-bottom: 0.1vw solid var(--fcColor);
  335. text {
  336. padding: 0 0 0 1vw;
  337. }
  338. }
  339. .list_2 {
  340. padding: 2vw;
  341. background-color: var(--mainColor);
  342. .list_2_1 {
  343. display: flex;
  344. .l {
  345. width: 20vw;
  346. .image {
  347. width: 100%;
  348. height: 20vw;
  349. border-radius: 5px;
  350. }
  351. }
  352. .c {
  353. width: 60vw;
  354. padding: 0 2vw;
  355. .Spec {
  356. font-size: var(--font12Size);
  357. color: var(--f85Color);
  358. }
  359. }
  360. .r {
  361. width: 15vw;
  362. text-align: right;
  363. }
  364. }
  365. .list_2_2 {
  366. padding: 0 1vw 1vw 0;
  367. font-size: var(--font14Size);
  368. }
  369. .list_2_3 {
  370. display: flex;
  371. justify-content: space-between;
  372. border: 1px solid var(--fcColor);
  373. border-radius: 5px;
  374. margin: 0 0 1vw 0;
  375. padding: 1vw;
  376. .left {
  377. .name {
  378. font-size: 14px;
  379. }
  380. .Spec {
  381. font-size: var(--font12Size);
  382. color: var(--f85Color);
  383. }
  384. }
  385. }
  386. }
  387. .list_3 {
  388. width: 96vw;
  389. padding: 2vw;
  390. background-color: var(--mainColor);
  391. .other {
  392. display: flex;
  393. justify-content: space-between;
  394. border-bottom: 0.1vw solid var(--fcColor);
  395. margin: 0 0 2vw 0;
  396. padding: 2vw 0;
  397. .other_1 {
  398. font-size: var(--font16Size);
  399. color: var(--f85Color);
  400. }
  401. .other_3 {
  402. flex-grow: 1;
  403. margin: 0 0 0 2vw;
  404. font-size: var(--font12Size);
  405. }
  406. text {
  407. padding: 0 1vw 0 0;
  408. font-size: var(--font20Szie);
  409. }
  410. }
  411. }
  412. }
  413. .other {
  414. display: flex;
  415. justify-content: space-between;
  416. background-color: var(--mainColor);
  417. border-bottom: 0.1vw solid var(--fcColor);
  418. width: 96vw;
  419. padding: 2vw;
  420. .other_1 {
  421. font-size: var(--font16Size);
  422. color: var(--f85Color);
  423. }
  424. .other_3 {
  425. flex-grow: 1;
  426. margin: 0 0 0 2vw;
  427. font-size: var(--font12Size);
  428. }
  429. .other_4 {
  430. color: var(--fFB1Color);
  431. }
  432. text {
  433. padding: 0 1vw 0 0;
  434. font-size: var(--font20Szie);
  435. }
  436. }
  437. }
  438. }
  439. .two {
  440. display: flex;
  441. justify-content: space-between;
  442. border-top: 0.1vw solid var(--fcColor);
  443. .two_1 {
  444. display: flex;
  445. align-items: center;
  446. padding: 0 2vw;
  447. font-size: var(--font16Size);
  448. view:last-child {
  449. margin: 0 0 0 2vw;
  450. color: var(--ff0Color);
  451. font-weight: bold;
  452. }
  453. }
  454. .two_2 {
  455. padding: 3vw 4vw;
  456. color: var(--mainColor);
  457. font-size: var(--font16Size);
  458. background-color: var(--ff0Color);
  459. }
  460. }
  461. }
  462. .scroll-view {
  463. position: absolute;
  464. top: 0;
  465. left: 0;
  466. right: 0;
  467. bottom: 0;
  468. .list-scroll-view {
  469. display: flex;
  470. flex-direction: row;
  471. flex-wrap: wrap;
  472. }
  473. }
  474. .popup {
  475. display: flex;
  476. flex-direction: column;
  477. height: 100vw;
  478. overflow-x: hidden;
  479. background-color: var(--f5Color);
  480. padding: 2vw;
  481. .list {
  482. .one {
  483. display: flex;
  484. justify-content: space-between;
  485. margin: 2vw 0 0 0;
  486. padding: 2vw;
  487. background-color: var(--mainColor);
  488. .name {
  489. font-size: var(--font16Size);
  490. }
  491. .address {
  492. font-size: var(--font14Size);
  493. }
  494. .iconfont {
  495. line-height: 15vw;
  496. font-size: var(--font20Szie);
  497. }
  498. }
  499. .two {
  500. display: flex;
  501. justify-content: space-between;
  502. border-top: 0.1vw solid var(--fcColor);
  503. padding: 2vw;
  504. background-color: var(--mainColor);
  505. font-size: var(--font14Size);
  506. .text {
  507. margin: 0 2vw 0 0;
  508. border: 0.1vw solid var(--fFB1Color);
  509. padding: 1vw;
  510. font-size: var(--font12Size);
  511. border-radius: 2vw;
  512. color: var(--fFB1Color);
  513. }
  514. }
  515. }
  516. }
  517. </style>