creatOrder.vue 15 KB

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