|
@@ -74,7 +74,7 @@
|
|
|
</view> -->
|
|
|
<view class="cart-footer-right-button">
|
|
|
<button class="btns" :loading="loading" v-if="!editFlag" type="warn" size="mini" @click="settlement">去结算({{totalNum}})</button>
|
|
|
- <button v-else class="btns" type="warn" plain size="mini" @click="batchRemove">删除({{totalNum}})</button>
|
|
|
+ <button v-else class="btns" type="warn" plain size="mini" @click="batchRemove">删除({{totalSel}})</button>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
@@ -91,7 +91,7 @@
|
|
|
} from 'vuex'
|
|
|
import productItem from '@/pagesB/cart/productitem.vue'
|
|
|
import { getCartList, updateCart, deleteCart } from '@/api/cart.js'
|
|
|
- import { purchaseSave } from '@/api/purchase.js'
|
|
|
+ import { purchaseSave, purchaseCheck } from '@/api/purchase.js'
|
|
|
export default {
|
|
|
components:{
|
|
|
productItem
|
|
@@ -116,11 +116,12 @@
|
|
|
},
|
|
|
// 查询条件
|
|
|
pageNo: 1,
|
|
|
- pageSize: 5,
|
|
|
+ pageSize: 10000,
|
|
|
list: [],
|
|
|
total: 0,
|
|
|
totalAmount: 0,
|
|
|
totalNum: 0,
|
|
|
+ totalSel: 0,
|
|
|
editFlag: false,
|
|
|
allChecked: false,
|
|
|
screenWidth: 325,
|
|
@@ -167,29 +168,43 @@
|
|
|
this.status = "loading"
|
|
|
getCartList(params).then(res => {
|
|
|
if (res.status == 200) {
|
|
|
- const list = res.data.list
|
|
|
- const ret = []
|
|
|
- list.forEach(key => {
|
|
|
- ret.push({
|
|
|
- id: key.id,
|
|
|
- checked: this.allChecked,
|
|
|
- cartSn: key.cartSn,
|
|
|
- price: key.price,
|
|
|
- qty: key.qty,
|
|
|
- productSn: key.productSn,
|
|
|
- productName: key.productEntity.productName,
|
|
|
- productImage: key.productEntity.images,
|
|
|
- productCode: key.productEntity.code,
|
|
|
- productOrigCode: key.productEntity.origCode,
|
|
|
- unit: key.productEntity.unit,
|
|
|
- status: key.status,
|
|
|
- dealerScopeFlag: key.dealerScopeFlag
|
|
|
- })
|
|
|
- })
|
|
|
- _this.list.push(ret)
|
|
|
_this.total = res.data.count || 0
|
|
|
- _this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
|
|
|
- _this.noDataText = _this.total>=_this.list.length ? '没有更多了' : '加载更多'
|
|
|
+ const list = res.data.list
|
|
|
+ for(let i=0;i<list.length;i=i+10){
|
|
|
+ _this.list.push(list.slice(i,(i+10)>list.length?list.length:(i+10)).map(key=>{
|
|
|
+ return {
|
|
|
+ id: key.id,
|
|
|
+ checked: _this.allChecked,
|
|
|
+ cartSn: key.cartSn,
|
|
|
+ price: key.price,
|
|
|
+ qty: key.qty,
|
|
|
+ productSn: key.productSn,
|
|
|
+ productName: key.productEntity.productName,
|
|
|
+ productImage: key.productEntity.images,
|
|
|
+ productCode: key.productEntity.code,
|
|
|
+ productOrigCode: key.productEntity.origCode,
|
|
|
+ unit: key.productEntity.unit,
|
|
|
+ status: key.status,
|
|
|
+ dealerScopeFlag: key.dealerScopeFlag
|
|
|
+ }
|
|
|
+ }))
|
|
|
+ }
|
|
|
+
|
|
|
+ // 默认全选
|
|
|
+ if(_this.pageNo == 1){
|
|
|
+ _this.$nextTick(()=>{
|
|
|
+ _this.chooseAll()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // 判断是否最后一页
|
|
|
+ const maxPages = Math.ceil(_this.total / _this.pageSize)
|
|
|
+ if(this.pageNo >= maxPages){
|
|
|
+ _this.status = 'nomore'
|
|
|
+ _this.noDataText = '没有更多了'
|
|
|
+ }else{
|
|
|
+ _this.status = 'loadmore'
|
|
|
+ _this.noDataText = '加载更多'
|
|
|
+ }
|
|
|
} else {
|
|
|
_this.list = []
|
|
|
_this.total = 0
|
|
@@ -297,13 +312,13 @@
|
|
|
}
|
|
|
this.allChecked = !this.allChecked
|
|
|
this.list.forEach(key => {
|
|
|
- // 编辑模式
|
|
|
+ // 非编辑模式
|
|
|
if(!this.editFlag){
|
|
|
key.filter(item=>item.status == 1 && item.dealerScopeFlag == 1).forEach(item => {
|
|
|
item.checked = this.allChecked
|
|
|
})
|
|
|
}else{
|
|
|
- // 非编辑模式
|
|
|
+ // 编辑模式
|
|
|
key.forEach(item => {
|
|
|
item.checked = this.allChecked
|
|
|
})
|
|
@@ -351,23 +366,21 @@
|
|
|
})
|
|
|
|
|
|
// 删除购物车
|
|
|
- _this.removeCart(snList,true)
|
|
|
+ _this.removeCart(snList,true,true)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
// 删除商品
|
|
|
- removeCart(snList,isBatch){
|
|
|
+ removeCart(snList,isBatch,isTip){
|
|
|
const _this = this
|
|
|
- uni.showLoading({
|
|
|
- title: '删除中'
|
|
|
- })
|
|
|
+ if(isTip){
|
|
|
+ uni.showLoading({
|
|
|
+ title: '删除中'
|
|
|
+ })
|
|
|
+ }
|
|
|
deleteCart({cartSns:snList}).then(ret => {
|
|
|
if(ret.status == 200){
|
|
|
- uni.showToast({
|
|
|
- title: '删除成功',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
snList.forEach(sn => {
|
|
|
_this.removeChoose(sn,isBatch)
|
|
|
})
|
|
@@ -377,6 +390,12 @@
|
|
|
// 判断是否全选
|
|
|
_this.isAllChecked()
|
|
|
}
|
|
|
+ if(isTip){
|
|
|
+ uni.showToast({
|
|
|
+ title: '删除成功',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
uni.hideLoading()
|
|
|
})
|
|
@@ -398,45 +417,61 @@
|
|
|
// 获取已选商品
|
|
|
const detailList = []
|
|
|
const cartSn = []
|
|
|
- const soldOutSn = []
|
|
|
- const sellOutSn = []
|
|
|
- this.list.forEach(key => {
|
|
|
+ _this.list.forEach(key => {
|
|
|
key.filter(item=>item.checked).forEach(item => {
|
|
|
- // 已下架产品提示
|
|
|
- if(item.status == 0){
|
|
|
- soldOutSn.push(item.productCode)
|
|
|
- }
|
|
|
- //售罄产品提示
|
|
|
- else if(item.dealerScopeFlag == 0){
|
|
|
- sellOutSn.push(item.productCode)
|
|
|
- }else{
|
|
|
- detailList.push({
|
|
|
- productSn:item.productSn,
|
|
|
- productCode:item.productCode,
|
|
|
- qty: item.qty,
|
|
|
- price:item.price,
|
|
|
- })
|
|
|
- cartSn.push(item.cartSn)
|
|
|
- }
|
|
|
+ detailList.push({
|
|
|
+ productSn:item.productSn,
|
|
|
+ productCode:item.productCode,
|
|
|
+ qty: item.qty,
|
|
|
+ price:item.price,
|
|
|
+ })
|
|
|
+ cartSn.push({
|
|
|
+ cartSn: item.cartSn,
|
|
|
+ productSn:item.productSn
|
|
|
+ })
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- // 提示信息
|
|
|
- if(soldOutSn.length || sellOutSn.length){
|
|
|
- uni.showModal({
|
|
|
- title: '提示',
|
|
|
- content: (soldOutSn.length ? `产品${soldOutSn.join(',')}已下架,`:'')+(sellOutSn.length?`产品${sellOutSn.join(',')}已售罄,`:'')+`不可采购。是否继续采购其他产品?`,
|
|
|
- success(res) {
|
|
|
- if(res.confirm){
|
|
|
- _this.submitForm(detailList,cartSn)
|
|
|
+ // 校验并提示信息
|
|
|
+ purchaseCheck({detailList:detailList}).then(res => {
|
|
|
+ if(res.status == 200){
|
|
|
+ const successList = res.data.successList.map(item => {
|
|
|
+ return {
|
|
|
+ productSn:item.productSn,
|
|
|
+ productCode: item.productCode,
|
|
|
+ qty: item.qty,
|
|
|
+ price:item.price
|
|
|
}
|
|
|
+ })
|
|
|
+ const delSn = cartSn.filter(item => successList.find(k => k.productSn == item.productSn)).map(item => item.cartSn)
|
|
|
+ const removeList = res.data.removeList.map(item => item.productCode)
|
|
|
+ const selloutList = res.data.selloutList.map(item => item.productCode)
|
|
|
+ console.log(successList,delSn)
|
|
|
+ console.log(removeList,selloutList)
|
|
|
+ // 有已下架或已售罄产品提示
|
|
|
+ if(removeList.length || selloutList.length){
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: (removeList.length ? `产品${removeList.join(',')}已下架,`:'')+(selloutList.length?`产品${selloutList.join(',')}已售罄,`:'')+`不可采购。`+(successList.length?'是否继续采购其他产品?':''),
|
|
|
+ showCancel: successList.length,
|
|
|
+ confirmText: successList.length?'确定':'只知道了',
|
|
|
+ success(ret) {
|
|
|
+ if(ret.confirm && successList.length){
|
|
|
+ _this.submitForm(successList,delSn)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ // 提交
|
|
|
+ _this.submitForm(successList,delSn)
|
|
|
}
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 提交
|
|
|
- this.submitForm(detailList,cartSn)
|
|
|
+ }else{
|
|
|
+ uni.showToast({
|
|
|
+ title: res.message,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
// 确认提交
|
|
|
submitForm(detailList,cartSn){
|
|
@@ -452,7 +487,7 @@
|
|
|
uni.hideLoading()
|
|
|
if(res.status == 200){
|
|
|
// 删除已提交产品
|
|
|
- this.removeCart(cartSn,true)
|
|
|
+ this.removeCart(cartSn,true,false)
|
|
|
res.data.detailList = []
|
|
|
this.$store.state.vuex_tempData = res.data
|
|
|
uni.navigateTo({
|
|
@@ -470,10 +505,12 @@
|
|
|
getChooseHeji(){
|
|
|
this.totalAmount = 0
|
|
|
this.totalNum = 0
|
|
|
+ this.totalSel = 0
|
|
|
this.list.forEach(key => {
|
|
|
key.filter(item=>item.checked).forEach(item => {
|
|
|
this.totalAmount += item.price * item.qty // 总金额
|
|
|
this.totalNum += item.qty // 总数量
|
|
|
+ this.totalSel += 1 // 已选数量
|
|
|
})
|
|
|
})
|
|
|
},
|