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

187 lines
7.4 KiB

  1. import moment from "moment";
  2. export default {
  3. dicts: ['business_pztj', 'business_cctj', 'business_nddw', 'business_tjdw', 'business_yxqdw', 'business_rqcz', 'business_jmdyzqdyp'],
  4. props: {
  5. templateData: {
  6. type: Object,
  7. default: () => { },
  8. },
  9. },
  10. watch: {
  11. templateData: {
  12. immediate: true,
  13. deep: true,
  14. handler(v) {
  15. if (v) {
  16. let n = { ...v };
  17. this.formData =n;
  18. if(v.resource){//试验试剂信息
  19. this.resource = JSON.parse(v.resource);
  20. }
  21. if (v.bdnr) {
  22. this.formData = { ...n, ...JSON.parse(v.bdnr) };
  23. }
  24. console.log(v, "formData from templateData")
  25. this.setTemplateData(n);
  26. }
  27. }
  28. }
  29. },
  30. data() {
  31. return {
  32. formData: {},
  33. templateDetail: {},
  34. resource: [],//试验试剂信息
  35. sysjColumns: [
  36. { label: "试剂名称", prop: "reagentName" },
  37. { label: "编号", prop: "reagentCode" },
  38. { label: "批号", prop: "reagentNo" },
  39. { label: "浓度/含量/纯度", prop: "concentration" },
  40. { label: "来源", prop: "source" },
  41. { label: "失效日", prop: "expireDate" },
  42. ],
  43. yqsColumns: [
  44. { label: "仪器名称", prop: "instrumentName" },
  45. { label: "仪器型号", prop: "instrumentModel" },
  46. { label: "仪器编号", prop: "instrumentCode" },
  47. { label: "下次测试/校准/检定日期", prop: "nextTestDate" },
  48. ]
  49. }
  50. },
  51. mounted() {
  52. },
  53. unmounted() {
  54. this.setTemplateData({});
  55. },
  56. methods: {
  57. getResource() {
  58. return this.resource;
  59. },
  60. //根据ref数组获取直接formData
  61. getFilledFormDataByRefs(refArr = []){
  62. let result = {};
  63. refArr.map(ref => {
  64. const refData = this.$refs[ref]?.getFilledFormData() || {};
  65. result = { ...result, ...refData };
  66. });
  67. return result;
  68. },
  69. //统一校验form表单是否填写
  70. async validFormFields(refArr = []) {
  71. let result = {};
  72. const refs = refArr.map(ref => {
  73. let refData = {};
  74. if (this.$refs[ref][0]) {
  75. refData = this.$refs[ref][0]?.getFormData() || {};
  76. } else {
  77. refData = this.$refs[ref]?.getFormData() || {};
  78. }
  79. return refData;
  80. });
  81. const validFormData = await Promise.all(refs).catch(err => {
  82. // this.$message.error(err);
  83. if (err.errorType && err.errorType === "step") {
  84. this.$message.error("请添加步骤");
  85. return
  86. }
  87. this.$message.error("表单内容未填完,请填写后再提交");
  88. });
  89. if (validFormData) {
  90. validFormData.forEach(item => {
  91. result = { ...result, ...item }
  92. })
  93. return result;
  94. }
  95. return false;
  96. },
  97. //试验配制条件options
  98. getDictOptions(dictType) {
  99. return this.dict.type[dictType] || [];
  100. },
  101. setTemplateData(data) {
  102. this.$store.commit('template/SET_TEMPLATE_DATA', data)
  103. },
  104. //统一处理删除行
  105. deleteRow(index) {
  106. this.$refs.stepTableRef.deleteRow(index);
  107. },
  108. //统一处理blur事件,因为有效周期和过期日期是相关的,所以需要在有效周期失焦时更新过期日期
  109. onHandleBlur(fields) {
  110. const { key, effectivePeriodUnit, effectivePeriod, codeSTD, targetStartSolution } = fields;
  111. const { startDate } = this.formData;
  112. if (key === "effectivePeriod") {//统一处理有效周期失焦,计算失效事件,保证字段名不能变
  113. if(!startDate) return;
  114. const start = moment(startDate);
  115. const end = start.add(Number(effectivePeriod), effectivePeriodUnit).format("YYYY-MM-DD HH:mm:ss");
  116. this.$refs.stepFormPackageRef.updateFormData("expireDate", end);
  117. } else if (key === "codeSTD") {//起始编号STD失焦时,更新stepDataSource
  118. const arr = Array.from({ length: codeSTD }, (item, index) => ({
  119. actSolutionVolumePrecision: 3,//小数点精度默认为3
  120. actSolutionConcentrationPrecision: 3,//小数点精度默认为3
  121. targetDiluentVolumePrecision: 3,//小数点精度默认为3
  122. targetStartSolutionVolumePrecision: 3,//小数点精度默认为3
  123. targetSolutionCode: `STD${Number(codeSTD) - index}`
  124. }));
  125. this.$refs.stepTableRef.updateDataSource(arr);
  126. } else if (key === "targetStartSolution") {//起始溶液体积失焦时,更新目标溶液预计浓度
  127. const arr = this.$refs.stepTableRef?.getDataSource();
  128. arr.forEach((item, rowIndex) => {
  129. this.updateTargetStartSolutionVolume(rowIndex, item, targetStartSolution);
  130. })
  131. }
  132. },
  133. //统一处理table失焦事件
  134. onHandleTableBlur(params) {
  135. const { rowIndex, colKey, value, item } = params;
  136. if (colKey === "targetSolutionVolume" || colKey === "targetSolutionConcentration" || colKey === "targetStartSolutionVolumePrecision" || colKey === "targetDiluentVolumePrecision") {
  137. const volume = this.$refs.stepFormPackageRef?.getFormDataByKey("targetStartSolution") || 0;
  138. if (volume) {
  139. this.updateTargetStartSolutionVolume(item, volume);
  140. }
  141. }else if(colKey === "actStartSolutionVolume" || colKey === "actDiluentVolume"){//实际起始溶液体积和实际目标溶液体积
  142. const targetAcSolution = this.$refs.stepFormPackageRef?.getFormDataByKey("targetAcSolution") || 0;//获取实际起始溶液浓度
  143. if(targetAcSolution){
  144. this.updateSjmbrynd(item,targetAcSolution);
  145. }
  146. }
  147. },
  148. //计算并更新实际目标溶液浓度 先计算实际目标溶液体积再计算实际目标溶液浓度
  149. updateSjmbrynd(item,targetAcSolution){
  150. //实际源溶液浓度÷(实际终体积÷源溶液加入体积);
  151. const precision = item.actSolutionConcentrationPrecision || 0;
  152. const volPrecision = item.actSolutionVolumePrecision || 0;
  153. //实际稀释液体积
  154. const actDiluentVolume = item.actDiluentVolume || 0;
  155. const actStartSolutionVolume = item.actStartSolutionVolume || 0;
  156. //实际高源溶液加入体积+实际稀释液加入体积
  157. const actVol = (Number(actStartSolutionVolume)+Number(actDiluentVolume)).toFixed(volPrecision);
  158. //实际目标溶液体积
  159. item.actSolutionVolume = actVol;
  160. //实际目标溶液浓度
  161. const actNd = (targetAcSolution / actStartSolutionVolume / actVol).toFixed(precision);
  162. item.actSolutionConcentration = actNd;
  163. },
  164. //更新起始溶液体积时,计算目标溶液预计浓度
  165. updateTargetStartSolutionVolume(item, volume) {
  166. const precision = item.targetStartSolutionVolumePrecision || 0;
  167. const concentration = item.targetSolutionConcentration || 0;
  168. const targetVolume = item.targetSolutionVolume || 0;
  169. //目标溶液预计浓度:(目标溶液预计体积 乘以 起始溶液浓度)除以 起始溶液体积
  170. const result = ((concentration * targetVolume) / volume).toFixed(precision);
  171. item.targetStartSolutionVolume = result;
  172. // this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetStartSolutionVolume: result });
  173. if (targetVolume) {
  174. //预设稀释液体积:目标溶液预计体积 减去 源溶液预计体积;
  175. const precision1 = item.targetDiluentVolumePrecision || 0;
  176. const result1 = (targetVolume - result).toFixed(precision1);
  177. item.targetDiluentVolume = result1;
  178. // this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetDiluentVolume: result1 });
  179. }
  180. }
  181. },
  182. }