Преглед на файлове

销售 添加删除产品

chenrui преди 3 години
родител
ревизия
9dfd6ce71a
променени са 2 файла, в които са добавени 60 реда и са изтрити 12 реда
  1. 59 11
      pages/sales/chooseProduct.vue
  2. 1 1
      pages/sales/selectedProductsModal.vue

+ 59 - 11
pages/sales/chooseProduct.vue

@@ -63,7 +63,7 @@
 		<!-- 添加/编辑产品 -->
 		<productModal :openModal="openProductModal" :infoData="productInfo" @confirm="productConfirm" @close="openProductModal=false" />
 		<!-- 已选产品 -->
-		<selectedProductsModal ref="selectedProducts" :openModal="openSelectedModal" :nowData="detailData" @edit="handleEdit" @confirm="handleChoose" @delete="init" @close="openSelectedModal=false" />
+		<selectedProductsModal ref="selectedProducts" :openModal="openSelectedModal" :nowData="detailData" @edit="handleEdit" @confirm="handleChoose" @delete="handleDel" @close="openSelectedModal=false" />
 		<!-- 弹框 -->
 		<common-modal :openModal="commonModal" :content="modalText" @confirm="handleCommon" @cancel="handleCancel" @close="commonModal=false" />
 	</view>
@@ -76,7 +76,7 @@
 	import commonModal from '@/pages/common/commonModal.vue'
 	import { toThousands } from '@/libs/tools'
 	import { querySumByProductLocation, stockByProductSn } from '@/api/stock'
-	import { salesDetail, supperCodeByVin, salesDetailInsert, salesDetailUpdate } from '@/api/sales'
+	import { salesDetail, supperCodeByVin, salesDetailInsert, salesDetailUpdate, salesDetailList } from '@/api/sales'
 	export default{
 		components: { ProductSearch, ProductModal, SelectedProductsModal, commonModal },
 		data(){
@@ -195,7 +195,6 @@
 			},
 			// 添加/编辑产品
 			handleAdd(data, type){
-				console.log(data)
 				if(type == 'add'){
 					this.productInfo = {
 						productName: data.productName,
@@ -225,7 +224,6 @@
 			},
 			// 已选产品  编辑
 			handleEdit(data){
-				console.log(data)
 				this.handleAdd(data, 'edit')
 			},
 			// 选好了
@@ -269,8 +267,6 @@
 					//  校验库存
 					stockByProductSn({ productSn: this.productData.productSn }).then(res => {
 						if (res.status == 200) {
-							console.log(!res.data.currentStockQty, this.editInfo.qty <= res.data.currentStockQty)
-							console.log(!res.data.currentStockQty || this.editInfo.qty <= res.data.currentStockQty)
 							if (res.data && (!res.data.currentStockQty || this.editInfo.qty <= res.data.currentStockQty)) {
 								this.editProduct()
 							} else {  // 库存不足
@@ -309,7 +305,7 @@
 				salesDetailInsert(params).then(res => {
 					if(res.status == 200){
 						this.toashMsg(res.message)
-						this.changeList(params)  // 变更  列表产品可选状态
+						this.changeList('add', params)  // 变更  列表产品可选状态
 						this.selectedProductTotal()  // 已选产品合计
 						this.commonModal = false
 						this.openProductModal = false
@@ -329,6 +325,7 @@
 					if(res.status == 200){
 						this.toashMsg(res.message)
 						this.$refs.selectedProducts.getList(1)
+						this.changeList('add', params)  // 变更  列表产品可选状态
 						this.selectedProductTotal()  // 已选产品合计
 						this.commonModal = false
 						this.openProductModal = false
@@ -336,13 +333,64 @@
 				})
 			},
 			// 更改产品列表参数
-			changeList(params){
-				this.listData.map(item => {
-					if((item.stockSn == params.stockSn) && (item.warehouseLocationSn == params.warehouseLocationSn)){
-						item.saleQty = 1  // 非0即可,用于判断是否显示添加产品按钮
+			changeList(type, obj){
+				const _this = this
+				// 查询已选产品列表中产品编码一致的产品,则为需要变更“已添加”状态的产品
+				let params = {
+					pageNo: 1,
+					pageSize: 100,
+					salesBillSn: this.detailData.salesBillSn,
+					productSn: obj.productSn
+				}
+				salesDetailList(params).then(res => {
+					if(res.status == 200){
+						if(res.data && res.data.list){
+							let listArr = []
+							let listInd = []
+							this.listData.filter(function(item, index){
+								if(item.productSn == obj.productSn){
+									listArr.push(item)
+									listInd.push(index)
+								}
+							})
+							let chooseList = res.data.list || []
+							if(type == 'add'){
+								console.log('添加', chooseList,'++',listArr)
+								listArr.map((subItem, subInd) => {
+									chooseList.map(item => {  // 已选产品 产品sn一致的数据
+										if(subItem.productSn == item.productSn && subItem.warehouseLocationSn == item.warehouseLocationSn){
+											_this.$nextTick(() => {
+												_this.listData[listInd[subInd]].saleQty = 1  // 非0即可,用于判断是否显示添加产品按钮
+											})
+										}
+									})
+								})
+							}else if(type == 'del'){
+								console.log('删除', chooseList,'++',listArr)
+								listArr.map((subItem, subInd) => {
+									_this.$nextTick(() => {
+										_this.listData[listInd[subInd]].saleQty = 0  // 非0即可,用于判断是否显示添加产品按钮
+									})
+								})
+								listArr.map((subItem, subInd) => {
+									chooseList.map(item => {  // 已选产品 产品sn一致的数据
+										if(subItem.productSn == item.productSn && subItem.warehouseLocationSn == item.warehouseLocationSn){
+											_this.$nextTick(() => {
+												_this.listData[listInd[subInd]].saleQty = 1  // 非0即可,用于判断是否显示添加产品按钮
+											})
+										}
+									})
+								})
+								this.selectedProductTotal()  // 更新产品款数
+							}
+						}
 					}
 				})
 			},
+			// 删除已选产品
+			handleDel(data){
+				this.changeList('del', data)  // 变更  列表产品可选状态
+			},
 			// 公共弹框  确定
 			handleCommon(){
 				if(this.commonType == 1){  // 添加产品时售价低于定价

+ 1 - 1
pages/sales/selectedProductsModal.vue

@@ -135,7 +135,7 @@
 					if(res.status == 200){
 						this.listData.splice(this.infoData.no, 1)
 						this.commonModal = false
-						this.$emit('delete')
+						this.$emit('delete', this.infoData)
 					}
 				})
 			},