creatOrder.vue 12 KB

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