create-order.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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 | NumFormat }}</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 | NumFormat }}</view>
  54. <view class="discount" v-if="discountedPrice > 0"
  55. >共减 ¥{{ discountedPrice | NumFormat }}</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. filters: {
  165. NumFormat(value) {
  166. //处理金额
  167. return Number(value).toFixed(2)
  168. }
  169. },
  170. methods: {
  171. // 获取可用优惠券
  172. fetchCouponList() {
  173. this.CouponService.GetCouponByProductIds({ userId: this.userId, productIds: this.productIds }).then(res => {
  174. this.receiveCouponList = setCouponUniqueId(res.data.receiveCouponList) // 去掉重复的优惠券
  175. this.filterCouponList()
  176. })
  177. },
  178. // 对优惠券进行分类排序
  179. filterCouponList() {
  180. this.goodsData.forEach(shop => this.productList.push(...shop.productList.map(prod => prod)))
  181. this.canUseCouponList = [] // 可以使用的优惠券
  182. this.notUseCouponList = [] // 需要凑单使用的优惠券
  183. this.receiveCouponList.forEach(coupon => {
  184. if (
  185. coupon.noThresholdFlag === 1 ||
  186. (coupon.productType === 1 && allProdoceUseCheck(this.productList, coupon)) ||
  187. (coupon.productType === 2 && someProductUseCheck(this.productList, coupon))
  188. ) {
  189. coupon.canSelect = true
  190. this.canUseCouponList.push(coupon)
  191. } else {
  192. coupon.canSelect = false
  193. this.notUseCouponList.push(coupon)
  194. }
  195. })
  196. // 金额高的排前面
  197. this.receiveCouponList = [...couponSort(this.canUseCouponList), ...couponSort(this.notUseCouponList)]
  198. // 当有可用优惠券时 默认选取第一个最优惠的
  199. if (this.canUseCouponList.length > 0) {
  200. this.currentCouponId = this.receiveCouponList[0].uniqueId
  201. this.currentCoupon = this.receiveCouponList[0]
  202. }
  203. // 显示界面
  204. this.isRequest = false
  205. },
  206. // 处理优惠券列表
  207. resetCouponList() {
  208. // 2将当前选中的优惠券从列表中删除
  209. // 3将当前选中的优惠券放入最前面
  210. // 4返回最新的优惠券列表
  211. // 查找选中优惠券的索引
  212. const index = this.canUseCouponList.findIndex(coupon => coupon.uniqueId === this.currentCouponId)
  213. // 从列表中删除
  214. const currentCoupon = this.canUseCouponList.splice(index, 1)
  215. // 重新排序 将选中的优惠券放到最前面
  216. this.canUseCouponList = [...currentCoupon, ...couponSort(this.canUseCouponList)]
  217. // 重新生成receiveCouponList
  218. this.receiveCouponList = [...this.canUseCouponList, ...this.notUseCouponList]
  219. },
  220. // 确认选中
  221. closeCouponList() {
  222. this.couponVisible = false
  223. this.resetCouponList()
  224. },
  225. // 选中优惠券
  226. chooseCoupon(coupon) {
  227. if (coupon.couponId > -1) {
  228. this.currentCoupon = coupon
  229. this.currentCouponId = coupon.uniqueId
  230. } else {
  231. this.currentCoupon = null
  232. this.currentCouponId = -1
  233. }
  234. // this.couponVisible = false
  235. },
  236. //确认订单初始化信息
  237. getInitCrearOrder(params) {
  238. this.OrderService.QueryOrderConfirm(params)
  239. .then(response => {
  240. let data = response.data
  241. this.goodsData = data.shopList
  242. this.allPrice = data.totalPrice
  243. this.fetchCouponList()
  244. })
  245. .catch(error => {
  246. this.$util.msg(error.msg, 2000)
  247. })
  248. },
  249. //获取地址信息
  250. getAddressData() {
  251. this.UserService.QueryAddressList({ pageNum: 1, pageSize: 1, userId: this.userId }).then(response => {
  252. this.isAddress = true
  253. this.addressData = {}
  254. if (response.data.list != '') {
  255. this.subParams.addressId = response.data.list[0].addressId
  256. this.townId = response.data.list[0].townId
  257. this.addressData = response.data.list[0]
  258. } else {
  259. this.addressData = this.addressData
  260. }
  261. })
  262. },
  263. handChangeInputGoodsList(data) {
  264. //对应供应商的留言信息
  265. this.goodsData = data
  266. },
  267. orderSubmitMit() {
  268. //提交订单
  269. if (this.isSubLoading) return
  270. if (this.subParams.addressId == '') return this.$util.msg('请先添加收货地址~', 2000)
  271. // 选中的优惠券id
  272. this.subParams.couponId = this.currentCouponId === -1 ? '' : this.currentCoupon.couponId
  273. this.subParams.couponShareId = this.currentCoupon ? this.currentCoupon.couponShareId : null
  274. this.subParams.payInfo.orderShouldPayFee = this.payAllPrice
  275. // 处理商品信息及留言
  276. this.subParams.orderInfo = this.goodsData.map(el => {
  277. let productInfo = []
  278. el.productList.forEach(pros => {
  279. productInfo.push({
  280. productId: pros.productId,
  281. productNum: pros.productCount,
  282. heUserId: pros.heUserId
  283. })
  284. })
  285. return { shopId: el.shopId, note: el.note ? el.note : '', productInfo: productInfo }
  286. })
  287. this.isSubLoading = true
  288. this.loadingText = '正在创建订单...'
  289. this.OrderService.CreatedOrderSubmit(this.subParams)
  290. .then(response => {
  291. const data = response.data
  292. this.orderInfo = response.data
  293. if (parseFloat(data.payableAmount) === 0) {
  294. uni.setStorageSync('orderInfo', this.hanldOrder.order)
  295. uni.redirectTo({ url: '/pages/user/order/success' })
  296. } else {
  297. this.miniWxPayFor(data)
  298. }
  299. })
  300. .catch(error => {
  301. this.isSubLoading = false
  302. this.$util.msg(error.msg, 2000)
  303. this.isSubLoading = false
  304. })
  305. }
  306. },
  307. onShow() {
  308. let pages = getCurrentPages()
  309. let currPage = pages[pages.length - 1]
  310. if (currPage.data.select == 'select') {
  311. this.isAddress = true
  312. let SelectData = uni.getStorageSync('selectAddress')
  313. this.subParams.addressId = SelectData.addressId
  314. this.addressData = SelectData
  315. } else {
  316. this.getAddressData()
  317. }
  318. }
  319. }
  320. </script>
  321. <style lang="scss" scoped>
  322. page {
  323. height: auto;
  324. background: #f7f7f7;
  325. }
  326. .container {
  327. height: initial;
  328. }
  329. .btn-hover {
  330. background: #ffffff;
  331. }
  332. .animation {
  333. /* transition: transform 0.3s ease;*/
  334. transition-property: transform;
  335. transition-duration: 0.3s;
  336. transition-timing-function: ease;
  337. }
  338. .invoice-freight {
  339. width: 702rpx;
  340. padding: 0 24rpx;
  341. height: 86rpx;
  342. line-height: 86rpx;
  343. font-size: $font-size-28;
  344. color: $text-color;
  345. background: #ffffff;
  346. float: left;
  347. font-weight: bold;
  348. .freight-left {
  349. float: left;
  350. .icon-yunfeishuoming {
  351. height: 100%;
  352. padding: 0 15rpx;
  353. color: $color-system;
  354. font-weight: normal;
  355. }
  356. }
  357. .freight-right {
  358. float: right;
  359. color: #2a81ff;
  360. }
  361. }
  362. .select-coupon,
  363. .share-reduce {
  364. display: flex;
  365. justify-content: space-between;
  366. align-items: center;
  367. padding: 0 24rpx;
  368. margin: 24rpx 0;
  369. height: 90rpx;
  370. background: #fff;
  371. .left-title {
  372. font-weight: bold;
  373. color: #333333;
  374. font-size: 28rpx;
  375. .high{
  376. color: #ff457b;
  377. }
  378. }
  379. .right-content {
  380. display: flex;
  381. justify-content: flex-start;
  382. align-items: center;
  383. .coupon-amount,
  384. .reduce-amount,
  385. .share-btn {
  386. font-size: 28rpx;
  387. color: #ff457b;
  388. margin-right: 12rpx;
  389. }
  390. .iconfont {
  391. font-size: 28rpx;
  392. color: #b2b2b2;
  393. }
  394. }
  395. }
  396. .invoice-balance {
  397. width: 702rpx;
  398. height: auto;
  399. padding: 0 24rpx;
  400. background: #ffffff;
  401. float: left;
  402. margin-top: 24rpx;
  403. margin-bottom: 24rpx;
  404. .balabce-t {
  405. width: 100%;
  406. height: 86rpx;
  407. line-height: 86rpx;
  408. font-size: $font-size-28;
  409. color: $text-color;
  410. float: left;
  411. .balabce-t-le {
  412. float: left;
  413. font-weight: bold;
  414. }
  415. .balabce-t-ri {
  416. float: right;
  417. display: flex;
  418. align-items: center;
  419. .money {
  420. display: flex;
  421. float: left;
  422. }
  423. .checkbox-box {
  424. display: flex;
  425. width: 60rpx;
  426. float: left;
  427. height: 100%;
  428. font-size: $font-size-24;
  429. .checkbox {
  430. width: 40rpx;
  431. text-align: right;
  432. box-sizing: border-box;
  433. text-align: center;
  434. text-decoration: none;
  435. border-radius: 0;
  436. -webkit-tap-highlight-color: transparent;
  437. overflow: hidden;
  438. color: $color-system;
  439. padding: 5rpx;
  440. }
  441. }
  442. }
  443. }
  444. .balabce-b {
  445. width: 100%;
  446. float: left;
  447. overflow: hidden;
  448. .balabce-b-text {
  449. width: 100%;
  450. line-height: 58rpx;
  451. font-size: $font-size-24;
  452. color: #ff457b;
  453. text-align: right;
  454. float: right;
  455. }
  456. &.balabce-b--hide {
  457. padding: 0 0;
  458. height: 0px;
  459. line-height: 0px;
  460. }
  461. }
  462. }
  463. .footer {
  464. position: fixed;
  465. left: 0;
  466. bottom: 0;
  467. z-index: 995;
  468. display: flex;
  469. align-items: center;
  470. width: 100%;
  471. height: 110rpx;
  472. justify-content: space-between;
  473. font-size: $font-size-28;
  474. background-color: #ffffff;
  475. z-index: 998;
  476. color: $text-color;
  477. border-top: 1px solid #f7f7f7;
  478. .footer-le {
  479. width: 570rpx;
  480. height: 100%;
  481. float: left;
  482. }
  483. .footer-count {
  484. float: left;
  485. padding-left: 24rpx;
  486. line-height: 110rpx;
  487. width: 170rpx;
  488. box-sizing: border-box;
  489. font-size: $font-size-26;
  490. }
  491. .footer-price {
  492. float: right;
  493. text-align: right;
  494. color: $text-color;
  495. padding-right: 20rpx;
  496. box-sizing: border-box;
  497. width: 370rpx;
  498. padding-left: 24rpx;
  499. .sum {
  500. display: flex;
  501. justify-content: center;
  502. flex-direction: column;
  503. align-items: flex-start;
  504. width: 100%;
  505. height: 110rpx;
  506. .price {
  507. font-size: $font-size-32;
  508. color: $color-system;
  509. }
  510. .discount {
  511. // margin-top: 32rpx;
  512. font-size: $font-size-24;
  513. color: #ff457b;
  514. }
  515. }
  516. }
  517. .footer-submit {
  518. display: flex;
  519. align-items: center;
  520. justify-content: center;
  521. width: 210rpx;
  522. height: 100%;
  523. box-sizing: border-box;
  524. padding: 15rpx 5rpx;
  525. .btn {
  526. width: 100%;
  527. height: 100%;
  528. color: #ffffff;
  529. background: $btn-confirm;
  530. font-size: $font-size-26;
  531. text-align: center;
  532. line-height: 80rpx;
  533. border-radius: 40rpx;
  534. &.disabled {
  535. background: #e4e8eb;
  536. color: #999999;
  537. }
  538. }
  539. }
  540. }
  541. .Rebate {
  542. width: 702rpx;
  543. height: auto;
  544. padding: 0 24rpx;
  545. background: #ffffff;
  546. float: left;
  547. margin-bottom: 24rpx;
  548. margin-bottom: 24rpx;
  549. line-height: 86rpx;
  550. .rebate-title {
  551. float: left;
  552. font-weight: bold;
  553. color: #333333;
  554. font-size: $font-size-28;
  555. }
  556. .iconfont {
  557. float: right;
  558. color: #b2b2b2;
  559. font-size: 40rpx;
  560. &.icon-yixuanze {
  561. color: $color-system;
  562. }
  563. }
  564. }
  565. </style>