creatOrder.vue 14 KB

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