create-order.vue 18 KB

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