creatOrder.vue 12 KB

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