creatOrder.vue 12 KB

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