Prechádzať zdrojové kódy

新增 销售编辑页编辑产品功能

chenrui 3 rokov pred
rodič
commit
6e9df05fbf
1 zmenil súbory, kde vykonal 125 pridanie a 41 odobranie
  1. 125 41
      pages/sales/edit.vue

+ 125 - 41
pages/sales/edit.vue

@@ -49,30 +49,32 @@
 			<!-- 产品列表 -->
 			<view class="sales-list-box">
 				<scroll-view class="sales-list-con" :style="{height: scrollH+'upx'}" scroll-y @scrolltolower="onreachBottom">
-					<view class="sales-list-item border-b font_13 flex justify_between" v-for="(item, index) in listData" :key="item.id">
-						<view class="pimgs">
-							<u-image :src="item.productMainImage?item.productMainImage:`../../static/${theme}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
-							<view v-if="item.oosFlag == 1" class="sign" :style="{backgroundColor: $config('errorColor')}">急</view>
-							<view v-if="item.price < item.cost" class="sign" :style="{backgroundColor: $config('errorColor')}">亏</view>
-							<view v-if="item.price == 0" class="sign" :style="{backgroundColor: $config('errorColor')}">赠</view>
-						</view>
-						<view class="sales-item-main flex_1">
-							<view class="sales-item-name">{{item.productName || '--'}}</view>
-							<view class="sales-item-txt flex align_center justify_between">
-								<view>{{item.productCode || '--'}}</view>
-								<u-icon v-if="pageData.type=='edit'" @click="handleDel(item)" name="trash-fill" :color="$config('errorColor')" size="34"></u-icon>
+					<view class="sales-list-item border-b flex align_center justify_between" v-for="(item, index) in listData" :key="item.id">
+						<view class="font_13 flex_1 flex justify_between" @click="handleEdit(item)">
+							<view class="pimgs">
+								<u-image :src="item.productMainImage?item.productMainImage:`../../static/${theme}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
+								<view v-if="item.oosFlag == 1" class="sign" :style="{backgroundColor: $config('errorColor')}">急</view>
+								<view v-if="item.price < item.cost" class="sign" :style="{backgroundColor: $config('errorColor')}">亏</view>
+								<view v-if="item.price == 0" class="sign" :style="{backgroundColor: $config('errorColor')}">赠</view>
 							</view>
-							<view class="sales-item-txt color_6" style="font-size: 24upx;" v-if="item.warehouseEntity&&item.warehouseEntity.name || item.warehouseLocationEntity&&item.warehouseLocationEntity.name">{{item.warehouseEntity&&item.warehouseEntity.name}} > {{item.warehouseLocationEntity&&item.warehouseLocationEntity.name}}</view>
-							<view class="sales-item-txt flex align_center justify_between">
-								<view class="sales-item-priceInfo">
-									<view :style="{color: $config('errorColor'), display: 'inline-block'}">¥<text style="font-size: 30upx;">{{toThousands(item.price||0, 2)}}</text></view>
-									<text style="display: inline-block;margin: 0 10upx;">*</text> 
-									<text style="font-size: 30upx;">{{toThousands(item.qty||0)}}</text>
-									{{item.productUnit}}
+							<view class="sales-item-main flex_1">
+								<view class="sales-item-name">{{item.productName || '--'}}</view>
+								<view class="sales-item-txt">{{item.productCode || '--'}}</view>
+								<view class="sales-item-txt color_6" style="font-size: 24upx;" v-if="item.warehouseEntity&&item.warehouseEntity.name || item.warehouseLocationEntity&&item.warehouseLocationEntity.name">{{item.warehouseEntity&&item.warehouseEntity.name}} > {{item.warehouseLocationEntity&&item.warehouseLocationEntity.name}}</view>
+								<view class="sales-item-txt flex align_center justify_between">
+									<view class="sales-item-priceInfo">
+										<view :style="{color: $config('errorColor'), display: 'inline-block'}">¥<text style="font-size: 30upx;">{{toThousands(item.price||0, 2)}}</text></view>
+										<text style="display: inline-block;margin: 0 10upx;">*</text> 
+										<text style="font-size: 30upx;">{{toThousands(item.qty||0)}}</text>
+										{{item.productUnit}}
+									</view>
+									<view class="sales-item-price">¥{{toThousands(item.totalAmount||0, 2)}}</view>
 								</view>
-								<view class="sales-item-price">¥{{toThousands(item.totalAmount||0, 2)}}</view>
+								<view class="sales-item-price" v-if="detailData&&detailData.discountAmount">折后¥{{toThousands(item.discountedAmount||0, 2)}}</view>
 							</view>
-							<view class="sales-item-price" v-if="detailData&&detailData.discountAmount">折后¥{{toThousands(item.discountedAmount||0, 2)}}</view>
+						</view>
+						<view class="btn-box">
+							<u-icon v-if="pageData.type=='edit'" @click="handleDel(item)" name="trash-fill" :color="$config('errorColor')" size="34"></u-icon>
 						</view>
 					</view>
 					<view v-if="listData && listData.length == 0">
@@ -94,7 +96,9 @@
 		<!-- 折扣 -->
 		<discountModal :openModal="discountModal" :infoData="detailData" :amount="detailData&&detailData.discountAmount" @confirm="discountConfirm" @close="discountModal=false" />
 		<!-- 删除产品/整单删除弹框 -->
-		<common-modal :openModal="delModal" :content="delText" @confirm="handleConfirm" @close="delModal=false" />
+		<common-modal :openModal="commonModal" :content="modalText" @confirm="handleCommon" @cancel="handleCancel" @close="commonModal=false" />
+		<!-- 添加/编辑产品 -->
+		<productModal :openModal="openProductModal" :infoData="productInfo" @confirm="productConfirm" @close="openProductModal=false" />
 	</view>
 </template>
 
@@ -102,10 +106,12 @@
 	import commonModal from '@/pages/common/commonModal.vue'
 	import OrderInfoModal from './orderInfoModal.vue'
 	import DiscountModal from './discountModal.vue'
+	import ProductModal from './productModal.vue'
 	import { toThousands } from '@/libs/tools'
-	import { salesDetailList, salesDetailDel, salesDel, salesDetail, salesSubmit, salesDiscount } from '@/api/sales'
+	import { stockByProductSn } from '@/api/stock'
+	import { salesDetailList, salesDetailDel, salesDel, salesDetail, salesSubmit, salesDiscount, salesDetailUpdate } from '@/api/sales'
 	export default{
-		components: { OrderInfoModal, DiscountModal, commonModal },
+		components: { OrderInfoModal, DiscountModal, commonModal, ProductModal },
 		data(){
 			return{
 				pageData: {
@@ -128,10 +134,14 @@
 				scrollH: 916,
 				infoModal: false,
 				discountModal: false,
-				delModal: false,
-				delText: '确认要删除吗?',
-				dataInfo: null,
-				detailData: null  // 销售单详情
+				commonModal: false,
+				modalText: '确认要删除吗?',
+				detailData: null,  // 销售单详情
+				openProductModal: false,  // 编辑产品信息弹框是否显示
+				productData: null,  // 当前操作的产品信息
+				productInfo: null,  // 编辑产品需要的参数
+				editInfo: null,  // 添加/编辑 提交的值
+				commonType: 1,  // 公共弹框类型  1删除产品,2删除销售单,3编辑产品时库存不足
 			}
 		},
 		onLoad(opt) {
@@ -220,32 +230,103 @@
 					}
 				})
 			},
+			// 编辑
+			handleEdit(data){
+				this.productInfo = {
+					productName: data.productName,
+					productMainImage: data.productMainImage,
+					productCode: data.productCode,
+					productOrigCode: data.productOrigCode,
+					warehouseName: data.warehouseEntity && data.warehouseEntity.name,
+					warehouseLocationName: data.warehouseLocationEntity && data.warehouseLocationEntity.name,
+					price: data.price,
+					qty: data.qty
+				}
+				this.openProductModal = true
+				this.productData = data
+			},
+			// 确认产品信息
+			productConfirm(data){
+				this.editInfo = data
+				this.validateStock()  //验证  库存是否不足
+			},
+			// 库存不足
+			validateStock(){
+				//  校验库存
+				stockByProductSn({ productSn: this.productData.productSn }).then(res => {
+					if (res.status == 200) {
+						if (res.data && (!res.data.currentStockQty || this.editInfo.qty <= res.data.currentStockQty)) {
+							this.editProduct()
+						} else {  // 库存不足
+							this.commonType = 3
+							this.modalText = '库存不足,将产生急件,确认修改吗?'
+							this.commonModal = true
+						}
+					}
+				})
+			},
+			// 编辑产品
+			editProduct(){
+				let params = {
+					id: this.productData.id,
+					qty: this.editInfo.qty,
+					price: this.editInfo.price,
+					productSn: this.productData.productSn,
+					salesBillSn: this.detailData.salesBillSn,
+				}
+				salesDetailUpdate(params).then(res => {
+					if(res.status == 200){
+						this.toashMsg(res.message)
+						this.init()
+						this.commonModal = false
+						this.openProductModal = false
+					}
+				})
+			},
 			// 删除
 			handleDel(item){
 				if(item){  // 删除产品
-					this.dataInfo = item
-					this.delText = '确认要删除吗?'
-					this.delModal = true
+					this.commonType = 1
+					this.productData = item
+					this.modalText = '确认要删除吗?'
+					this.commonModal = true
 				}else{  // 整单删除
-					this.dataInfo = null
-					this.delText = '确认删除该销售单吗?'
-					this.delModal = true
+					this.commonType = 2
+					this.productData = null
+					this.modalText = '确认删除该销售单吗?'
+					this.commonModal = true
+				}
+			},
+			// 公共弹框  确定
+			handleCommon(){
+				if(this.commonType == 1){  // 删除产品
+					this.delFun()
+				}else if(this.commonType == 2){  // 整单删除
+					this.delFun()
+				}else if(this.commonType == 3){  // 编辑产品时库存不足
+					this.editProduct()
 				}
 			},
+			// 公共弹框  取消
+			handleCancel(){
+				this.openProductModal = false
+			},
 			// 删除
-			handleConfirm(){
+			delFun(){
 				let url = salesDetailDel
 				let params = {}
-				if(this.dataInfo){  // 删除产品
+				console.log(this.commonType)
+				if(this.commonType == 1){  // 删除产品
 					url = salesDetailDel
-					params = { id: this.dataInfo.id }
-				}else{  // 整单删除
+					params = { id: this.productData.id }
+				}else if(this.commonType == 2){  // 整单删除
+					console.log('整单删除', this.detailData)
 					url = salesDel
 					params = { id: this.detailData && this.detailData.id }
 				}
 				url(params).then(res => {
 					if (res.status == 200) {
-						if(this.dataInfo){  // 删除产品
+						if(this.productData){  // 删除产品
 							this.toashMsg(res.message)
 							this.init()
 						}else{  // 整单删除
@@ -253,9 +334,9 @@
 							uni.$emit('refreshBL')
 							uni.navigateBack()
 						}
-						this.delModal = false
+						this.commonModal = false
 					} else {
-						this.delModal = false
+						this.commonModal = false
 					}
 				})
 			},
@@ -404,6 +485,9 @@
 								text-align: right;
 							}
 						}
+						.btn-box{
+							padding: 30upx 30upx;
+						}
 					}
 					.sales-list-item:last-child{
 						border: none;