order-create.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <template>
  2. <view class="create-order">
  3. <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
  4. <!-- 收货地址 -->
  5. <view class="order-top"><cm-choose-address :addressData="addressData"></cm-choose-address></view>
  6. <view class="grid"></view>
  7. <!-- 订单列表 -->
  8. <view class="order-list">
  9. <view v-for="(shopInfo, shopInfoIndex) in goodsData" :key="shopInfoIndex">
  10. <view class="line"></view>
  11. <view class="order-section">
  12. <!-- 供应商 -->
  13. <view class="origin">
  14. <image class="cover" :src="shopInfo.logo"></image>
  15. <view class="name">{{ shopInfo.name }}</view>
  16. </view>
  17. <!-- 商品列表 -->
  18. <view class="goods-list">
  19. <!-- 商品信息 -->
  20. <view class="order-goods" v-for="goods in shopInfo.productList" :key="goods.productId">
  21. <cm-order-prodcut :goods-data="goods"></cm-order-prodcut>
  22. </view>
  23. </view>
  24. <!-- 合计 -->
  25. <!-- <view class="total-price">
  26. <text>合计:</text> <text class="price">¥{{ shopInfo.shopTotalPrice | formatPrice }}</text>
  27. </view> -->
  28. <!-- 留言 -->
  29. <view class="remark">
  30. <view class="label">留言:</view>
  31. <input class="control" type="text" v-model="shopInfo.note" placeholder="请输入内容" />
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 优惠券 -->
  37. <template v-if="receiveCouponList.length > 0">
  38. <view class="grid"></view>
  39. <cm-order-coupon-section @click="couponVisible = true" :coupon="currentCoupon"></cm-order-coupon-section>
  40. </template>
  41. <!-- 分享减免 -->
  42. <template v-if="reduction">
  43. <view class="grid"></view>
  44. <cm-order-share-reduce :reductionData="shareReductionData"></cm-order-share-reduce>
  45. </template>
  46. <!-- 运费 -->
  47. <view class="grid"></view>
  48. <cm-order-freight-section></cm-order-freight-section>
  49. <view class="grid"></view>
  50. <!-- 提交导航 -->
  51. <cm-order-submit-nav :orderInfo="submitOrderInfo" @commit="orderSubmit"></cm-order-submit-nav>
  52. <!-- 优惠券列表 -->
  53. <cm-coupon-list
  54. title="优惠券"
  55. listType="use"
  56. :visible="couponVisible"
  57. @close="closeCouponList"
  58. :chooseAble="true"
  59. :showStatus="false"
  60. :couponList="receiveCouponList"
  61. @chooseCoupon="chooseCoupon"
  62. @confirm="closeCouponList"
  63. :currentId="currentCouponUniqueId"
  64. ></cm-coupon-list>
  65. <!-- 阻止下单弹框 -->
  66. <tui-modal
  67. :show="preventModal"
  68. :size="30"
  69. :button="[{ text: '确定', type: 'danger' }]"
  70. shape="circle"
  71. color="#333333"
  72. title="提示"
  73. :content="preventText"
  74. @click="onPreventConfirm"
  75. ></tui-modal>
  76. <cm-loading :visible="isSubLoading" :text="loadingText"></cm-loading>
  77. <view class="reserved" v-if="isIphoneX"></view>
  78. </view>
  79. </template>
  80. <script>
  81. import CmChooseAddress from '@/components/cm-module/cm-choose-address/cm-choose-address.vue'
  82. import CmOrderProdcut from '@/components/cm-module/cm-order-prodcut/cm-order-prodcut.vue'
  83. import CmOrderSubmitNav from '@/components/cm-module/cm-order-submit-nav/cm-order-submit-nav.vue'
  84. import CmOrderCouponSection from '@/components/cm-module/cm-order-coupon-section/cm-order-coupon-section.vue'
  85. import CmOrderFreightSection from '@/components/cm-module/cm-order-freight-section/cm-order-freight-section.vue'
  86. import CmOrderShareReduce from '@/components/cm-module/cm-order-share-reduce/cm-order-share-reduce.vue'
  87. import CmLoading from '@/components/cm-module/cm-loading/cm-loading.vue'
  88. import CmCouponList from '@/components/cm-module/cm-coupon-list/cm-coupon-list'
  89. import { allProdoceUseCheck, someProductUseCheck, couponSort, setCouponUniqueId } from '@/common/couponUtil.js'
  90. import { mapGetters } from 'vuex'
  91. import wechatPay from './mixins/wechatPay.js'
  92. export default {
  93. // 混入
  94. mixins: [wechatPay],
  95. components: {
  96. CmOrderProdcut,
  97. CmChooseAddress,
  98. CmOrderSubmitNav,
  99. CmOrderCouponSection,
  100. CmOrderFreightSection,
  101. CmOrderShareReduce,
  102. CmCouponList,
  103. CmLoading
  104. },
  105. data() {
  106. return {
  107. preventModal: false,
  108. preventText: '抱歉,该商品支付正在调整暂不支持下单!',
  109. isRequest: true,
  110. // 收货地址
  111. addressData: {},
  112. productIds: '',
  113. // 初始化订单信息参数列表
  114. params: {},
  115. // 订单提交参数
  116. subParams: {
  117. userId: 0,
  118. orderInfo: [], //提交的商品信息
  119. addressId: 0,
  120. cartType: 0,
  121. payInfo: {
  122. orderShouldPayFee: 0
  123. },
  124. discountInfo: null
  125. },
  126. goodsData: [], // 供应商下的商品
  127. allPrice: 0,
  128. productList: [], // 商品列表
  129. allCount: 0,
  130. hanldOrder: {},
  131. // 优惠券
  132. couponVisible: false,
  133. receiveCouponList: [], // 已领取优惠券列表
  134. currentCouponUniqueId: -1, // 选中的优惠券唯一id 注意:非优惠券id,选中优惠券id通过currentCoupon.couponId获取
  135. currentCoupon: {}, // 选中的优惠券信息
  136. canUseCouponList: [], // 能够使用的优惠券列表
  137. notUseCouponList: [], // 暂未满足条件的优惠券列表
  138. // 拼团
  139. collageFlag: 0, //拼团标识:0不参与拼团,1参与拼团
  140. collageId: 0, //拼团id:参与拼团,若拼团id为空则发起拼团,不为空则与他人拼团
  141. // 分享抵扣
  142. shareReductStatus: false,
  143. reduction: null,
  144. reductionUserId: 0, //分享抵扣用户id
  145. shareData: {
  146. type: 0
  147. }
  148. }
  149. },
  150. computed: {
  151. ...mapGetters(['userId', 'isIphoneX']),
  152. // 选中的优惠券的金额
  153. couponAmount() {
  154. return this.currentCoupon.couponAmount || 0
  155. },
  156. // 最终支付金额
  157. payAllPrice() {
  158. const payAllPrice = this.allPrice - this.couponAmount - this.shareReducedAmount
  159. return payAllPrice <= 0 ? 0 : payAllPrice
  160. },
  161. // 总优惠价格
  162. discountedPrice() {
  163. return this.couponAmount + this.shareReducedAmount
  164. },
  165. // 提交组件状态信息
  166. submitOrderInfo() {
  167. return {
  168. allCount: this.allCount,
  169. payAllPrice: this.payAllPrice,
  170. discountedPrice: this.discountedPrice
  171. }
  172. },
  173. // 优惠券,分享活动相关参数
  174. discountInfo() {
  175. return {
  176. //优惠券ID
  177. couponId: this.currentCoupon.couponId || 0,
  178. //优惠券分享ID
  179. couponShareId: this.currentCoupon.couponShareId || 0,
  180. //拼团标识:0不参与拼团,1参与拼团
  181. collageFlag: this.collageFlag,
  182. //拼团id:参与拼团,若拼团id为空则发起拼团,不为空则与他人拼团
  183. collageId: this.collageId,
  184. //分享抵扣用户id
  185. reductionUserId: this.reductionUserId
  186. }
  187. },
  188. // 分享减免金额
  189. shareReducedAmount() {
  190. return this.reduction && this.shareReductStatus ? this.reduction.reducedAmount : 0
  191. },
  192. // 分享减免组件状态信息
  193. shareReductionData() {
  194. return {
  195. status: this.shareReductStatus,
  196. reduction: this.reduction
  197. }
  198. }
  199. },
  200. onLoad(options) {
  201. this.isRequest = true
  202. this.getAddressData()
  203. this.initOptions(options)
  204. // this.orderPaySuccess() // 支付回调
  205. },
  206. onShow() {
  207. let pages = getCurrentPages()
  208. let currPage = pages[pages.length - 1]
  209. if (currPage.data.select == 'select') {
  210. this.isAddress = true
  211. let SelectData = uni.getStorageSync('selectAddress')
  212. this.subParams.addressId = SelectData.addressId
  213. this.addressData = SelectData
  214. } else {
  215. this.getAddressData()
  216. }
  217. },
  218. beforeDestroy() {
  219. uni.removeStorageSync('commitProductInfo')
  220. uni.removeStorageSync('commitCartPramsData')
  221. },
  222. // 分享朋友圈
  223. // onShareTimeline() {
  224. // this.handleShare(2)
  225. // // 加密
  226. // const state_str = encodeURIComponent(this.$crypto.encrypt(this.shareData))
  227. // return {
  228. // title: '护肤上颜选,正品有好货~',
  229. // query: `/pages/tabBar/index/index?state_str=${state_str}`,
  230. // imageUrl: this.$Static + 'icon-index-share.jpg'
  231. // }
  232. // },
  233. // 分享
  234. onShareAppMessage(e) {
  235. this.handleShare(1)
  236. // 加密
  237. const state_str = encodeURIComponent(this.$crypto.encrypt(this.shareData))
  238. return {
  239. title: '护肤上颜选,正品有好货~',
  240. path: `/pages/tabBar/index/index?state_str=${state_str}`,
  241. imageUrl: this.$Static + 'icon-index-share.jpg'
  242. }
  243. },
  244. methods: {
  245. onPreventConfirm() {
  246. uni.navigateBack({ delta: 1 })
  247. },
  248. // 支付回调执行函数
  249. orderPaySuccess() {
  250. this.$on('orderPaySuccess', () => {
  251. if (this.collageFlag === 1) {
  252. uni.redirectTo({ url: `/pages/fight-order/fight-detail?collageId=${this.collageId}` })
  253. } else {
  254. uni.redirectTo({ url: '/pages/order/success' })
  255. }
  256. })
  257. },
  258. // 分享
  259. handleShare(shareType) {
  260. if (!this.reduction) return
  261. const { reductionId } = this.reduction
  262. this.OrderService.OrderReductionShare({ reductionId, shareType, userId: this.userId })
  263. .then(res => {
  264. this.$util.msg(res.msg, 2000)
  265. this.reductionUserId = res.data
  266. this.shareReductStatus = true
  267. })
  268. .catch(err => {
  269. this.$util.msg(error.msg, 2000)
  270. this.shareReductStatus = false
  271. })
  272. },
  273. // 初始化参数信息
  274. initOptions(options) {
  275. // 从商品详情进入
  276. if (options.type == 'prodcut') {
  277. const productInfo = uni.getStorageSync('commitProductInfo')
  278. this.subParams.cartType = 2 // 从商品详情提交
  279. this.params.productCount = productInfo.productCount
  280. this.params.productId = productInfo.productId
  281. this.params.heUserId = productInfo.heUserId || 0
  282. this.params.collageFlag = this.collageFlag = productInfo.collageFlag
  283. this.productIds = productInfo.productId.toString()
  284. this.allCount = productInfo.allCount
  285. this.collageId = parseInt(productInfo.collageId) || 0
  286. } else {
  287. const cartPramsData = uni.getStorageSync('commitCartPramsData')
  288. this.subParams.cartType = 1 // 从购物车提交
  289. this.params.cartIds = cartPramsData.cartIds
  290. this.productIds = cartPramsData.productIds
  291. this.allCount = cartPramsData.allCount
  292. }
  293. this.params.userId = this.userId
  294. this.subParams.userId = this.userId
  295. this.getInitCrearOrder(this.params)
  296. },
  297. // 获取可用优惠券
  298. fetchCouponList() {
  299. this.CouponService.GetCouponByProductIds({ userId: this.userId, productIds: this.productIds }).then(res => {
  300. this.receiveCouponList = setCouponUniqueId(res.data.receiveCouponList) // 去掉重复的优惠券
  301. this.filterCouponList()
  302. })
  303. },
  304. // 对优惠券进行分类排序
  305. filterCouponList() {
  306. this.goodsData.forEach(shop => this.productList.push(...shop.productList.map(prod => prod)))
  307. this.canUseCouponList = [] // 可以使用的优惠券
  308. this.notUseCouponList = [] // 需要凑单使用的优惠券
  309. this.receiveCouponList.forEach(coupon => {
  310. if (
  311. coupon.noThresholdFlag === 1 ||
  312. (coupon.productType === 1 && allProdoceUseCheck(this.productList, coupon)) ||
  313. (coupon.productType === 2 && someProductUseCheck(this.productList, coupon))
  314. ) {
  315. coupon.canSelect = true
  316. this.canUseCouponList.push(coupon)
  317. } else {
  318. coupon.canSelect = false
  319. this.notUseCouponList.push(coupon)
  320. }
  321. })
  322. // 金额高的排前面
  323. this.receiveCouponList = [...couponSort(this.canUseCouponList), ...couponSort(this.notUseCouponList)]
  324. // 当有可用优惠券时 默认选取第一个最优惠的
  325. if (this.canUseCouponList.length > 0) {
  326. this.currentCouponUniqueId = this.receiveCouponList[0].uniqueId
  327. this.currentCoupon = this.receiveCouponList[0] || {}
  328. }
  329. // 显示界面
  330. this.isRequest = false
  331. },
  332. // 处理优惠券列表
  333. resetCouponList() {
  334. // 1将当前选中的优惠券从列表中删除
  335. // 2将当前选中的优惠券放入最前面
  336. // 3返回最新的优惠券列表
  337. // 4查找选中优惠券的索引
  338. const index = this.canUseCouponList.findIndex(coupon => coupon.uniqueId === this.currentCouponUniqueId)
  339. // 从列表中删除
  340. const currentCoupon = this.canUseCouponList.splice(index, 1)
  341. // 重新排序 将选中的优惠券放到最前面
  342. this.canUseCouponList = [...currentCoupon, ...couponSort(this.canUseCouponList)]
  343. // 重新生成receiveCouponList
  344. this.receiveCouponList = [...this.canUseCouponList, ...this.notUseCouponList]
  345. },
  346. // 确认选中
  347. closeCouponList() {
  348. this.couponVisible = false
  349. this.resetCouponList()
  350. },
  351. // 选中优惠券
  352. chooseCoupon(coupon) {
  353. if (coupon.couponId > -1) {
  354. this.currentCoupon = coupon
  355. this.currentCouponUniqueId = coupon.uniqueId
  356. } else {
  357. this.currentCoupon = {}
  358. this.currentCouponUniqueId = -1
  359. }
  360. // this.couponVisible = false
  361. },
  362. //确认订单初始化信息
  363. getInitCrearOrder(params) {
  364. this.OrderService.QueryOrderConfirm(params)
  365. .then(res => {
  366. let data = res.data
  367. this.goodsData = this.bindRemark(data.shopList)
  368. console.log(this.goodsData)
  369. this.allPrice = data.totalPrice
  370. this.fetchCouponList()
  371. this.reduction = res.data.reduction
  372. this.isRequest = false
  373. if (res.data.onlinePay === -1) {
  374. this.preventModal = true
  375. this.preventText = '抱歉,该商品支付正在调整,暂不支持下单'
  376. }
  377. if (res.data.onlinePay === -2) {
  378. this.preventModal = true
  379. this.preventText = '抱歉,部分商品支付正在调整,暂不支持下单'
  380. }
  381. })
  382. .catch(error => {
  383. this.$util.msg(error.msg, 2000)
  384. })
  385. },
  386. // 为共供应商绑定留言信息
  387. bindRemark(shopList) {
  388. return shopList.map(item => {
  389. item.note = ''
  390. return item
  391. })
  392. },
  393. //获取地址信息
  394. getAddressData() {
  395. this.UserService.QueryAddressList({ pageNum: 1, pageSize: 1, userId: this.userId }).then(res => {
  396. this.addressData = res.data.list[0]
  397. // 设置收货地址
  398. this.subParams.addressId = this.addressData.addressId
  399. })
  400. },
  401. orderSubmit() {
  402. //提交订单
  403. if (this.isSubLoading) return
  404. if (this.subParams.addressId == '') return this.$util.msg('请先添加收货地址~', 2000)
  405. // 优惠券,分享活动相关参数
  406. this.subParams.discountInfo = this.discountInfo
  407. // 要支付的金额
  408. this.subParams.payInfo.orderShouldPayFee = this.payAllPrice
  409. //
  410. // 处理商品信息及留言
  411. this.subParams.orderInfo = this.goodsData.map(el => {
  412. let productInfo = []
  413. el.productList.forEach(pros => {
  414. productInfo.push({
  415. productId: pros.productId,
  416. productNum: pros.productCount,
  417. heUserId: pros.heUserId
  418. })
  419. })
  420. return { shopId: el.shopId, note: el.note ? el.note : '', productInfo, splitCode: el.splitCode }
  421. })
  422. // 调试提交参数
  423. console.log(this.subParams)
  424. // return
  425. this.isSubLoading = true
  426. this.loadingText = '正在创建订单...'
  427. this.OrderService.CreatedOrderSubmit(this.subParams)
  428. .then(response => {
  429. this.isSubLoading = false
  430. // const data = response.data
  431. // this.hanldOrder.order = response.data
  432. // this.collageId = data.collageId
  433. // if (parseFloat(data.payableAmount) === 0) {
  434. // uni.setStorageSync('orderInfo', this.hanldOrder.order)
  435. // uni.redirectTo({ url: '/pages/order/success' })
  436. // } else {
  437. // this.miniWxPayFor(data)
  438. // }
  439. uni.redirectTo({ url: `/pages/order/order-pay?orderId=${response.data.orderId}` })
  440. })
  441. .catch(error => {
  442. // this.$util.msg(error.msg, 2000)
  443. this.isSubLoading = false
  444. this.preventModal = true
  445. this.preventText = error.msg
  446. })
  447. }
  448. }
  449. }
  450. </script>
  451. <style lang="scss" scoped>
  452. .create-order {
  453. background: #f7f7f7;
  454. min-height: 100vh;
  455. padding-top: 134rpx;
  456. padding-bottom: 100rpx;
  457. box-sizing: border-box;
  458. .order-top {
  459. width: 100%;
  460. position: fixed;
  461. top: 0;
  462. left: 0;
  463. z-index: 999;
  464. }
  465. }
  466. .grid {
  467. width: 100%;
  468. height: 20rpx;
  469. background: #f7f7f7;
  470. }
  471. .line {
  472. width: 702rpx;
  473. height: 1rpx;
  474. margin: 0 auto;
  475. background: #f7f7f7;
  476. }
  477. .order-list {
  478. background: #fff;
  479. .order-section {
  480. padding: 38rpx 0;
  481. }
  482. .goods-list {
  483. .order-goods {
  484. padding-top: 32rpx;
  485. &:first-child {
  486. padding-top: 0;
  487. }
  488. }
  489. }
  490. .origin {
  491. padding: 0 24rpx;
  492. margin-bottom: 16rpx;
  493. display: flex;
  494. justify-content: flex-start;
  495. align-items: center;
  496. .cover {
  497. width: 56rpx;
  498. height: 56rpx;
  499. border-radius: 4rpx;
  500. }
  501. .name {
  502. margin-left: 16rpx;
  503. font-size: 30rpx;
  504. color: #333333;
  505. }
  506. }
  507. }
  508. .total-price {
  509. padding: 24rpx;
  510. text-align: right;
  511. font-size: 26rpx;
  512. color: #333;
  513. background: #fff;
  514. .price {
  515. color: #ff457b;
  516. }
  517. }
  518. .remark {
  519. padding: 24rpx 24rpx 0;
  520. display: flex;
  521. justify-content: space-between;
  522. align-items: center;
  523. background: #fff;
  524. .label {
  525. width: 78rpx;
  526. font-size: 26rpx;
  527. color: #999999;
  528. margin-right: 16rpx;
  529. }
  530. .control {
  531. flex: 1;
  532. font-size: 26rpx;
  533. color: #333333;
  534. padding: 8rpx 16rpx;
  535. background: #f7f7f7;
  536. border-radius: 8rpx;
  537. }
  538. }
  539. </style>