create-order.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <template>
  2. <view class="container order clearfix" :style="{ paddingBottom: isIphoneX ? '170rpx' : '134rpx' }">
  3. <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
  4. <template v-else>
  5. <!-- 地址选择 v-if="isAddress" -->
  6. <choice-address ref="choiceAddress" :addressData="addressData"></choice-address>
  7. <!-- 商品 -->
  8. <goodsList ref="goods" :goodsData="goodsData" @handleGoodList="handChangeInputGoodsList"></goodsList>
  9. <!-- 选择优惠券 -->
  10. <view class="select-coupon" @click="couponVisible = true" v-if="receiveCouponList.length > 0">
  11. <view class="left-title">优惠券</view>
  12. <view class="right-content">
  13. <view class="coupon-amount">-¥{{ couponAmount | formatPrice }}</view>
  14. <view class="iconfont icon-chakangengduo"></view>
  15. </view>
  16. </view>
  17. <!-- 分享减免 TODO-->
  18. <view class="share-reduce">
  19. <template v-if="false">
  20. <view class="left-title high">金额满100元,分享可立减10元</view>
  21. <view class="right-content"> <view class="share-btn">点击分享</view> </view>
  22. </template>
  23. <template v-else>
  24. <view class="left-title">分享减免</view>
  25. <view class="right-content">
  26. <view class="reduce-amount">-¥200.00</view> <view class="iconfont icon-chakangengduo"></view>
  27. </view>
  28. </template>
  29. </view>
  30. <!-- 优惠券列表 -->
  31. <cm-coupon-list
  32. title="优惠券"
  33. listType="use"
  34. :visible="couponVisible"
  35. @close="closeCouponList"
  36. :chooseAble="true"
  37. :showStatus="false"
  38. :couponList="receiveCouponList"
  39. @chooseCoupon="chooseCoupon"
  40. @confirm="closeCouponList"
  41. :currentId="currentCouponId"
  42. ></cm-coupon-list>
  43. <!-- 运费 -->
  44. <seller-freight ref="freight" :freightDatas="freightData"> </seller-freight>
  45. <!-- 底部 -->
  46. <view class="footer" :style="{ paddingBottom: isIphoneX ? '68rpx' : '0rpx' }">
  47. <view class="footer-le">
  48. <view class="footer-count">
  49. <text>共{{ allCount }}件商品</text>
  50. </view>
  51. <view class="footer-price">
  52. <view class="sum" :class="totalFullReduction == 0 ? 'none' : ''">
  53. <view class="price">总价:¥{{ payAllPrice | formatPrice }}</view>
  54. <view class="discount" v-if="discountedPrice > 0"
  55. >共减 ¥{{ discountedPrice | formatPrice }}</view
  56. >
  57. </view>
  58. </view>
  59. </view>
  60. <view class="footer-submit" @click.stop="orderSubmitMit">
  61. <view class="btn" :class="isSubLoading ? 'disabled' : ''">提交订单</view>
  62. </view>
  63. </view>
  64. </template>
  65. <cm-loading :visible="isSubLoading" :text="loadingText"></cm-loading>
  66. </view>
  67. </template>
  68. <script>
  69. import authorize from '@/common/authorize.js'
  70. import choiceAddress from '@/components/cm-module/createOrder/address'
  71. import goodsList from '@/components/cm-module/createOrder/goodsList'
  72. import sellerFreight from '@/components/cm-module/createOrder/sellerFreight'
  73. import CmCouponList from '@/components/cm-module/cm-coupon-list/cm-coupon-list'
  74. import CmLoading from '@/components/cm-module/cm-loading/cm-loading.vue'
  75. import { allProdoceUseCheck, someProductUseCheck, couponSort, setCouponUniqueId } from '@/common/couponUtil.js'
  76. import { mapGetters } from 'vuex'
  77. import wechatPay from '@/mixins/wechatPay.js'
  78. export default {
  79. components: {
  80. choiceAddress,
  81. goodsList,
  82. sellerFreight,
  83. CmCouponList,
  84. CmLoading
  85. },
  86. // 混入
  87. mixins: [wechatPay],
  88. data() {
  89. return {
  90. couponVisible: false,
  91. productIds: '', //获取上一级页面商品信息
  92. productCount: '', //获取上一级页面商品数量
  93. allCount: 1, //订单提交总数量
  94. totalFullReduction: 0, //满减金额
  95. allPrice: 0.0, //订单总金额
  96. townId: '', //区ID
  97. isRequest: true, //是否加载完成渲染子组件
  98. isAddress: false, //是否加载完成地址
  99. addressData: {}, //初始化地址信息
  100. goodsData: [], //初始化商品信息
  101. freightData: {}, //邮费数据
  102. productList: [],
  103. params: {
  104. userId: 0
  105. },
  106. subParams: {
  107. userId: 0,
  108. orderInfo: [], //提交的商品信息
  109. addressId: 0,
  110. cartType: 0,
  111. payInfo: {
  112. orderShouldPayFee: 0
  113. }
  114. },
  115. orderInfo: '',
  116. receiveCouponList: [],
  117. currentCouponId: -1,
  118. currentCoupon: null,
  119. loadingText: '正在创建订单',
  120. canUseCouponList: [],
  121. notUseCouponList: []
  122. }
  123. },
  124. onLoad(option) {
  125. //商品数据
  126. let data = JSON.parse(option.data)
  127. this.allCount = data.data.allCount
  128. if (option.type == 'prodcut') {
  129. this.subParams.cartType = 2
  130. this.params.productCount = data.data.productCount
  131. this.params.productId = data.data.productId
  132. this.params.heUserId = data.data.heUserId ? data.data.heUserId : 0
  133. this.productIds = data.data.productId.toString()
  134. } else {
  135. this.subParams.cartType = 1
  136. this.params.cartIds = data.data.cartIds
  137. this.productIds = data.data.productIds
  138. }
  139. this.params.userId = this.userId
  140. this.subParams.userId = this.userId
  141. this.getInitCrearOrder(this.params)
  142. },
  143. computed: {
  144. ...mapGetters(['userId', 'isIphoneX']),
  145. // 选中的优惠券的金额
  146. couponAmount() {
  147. return this.currentCoupon ? this.currentCoupon.couponAmount : 0
  148. },
  149. // 优惠价格
  150. discountedPrice() {
  151. return this.couponAmount
  152. },
  153. // 支付金额
  154. payAllPrice() {
  155. const payAllPrice = this.allPrice - this.couponAmount
  156. return payAllPrice < 0 ? 0 : payAllPrice
  157. },
  158. hanldOrder() {
  159. return {
  160. order: this.orderInfo
  161. }
  162. }
  163. },
  164. methods: {
  165. // 获取可用优惠券
  166. fetchCouponList() {
  167. this.CouponService.GetCouponByProductIds({ userId: this.userId, productIds: this.productIds }).then(res => {
  168. this.receiveCouponList = setCouponUniqueId(res.data.receiveCouponList) // 去掉重复的优惠券
  169. this.filterCouponList()
  170. })
  171. },
  172. // 对优惠券进行分类排序
  173. filterCouponList() {
  174. this.goodsData.forEach(shop => this.productList.push(...shop.productList.map(prod => prod)))
  175. this.canUseCouponList = [] // 可以使用的优惠券
  176. this.notUseCouponList = [] // 需要凑单使用的优惠券
  177. this.receiveCouponList.forEach(coupon => {
  178. if (
  179. coupon.noThresholdFlag === 1 ||
  180. (coupon.productType === 1 && allProdoceUseCheck(this.productList, coupon)) ||
  181. (coupon.productType === 2 && someProductUseCheck(this.productList, coupon))
  182. ) {
  183. coupon.canSelect = true
  184. this.canUseCouponList.push(coupon)
  185. } else {
  186. coupon.canSelect = false
  187. this.notUseCouponList.push(coupon)
  188. }
  189. })
  190. // 金额高的排前面
  191. this.receiveCouponList = [...couponSort(this.canUseCouponList), ...couponSort(this.notUseCouponList)]
  192. // 当有可用优惠券时 默认选取第一个最优惠的
  193. if (this.canUseCouponList.length > 0) {
  194. this.currentCouponId = this.receiveCouponList[0].uniqueId
  195. this.currentCoupon = this.receiveCouponList[0]
  196. }
  197. // 显示界面
  198. this.isRequest = false
  199. },
  200. // 处理优惠券列表
  201. resetCouponList() {
  202. // 2将当前选中的优惠券从列表中删除
  203. // 3将当前选中的优惠券放入最前面
  204. // 4返回最新的优惠券列表
  205. // 查找选中优惠券的索引
  206. const index = this.canUseCouponList.findIndex(coupon => coupon.uniqueId === this.currentCouponId)
  207. // 从列表中删除
  208. const currentCoupon = this.canUseCouponList.splice(index, 1)
  209. // 重新排序 将选中的优惠券放到最前面
  210. this.canUseCouponList = [...currentCoupon, ...couponSort(this.canUseCouponList)]
  211. // 重新生成receiveCouponList
  212. this.receiveCouponList = [...this.canUseCouponList, ...this.notUseCouponList]
  213. },
  214. // 确认选中
  215. closeCouponList() {
  216. this.couponVisible = false
  217. this.resetCouponList()
  218. },
  219. // 选中优惠券
  220. chooseCoupon(coupon) {
  221. if (coupon.couponId > -1) {
  222. this.currentCoupon = coupon
  223. this.currentCouponId = coupon.uniqueId
  224. } else {
  225. this.currentCoupon = null
  226. this.currentCouponId = -1
  227. }
  228. // this.couponVisible = false
  229. },
  230. //确认订单初始化信息
  231. getInitCrearOrder(params) {
  232. this.OrderService.QueryOrderConfirm(params)
  233. .then(response => {
  234. let data = response.data
  235. this.goodsData = data.shopList
  236. this.allPrice = data.totalPrice
  237. this.fetchCouponList()
  238. })
  239. .catch(error => {
  240. this.$util.msg(error.msg, 2000)
  241. })
  242. },
  243. //获取地址信息
  244. getAddressData() {
  245. this.UserService.QueryAddressList({ pageNum: 1, pageSize: 1, userId: this.userId }).then(response => {
  246. this.isAddress = true
  247. this.addressData = {}
  248. if (response.data.list != '') {
  249. this.subParams.addressId = response.data.list[0].addressId
  250. this.townId = response.data.list[0].townId
  251. this.addressData = response.data.list[0]
  252. } else {
  253. this.addressData = this.addressData
  254. }
  255. })
  256. },
  257. handChangeInputGoodsList(data) {
  258. //对应供应商的留言信息
  259. this.goodsData = data
  260. },
  261. orderSubmitMit() {
  262. //提交订单
  263. if (this.isSubLoading) return
  264. if (this.subParams.addressId == '') return this.$util.msg('请先添加收货地址~', 2000)
  265. // 选中的优惠券id
  266. this.subParams.couponId = this.currentCouponId === -1 ? '' : this.currentCoupon.couponId
  267. this.subParams.couponShareId = this.currentCoupon ? this.currentCoupon.couponShareId : null
  268. this.subParams.payInfo.orderShouldPayFee = this.payAllPrice
  269. // 处理商品信息及留言
  270. this.subParams.orderInfo = this.goodsData.map(el => {
  271. let productInfo = []
  272. el.productList.forEach(pros => {
  273. productInfo.push({
  274. productId: pros.productId,
  275. productNum: pros.productCount,
  276. heUserId: pros.heUserId
  277. })
  278. })
  279. return { shopId: el.shopId, note: el.note ? el.note : '', productInfo: productInfo }
  280. })
  281. this.isSubLoading = true
  282. this.loadingText = '正在创建订单...'
  283. this.OrderService.CreatedOrderSubmit(this.subParams)
  284. .then(response => {
  285. const data = response.data
  286. this.orderInfo = response.data
  287. if (parseFloat(data.payableAmount) === 0) {
  288. uni.setStorageSync('orderInfo', this.hanldOrder.order)
  289. uni.redirectTo({ url: '/pages/user/order/success' })
  290. } else {
  291. this.miniWxPayFor(data)
  292. }
  293. })
  294. .catch(error => {
  295. this.isSubLoading = false
  296. this.$util.msg(error.msg, 2000)
  297. this.isSubLoading = false
  298. })
  299. }
  300. },
  301. onShow() {
  302. let pages = getCurrentPages()
  303. let currPage = pages[pages.length - 1]
  304. if (currPage.data.select == 'select') {
  305. this.isAddress = true
  306. let SelectData = uni.getStorageSync('selectAddress')
  307. this.subParams.addressId = SelectData.addressId
  308. this.addressData = SelectData
  309. } else {
  310. this.getAddressData()
  311. }
  312. }
  313. }
  314. </script>
  315. <style lang="scss" scoped>
  316. page {
  317. height: auto;
  318. background: #f7f7f7;
  319. }
  320. .container {
  321. height: initial;
  322. }
  323. .btn-hover {
  324. background: #ffffff;
  325. }
  326. .animation {
  327. /* transition: transform 0.3s ease;*/
  328. transition-property: transform;
  329. transition-duration: 0.3s;
  330. transition-timing-function: ease;
  331. }
  332. .invoice-freight {
  333. width: 702rpx;
  334. padding: 0 24rpx;
  335. height: 86rpx;
  336. line-height: 86rpx;
  337. font-size: $font-size-28;
  338. color: $text-color;
  339. background: #ffffff;
  340. float: left;
  341. font-weight: bold;
  342. .freight-left {
  343. float: left;
  344. .icon-yunfeishuoming {
  345. height: 100%;
  346. padding: 0 15rpx;
  347. color: $color-system;
  348. font-weight: normal;
  349. }
  350. }
  351. .freight-right {
  352. float: right;
  353. color: #2a81ff;
  354. }
  355. }
  356. .select-coupon,
  357. .share-reduce {
  358. display: flex;
  359. justify-content: space-between;
  360. align-items: center;
  361. padding: 0 24rpx;
  362. margin: 24rpx 0;
  363. height: 90rpx;
  364. background: #fff;
  365. .left-title {
  366. font-weight: bold;
  367. color: #333333;
  368. font-size: 28rpx;
  369. .high{
  370. color: #ff457b;
  371. }
  372. }
  373. .right-content {
  374. display: flex;
  375. justify-content: flex-start;
  376. align-items: center;
  377. .coupon-amount,
  378. .reduce-amount,
  379. .share-btn {
  380. font-size: 28rpx;
  381. color: #ff457b;
  382. margin-right: 12rpx;
  383. }
  384. .iconfont {
  385. font-size: 28rpx;
  386. color: #b2b2b2;
  387. }
  388. }
  389. }
  390. .invoice-balance {
  391. width: 702rpx;
  392. height: auto;
  393. padding: 0 24rpx;
  394. background: #ffffff;
  395. float: left;
  396. margin-top: 24rpx;
  397. margin-bottom: 24rpx;
  398. .balabce-t {
  399. width: 100%;
  400. height: 86rpx;
  401. line-height: 86rpx;
  402. font-size: $font-size-28;
  403. color: $text-color;
  404. float: left;
  405. .balabce-t-le {
  406. float: left;
  407. font-weight: bold;
  408. }
  409. .balabce-t-ri {
  410. float: right;
  411. display: flex;
  412. align-items: center;
  413. .money {
  414. display: flex;
  415. float: left;
  416. }
  417. .checkbox-box {
  418. display: flex;
  419. width: 60rpx;
  420. float: left;
  421. height: 100%;
  422. font-size: $font-size-24;
  423. .checkbox {
  424. width: 40rpx;
  425. text-align: right;
  426. box-sizing: border-box;
  427. text-align: center;
  428. text-decoration: none;
  429. border-radius: 0;
  430. -webkit-tap-highlight-color: transparent;
  431. overflow: hidden;
  432. color: $color-system;
  433. padding: 5rpx;
  434. }
  435. }
  436. }
  437. }
  438. .balabce-b {
  439. width: 100%;
  440. float: left;
  441. overflow: hidden;
  442. .balabce-b-text {
  443. width: 100%;
  444. line-height: 58rpx;
  445. font-size: $font-size-24;
  446. color: #ff457b;
  447. text-align: right;
  448. float: right;
  449. }
  450. &.balabce-b--hide {
  451. padding: 0 0;
  452. height: 0px;
  453. line-height: 0px;
  454. }
  455. }
  456. }
  457. .footer {
  458. position: fixed;
  459. left: 0;
  460. bottom: 0;
  461. z-index: 995;
  462. display: flex;
  463. align-items: center;
  464. width: 100%;
  465. height: 110rpx;
  466. justify-content: space-between;
  467. font-size: $font-size-28;
  468. background-color: #ffffff;
  469. z-index: 998;
  470. color: $text-color;
  471. border-top: 1px solid #f7f7f7;
  472. .footer-le {
  473. width: 570rpx;
  474. height: 100%;
  475. float: left;
  476. }
  477. .footer-count {
  478. float: left;
  479. padding-left: 24rpx;
  480. line-height: 110rpx;
  481. width: 170rpx;
  482. box-sizing: border-box;
  483. font-size: $font-size-26;
  484. }
  485. .footer-price {
  486. float: right;
  487. text-align: right;
  488. color: $text-color;
  489. padding-right: 20rpx;
  490. box-sizing: border-box;
  491. width: 370rpx;
  492. padding-left: 24rpx;
  493. .sum {
  494. display: flex;
  495. justify-content: center;
  496. flex-direction: column;
  497. align-items: flex-start;
  498. width: 100%;
  499. height: 110rpx;
  500. .price {
  501. font-size: $font-size-32;
  502. color: $color-system;
  503. }
  504. .discount {
  505. // margin-top: 32rpx;
  506. font-size: $font-size-24;
  507. color: #ff457b;
  508. }
  509. }
  510. }
  511. .footer-submit {
  512. display: flex;
  513. align-items: center;
  514. justify-content: center;
  515. width: 210rpx;
  516. height: 100%;
  517. box-sizing: border-box;
  518. padding: 15rpx 5rpx;
  519. .btn {
  520. width: 100%;
  521. height: 100%;
  522. color: #ffffff;
  523. background: $btn-confirm;
  524. font-size: $font-size-26;
  525. text-align: center;
  526. line-height: 80rpx;
  527. border-radius: 40rpx;
  528. &.disabled {
  529. background: #e4e8eb;
  530. color: #999999;
  531. }
  532. }
  533. }
  534. }
  535. .Rebate {
  536. width: 702rpx;
  537. height: auto;
  538. padding: 0 24rpx;
  539. background: #ffffff;
  540. float: left;
  541. margin-bottom: 24rpx;
  542. margin-bottom: 24rpx;
  543. line-height: 86rpx;
  544. .rebate-title {
  545. float: left;
  546. font-weight: bold;
  547. color: #333333;
  548. font-size: $font-size-28;
  549. }
  550. .iconfont {
  551. float: right;
  552. color: #b2b2b2;
  553. font-size: 40rpx;
  554. &.icon-yixuanze {
  555. color: $color-system;
  556. }
  557. }
  558. }
  559. </style>