order.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. that.$set(that, 'change', true);
  313. } else if (that.total == list.length) {
  314. that.$set(that, `actList`, [])
  315. that.$set(that, `skip`, 0)
  316. that.$set(that, `limit`, 5)
  317. that.$set(that, `page`, 0)
  318. that.$set(that, `change`, false)
  319. that.searchAct();
  320. }
  321. },
  322. // 提交订单
  323. async toSubmit() {
  324. const that = this;
  325. let system = that.system;
  326. if (that.address) {
  327. let obj = {
  328. address: that.address,
  329. goods: that.orderList,
  330. total_detail: that.total_detail,
  331. coupon: that.coupon,
  332. type: that.type,
  333. inviter: that.inviter
  334. }
  335. if (that.group_id) obj.group = that.group_id;
  336. // 创建订单
  337. let p1 = await that.$api(`/order`, 'POST', obj);
  338. if (p1.errcode == '0') {
  339. if (system.uniPlatform == "mp-weixin") {
  340. // 微信支付
  341. uni.showLoading({
  342. title: '加载中'
  343. })
  344. // 支付信息
  345. let p2 = await that.$api('/pay/toPayOrder', 'POST', {
  346. order_id: p1.data,
  347. type: '0'
  348. })
  349. if (p2.errcode == '0' && p2.data.paySign) {
  350. uni.requestPayment({
  351. "provider": "wxpay",
  352. ...p2.data,
  353. success: async function(res) {
  354. // 获取团信息
  355. let p3 = await that.$api('/group/getGroup', 'GET', {
  356. order_id: p1.data,
  357. })
  358. if (p3.errcode == '0') {
  359. uni.hideLoading();
  360. if (p3.data) {
  361. uni.reLaunch({
  362. url: `/pagesHome/group/share?id=${p3.data}`
  363. })
  364. } else {
  365. uni.reLaunch({
  366. url: `/pagesMy/order/index?status=${'1'}`
  367. })
  368. }
  369. } else {
  370. uni.showToast({
  371. title: p3.errmsg,
  372. icon: 'none'
  373. })
  374. }
  375. },
  376. fail: function(err) {
  377. uni.showToast({
  378. title: `支付失败`,
  379. icon: 'none'
  380. })
  381. uni.hideLoading();
  382. uni.reLaunch({
  383. url: `/pagesMy/order/index?status=${'0'}`
  384. })
  385. }
  386. })
  387. } else {
  388. uni.showToast({
  389. title: p2.errmsg,
  390. icon: 'none'
  391. })
  392. }
  393. } else if (system.uniPlatform == "app") {
  394. uni.requestPayment({
  395. provider: 'alipay',
  396. orderInfo: 'orderInfo',
  397. success: function(res) {
  398. console.log('success:' + JSON.stringify(res));
  399. },
  400. fail: function(err) {
  401. console.log('fail:' + JSON.stringify(err));
  402. }
  403. });
  404. } else {
  405. uni.showToast({
  406. title: `平台不支持支付`,
  407. icon: 'none'
  408. })
  409. }
  410. } else {
  411. uni.showToast({
  412. title: p1.errmsg,
  413. icon: 'none'
  414. })
  415. }
  416. } else {
  417. uni.showToast({
  418. title: `没有收货地址`,
  419. icon: 'none'
  420. })
  421. }
  422. },
  423. async computedTotal() {
  424. const total_detail = this.total_detail;
  425. let total = this.$plus(total_detail.freight_total, total_detail.goods_total)
  426. if (this.coupon.length > 0) {
  427. let discount = 0;
  428. for (const coupon of this.coupon) {
  429. const r = this.couponList.find(f => f._id === coupon)
  430. if (!r) continue;
  431. const {
  432. discount_config,
  433. discount_type
  434. } = r;
  435. if (discount_type === 'min') {
  436. const min = discount_config.min;
  437. discount = this.$plus(discount, min)
  438. } else if (discount_type === 'discount') {
  439. const min = discount_config.min || 0;
  440. let discount_money = 0;
  441. const max = discount_config.max || 0;
  442. // TODO 现在是平台发放的优惠券,所以可以直接用总价*折扣,如果是店铺的折扣券,则需要将金额分开,对应店铺计算折扣
  443. // const dm = min / 10 * total;
  444. const dm = this.$multiply(this.divide(min, 10), total)
  445. if (max !== 0) {
  446. if (max > dm) discount_money = dm;
  447. else discount_money = max
  448. }
  449. discount += discount_money
  450. }
  451. }
  452. total = this.$minus(total, discount)
  453. }
  454. if (total >= 0) {
  455. this.$set(this, `goods_total`, total);
  456. } else {
  457. uni.showToast({
  458. title: `实付金额不能为负数 不能使用该优惠劵`,
  459. icon: 'none'
  460. })
  461. }
  462. }
  463. }
  464. }
  465. </script>
  466. <style lang="scss">
  467. .main {
  468. display: flex;
  469. flex-direction: column;
  470. width: 100vw;
  471. height: 100vh;
  472. .one {
  473. position: relative;
  474. flex-grow: 1;
  475. background-color: var(--f1Color);
  476. .one_1 {
  477. display: flex;
  478. justify-content: space-between;
  479. align-items: center;
  480. width: 100vw;
  481. padding: 2vw;
  482. border-bottom: 1vw dashed var(--fcColor);
  483. .address {
  484. flex-grow: 1;
  485. margin: 0 0 0 2vw;
  486. font-size: var(--font14Size);
  487. color: var(--f85Color);
  488. }
  489. .iconfont {
  490. font-size: var(--font20Szie);
  491. }
  492. .other {
  493. width: 82vw;
  494. padding: 0 2vw;
  495. .name {
  496. font-size: var(--font16Size);
  497. }
  498. .other_1 {
  499. font-size: var(--font14Size);
  500. color: var(--f85Color);
  501. text {
  502. margin: 0 1vw 0 0;
  503. }
  504. }
  505. }
  506. }
  507. .one_2 {
  508. margin: 2vw 0 0 0;
  509. .list {
  510. width: 100vw;
  511. margin: 2vw 0;
  512. .list_1 {
  513. padding: 2vw;
  514. background-color: var(--mainColor);
  515. border-bottom: 0.1vw solid var(--fcColor);
  516. text {
  517. padding: 0 0 0 1vw;
  518. }
  519. }
  520. .list_2 {
  521. padding: 2vw;
  522. display: flex;
  523. background-color: var(--mainColor);
  524. .l {
  525. width: 20vw;
  526. .image {
  527. width: 100%;
  528. height: 20vw;
  529. border-radius: 5px;
  530. }
  531. }
  532. .c {
  533. width: 60vw;
  534. padding: 0 2vw;
  535. .Spec {
  536. font-size: var(--font12Size);
  537. color: var(--f85Color);
  538. }
  539. }
  540. .r {
  541. width: 15vw;
  542. text-align: right;
  543. }
  544. }
  545. .list_3 {
  546. width: 96vw;
  547. padding: 2vw;
  548. background-color: var(--mainColor);
  549. .other {
  550. display: flex;
  551. justify-content: space-between;
  552. border-bottom: 0.1vw solid var(--fcColor);
  553. margin: 0 0 2vw 0;
  554. padding: 2vw 0;
  555. .other_1 {
  556. font-size: var(--font16Size);
  557. color: var(--f85Color);
  558. }
  559. .other_3 {
  560. flex-grow: 1;
  561. margin: 0 0 0 2vw;
  562. font-size: var(--font12Size);
  563. }
  564. text {
  565. padding: 0 1vw 0 0;
  566. font-size: var(--font20Szie);
  567. }
  568. }
  569. }
  570. }
  571. .act {
  572. background-color: var(--mainColor);
  573. border-bottom: 0.1vw solid var(--fcColor);
  574. margin: 0 0 2vw 0;
  575. width: 96vw;
  576. padding: 2vw;
  577. .act_1 {
  578. font-size: var(--font14Size);
  579. font-weight: bold;
  580. text {
  581. color: #FFA500;
  582. }
  583. }
  584. .act_2 {
  585. .actList {
  586. display: flex;
  587. margin: 2vw 0;
  588. .image {
  589. width: 12vw;
  590. height: 10vw;
  591. border: 1px solid #ffffff;
  592. }
  593. .name {
  594. width: 52vw;
  595. font-size: 12px;
  596. margin: 0 0 0 1vw;
  597. }
  598. .money {
  599. width: 25vw;
  600. .text_1 {
  601. font-size: 12px;
  602. color: #858585;
  603. text-decoration: line-through;
  604. }
  605. .text_2 {
  606. font-size: 14px;
  607. color: #ff0000;
  608. }
  609. }
  610. .checkbox {
  611. width: 7vw;
  612. }
  613. }
  614. }
  615. .bottom {
  616. text-align: center;
  617. }
  618. }
  619. .other {
  620. display: flex;
  621. justify-content: space-between;
  622. background-color: var(--mainColor);
  623. border-bottom: 0.1vw solid var(--fcColor);
  624. margin: 0 0 2vw 0;
  625. width: 96vw;
  626. padding: 2vw;
  627. .other_1 {
  628. font-size: var(--font16Size);
  629. color: var(--f85Color);
  630. }
  631. .other_3 {
  632. flex-grow: 1;
  633. margin: 0 0 0 2vw;
  634. font-size: var(--font12Size);
  635. }
  636. text {
  637. padding: 0 1vw 0 0;
  638. font-size: var(--font20Szie);
  639. }
  640. }
  641. }
  642. }
  643. .two {
  644. display: flex;
  645. justify-content: space-between;
  646. border-top: 0.1vw solid var(--fcColor);
  647. .two_1 {
  648. display: flex;
  649. align-items: center;
  650. padding: 0 2vw;
  651. font-size: var(--font16Size);
  652. view:last-child {
  653. margin: 0 0 0 2vw;
  654. color: var(--ff0Color);
  655. font-weight: bold;
  656. }
  657. }
  658. .two_2 {
  659. padding: 3vw 4vw;
  660. color: var(--mainColor);
  661. font-size: var(--font16Size);
  662. background-color: var(--ff0Color);
  663. }
  664. }
  665. }
  666. .scroll-view {
  667. position: absolute;
  668. top: 0;
  669. left: 0;
  670. right: 0;
  671. bottom: 0;
  672. .list-scroll-view {
  673. display: flex;
  674. flex-direction: row;
  675. flex-wrap: wrap;
  676. }
  677. }
  678. .popup {
  679. display: flex;
  680. flex-direction: column;
  681. height: 100vw;
  682. overflow-x: hidden;
  683. background-color: var(--f5Color);
  684. padding: 2vw;
  685. .list {
  686. .one {
  687. display: flex;
  688. justify-content: space-between;
  689. margin: 2vw 0 0 0;
  690. padding: 2vw;
  691. background-color: var(--mainColor);
  692. .name {
  693. font-size: var(--font16Size);
  694. }
  695. .address {
  696. font-size: var(--font14Size);
  697. }
  698. .iconfont {
  699. line-height: 15vw;
  700. font-size: var(--font20Szie);
  701. }
  702. }
  703. .two {
  704. display: flex;
  705. justify-content: space-between;
  706. border-top: 0.1vw solid var(--fcColor);
  707. padding: 2vw;
  708. background-color: var(--mainColor);
  709. font-size: var(--font14Size);
  710. .text {
  711. margin: 0 2vw 0 0;
  712. border: 0.1vw solid var(--fFB1Color);
  713. padding: 1vw;
  714. font-size: var(--font12Size);
  715. border-radius: 2vw;
  716. color: var(--fFB1Color);
  717. }
  718. }
  719. }
  720. }
  721. </style>