ソースを参照

检测数据获取和展示价格逻辑修改

cyy 4 時間 前
親
コミット
2b328e3e78
2 ファイル変更、115 行追加、8 行削除
  1. 56 4
      pages/jiance/order.vue
  2. 59 4
      pages/jiance/order/lhypbMessage.vue

+ 56 - 4
pages/jiance/order.vue

@@ -179,7 +179,7 @@
 
 		<u-popup v-model="lhypbShow" mode="bottom" height="80%" border-radius="20">
 			<view>
-				<lhypb-message ref="lhypbMessage" :type="lhypbIndexData" :jianCeTypeList="jianCeTypeList" :taoCanShow="taoCanShow" :heTongId="form.heTongId" :itemType="itemType" :chuJuBaoGaoYaoQiu="form.chuJuBaoGaoYaoQiu" @deletClick="deletClick" @sumbitSingClick="sumbitSingClick" @getParentContent="getJianXiangData">
+				<lhypb-message ref="lhypbMessage" :type="lhypbIndexData" :jianCeTypeList="jianCeTypeList" :taoCanShow="taoCanShow" :heTongId="form.heTongId" :itemType="itemType" :chuJuBaoGaoYaoQiu="form.chuJuBaoGaoYaoQiu" @deletClick="deletClick" @sumbitSingClick="sumbitSingClick" @getParentContent="getJianXiangData" @refreshJianCe="refreshJianCe">
 				</lhypb-message>
 			</view>
 		</u-popup>
@@ -743,7 +743,9 @@
 				}
 			},
 			//根据合同id选择检测项目
-			getJiance(id, type, weiTouId) {
+			//isRefresh: 是否为刷新模式(刷新时重建检测类型,并保留已勾选状态)
+			//callback: 数据更新完成后的回调(回传最新的检测项目与检测类型)
+			getJiance(id, type, weiTouId, isRefresh = false, callback) {
 				let sql =
 					`select tw.*,tb.zhe_hou_jia_ge_,tb.xiang_mu_dan_jia_ from t_htjcxmjmb tb left join t_mjjcnlfw tw on tb.jian_ce_xiang_mu_ = tw.id_ and tb.shi_fou_you_xiao_='有效' where tb.parent_id_ = '${id}' and tw.xiang_mu_bian_hao not like '%/%' order by tw.nodekey1_ asc`
 				let requestData = this.$sig(sql)
@@ -751,6 +753,17 @@
 					if (res.data.state == 200) {
 						let result = res.data.variables.data
 						if (result.length > 0) {
+							//刷新时记录已勾选的项目,刷新后保持勾选状态
+							let checkedIds = []
+							if (isRefresh) {
+								this.jianCeList.forEach(it => {
+									if (it.checked) {
+										checkedIds.push(it.id_)
+									}
+								})
+								//刷新时重建检测类型,保证能拿到最新加入的检测类型
+								this.jianCeTypeList = []
+							}
 
 							result.forEach((item, index) => {
 
@@ -780,15 +793,24 @@
 							})
 							result.forEach((item, index) => {
 								item.zhe_hou_jia_ge_ = (parseFloat(item.zhe_hou_jia_ge_)).toFixed(2)
-								this.$set(item, 'checked', false)
+								this.$set(item, 'checked', checkedIds.indexOf(item.id_) > -1)
 							})
 							this.jianCeList = result
 
 							if (type != "") {
 								this.getYangPin(weiTouId)
 							}
+
+							if (typeof callback === 'function') {
+								callback(this.jianCeList, this.jianCeTypeList)
+							}
 						} else {
-							meth.getPrompt('该合同没有检测项目')
+							if (!isRefresh) {
+								meth.getPrompt('该合同没有检测项目')
+							}
+							if (typeof callback === 'function') {
+								callback([], this.jianCeTypeList)
+							}
 						}
 					}
 				});
@@ -1441,6 +1463,36 @@
 			deletClick() {
 				this.lhypbShow = false
 			},
+			//样品弹窗点击检测类型选择时,重新获取最新的检测项目数据
+			refreshJianCe(callback) {
+				if (!this.form.heTongId) {
+					if (typeof callback === 'function') {
+						callback(this.jianCeList, this.jianCeTypeList)
+					}
+					return
+				}
+				this.getJiance(this.form.heTongId, '', '', true, (list, typeList) => {
+					//同步所有样品的检测项目,保留各自已勾选状态
+					if (list && list.length > 0) {
+						this.form.lhypb.forEach(sample => {
+							if (!sample.jianCeList) {
+								return
+							}
+							let oldList = sample.jianCeList
+							let newArr = JSON.parse(JSON.stringify(list))
+							newArr.forEach(it => {
+								let old = oldList.find(o => o.id_ == it.id_)
+								it.checked = old ? !!old.checked : false
+							})
+							sample.jianCeList = newArr
+						})
+						this.getTotal()
+					}
+					if (typeof callback === 'function') {
+						callback(list, typeList)
+					}
+				})
+			},
 			//样品保存返回数据保存到样品表上,修改样品对对应的样品表
 			sumbitSingClick(item) {
 				if (this.lhypbIndexData == 'add') {

+ 59 - 4
pages/jiance/order/lhypbMessage.vue

@@ -84,7 +84,7 @@
 									<view class="l-info" @click.stop="getSty(item)">
 										<view class="l-address-desc">
 											{{item.xiang_mu_bian_hao || ''}}-{{item.jian_ce_xiang_mu_ || ''}}
-											<text style="color: red;">[{{item.zhe_hou_jia_ge_ || '0'}}元]</text>
+											<text style="color: red;">[{{getShowPrice(item)}}元]</text>
 										</view>
 										<view class="l-userinfo">
 											检测类别:
@@ -140,7 +140,7 @@
 							<view class="jiancexiangm">
 								<view>
 									{{it.jian_ce_lei_bie_ || ''}}-{{it.jian_ce_xiang_mu_ || ''}}
-									<text style="color: red;">[{{it.zhe_hou_jia_ge_ || '0'}}元]</text>
+									<text style="color: red;">[{{getShowPrice(it)}}元]</text>
 								</view>
 								<view>{{it.yi_ju_de_biao_zhu || ''}}</view>
 							</view>
@@ -335,7 +335,7 @@
 									<view class="l-info" @click.stop="getSty(item)">
 										<view class="l-address-desc">
 											{{item.xiang_mu_bian_hao || ''}}-{{item.jian_ce_xiang_mu_ || ''}}
-											<text style="color: red;">[{{item.zhe_hou_jia_ge_ || '0'}}元]</text>
+											<text style="color: red;">[{{getShowPrice(item)}}元]</text>
 										</view>
 										<view class="l-userinfo">
 											检测类别:
@@ -469,6 +469,34 @@
 			getInit(data) {
 				this.form = JSON.parse(JSON.stringify(data))
 			},
+			//显示价格:折扣后价格为NaN时,取项目单价;若单价也无效则显示0
+			//统一保留两位小数,避免整数出现".00"与无小数混排的情况
+			getShowPrice(item) {
+				let zheHou = item.zhe_hou_jia_ge_
+				if (this.isValidPrice(zheHou)) {
+					return this.formatPrice(zheHou)
+				}
+				let danJia = item.xiang_mu_dan_jia_
+				if (this.isValidPrice(danJia)) {
+					return this.formatPrice(danJia)
+				}
+				return this.formatPrice(0)
+			},
+			//判断价格是否为有效数字(排除NaN、null、空值、非数字文本)
+			isValidPrice(val) {
+				if (val === null || val === undefined || val === '') {
+					return false
+				}
+				return !isNaN(parseFloat(val))
+			},
+			//价格格式化,统一保留两位小数
+			formatPrice(val) {
+				let num = parseFloat(val)
+				if (isNaN(num)) {
+					return '0.00'
+				}
+				return num.toFixed(2)
+			},
 			//样品类型
 			getYplxb() {
 				let sql =
@@ -618,7 +646,12 @@
 					this.list = this.dispositionList
 				}
 				if (type == 'jianCeType') {
-					this.list = this.jianCeTypeList
+					//点击检测类型选择时,重新获取最新的检测项目数据(含后来新增的检测类型)
+					this.refreshJianCe((typeList) => {
+						this.list = typeList && typeList.length > 0 ? typeList : this.jianCeTypeList
+						this.$refs['picker'].show();
+					})
+					return
 				}
 
 				if (type.includes('specification') || type.includes('yangpinType') || type == 'jianCeType') {
@@ -628,6 +661,28 @@
 				}
 
 			},
+			//请求父组件重新获取检测项目数据
+			refreshJianCe(callback) {
+				this.$emit('refreshJianCe', (list, typeList) => {
+					if (list && list.length > 0) {
+						this.updateJianCeList(list)
+					}
+					if (typeof callback === 'function') {
+						callback(typeList && typeList.length > 0 ? typeList : this.jianCeTypeList)
+					}
+				})
+			},
+			//更新当前样品的检测项目,保留已勾选状态
+			updateJianCeList(newList) {
+				let oldList = this.form.jianCeList || []
+				let newArr = JSON.parse(JSON.stringify(newList))
+				newArr.forEach(it => {
+					let old = oldList.find(o => o.id_ == it.id_)
+					it.checked = old ? !!old.checked : false
+				})
+				this.form.jianCeList = newArr
+				this.getTotal()
+			},
 			//弹出框初始化
 			selectConfirm(e) {
 				let that = this