create-order.vue 17 KB

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