order.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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="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" v-if="type=='0'">
  44. ¥{{tag.price}}
  45. </view>
  46. <view v-else class="price">
  47. ¥{{tag.group_sell_money}}
  48. </view>
  49. <view class="num">
  50. ×{{tag.num}}
  51. </view>
  52. </view>
  53. </view>
  54. <view class="list_3">
  55. <view class="other">
  56. <view class="other_1">配送方式</view>
  57. <view class="other_2"><text class="iconfont icon-duihao"></text>快递配送</view>
  58. </view>
  59. <view class="other">
  60. <view class="other_1">运费</view>
  61. <view class="other_2" v-if="!item.freight_total==0">¥{{item.freight_total}}
  62. </view>
  63. <view class="other_2" v-else>包邮</view>
  64. </view>
  65. <view class="other">
  66. <view class="other_1">订单备注</view>
  67. <view class="other_3">
  68. <input type="text" v-model="item.remarks" placeholder="选填,可填写您与卖家达成一致的要求" />
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. <view class="act" v-if="total>0">
  74. <view class="act_1">
  75. 订单已满<text>{{act.money||0}}</text>元,为你推荐优惠商品搭配
  76. </view>
  77. <view class="act_2">
  78. <checkbox-group @change="checkboxChange">
  79. <label class="actList" v-for="(item,index) in actList" :key="index">
  80. <image class="image"
  81. :src="item.file.length>0?item.file[0].url:item.file[0].url"
  82. mode="aspectFill"></image>
  83. <view class="name">{{item.goods_name}}</view>
  84. <view class="money">
  85. <text class="text_1">¥{{item.flow_money}}</text>
  86. <text class="text_2">¥{{item.sell_money}}</text>
  87. </view>
  88. <view class="checkbox">
  89. <checkbox color="#FB1438" style="transform:scale(0.7)" :value="item._id"
  90. :checked="item.checked" />
  91. </view>
  92. </label>
  93. </checkbox-group>
  94. <view class="bottom" @tap="toOpen">
  95. <text
  96. :class="[change==false?'iconfont icon-xiajiantou-copy':'iconfont icon-shangjiantou-copy']"></text>
  97. </view>
  98. </view>
  99. </view>
  100. <view class="other" v-if="type=='0'">
  101. <view class="other_1">优惠劵</view>
  102. <view class="other_2" @click="toCoupon" v-if="couponList.length">
  103. {{coupon_name||'请选择优惠劵'}}
  104. </view>
  105. <view class="other_2" v-else>暂无优惠劵使用</view>
  106. </view>
  107. </view>
  108. </view>
  109. </scroll-view>
  110. </view>
  111. <view class="two">
  112. <view class="two_1">
  113. <view>实付金额:</view>
  114. <view>¥{{goods_total}}</view>
  115. </view>
  116. <view class="two_2">
  117. <text @tap="toSubmit">提交订单</text>
  118. </view>
  119. </view>
  120. </view>
  121. <uni-popup ref="popup" background-color="#fff" type="bottom">
  122. <view class="popup" v-if="popup.type=='1'">
  123. <scroll-view scroll-y="true" class="scroll-view">
  124. <discount :Style="Style" :couponList="couponList" @toDiscount="toDiscount"></discount>
  125. </scroll-view>
  126. </view>
  127. </uni-popup>
  128. </mobile-frame>
  129. </template>
  130. <script>
  131. import discount from '@/components/discount/index.vue';
  132. export default {
  133. components: {
  134. discount
  135. },
  136. data() {
  137. return {
  138. // 设备平台信息
  139. system: {},
  140. popup: {
  141. type: '1'
  142. },
  143. Style: {
  144. btn: true
  145. },
  146. user: {},
  147. key: '',
  148. address: {},
  149. orderList: [],
  150. shop: [],
  151. goods_total: 0,
  152. // 金额明细
  153. total_detail: {},
  154. // 收货地址
  155. addressList: [],
  156. // 优惠劵
  157. couponList: [],
  158. coupon: [],
  159. // 优惠劵名称
  160. coupon_name: '',
  161. // 是否开团
  162. type: '0',
  163. // 团id
  164. group_id: '',
  165. // 分享人id
  166. inviter: '',
  167. // 活动商品
  168. actList: [],
  169. total: 0,
  170. page: 0,
  171. skip: 0,
  172. limit: 5,
  173. change: false,
  174. };
  175. },
  176. onLoad: function(e) {
  177. const that = this;
  178. uni.$on("id", async (id) => {
  179. let arr = await that.$api(`/address/${id}`, `GET`)
  180. if (arr.errcode == '0') {
  181. that.$set(that, `address`, arr.data)
  182. }
  183. })
  184. that.$set(that, `key`, e.key || '');
  185. that.$set(that, `group_id`, e.group_id || '');
  186. that.watchLogin()
  187. },
  188. methods: {
  189. // 监听用户是否登录
  190. watchLogin() {
  191. const that = this;
  192. uni.getStorage({
  193. key: 'token',
  194. success: function(res) {
  195. let user = that.$jwt(res.data);
  196. that.$set(that, `user`, user);
  197. // 设备平台信息
  198. let config = that.$config;
  199. that.$set(that, `system`, config.system);
  200. that.search()
  201. },
  202. fail: function(err) {
  203. uni.navigateTo({
  204. url: `/pages/login/index`
  205. })
  206. }
  207. })
  208. },
  209. // 查询列表
  210. async search() {
  211. const that = this;
  212. let user = that.user;
  213. const res = await that.$api(`/address`, 'GET', {
  214. customer: user._id
  215. })
  216. if (res.errcode == '0') {
  217. that.$set(that, `addressList`, res.data.reverse());
  218. }
  219. const arr = await that.$api(`/order/toMakeOrder`, 'POST', {
  220. key: that.key
  221. })
  222. if (arr.errcode == '0') {
  223. // 查询活动商品列表
  224. that.searchAct();
  225. // 分享人id
  226. that.$set(that, `inviter`, arr.data.inviter);
  227. // 地址
  228. that.$set(that, `address`, arr.data.address);
  229. // 订单
  230. that.$set(that, `orderList`, arr.data.goodsData);
  231. // 总价
  232. that.$set(that, `total_detail`, arr.data.orderTotal);
  233. that.$set(that, `type`, arr.data.type);
  234. this.computedTotal();
  235. // 优惠劵
  236. that.$set(that, `couponList`, arr.data.couponList);
  237. }
  238. },
  239. // 查询活动商品列表
  240. async searchAct() {
  241. const that = this;
  242. let info = {
  243. skip: that.skip,
  244. limit: that.limit,
  245. platform_act: '6371dad40aa8e005d5a47832',
  246. goods_type: 'plus'
  247. }
  248. let res = await that.$api(`/goodsJoinAct`, 'GET', {
  249. ...info,
  250. })
  251. if (res.errcode == '0') {
  252. let list = [...that.actList, ...res.data];
  253. that.$set(that, `actList`, list)
  254. that.$set(that, `total`, res.total)
  255. }
  256. },
  257. // 使用优惠劵
  258. toDiscount(e) {
  259. const that = this;
  260. that.$set(that, 'coupon_name', e.name)
  261. that.coupon.push(e._id)
  262. that.$refs.popup.close();
  263. this.computedTotal();
  264. },
  265. // 选择收货地址
  266. toChoose() {
  267. const that = this;
  268. if (that.address?._id) {
  269. uni.navigateTo({
  270. url: `/pagesMy/address/index?type=${"shopping"}&id=${that.address._id}`
  271. })
  272. } else {
  273. uni.navigateTo({
  274. url: `/pagesMy/address/index?type=${"shopping"}`
  275. })
  276. }
  277. },
  278. // 选择优惠劵
  279. toCoupon() {
  280. const that = this;
  281. that.$set(that.popup, 'type', '1')
  282. that.$set(that, 'coupon', [])
  283. that.$refs.popup.open();
  284. },
  285. // 选择活动商品
  286. checkboxChange(e) {
  287. const that = this;
  288. var actList = that.actList,
  289. values = e.detail.value;
  290. for (var i = 0, lenI = actList.length; i < lenI; ++i) {
  291. const item = actList[i]
  292. if (values.includes(item._id)) that.$set(item, 'checked', true)
  293. else that.$set(item, 'checked', false)
  294. }
  295. },
  296. // 展开更多
  297. toOpen() {
  298. const that = this;
  299. let list = that.actList;
  300. let limit = that.limit;
  301. if (that.total > list.length) {
  302. uni.showLoading({
  303. title: '加载中',
  304. mask: true
  305. })
  306. let page = that.page + 1;
  307. that.$set(that, `page`, page)
  308. let skip = page * limit;
  309. that.$set(that, `skip`, skip)
  310. that.searchAct();
  311. uni.hideLoading();
  312. } else {
  313. that.$set(that, 'change', true);
  314. uni.showToast({
  315. title: '没有更多优惠商品了',
  316. icon: 'none'
  317. })
  318. }
  319. },
  320. // 提交订单
  321. async toSubmit() {
  322. const that = this;
  323. let system = that.system;
  324. if (that.address) {
  325. let obj = {
  326. address: that.address,
  327. goods: that.orderList,
  328. total_detail: that.total_detail,
  329. coupon: that.coupon,
  330. type: that.type,
  331. inviter: that.inviter
  332. }
  333. if (that.group_id) obj.group = that.group_id;
  334. // 创建订单
  335. let p1 = await that.$api(`/order`, 'POST', obj);
  336. if (p1.errcode == '0') {
  337. if (system.uniPlatform == "mp-weixin") {
  338. // 微信支付
  339. uni.showLoading({
  340. title: '加载中'
  341. })
  342. // 支付信息
  343. let p2 = await that.$api('/pay/toPayOrder', 'POST', {
  344. order_id: p1.data,
  345. type: '0'
  346. })
  347. if (p2.errcode == '0' && p2.data.paySign) {
  348. uni.requestPayment({
  349. "provider": "wxpay",
  350. ...p2.data,
  351. success: async function(res) {
  352. // 获取团信息
  353. let p3 = await that.$api('/group/getGroup', 'GET', {
  354. order_id: p1.data,
  355. })
  356. if (p3.errcode == '0') {
  357. uni.hideLoading();
  358. if (p3.data) {
  359. uni.reLaunch({
  360. url: `/pagesHome/group/share?id=${p3.data}`
  361. })
  362. } else {
  363. uni.reLaunch({
  364. url: `/pagesMy/order/index?status=${'1'}`
  365. })
  366. }
  367. } else {
  368. uni.showToast({
  369. title: p3.errmsg,
  370. icon: 'none'
  371. })
  372. }
  373. },
  374. fail: function(err) {
  375. uni.showToast({
  376. title: `支付失败`,
  377. icon: 'none'
  378. })
  379. uni.hideLoading();
  380. uni.reLaunch({
  381. url: `/pagesMy/order/index?status=${'0'}`
  382. })
  383. }
  384. })
  385. } else {
  386. uni.showToast({
  387. title: p2.errmsg,
  388. icon: 'none'
  389. })
  390. }
  391. } else if (system.uniPlatform == "app") {
  392. uni.requestPayment({
  393. provider: 'alipay',
  394. orderInfo: 'orderInfo',
  395. success: function(res) {
  396. console.log('success:' + JSON.stringify(res));
  397. },
  398. fail: function(err) {
  399. console.log('fail:' + JSON.stringify(err));
  400. }
  401. });
  402. } else {
  403. uni.showToast({
  404. title: `平台不支持支付`,
  405. icon: 'none'
  406. })
  407. }
  408. } else {
  409. uni.showToast({
  410. title: p1.errmsg,
  411. icon: 'none'
  412. })
  413. }
  414. } else {
  415. uni.showToast({
  416. title: `没有收货地址`,
  417. icon: 'none'
  418. })
  419. }
  420. },
  421. async computedTotal() {
  422. const total_detail = this.total_detail;
  423. let total = this.$plus(total_detail.freight_total, total_detail.goods_total)
  424. if (this.coupon.length > 0) {
  425. let discount = 0;
  426. for (const coupon of this.coupon) {
  427. const r = this.couponList.find(f => f._id === coupon)
  428. if (!r) continue;
  429. const {
  430. discount_config,
  431. discount_type
  432. } = r;
  433. if (discount_type === 'min') {
  434. const min = discount_config.min;
  435. discount = this.$plus(discount, min)
  436. } else if (discount_type === 'discount') {
  437. const min = discount_config.min || 0;
  438. let discount_money = 0;
  439. const max = discount_config.max || 0;
  440. // TODO 现在是平台发放的优惠券,所以可以直接用总价*折扣,如果是店铺的折扣券,则需要将金额分开,对应店铺计算折扣
  441. // const dm = min / 10 * total;
  442. const dm = this.$multiply(this.divide(min, 10), total)
  443. if (max !== 0) {
  444. if (max > dm) discount_money = dm;
  445. else discount_money = max
  446. }
  447. discount += discount_money
  448. }
  449. }
  450. total = this.$minus(total, discount)
  451. }
  452. if (total >= 0) {
  453. this.$set(this, `goods_total`, total);
  454. } else {
  455. uni.showToast({
  456. title: `实付金额不能为负数 不能使用该优惠劵`,
  457. icon: 'none'
  458. })
  459. }
  460. }
  461. }
  462. }
  463. </script>
  464. <style lang="scss">
  465. .main {
  466. display: flex;
  467. flex-direction: column;
  468. width: 100vw;
  469. height: 100vh;
  470. .one {
  471. position: relative;
  472. flex-grow: 1;
  473. background-color: var(--f1Color);
  474. .one_1 {
  475. display: flex;
  476. justify-content: space-between;
  477. align-items: center;
  478. width: 100vw;
  479. padding: 2vw;
  480. border-bottom: 1vw dashed var(--fcColor);
  481. .address {
  482. flex-grow: 1;
  483. margin: 0 0 0 2vw;
  484. font-size: var(--font14Size);
  485. color: var(--f85Color);
  486. }
  487. .iconfont {
  488. font-size: var(--font20Szie);
  489. }
  490. .other {
  491. width: 82vw;
  492. padding: 0 2vw;
  493. .name {
  494. font-size: var(--font16Size);
  495. }
  496. .other_1 {
  497. font-size: var(--font14Size);
  498. color: var(--f85Color);
  499. text {
  500. margin: 0 1vw 0 0;
  501. }
  502. }
  503. }
  504. }
  505. .one_2 {
  506. margin: 2vw 0 0 0;
  507. .list {
  508. width: 100vw;
  509. margin: 2vw 0;
  510. .list_1 {
  511. padding: 2vw;
  512. background-color: var(--mainColor);
  513. border-bottom: 0.1vw solid var(--fcColor);
  514. text {
  515. padding: 0 0 0 1vw;
  516. }
  517. }
  518. .list_2 {
  519. padding: 2vw;
  520. display: flex;
  521. background-color: var(--mainColor);
  522. .l {
  523. width: 20vw;
  524. .image {
  525. width: 100%;
  526. height: 20vw;
  527. border-radius: 5px;
  528. }
  529. }
  530. .c {
  531. width: 60vw;
  532. padding: 0 2vw;
  533. .Spec {
  534. font-size: var(--font12Size);
  535. color: var(--f85Color);
  536. }
  537. }
  538. .r {
  539. width: 15vw;
  540. text-align: right;
  541. }
  542. }
  543. .list_3 {
  544. width: 96vw;
  545. padding: 2vw;
  546. background-color: var(--mainColor);
  547. .other {
  548. display: flex;
  549. justify-content: space-between;
  550. border-bottom: 0.1vw solid var(--fcColor);
  551. margin: 0 0 2vw 0;
  552. padding: 2vw 0;
  553. .other_1 {
  554. font-size: var(--font16Size);
  555. color: var(--f85Color);
  556. }
  557. .other_3 {
  558. flex-grow: 1;
  559. margin: 0 0 0 2vw;
  560. font-size: var(--font12Size);
  561. }
  562. text {
  563. padding: 0 1vw 0 0;
  564. font-size: var(--font20Szie);
  565. }
  566. }
  567. }
  568. }
  569. .act {
  570. background-color: var(--mainColor);
  571. border-bottom: 0.1vw solid var(--fcColor);
  572. margin: 0 0 2vw 0;
  573. width: 96vw;
  574. padding: 2vw;
  575. .act_1 {
  576. font-size: var(--font14Size);
  577. font-weight: bold;
  578. text {
  579. color: #FFA500;
  580. }
  581. }
  582. .act_2 {
  583. .actList {
  584. display: flex;
  585. margin: 2vw 0;
  586. .image {
  587. width: 12vw;
  588. height: 10vw;
  589. border: 1px solid #ffffff;
  590. }
  591. .name {
  592. width: 52vw;
  593. font-size: 12px;
  594. margin: 0 0 0 1vw;
  595. }
  596. .money {
  597. width: 25vw;
  598. .text_1 {
  599. font-size: 12px;
  600. color: #858585;
  601. text-decoration: line-through;
  602. }
  603. .text_2 {
  604. font-size: 14px;
  605. color: #ff0000;
  606. }
  607. }
  608. .checkbox {
  609. width: 7vw;
  610. }
  611. }
  612. }
  613. .bottom {
  614. text-align: center;
  615. }
  616. }
  617. .other {
  618. display: flex;
  619. justify-content: space-between;
  620. background-color: var(--mainColor);
  621. border-bottom: 0.1vw solid var(--fcColor);
  622. margin: 0 0 2vw 0;
  623. width: 96vw;
  624. padding: 2vw;
  625. .other_1 {
  626. font-size: var(--font16Size);
  627. color: var(--f85Color);
  628. }
  629. .other_3 {
  630. flex-grow: 1;
  631. margin: 0 0 0 2vw;
  632. font-size: var(--font12Size);
  633. }
  634. text {
  635. padding: 0 1vw 0 0;
  636. font-size: var(--font20Szie);
  637. }
  638. }
  639. }
  640. }
  641. .two {
  642. display: flex;
  643. justify-content: space-between;
  644. border-top: 0.1vw solid var(--fcColor);
  645. .two_1 {
  646. display: flex;
  647. align-items: center;
  648. padding: 0 2vw;
  649. font-size: var(--font16Size);
  650. view:last-child {
  651. margin: 0 0 0 2vw;
  652. color: var(--ff0Color);
  653. font-weight: bold;
  654. }
  655. }
  656. .two_2 {
  657. padding: 3vw 4vw;
  658. color: var(--mainColor);
  659. font-size: var(--font16Size);
  660. background-color: var(--ff0Color);
  661. }
  662. }
  663. }
  664. .scroll-view {
  665. position: absolute;
  666. top: 0;
  667. left: 0;
  668. right: 0;
  669. bottom: 0;
  670. .list-scroll-view {
  671. display: flex;
  672. flex-direction: row;
  673. flex-wrap: wrap;
  674. }
  675. }
  676. .popup {
  677. display: flex;
  678. flex-direction: column;
  679. height: 100vw;
  680. overflow-x: hidden;
  681. background-color: var(--f5Color);
  682. padding: 2vw;
  683. .list {
  684. .one {
  685. display: flex;
  686. justify-content: space-between;
  687. margin: 2vw 0 0 0;
  688. padding: 2vw;
  689. background-color: var(--mainColor);
  690. .name {
  691. font-size: var(--font16Size);
  692. }
  693. .address {
  694. font-size: var(--font14Size);
  695. }
  696. .iconfont {
  697. line-height: 15vw;
  698. font-size: var(--font20Szie);
  699. }
  700. }
  701. .two {
  702. display: flex;
  703. justify-content: space-between;
  704. border-top: 0.1vw solid var(--fcColor);
  705. padding: 2vw;
  706. background-color: var(--mainColor);
  707. font-size: var(--font14Size);
  708. .text {
  709. margin: 0 2vw 0 0;
  710. border: 0.1vw solid var(--fFB1Color);
  711. padding: 1vw;
  712. font-size: var(--font12Size);
  713. border-radius: 2vw;
  714. color: var(--fFB1Color);
  715. }
  716. }
  717. }
  718. }
  719. </style>