creatOrder.vue 13 KB

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