create-order.vue 18 KB

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