华西海圻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.

278 lines
9.5 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. endDate
  45. } = v
  46. if (v.resource) {
  47. //试验试剂信息
  48. this.resource = JSON.parse(v.resource)
  49. }
  50. if (v.bdnr) {
  51. this.formData = {
  52. ...JSON.parse(v.bdnr),
  53. studyMc,
  54. studySn,
  55. templateMc,
  56. templateMcEn,
  57. templateSn,
  58. startDate,
  59. endDate
  60. }
  61. }else{
  62. this.formData = {
  63. studyMc,
  64. studySn,
  65. templateMc,
  66. templateMcEn,
  67. templateSn,
  68. startDate,
  69. endDate
  70. }
  71. }
  72. const { effectivePeriod, effectivePeriodUnit, expireDate } =
  73. this.formData
  74. //实际填报的时候,如果有了开始时间,并且有有效周期,但是没有失效日,就计算失效日为开始时间+有效周期
  75. if (
  76. startDate &&
  77. this.fillType === 'actFill' &&
  78. effectivePeriod &&
  79. effectivePeriodUnit &&
  80. !expireDate
  81. ) {
  82. const start = moment(startDate)
  83. const end = start
  84. .add(Number(effectivePeriod), effectivePeriodUnit)
  85. .format('YYYY-MM-DD HH:mm:ss')
  86. this.formData = { ...this.formData, expireDate: end }
  87. }
  88. console.log(this.formData, 'formData from templateData')
  89. this.setTemplateData(v)
  90. }
  91. }
  92. }
  93. },
  94. data() {
  95. return {
  96. formData: {},
  97. templateDetail: {},
  98. resource: [], //试验试剂信息
  99. sysjColumns: [
  100. { label: '试剂名称', prop: 'reagentName' },
  101. { label: '编号', prop: 'reagentCode' },
  102. { label: '批号', prop: 'reagentNo' },
  103. { label: '浓度/含量/纯度', prop: 'concentration' },
  104. { label: '来源', prop: 'source' },
  105. { label: '失效日', prop: 'expireDate' }
  106. ],
  107. yqsColumns: [
  108. { label: '仪器名称', prop: 'instrumentName' },
  109. { label: '仪器型号', prop: 'instrumentModel' },
  110. { label: '仪器编号', prop: 'instrumentCode' },
  111. { label: '下次测试/校准/检定日期', prop: 'nextTestDate' }
  112. ]
  113. }
  114. },
  115. mounted() {},
  116. unmounted() {
  117. this.setTemplateData({})
  118. },
  119. methods: {
  120. getResource() {
  121. return this.resource
  122. },
  123. //根据ref数组获取直接formData
  124. getFilledFormDataByRefs(refArr = []) {
  125. let result = {}
  126. refArr.map((ref) => {
  127. const refData = this.$refs[ref]?.getFilledFormData() || {}
  128. result = { ...result, ...refData }
  129. })
  130. return result
  131. },
  132. //统一校验form表单是否填写
  133. async validFormFields(refArr = []) {
  134. let result = {}
  135. const refs = refArr.map((ref) => {
  136. let refData = {}
  137. if (this.$refs[ref][0]) {
  138. refData = this.$refs[ref][0]?.getFormData() || {}
  139. } else {
  140. refData = this.$refs[ref]?.getFormData() || {}
  141. }
  142. return refData
  143. })
  144. const validFormData = await Promise.all(refs).catch((err) => {
  145. // this.$message.error(err);
  146. if (err.errorType && err.errorType === 'step') {
  147. this.$message.error('请添加步骤')
  148. return
  149. }
  150. this.$message.error('表单内容未填完,请填写后再提交')
  151. })
  152. if (validFormData) {
  153. validFormData.forEach((item) => {
  154. result = { ...result, ...item }
  155. })
  156. return result
  157. }
  158. return false
  159. },
  160. //试验配制条件options
  161. getDictOptions(dictType) {
  162. return this.dict.type[dictType] || []
  163. },
  164. setTemplateData(data) {
  165. this.$store.commit('template/SET_TEMPLATE_DATA', data)
  166. },
  167. //统一处理删除行
  168. deleteRow(index) {
  169. this.$refs.stepTableRef.deleteRow(index)
  170. },
  171. //统一处理blur事件,因为有效周期和过期日期是相关的,所以需要在有效周期失焦时更新过期日期
  172. onHandleBlur(fields) {
  173. const {
  174. key,
  175. effectivePeriodUnit,
  176. effectivePeriod,
  177. codeSTD,
  178. targetStartSolution
  179. } = fields
  180. const { startDate } = this.formData
  181. if (key === 'codeSTD') {
  182. //起始编号STD失焦时,更新stepDataSource
  183. const arr = Array.from({ length: codeSTD }, (item, index) => ({
  184. actSolutionVolumePrecision: 3, //小数点精度默认为3
  185. actSolutionConcentrationPrecision: 3, //小数点精度默认为3
  186. targetDiluentVolumePrecision: 3, //小数点精度默认为3
  187. targetStartSolutionVolumePrecision: 3, //小数点精度默认为3
  188. targetSolutionCode: `STD${Number(codeSTD) - index}`
  189. }))
  190. this.$refs.stepTableRef.updateDataSource(arr)
  191. } else if (key === 'targetStartSolution') {
  192. //起始溶液体积失焦时,更新目标溶液预计浓度
  193. const arr = this.$refs.stepTableRef?.getDataSource()
  194. arr.forEach((item, rowIndex) => {
  195. this.updateTargetStartSolutionVolume(
  196. rowIndex,
  197. item,
  198. targetStartSolution
  199. )
  200. })
  201. }
  202. },
  203. //统一处理table失焦事件
  204. onHandleTableBlur(params) {
  205. const { rowIndex, colKey, value, item } = params
  206. if (
  207. colKey === 'targetSolutionVolume' ||
  208. colKey === 'targetSolutionConcentration' ||
  209. colKey === 'targetStartSolutionVolumePrecision' ||
  210. colKey === 'targetDiluentVolumePrecision'
  211. ) {
  212. const volume =
  213. this.$refs.stepFormPackageRef?.getFormDataByKey(
  214. 'targetStartSolution'
  215. ) || 0
  216. if (volume) {
  217. this.updateTargetStartSolutionVolume(item, volume)
  218. }
  219. } else if (
  220. colKey === 'actStartSolutionVolume' ||
  221. colKey === 'actDiluentVolume'
  222. ) {
  223. //实际起始溶液体积和实际目标溶液体积
  224. const targetAcSolution =
  225. this.$refs.stepFormPackageRef?.getFormDataByKey('targetAcSolution') ||
  226. 0 //获取实际起始溶液浓度
  227. if (targetAcSolution) {
  228. this.updateSjmbrynd(item, targetAcSolution)
  229. }
  230. }
  231. },
  232. //计算并更新实际目标溶液浓度 先计算实际目标溶液体积再计算实际目标溶液浓度
  233. updateSjmbrynd(item, targetAcSolution) {
  234. //实际源溶液浓度÷(实际终体积÷源溶液加入体积);
  235. const precision = item.actSolutionConcentrationPrecision || 0
  236. const volPrecision = item.actSolutionVolumePrecision || 0
  237. //实际稀释液体积
  238. const actDiluentVolume = item.actDiluentVolume || 0
  239. const actStartSolutionVolume = item.actStartSolutionVolume || 0
  240. //实际高源溶液加入体积+实际稀释液加入体积
  241. const actVol = (
  242. Number(actStartSolutionVolume) + Number(actDiluentVolume)
  243. ).toFixed(volPrecision)
  244. //实际目标溶液体积
  245. item.actSolutionVolume = actVol
  246. //实际目标溶液浓度
  247. const actNd = (
  248. targetAcSolution /
  249. actStartSolutionVolume /
  250. actVol
  251. ).toFixed(precision)
  252. item.actSolutionConcentration = actNd
  253. },
  254. //更新起始溶液体积时,计算目标溶液预计浓度
  255. updateTargetStartSolutionVolume(item, volume) {
  256. const precision = item.targetStartSolutionVolumePrecision || 0
  257. const concentration = item.targetSolutionConcentration || 0
  258. const targetVolume = item.targetSolutionVolume || 0
  259. //目标溶液预计浓度:(目标溶液预计体积 乘以 起始溶液浓度)除以 起始溶液体积
  260. const result = ((concentration * targetVolume) / volume).toFixed(
  261. precision
  262. )
  263. item.targetStartSolutionVolume = result
  264. // this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetStartSolutionVolume: result });
  265. if (targetVolume) {
  266. //预设稀释液体积:目标溶液预计体积 减去 源溶液预计体积;
  267. const precision1 = item.targetDiluentVolumePrecision || 0
  268. const result1 = (targetVolume - result).toFixed(precision1)
  269. item.targetDiluentVolume = result1
  270. // this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetDiluentVolume: result1 });
  271. }
  272. }
  273. }
  274. }