creatOrder.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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">
  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">抵扣(余额:¥{{storeAccount.giveBalance}})</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>¥{{subsidyAmount}}</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>¥{{subsidyAmount}}</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="hasBalancePay" :disableCz="disCzOption" :hasPay="shelfInfo&&shelfInfo.payOnlineFlag&&shelfInfo.payOnlineFlag=='1'" @change="v=>hasKdk=v!=2" :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. this.payType = v ? 0 : (this.hasPay ? 1 : 2)
  154. }
  155. },
  156. computed: {
  157. ...mapState(['hasLogin']),
  158. userInfo(){
  159. return this.$store.state.vuex_userInfo
  160. },
  161. // 结算金额
  162. settleAmount(){
  163. return Number(this.hasKdk?this.totalAmount-this.subsidyAmount:this.totalAmount).toFixed(2).toString().split('.')
  164. },
  165. // 货架经销商信息
  166. shelfInfo(){
  167. return this.$store.state.vuex_storeShelf
  168. },
  169. // 抵扣余额支付是否可用
  170. showBalanceAuth(){
  171. return this.$store.state.vuex_showBalanceAuth
  172. },
  173. // 充值余额支付是否显示,合计金额小于充值余额
  174. hasBalancePay(){
  175. return this.$store.state.vuex_showBalanceAuth&&this.storeAccount&&!this.disCzOption
  176. },
  177. // 抵扣余额
  178. storeAccount(){
  179. return this.$store.state.vuex_storeAccount
  180. },
  181. // 禁用抵扣金额
  182. disKdk(){
  183. const kdk = this.storeAccount&&this.subsidyAmount>0&&this.subsidyAmount<=this.storeAccount.giveBalance
  184. return this.payType==2 || !kdk
  185. },
  186. // 禁用的支付选项
  187. disCzOption(){
  188. const ta = this.hasKdk&&this.totalAmount?this.totalAmount-this.subsidyAmount:this.totalAmount
  189. return ta>this.storeAccount.rechargeBalance
  190. },
  191. // 最小支付金额
  192. minPayAmount(){
  193. const shelfInfo = this.shelfInfo
  194. return shelfInfo&&shelfInfo.minAmount ? shelfInfo.minAmount : 0
  195. },
  196. //是否开启线上支付
  197. hasPay(){
  198. const shelfInfo = this.shelfInfo
  199. return shelfInfo&&shelfInfo.payOnlineFlag&&shelfInfo.payOnlineFlag=='1'&&this.payType!=2
  200. },
  201. // 付款信息
  202. payInfo(){
  203. return this.$store.state.vuex_tempOrderData
  204. }
  205. },
  206. methods: {
  207. goBack(){
  208. uni.navigateBack()
  209. },
  210. // 去结算
  211. settlement(){
  212. if(this.totalAmount>0){
  213. if(this.hasPay && this.minPayAmount>this.totalAmount){
  214. uni.showModal({
  215. content: '支付金额不能小于'+this.minPayAmount+'元!',
  216. showCancel:false,
  217. confirmText:'知道了'
  218. })
  219. }else{
  220. this.submitOrder()
  221. }
  222. }else{
  223. uni.showToast({
  224. title: '请选择产品',
  225. icon: 'none',
  226. mask: true,
  227. duration: 3000
  228. })
  229. }
  230. },
  231. // 去结算
  232. submitOrder(){
  233. const _this = this
  234. // 获取已选商品
  235. const detailList = []
  236. const cartSn = []
  237. _this.list.forEach(key => {
  238. key.filter(item=>item.checked).forEach(item => {
  239. detailList.push({
  240. productSn:item.productSn,
  241. productCode:item.productCode,
  242. qty: item.qty,
  243. price:item.orginPrice,
  244. promoSn: item.promoSn,
  245. shopProductSubsidy: item.shopProductSubsidy,
  246. shopPromoProduct: item.shopPromoProduct
  247. })
  248. cartSn.push({
  249. cartSn: item.cartSn,
  250. productSn:item.productSn
  251. })
  252. })
  253. })
  254. // 校验并提示信息
  255. purchaseCheck({detailList:detailList}).then(res => {
  256. if(res.status == 200){
  257. const promoChangeFlag = res.data.promoChangeFlag
  258. // 活动变更
  259. if(promoChangeFlag){
  260. uni.showModal({
  261. title: '提示',
  262. content: '促销活动已变更,请返回购物车重新选择?',
  263. confirmText:'确定刷新',
  264. success(ret) {
  265. if(ret.confirm){
  266. _this.goBack()
  267. uni.$emit('refashCartList')
  268. }
  269. }
  270. })
  271. return
  272. }
  273. const successList = res.data.successList.map(item => {
  274. return {
  275. productSn:item.productSn,
  276. productCode: item.productCode,
  277. qty: item.qty,
  278. price: item.price,
  279. promoSn: item.promoSn,
  280. shopProductSubsidy: item.shopProductSubsidy,
  281. shopPromoProduct: item.shopPromoProduct
  282. }
  283. })
  284. const delSn = cartSn.filter(item => successList.find(k => k.productSn == item.productSn)).map(item => item.cartSn)
  285. const removeList = res.data.removeList.map(item => item.productCode)
  286. const selloutList = res.data.selloutList.map(item => item.productCode)
  287. console.log(successList,delSn)
  288. console.log(removeList,selloutList)
  289. // 有已下架或已售罄产品提示
  290. if(removeList.length || selloutList.length){
  291. uni.showModal({
  292. title: '提示',
  293. content: (removeList.length ? `产品${removeList.join(',')}已下架,`:'')+(selloutList.length?`产品${selloutList.join(',')}已售罄,`:'')+`不可采购。`+(successList.length?'是否继续采购其他产品?':''),
  294. showCancel: successList.length,
  295. confirmText: successList.length?'确定':'知道了',
  296. success(ret) {
  297. if(ret.confirm && successList.length){
  298. _this.submitForm(successList,delSn)
  299. }
  300. }
  301. })
  302. }else{
  303. // 提交
  304. _this.submitForm(successList,delSn)
  305. }
  306. }else{
  307. uni.showToast({
  308. title: res.message,
  309. icon: 'none'
  310. })
  311. }
  312. })
  313. },
  314. // 确认提交
  315. submitForm(detailList,cartSn){
  316. uni.showLoading({
  317. title: '提交中...',
  318. mask: true
  319. })
  320. this.loading = true
  321. purchaseSave({
  322. detailList: detailList,
  323. payOnlineType: this.payType == 0 ? 'RECHARGE_BALANCE' : this.payType == 1 ? 'PAY_WECHAT_ONLINE' : ''
  324. }).then(res => {
  325. this.loading = false
  326. uni.hideLoading()
  327. if(res.status == 200){
  328. // 删除已提交产品
  329. uni.$emit('removeCatGood',cartSn,true,false)
  330. res.data.detailList = []
  331. this.$store.state.vuex_tempOrderData = res.data
  332. // 这里判断是否开通支付,如果开通打开确认付款弹框
  333. if(this.hasPay){
  334. purchasePay({
  335. bizSn:res.data.purchaseSn,
  336. bizNo:res.data.purchaseNo,
  337. bizType:'SETTLE_BILL',
  338. payUserOpenId: this.$store.state.vuex_openid || uni.getStorageSync('openid'),
  339. settleType: this.payType == 0 ? 'RECHARGE_BALANCE' : 'PAY_WECHAT_ONLINE'
  340. }).then(ret=>{
  341. if(ret.status == 200){
  342. // 微信支付
  343. if(this.payType == 1){
  344. this.showPopu = true
  345. this.payData = ret.data?ret.data.payRequestRest:null
  346. }else{
  347. // 余额支付
  348. this.payComplete(null,true)
  349. }
  350. }else{
  351. uni.showToast({
  352. title: ret.message,
  353. icon: 'none'
  354. })
  355. }
  356. })
  357. }else{
  358. this.payComplete(null,true)
  359. }
  360. }else{
  361. uni.showToast({
  362. title: res.message,
  363. icon: 'none'
  364. })
  365. }
  366. })
  367. },
  368. // 订单详情页
  369. payComplete(data){
  370. // 创建成功,跳转到订单详情页
  371. uni.redirectTo({
  372. url: "/pagesB/procureOrder/orderDetail?purchaseSn="+this.$store.state.vuex_tempOrderData.purchaseSn
  373. })
  374. },
  375. // 计算总款数、合计、数量
  376. getChooseHeji(){
  377. this.totalAmount = 0
  378. this.totalDiscount = 0
  379. this.subsidyAmount = 0
  380. this.totalCoupon = 0
  381. this.total = 0
  382. this.totalNum = 0
  383. this.list.forEach(key => {
  384. key.filter(item=>item.checked).forEach(item => {
  385. this.totalAmount += item.price * item.qty // 总金额
  386. this.totalNum += item.qty // 总数量
  387. this.total += 1 // 总款数
  388. // 有抵扣金额,且没有促销活动
  389. if(item.shopProductSubsidy&&!item.shopPromoProduct){
  390. this.subsidyAmount += (item.shopProductSubsidy.subsidyAmount||0) * item.qty
  391. }
  392. // 如果是返券类型
  393. if(item.promoType=='BUY_PROD_GIVE_VALID'){
  394. this.totalCoupon += item.resultValue * item.qty
  395. }
  396. // 特价
  397. if(item.promoType=='PROMO_PROD'){
  398. this.totalDiscount += (item.orginPrice - item.conditionValue) * item.qty
  399. }
  400. // 满赠
  401. item.giftQty = item.promoType=='BUY_PROD_GIVE_PROD' ? Math.floor(item.qty / item.conditionValue)*item.resultValue : 0
  402. })
  403. })
  404. // 总可抵扣金额有余额支付权限,且抵扣金额小于等于抵扣余额
  405. this.hasKdk = this.subsidyAmount>0&&this.storeAccount&&this.subsidyAmount<=this.storeAccount.giveBalance&&this.showBalanceAuth
  406. },
  407. }
  408. }
  409. </script>
  410. <style lang="less">
  411. .pages{
  412. height: 100vh;
  413. display: flex;
  414. flex-direction: column;
  415. .cart-body{
  416. position: relative;
  417. flex-grow: 1;
  418. display: flex;
  419. flex-direction: column;
  420. .cart-head{
  421. display: flex;
  422. justify-content: space-between;
  423. align-items: center;
  424. padding: 0 20rpx;
  425. background-color: #FFFFFF;
  426. height: 40px;
  427. .cart-head-left{
  428. display: flex;
  429. align-items: center;
  430. font-size: 28rpx;
  431. color: #333333;
  432. height: 100%;
  433. }
  434. .cart-head-right{
  435. display: flex;
  436. align-items: center;
  437. font-size: 24rpx;
  438. color: #666;
  439. height: 100%;
  440. text{
  441. color: #d81e06;
  442. margin: 0 10rpx;
  443. }
  444. }
  445. }
  446. .cart-list{
  447. flex-grow: 1;
  448. background-color: #F5F5F5;
  449. width: 100%;
  450. .loading-bar{
  451. text-align: center;
  452. padding: 10px 0;
  453. color: #999999;
  454. }
  455. .empty-bar{
  456. display: flex;
  457. flex-direction: column;
  458. align-items: center;
  459. justify-content: center;
  460. padding: 20px 0;
  461. margin-top: 20vh;
  462. image{
  463. width: 100px;
  464. height: 100px;
  465. }
  466. view{
  467. font-size: 14px;
  468. color: #999999;
  469. margin-top: 10px;
  470. }
  471. }
  472. .product-price{
  473. padding:0 6px;
  474. margin: 6px 0;
  475. > view{
  476. background: #fff;
  477. padding: 10px;
  478. border-radius: 10px;
  479. .product-price-item{
  480. display:flex;
  481. align-items: center;
  482. justify-content: space-between;
  483. padding: 6px 0;
  484. font-size: 24rpx;
  485. .price{
  486. color: #333;
  487. }
  488. &:last-child{
  489. font-size: 28rpx;
  490. justify-content: flex-end;
  491. .price{
  492. color: #d81e06;
  493. font-weight: bold;
  494. }
  495. }
  496. }
  497. }
  498. }
  499. }
  500. .cart-footer{
  501. width: 100%;
  502. background-color: #FFFFFF;
  503. .cart-footer-box{
  504. width: 100%;
  505. height: 100rpx;
  506. display: flex;
  507. justify-content: space-between;
  508. align-items: center;
  509. }
  510. .cart-footer-left{
  511. display: flex;
  512. align-items: baseline;
  513. padding: 0 20rpx 0 36rpx;
  514. font-size: 24rpx;
  515. }
  516. .cart-footer-left-price-num{
  517. display: flex;
  518. align-items: baseline;
  519. font-size: 24rpx;
  520. color: #d81e06;
  521. text{
  522. font-size: 36rpx;
  523. }
  524. }
  525. .cart-footer-right{
  526. padding: 0 20rpx;
  527. display: flex;
  528. align-items: center;
  529. justify-content: space-between;
  530. flex-grow:1;
  531. .cart-footer-right-button{
  532. display: flex;
  533. align-items: center;
  534. margin-left: 20rpx;
  535. text-align: right;
  536. .btns{
  537. border-radius: 100rpx;
  538. height: 36px;
  539. padding: 0 10px;
  540. min-width: 80px;
  541. }
  542. }
  543. }
  544. }
  545. }
  546. }
  547. </style>