creatOrder.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <template>
  2. <view class="pages">
  3. <!-- head -->
  4. <sklineHeader title="确认采购订单"></sklineHeader>
  5. <view class="cart-body">
  6. <!-- 内容 -->
  7. <scroll-view
  8. scroll-y
  9. class="cart-list"
  10. type="custom"
  11. :bounces="false"
  12. >
  13. <sticky-header>
  14. <!-- 头部 -->
  15. <view class="cart-head" v-if="total>0">
  16. <view class="cart-head-left">商品列表</view>
  17. <view class="cart-head-right">
  18. 共<text>{{total}}</text>款<text>{{totalNum}}</text>件商品
  19. </view>
  20. </view>
  21. </sticky-header>
  22. <productItem
  23. v-for="(item, index) in list"
  24. :key="index"
  25. :list="item"
  26. type="views"
  27. >
  28. </productItem>
  29. <!-- loading -->
  30. <view class="loading-bar" v-if="total>0 && status!='loading'">{{noDataText}}</view>
  31. <view class="empty-bar" v-if="total==0 && status!='loading'" @click="goBack">
  32. <view>{{empty.tip}}</view>
  33. </view>
  34. <!-- 商品总计,优惠金额、代金券,抵扣至少有一个时显示 -->
  35. <view class="product-price">
  36. <view>
  37. <view class="product-price-item" v-if="totalDiscount||totalCoupon||showBalanceAuth&&subsidyAmount">
  38. <text>总金额</text>
  39. <text class="price">¥{{Number(totalAmount).toFixed(2)}}</text>
  40. </view>
  41. <view class="product-price-item" v-if="showBalanceAuth&&subsidyAmount">
  42. <view class="flex align_center" v-if="storeAccount">抵扣(余额:¥{{Number(storeAccount.giveBalance).toFixed(2)}})</view>
  43. <view class="flex align_center" v-if="!disKdk" @click="hasKdk=!hasKdk">
  44. <uni-icons size="18" :type="hasKdk?'checkbox-filled':'checkbox'" color="#2196f3"></uni-icons>
  45. <text>¥{{Number(subsidyAmount).toFixed(2)}}</text>
  46. </view>
  47. <view class="flex align_center" v-else>
  48. <uni-icons size="18" type="circle-filled" color="#aaa"></uni-icons>
  49. <text>¥{{Number(subsidyAmount).toFixed(2)}}</text>
  50. </view>
  51. </view>
  52. <view class="product-price-item" v-if="totalDiscount">
  53. <text>优惠金额</text>
  54. <text class="price">¥{{Number(totalDiscount).toFixed(2)}}</text>
  55. </view>
  56. <view class="product-price-item" v-if="totalCoupon">
  57. <text>代金券</text>
  58. <text class="price">¥{{Number(totalCoupon).toFixed(2)}}</text>
  59. </view>
  60. <view class="product-price-item">
  61. <text>合计:</text>
  62. <text class="price">¥{{settleAmount.join('.')}}</text>
  63. </view>
  64. </view>
  65. <view style="margin-top: 10px;">
  66. <payOptions v-model="payType" :hasBalancePay="showBalanceAuth" :disableCz="disCzOption" :hasPay="shelfInfo&&shelfInfo.payOnlineFlag&&shelfInfo.payOnlineFlag=='1'" @change="payTypeChange" :balance="storeAccount?storeAccount.rechargeBalance:0"></payOptions>
  67. </view>
  68. </view>
  69. </scroll-view>
  70. <!-- 底部 -->
  71. <view class="cart-footer" v-if="total>0">
  72. <view class="cart-footer-box">
  73. <view class="cart-footer-left">
  74. 结算金额:
  75. <view class="cart-footer-left-price-num">
  76. ¥<text>{{settleAmount[0]}}</text>.{{settleAmount[1]}}
  77. </view>
  78. </view>
  79. <view class="cart-footer-right">
  80. <view></view>
  81. <view class="cart-footer-right-button">
  82. <button class="btns" :loading="loading" type="warn" size="mini" @click="settlement">提交订单</button>
  83. </view>
  84. </view>
  85. </view>
  86. <view :style="{height:safeAreaBottom+'px'}"></view>
  87. </view>
  88. </view>
  89. <!-- 付款弹框 -->
  90. <payModal v-if="hasPay" :showPopu="showPopu" :payInfo="payInfo" :payData="payData" @close="showPopu=false" @payComplete="payComplete"></payModal>
  91. </view>
  92. </template>
  93. <script>
  94. import {
  95. mapState,
  96. mapMutations,
  97. } from 'vuex'
  98. import productItem from '@/pagesB/cart/productitem.vue'
  99. import sklineHeader from '../../components/skline/sklineHeader.vue'
  100. import payModal from '../components/payModal.vue'
  101. import payOptions from '../components/payOptions.vue'
  102. import { purchaseSave, purchaseCheck, purchasePay } from '@/api/purchase.js'
  103. export default {
  104. components:{
  105. productItem,
  106. sklineHeader,
  107. payModal,
  108. payOptions
  109. },
  110. onLoad() {
  111. // 计算区域高度
  112. this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight
  113. this.screenWidth = uni.getSystemInfoSync().windowWidth
  114. this.screenHeight = uni.getSystemInfoSync().windowHeight
  115. this.safeAreaBottom = uni.getSystemInfoSync().safeAreaInsets.bottom
  116. // 列表原始数据
  117. this.list = this.$store.state.vuex_tempData||[]
  118. this.getChooseHeji()
  119. },
  120. onUnload() {
  121. this.$store.state.vuex_tempData = null
  122. },
  123. onShow() {
  124. },
  125. data() {
  126. return {
  127. loading: false,
  128. status: 'loading',
  129. noDataText: '暂无产品',
  130. empty: {
  131. tip: '暂无产品',
  132. },
  133. // 查询条件
  134. list: [], // 列表数据
  135. total: 0, // 总款数
  136. totalAmount: 0, // 总金额
  137. totalDiscount:0, // 总优惠
  138. subsidyAmount:0, // 总可抵扣金额
  139. totalCoupon: 0, // 总代金券
  140. totalNum: 0, // 总数量
  141. screenWidth: 325, // 屏幕宽度
  142. screenHeight: 0, // 屏幕高度
  143. statusBarHeight: 44, // 状态栏高度
  144. safeAreaBottom: 0, // 底部安全区域高度
  145. showPopu: false, // 弹框
  146. payData: null ,// 付款参数
  147. payType: 0, // 支付方式,0抵扣、1微信,2线下
  148. hasKdk: false, // 是否使用抵扣金额
  149. }
  150. },
  151. watch: {
  152. hasBalancePay(v){
  153. console.log(v,'0000')
  154. this.payType = v ? 0 : (this.hasPay ? 1 : 2)
  155. },
  156. disKdk(v){
  157. this.hasKdk = !v
  158. }
  159. },
  160. computed: {
  161. ...mapState(['hasLogin']),
  162. userInfo(){
  163. return this.$store.state.vuex_userInfo
  164. },
  165. // 结算金额
  166. settleAmount(){
  167. return Number(this.hasKdk&&this.showBalanceAuth?this.totalAmount-this.subsidyAmount:this.totalAmount).toFixed(2).toString().split('.')
  168. },
  169. // 货架经销商信息
  170. shelfInfo(){
  171. return this.$store.state.vuex_storeShelf
  172. },
  173. // 抵扣余额支付是否可用
  174. showBalanceAuth(){
  175. return this.$store.state.vuex_showBalanceAuth
  176. },
  177. // 充值余额支付是否显示,合计金额小于充值余额
  178. hasBalancePay(){
  179. return this.showBalanceAuth&&this.storeAccount&&!this.disCzOption
  180. },
  181. // 抵扣余额
  182. storeAccount(){
  183. return this.$store.state.vuex_storeAccount
  184. },
  185. // 禁用抵扣金额,选择线上支付时,禁用抵扣金额
  186. disKdk(){
  187. const kdk = this.storeAccount&&this.subsidyAmount>0&&this.subsidyAmount<=this.storeAccount.giveBalance
  188. return !kdk||this.payType==2
  189. },
  190. // 禁用的充值支付选项,合计金额大于充值余额禁用
  191. disCzOption(){
  192. const ta = this.hasKdk&&this.totalAmount?this.totalAmount-this.subsidyAmount:this.totalAmount
  193. return ta>this.storeAccount.rechargeBalance
  194. },
  195. // 最小支付金额
  196. minPayAmount(){
  197. const shelfInfo = this.shelfInfo
  198. return shelfInfo&&shelfInfo.minAmount ? shelfInfo.minAmount : 0
  199. },
  200. //是否开启线上支付
  201. hasPay(){
  202. const shelfInfo = this.shelfInfo
  203. return shelfInfo&&shelfInfo.payOnlineFlag&&shelfInfo.payOnlineFlag=='1'
  204. },
  205. // 付款信息
  206. payInfo(){
  207. return this.$store.state.vuex_tempOrderData
  208. }
  209. },
  210. methods: {
  211. goBack(){
  212. uni.navigateBack()
  213. },
  214. payTypeChange(v){
  215. // 线下支付,不可使用抵扣金额
  216. if(v==2){
  217. this.hasKdk = false
  218. }
  219. },
  220. // 去结算
  221. settlement(){
  222. if(this.totalAmount>0){
  223. if(this.hasPay && this.minPayAmount>this.totalAmount){
  224. uni.showModal({
  225. content: '支付金额不能小于'+this.minPayAmount+'元!',
  226. showCancel:false,
  227. confirmText:'知道了'
  228. })
  229. }else{
  230. this.submitOrder()
  231. }
  232. }else{
  233. uni.showToast({
  234. title: '请选择产品',
  235. icon: 'none',
  236. mask: true,
  237. duration: 3000
  238. })
  239. }
  240. },
  241. // 去结算
  242. submitOrder(){
  243. const _this = this
  244. // 获取已选商品
  245. const detailList = []
  246. const cartSn = []
  247. _this.list.forEach(key => {
  248. key.filter(item=>item.checked).forEach(item => {
  249. detailList.push({
  250. productSn:item.productSn,
  251. productCode:item.productCode,
  252. qty: item.qty,
  253. price:item.orginPrice,
  254. promoSn: item.promoSn,
  255. promoProductSn: item.shopProductSubsidy&&item.shopProductSubsidy.productSubsidySn,
  256. resultValue: item.shopProductSubsidy&&item.shopProductSubsidy.subsidyAmount,
  257. useSubsidyFlag: this.hasKdk&&!this.disKdk? '1' : '0'
  258. })
  259. cartSn.push({
  260. cartSn: item.cartSn,
  261. productSn:item.productSn
  262. })
  263. })
  264. })
  265. this.loading = true
  266. // 校验并提示信息
  267. purchaseCheck({
  268. detailList:detailList,
  269. useSubsidyFlag: this.hasKdk&&!this.disKdk? '1' : '0',
  270. payOnlineType: this.payType == 0 ? 'RECHARGE_BALANCE' : this.payType == 1 ? 'PAY_WECHAT_ONLINE' : ''
  271. }).then(res => {
  272. if(res.status == 200){
  273. const promoChangeFlag = res.data.promoChangeFlag
  274. const subsidyChangeFlag = res.data.subsidyChangeFlag
  275. // 活动变更
  276. if(promoChangeFlag||subsidyChangeFlag){
  277. uni.showModal({
  278. title: '提示',
  279. content: promoChangeFlag ? '促销活动已变更,请刷新!' : (subsidyChangeFlag?'抵扣规则已变更,请刷新!':''),
  280. confirmText:'确定刷新',
  281. success(ret) {
  282. if(ret.confirm){
  283. _this.goBack()
  284. uni.$emit('refashCartList')
  285. }
  286. }
  287. })
  288. this.loading = false
  289. return
  290. }
  291. const successList = res.data.successList.map(item => {
  292. return {
  293. productSn:item.productSn,
  294. productCode: item.productCode,
  295. qty: item.qty,
  296. price: item.price,
  297. promoSn: item.promoSn,
  298. promoProductSn: item.promoProductSn,
  299. resultValue: item.resultValue
  300. }
  301. })
  302. const delSn = cartSn.filter(item => successList.find(k => k.productSn == item.productSn)).map(item => item.cartSn)
  303. const removeList = res.data.removeList.map(item => item.productCode)
  304. const selloutList = res.data.selloutList.map(item => item.productCode)
  305. console.log(successList,delSn)
  306. console.log(removeList,selloutList)
  307. // 有已下架或已售罄产品提示
  308. if(removeList.length || selloutList.length){
  309. uni.showModal({
  310. title: '提示',
  311. content: (removeList.length ? `产品${removeList.join(',')}已下架,`:'')+(selloutList.length?`产品${selloutList.join(',')}已售罄,`:'')+`不可采购。`+(successList.length?'是否继续采购其他产品?':''),
  312. showCancel: successList.length,
  313. confirmText: successList.length?'确定':'知道了',
  314. success(ret) {
  315. if(ret.confirm && successList.length){
  316. _this.submitForm(successList,delSn)
  317. }
  318. }
  319. })
  320. }else{
  321. // 提交
  322. _this.submitForm(successList,delSn)
  323. }
  324. }else{
  325. this.loading = false
  326. uni.showToast({
  327. title: res.message,
  328. icon: 'none'
  329. })
  330. }
  331. })
  332. },
  333. // 确认提交
  334. submitForm(detailList,cartSn){
  335. uni.showLoading({
  336. title: '提交中...',
  337. mask: true
  338. })
  339. this.loading = true
  340. purchaseSave({
  341. detailList: detailList,
  342. useSubsidyFlag: this.hasKdk? '1' : '0',
  343. payOnlineType: this.payType == 0 ? 'RECHARGE_BALANCE' : this.payType == 1 ? 'PAY_WECHAT_ONLINE' : ''
  344. }).then(res => {
  345. uni.hideLoading()
  346. if(res.status == 200){
  347. // 删除已提交产品
  348. uni.$emit('removeCatGood',cartSn,true,false)
  349. res.data.detailList = []
  350. this.$store.state.vuex_tempOrderData = res.data
  351. // 这里判断是否开通支付或充值余额支付,如果开通打开确认付款弹框
  352. if(this.hasPay||this.payType==0){
  353. purchasePay({
  354. bizSn:res.data.purchaseSn,
  355. bizNo:res.data.purchaseNo,
  356. bizType:'SETTLE_BILL',
  357. payUserOpenId: this.$store.state.vuex_openid || uni.getStorageSync('openid'),
  358. settleType: this.payType == 0 ? 'RECHARGE_BALANCE' : 'PAY_WECHAT_ONLINE'
  359. }).then(ret=>{
  360. if(ret.status == 200){
  361. // 微信支付
  362. if(this.payType == 1){
  363. this.showPopu = true
  364. this.payData = ret.data?ret.data.payRequestRest:null
  365. }else{
  366. // 余额支付
  367. this.payError()
  368. }
  369. }else{
  370. // 支付失败
  371. this.payError(ret.message)
  372. }
  373. uni.$emit("refashPayBalance")
  374. })
  375. }else{
  376. this.loading = false
  377. uni.$emit("refashPayBalance")
  378. this.payComplete(null,true)
  379. }
  380. }else{
  381. this.loading = false
  382. uni.$emit("refashPayBalance")
  383. uni.showToast({
  384. title: res.message,
  385. icon: 'none'
  386. })
  387. }
  388. })
  389. },
  390. // 支付失败关闭弹框并跳到订单详情页面
  391. payError(msg){
  392. if(msg){
  393. uni.showModal({
  394. title: '提示',
  395. content: msg,
  396. showCancel: false,
  397. confirmText: '确定',
  398. success: (res) => {
  399. if (res.confirm) {
  400. this.payComplete(null,true)
  401. }
  402. }
  403. })
  404. }else{
  405. // 充值余额支付成功
  406. this.payComplete(null,true)
  407. }
  408. this.loading = false
  409. },
  410. // 订单详情页
  411. payComplete(data){
  412. // 创建成功,跳转到订单详情页
  413. uni.redirectTo({
  414. url: "/pagesB/procureOrder/orderDetail?purchaseSn="+this.$store.state.vuex_tempOrderData.purchaseSn
  415. })
  416. },
  417. // 计算总款数、合计、数量
  418. getChooseHeji(){
  419. this.totalAmount = 0
  420. this.totalDiscount = 0
  421. this.subsidyAmount = 0
  422. this.totalCoupon = 0
  423. this.total = 0
  424. this.totalNum = 0
  425. this.list.forEach(key => {
  426. key.filter(item=>item.checked).forEach(item => {
  427. this.totalAmount += item.price * item.qty // 总金额
  428. this.totalNum += item.qty // 总数量
  429. this.total += 1 // 总款数
  430. // 有抵扣金额,且没有促销活动
  431. if(item.shopProductSubsidy&&!item.shopPromoProduct){
  432. // 抵扣金额是否小于售价
  433. const isXPrice = item.shopProductSubsidy.subsidyAmount<=item.price
  434. this.subsidyAmount += isXPrice ? (item.shopProductSubsidy.subsidyAmount||0) * item.qty : 0
  435. }
  436. // 如果是返券类型
  437. if(item.promoType=='BUY_PROD_GIVE_VALID'){
  438. this.totalCoupon += item.resultValue * item.qty
  439. }
  440. // 特价
  441. if(item.promoType=='PROMO_PROD'){
  442. this.totalDiscount += (item.orginPrice - item.conditionValue) * item.qty
  443. }
  444. // 满赠
  445. item.giftQty = item.promoType=='BUY_PROD_GIVE_PROD' ? Math.floor(item.qty / item.conditionValue)*item.resultValue : 0
  446. })
  447. })
  448. // 默认支付方式
  449. this.payType = this.showBalanceAuth ? 0 : (this.hasPay ? 1 : 2)
  450. // 总可抵扣金额有余额支付权限,且总抵扣金额小于等于抵扣余额,且支付方式不是线下支付
  451. this.hasKdk = this.subsidyAmount>0&&this.storeAccount&&this.subsidyAmount<=this.storeAccount.giveBalance&&this.showBalanceAuth&&this.payType!=2
  452. },
  453. }
  454. }
  455. </script>
  456. <style lang="less">
  457. .pages{
  458. height: 100vh;
  459. display: flex;
  460. flex-direction: column;
  461. .cart-body{
  462. position: relative;
  463. flex-grow: 1;
  464. display: flex;
  465. flex-direction: column;
  466. .cart-head{
  467. display: flex;
  468. justify-content: space-between;
  469. align-items: center;
  470. padding: 0 20rpx;
  471. background-color: #FFFFFF;
  472. height: 40px;
  473. .cart-head-left{
  474. display: flex;
  475. align-items: center;
  476. font-size: 28rpx;
  477. color: #333333;
  478. height: 100%;
  479. }
  480. .cart-head-right{
  481. display: flex;
  482. align-items: center;
  483. font-size: 24rpx;
  484. color: #666;
  485. height: 100%;
  486. text{
  487. color: #d81e06;
  488. margin: 0 10rpx;
  489. }
  490. }
  491. }
  492. .cart-list{
  493. flex-grow: 1;
  494. background-color: #F5F5F5;
  495. width: 100%;
  496. .loading-bar{
  497. text-align: center;
  498. padding: 10px 0;
  499. color: #999999;
  500. }
  501. .empty-bar{
  502. display: flex;
  503. flex-direction: column;
  504. align-items: center;
  505. justify-content: center;
  506. padding: 20px 0;
  507. margin-top: 20vh;
  508. image{
  509. width: 100px;
  510. height: 100px;
  511. }
  512. view{
  513. font-size: 14px;
  514. color: #999999;
  515. margin-top: 10px;
  516. }
  517. }
  518. .product-price{
  519. padding:0 6px;
  520. margin: 6px 0;
  521. > view{
  522. background: #fff;
  523. padding: 10px;
  524. border-radius: 10px;
  525. .product-price-item{
  526. display:flex;
  527. align-items: center;
  528. justify-content: space-between;
  529. padding: 6px 0;
  530. font-size: 24rpx;
  531. .price{
  532. color: #333;
  533. }
  534. &:last-child{
  535. font-size: 28rpx;
  536. justify-content: flex-end;
  537. .price{
  538. color: #d81e06;
  539. font-weight: bold;
  540. }
  541. }
  542. }
  543. }
  544. }
  545. }
  546. .cart-footer{
  547. width: 100%;
  548. background-color: #FFFFFF;
  549. .cart-footer-box{
  550. width: 100%;
  551. height: 100rpx;
  552. display: flex;
  553. justify-content: space-between;
  554. align-items: center;
  555. }
  556. .cart-footer-left{
  557. display: flex;
  558. align-items: baseline;
  559. padding: 0 20rpx 0 36rpx;
  560. font-size: 24rpx;
  561. }
  562. .cart-footer-left-price-num{
  563. display: flex;
  564. align-items: baseline;
  565. font-size: 24rpx;
  566. color: #d81e06;
  567. text{
  568. font-size: 36rpx;
  569. }
  570. }
  571. .cart-footer-right{
  572. padding: 0 20rpx;
  573. display: flex;
  574. align-items: center;
  575. justify-content: space-between;
  576. flex-grow:1;
  577. .cart-footer-right-button{
  578. display: flex;
  579. align-items: center;
  580. margin-left: 20rpx;
  581. text-align: right;
  582. .btns{
  583. border-radius: 100rpx;
  584. height: 36px;
  585. padding: 0 10px;
  586. min-width: 80px;
  587. }
  588. }
  589. }
  590. }
  591. }
  592. }
  593. </style>