creatOrder.vue 11 KB

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