华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
10 KiB

  1. import moment from 'moment'
  2. export default {
  3. dicts: [
  4. 'business_pztj',
  5. 'business_cctj',
  6. 'business_nddw',
  7. 'business_tjdw',
  8. 'business_yxqdw',
  9. 'business_rqcz',
  10. 'business_sp_jmdyzqdyp', //色谱-编号-准确度与精密度
  11. 'business_sp_nbgzy', //色谱-编号-内标工作液
  12. 'business_sp_zkgzy', //色谱-编号-质控工作液
  13. 'business_sp_bqgzy', //色谱-编号-标曲工作液
  14. 'business_sp_bzqxzkypzbb', //色谱-编号-标准曲线/质控样品制备表
  15. 'business_sp_tqhsl', //色谱-编号-提取回收率
  16. 'business_sp_qxwdx', //色谱-编号-全血稳定性
  17. 'business_sp_cbyhgzywdx', //色谱-编号-储备液和工作液稳定性
  18. 'business_sp_rxjzxy', //色谱-编号-溶血基质效应
  19. 'business_sp_jzxy', //色谱-编号-基质效应
  20. 'business_sp_xzxytyx', //色谱-编号-选择性与特异性
  21. 'business_sp_zdybs', //色谱-编号-最大样本数
  22. 'business_sp_xskkx', //色谱-编号-稀释可靠性
  23. 'business_sp_cbydb' //色谱-编号-储备液对比
  24. ],
  25. props: {
  26. templateData: {
  27. type: Object,
  28. default: () => {}
  29. }
  30. },
  31. watch: {
  32. templateData: {
  33. immediate: true,
  34. deep: true,
  35. handler(v) {
  36. if (v) {
  37. const {
  38. studyMc,
  39. studySn,
  40. templateMc,
  41. templateMcEn,
  42. templateSn,
  43. startDate,
  44. bdmc,
  45. endDate,
  46. id
  47. } = v
  48. if (v.resource) {
  49. //试验试剂信息
  50. this.resource = JSON.parse(v.resource)
  51. }
  52. if (v.bdnr) {
  53. this.formData = {
  54. ...JSON.parse(v.bdnr),
  55. studyMc,
  56. studySn,
  57. templateMc,
  58. templateMcEn,
  59. templateSn,
  60. startDate,
  61. bdmc,
  62. endDate,
  63. id
  64. }
  65. } else {
  66. this.formData = {
  67. studyMc,
  68. studySn,
  69. templateMc,
  70. templateMcEn,
  71. templateSn,
  72. startDate,
  73. bdmc,
  74. endDate,
  75. id
  76. }
  77. }
  78. const { effectivePeriod, effectivePeriodUnit, expireDate } =
  79. this.formData
  80. //实际填报的时候,如果有了开始时间,并且有有效周期,但是没有失效日,就计算失效日为开始时间+有效周期
  81. if (
  82. startDate &&
  83. this.fillType === 'actFill' &&
  84. effectivePeriod &&
  85. effectivePeriodUnit &&
  86. !expireDate
  87. ) {
  88. const start = moment(startDate)
  89. const end = start
  90. .add(Number(effectivePeriod), effectivePeriodUnit)
  91. .format('YYYY-MM-DD HH:mm:ss')
  92. this.formData = { ...this.formData, expireDate: end }
  93. }
  94. console.log(this.formData, 'formData from templateData')
  95. this.setTemplateData(v)
  96. }
  97. }
  98. }
  99. },
  100. data() {
  101. return {
  102. formData: {},
  103. templateDetail: {},
  104. resource: [], //试验试剂信息
  105. sysjColumns: [
  106. { label: '试剂名称', prop: 'reagentName' },
  107. { label: '编号', prop: 'reagentCode' },
  108. { label: '批号', prop: 'reagentNo' },
  109. { label: '浓度/含量/纯度', prop: 'concentration' },
  110. { label: '来源', prop: 'source' },
  111. { label: '失效日', prop: 'expireDate' }
  112. ],
  113. yqsColumns: [
  114. { label: '仪器名称', prop: 'instrumentName' },
  115. { label: '仪器型号', prop: 'instrumentModel' },
  116. { label: '仪器编号', prop: 'instrumentCode' },
  117. { label: '下次测试/校准/检定日期', prop: 'nextTestDate' }
  118. ]
  119. }
  120. },
  121. mounted() {},
  122. unmounted() {
  123. this.setTemplateData({})
  124. },
  125. methods: {
  126. getResource() {
  127. return this.resource
  128. },
  129. //根据ref数组获取直接formData
  130. getFilledFormDataByRefs(refArr = []) {
  131. let result = {}
  132. refArr.map((ref) => {
  133. const refData = this.$refs[ref]?.getFilledFormData() || {}
  134. result = { ...result, ...refData }
  135. })
  136. return result
  137. },
  138. //统一校验form表单是否填写
  139. async validFormFields(refArr = []) {
  140. let result = {}
  141. const refs = refArr.map((ref) => {
  142. let refData = {}
  143. if (this.$refs[ref][0]) {
  144. refData = this.$refs[ref][0]?.getFormData() || {}
  145. } else {
  146. refData = this.$refs[ref]?.getFormData() || {}
  147. }
  148. return refData
  149. })
  150. const validFormData = await Promise.all(refs).catch((err) => {
  151. // this.$message.error(err);
  152. if (err.errorType && err.errorType === 'step') {
  153. this.$message.error('请添加步骤')
  154. return
  155. }
  156. this.$message.error('表单内容未填完,请填写后再提交')
  157. })
  158. if (validFormData) {
  159. validFormData.forEach((item) => {
  160. for (const [key, value] of Object.entries(item)) {
  161. let index = 0
  162. // 如果当前键是可能重复的字段,且结果对象中已经存在该键,则添加索引后缀
  163. if (
  164. (key === 'headerSelectFields' || key === 'stepTableFormData') &&
  165. result.hasOwnProperty(key)
  166. ) {
  167. // 为重复字段生成带索引的键名,从1开始(因为第一个组件不需要后缀)
  168. const newKey = `${key}_${++index}`
  169. result[newKey] = value
  170. } else {
  171. // 正常合并其他字段
  172. result[key] = value
  173. }
  174. }
  175. })
  176. return result
  177. }
  178. return false
  179. },
  180. //试验配制条件options
  181. getDictOptions(dictType) {
  182. return this.dict.type[dictType] || []
  183. },
  184. setTemplateData(data) {
  185. this.$store.commit('template/SET_TEMPLATE_DATA', data)
  186. },
  187. //统一处理删除行
  188. deleteRow(index) {
  189. this.$refs.stepTableRef.deleteRow(index)
  190. },
  191. //统一处理blur事件,因为有效周期和过期日期是相关的,所以需要在有效周期失焦时更新过期日期
  192. onHandleBlur(fields) {
  193. const {
  194. key,
  195. effectivePeriodUnit,
  196. effectivePeriod,
  197. codeSTD,
  198. targetStartSolution
  199. } = fields
  200. const { startDate } = this.formData
  201. if (key === 'codeSTD') {
  202. //起始编号STD失焦时,更新stepDataSource
  203. const arr = Array.from({ length: codeSTD }, (item, index) => ({
  204. actSolutionVolumePrecision: 3, //小数点精度默认为3
  205. actSolutionConcentrationPrecision: 3, //小数点精度默认为3
  206. targetDiluentVolumePrecision: 3, //小数点精度默认为3
  207. targetStartSolutionVolumePrecision: 3, //小数点精度默认为3
  208. targetSolutionCode: `STD${Number(codeSTD) - index}`
  209. }))
  210. this.$refs.stepTableRef.updateDataSource(arr)
  211. } else if (key === 'targetStartSolution') {
  212. //起始溶液体积失焦时,更新目标溶液预计浓度
  213. const arr = this.$refs.stepTableRef?.getDataSource()
  214. arr.forEach((item, rowIndex) => {
  215. this.updateTargetStartSolutionVolume(
  216. rowIndex,
  217. item,
  218. targetStartSolution
  219. )
  220. })
  221. }
  222. },
  223. //统一处理table失焦事件
  224. onHandleTableBlur(params) {
  225. const { rowIndex, colKey, value, item } = params
  226. if (
  227. colKey === 'targetSolutionVolume' ||
  228. colKey === 'targetSolutionConcentration' ||
  229. colKey === 'targetStartSolutionVolumePrecision' ||
  230. colKey === 'targetDiluentVolumePrecision'
  231. ) {
  232. const volume =
  233. this.$refs.stepFormPackageRef?.getFormDataByKey(
  234. 'targetStartSolution'
  235. ) || 0
  236. if (volume) {
  237. this.updateTargetStartSolutionVolume(item, volume)
  238. }
  239. } else if (
  240. colKey === 'actStartSolutionVolume' ||
  241. colKey === 'actDiluentVolume'
  242. ) {
  243. //实际起始溶液体积和实际目标溶液体积
  244. const targetAcSolution =
  245. this.$refs.stepFormPackageRef?.getFormDataByKey('targetAcSolution') ||
  246. 0 //获取实际起始溶液浓度
  247. if (targetAcSolution) {
  248. this.updateSjmbrynd(item, targetAcSolution)
  249. }
  250. }
  251. },
  252. //计算并更新实际目标溶液浓度 先计算实际目标溶液体积再计算实际目标溶液浓度
  253. updateSjmbrynd(item, targetAcSolution) {
  254. //实际源溶液浓度÷(实际终体积÷源溶液加入体积);
  255. const precision = item.actSolutionConcentrationPrecision || 0
  256. const volPrecision = item.actSolutionVolumePrecision || 0
  257. //实际稀释液体积
  258. const actDiluentVolume = item.actDiluentVolume || 0
  259. const actStartSolutionVolume = item.actStartSolutionVolume || 0
  260. //实际高源溶液加入体积+实际稀释液加入体积
  261. const actVol = (
  262. Number(actStartSolutionVolume) + Number(actDiluentVolume)
  263. ).toFixed(volPrecision)
  264. //实际目标溶液体积
  265. item.actSolutionVolume = actVol
  266. //实际目标溶液浓度
  267. const actNd = (
  268. targetAcSolution /
  269. actStartSolutionVolume /
  270. actVol
  271. ).toFixed(precision)
  272. item.actSolutionConcentration = actNd
  273. },
  274. //更新起始溶液体积时,计算目标溶液预计浓度
  275. updateTargetStartSolutionVolume(item, volume) {
  276. const precision = item.targetStartSolutionVolumePrecision || 0
  277. const concentration = item.targetSolutionConcentration || 0
  278. const targetVolume = item.targetSolutionVolume || 0
  279. //目标溶液预计浓度:(目标溶液预计体积 乘以 起始溶液浓度)除以 起始溶液体积
  280. const result = ((concentration * targetVolume) / volume).toFixed(
  281. precision
  282. )
  283. item.targetStartSolutionVolume = result
  284. // this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetStartSolutionVolume: result });
  285. if (targetVolume) {
  286. //预设稀释液体积:目标溶液预计体积 减去 源溶液预计体积;
  287. const precision1 = item.targetDiluentVolumePrecision || 0
  288. const result1 = (targetVolume - result).toFixed(precision1)
  289. item.targetDiluentVolume = result1
  290. // this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetDiluentVolume: result1 });
  291. }
  292. }
  293. }
  294. }