create-order.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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 } 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 = 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].couponId
  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.couponId === 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.couponId
  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.currentCouponId
  260. this.subParams.payInfo.orderShouldPayFee = this.payAllPrice
  261. // 处理商品信息及留言
  262. this.subParams.orderInfo = this.goodsData.map(el => {
  263. let productInfo = []
  264. el.productList.forEach(pros => {
  265. productInfo.push({
  266. productId: pros.productId,
  267. productNum: pros.productCount,
  268. heUserId: pros.heUserId
  269. })
  270. })
  271. return { shopId: el.shopId, note: el.note ? el.note : '', productInfo: productInfo }
  272. })
  273. this.isSubLoading = true
  274. this.loadingText = '正在创建订单...'
  275. this.OrderService.CreatedOrderSubmit(this.subParams)
  276. .then(response => {
  277. const data = response.data
  278. this.orderInfo = response.data
  279. this.miniWxPayFor(data)
  280. })
  281. .catch(error => {
  282. this.isSubLoading = false
  283. this.$util.msg(error.msg, 2000)
  284. this.isSubLoading = false
  285. })
  286. }
  287. },
  288. onShow() {
  289. let pages = getCurrentPages()
  290. let currPage = pages[pages.length - 1]
  291. if (currPage.data.select == 'select') {
  292. this.isAddress = true
  293. let SelectData = uni.getStorageSync('selectAddress')
  294. this.subParams.addressId = SelectData.addressId
  295. this.addressData = SelectData
  296. } else {
  297. this.getAddressData()
  298. }
  299. }
  300. }
  301. </script>
  302. <style lang="scss" scoped>
  303. page {
  304. height: auto;
  305. background: #f7f7f7;
  306. }
  307. .container {
  308. height: initial;
  309. }
  310. .btn-hover {
  311. background: #ffffff;
  312. }
  313. .animation {
  314. /* transition: transform 0.3s ease;*/
  315. transition-property: transform;
  316. transition-duration: 0.3s;
  317. transition-timing-function: ease;
  318. }
  319. .invoice-freight {
  320. width: 702rpx;
  321. padding: 0 24rpx;
  322. height: 86rpx;
  323. line-height: 86rpx;
  324. font-size: $font-size-28;
  325. color: $text-color;
  326. background: #ffffff;
  327. float: left;
  328. font-weight: bold;
  329. .freight-left {
  330. float: left;
  331. .icon-yunfeishuoming {
  332. height: 100%;
  333. padding: 0 15rpx;
  334. color: $color-system;
  335. font-weight: normal;
  336. }
  337. }
  338. .freight-right {
  339. float: right;
  340. color: #2a81ff;
  341. }
  342. }
  343. .select-coupon {
  344. display: flex;
  345. justify-content: space-between;
  346. align-items: center;
  347. padding: 0 24rpx;
  348. margin: 24rpx 0;
  349. height: 90rpx;
  350. background: #fff;
  351. .left-title {
  352. font-weight: bold;
  353. color: #333333;
  354. font-size: 28rpx;
  355. }
  356. .right-content {
  357. display: flex;
  358. justify-content: flex-start;
  359. align-items: center;
  360. .coupon-amount {
  361. font-size: 28rpx;
  362. color: #ff457b;
  363. margin-right: 12rpx;
  364. }
  365. .iconfont {
  366. font-size: 28rpx;
  367. color: #b2b2b2;
  368. }
  369. }
  370. }
  371. .invoice-balance {
  372. width: 702rpx;
  373. height: auto;
  374. padding: 0 24rpx;
  375. background: #ffffff;
  376. float: left;
  377. margin-top: 24rpx;
  378. margin-bottom: 24rpx;
  379. .balabce-t {
  380. width: 100%;
  381. height: 86rpx;
  382. line-height: 86rpx;
  383. font-size: $font-size-28;
  384. color: $text-color;
  385. float: left;
  386. .balabce-t-le {
  387. float: left;
  388. font-weight: bold;
  389. }
  390. .balabce-t-ri {
  391. float: right;
  392. display: flex;
  393. align-items: center;
  394. .money {
  395. display: flex;
  396. float: left;
  397. }
  398. .checkbox-box {
  399. display: flex;
  400. width: 60rpx;
  401. float: left;
  402. height: 100%;
  403. font-size: $font-size-24;
  404. .checkbox {
  405. width: 40rpx;
  406. text-align: right;
  407. box-sizing: border-box;
  408. text-align: center;
  409. text-decoration: none;
  410. border-radius: 0;
  411. -webkit-tap-highlight-color: transparent;
  412. overflow: hidden;
  413. color: $color-system;
  414. padding: 5rpx;
  415. }
  416. }
  417. }
  418. }
  419. .balabce-b {
  420. width: 100%;
  421. float: left;
  422. overflow: hidden;
  423. .balabce-b-text {
  424. width: 100%;
  425. line-height: 58rpx;
  426. font-size: $font-size-24;
  427. color: #ff457b;
  428. text-align: right;
  429. float: right;
  430. }
  431. &.balabce-b--hide {
  432. padding: 0 0;
  433. height: 0px;
  434. line-height: 0px;
  435. }
  436. }
  437. }
  438. .footer {
  439. position: fixed;
  440. left: 0;
  441. bottom: 0;
  442. z-index: 995;
  443. display: flex;
  444. align-items: center;
  445. width: 100%;
  446. height: 110rpx;
  447. justify-content: space-between;
  448. font-size: $font-size-28;
  449. background-color: #ffffff;
  450. z-index: 998;
  451. color: $text-color;
  452. border-top: 1px solid #f7f7f7;
  453. .footer-le {
  454. width: 570rpx;
  455. height: 100%;
  456. float: left;
  457. }
  458. .footer-count {
  459. float: left;
  460. padding-left: 24rpx;
  461. line-height: 110rpx;
  462. width: 170rpx;
  463. box-sizing: border-box;
  464. font-size: $font-size-26;
  465. }
  466. .footer-price {
  467. float: right;
  468. text-align: right;
  469. color: $text-color;
  470. padding-right: 20rpx;
  471. box-sizing: border-box;
  472. width: 370rpx;
  473. padding-left: 24rpx;
  474. .sum {
  475. display: flex;
  476. justify-content: center;
  477. flex-direction: column;
  478. align-items: flex-start;
  479. width: 100%;
  480. height: 110rpx;
  481. .price {
  482. font-size: $font-size-32;
  483. color: $color-system;
  484. }
  485. .discount {
  486. // margin-top: 32rpx;
  487. font-size: $font-size-24;
  488. color: #ff457b;
  489. }
  490. }
  491. }
  492. .footer-submit {
  493. display: flex;
  494. align-items: center;
  495. justify-content: center;
  496. width: 210rpx;
  497. height: 100%;
  498. box-sizing: border-box;
  499. padding: 15rpx 5rpx;
  500. .btn {
  501. width: 100%;
  502. height: 100%;
  503. color: #ffffff;
  504. background: $btn-confirm;
  505. font-size: $font-size-26;
  506. text-align: center;
  507. line-height: 80rpx;
  508. border-radius: 40rpx;
  509. &.disabled {
  510. background: #e4e8eb;
  511. color: #999999;
  512. }
  513. }
  514. }
  515. }
  516. .Rebate {
  517. width: 702rpx;
  518. height: auto;
  519. padding: 0 24rpx;
  520. background: #ffffff;
  521. float: left;
  522. margin-bottom: 24rpx;
  523. margin-bottom: 24rpx;
  524. line-height: 86rpx;
  525. .rebate-title {
  526. float: left;
  527. font-weight: bold;
  528. color: #333333;
  529. font-size: $font-size-28;
  530. }
  531. .iconfont {
  532. float: right;
  533. color: #b2b2b2;
  534. font-size: 40rpx;
  535. &.icon-yixuanze {
  536. color: $color-system;
  537. }
  538. }
  539. }
  540. </style>