creatOrder.vue 14 KB

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