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

147 lines
5.5 KiB

  1. import moment from "moment";
  2. export default {
  3. dicts: ['business_pztj','business_cctj','business_nddw','business_tjdw','business_yxqdw','business_rqcz'],
  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. }
  36. },
  37. mounted() {
  38. // this.setTemplateStatus("actFill");
  39. this.setTemplateStatus(this.fillType);
  40. },
  41. unmounted() {
  42. this.setTemplateStatus("");
  43. this.setTemplateData({});
  44. },
  45. methods: {
  46. getResource(){
  47. return this.resource;
  48. },
  49. //统一校验form表单是否填写
  50. async validFormFields(refArr = []) {
  51. let result = {};
  52. const refs = refArr.map(ref => {
  53. const refData = this.$refs[ref].getFormData();
  54. return refData;
  55. });
  56. const validFormData = await Promise.all(refs).catch(err => {
  57. // this.$message.error(err);
  58. if(err.errorType && err.errorType === "step"){
  59. this.$message.error("请添加步骤");
  60. return
  61. }
  62. console.log(err,"err")
  63. this.$message.error("表单内容未填完,请填写后再提交");
  64. });
  65. if(validFormData){
  66. validFormData.forEach(item => {
  67. result = {...result,...item}
  68. })
  69. return result;
  70. }
  71. return false;
  72. },
  73. //试验配制条件options
  74. getDictOptions(dictType) {
  75. return this.dict.type[dictType] || [];
  76. },
  77. setTemplateStatus(status) {
  78. this.$store.commit('template/SET_TEMPLATE_STATUS', status)
  79. },
  80. setConditionOptions(options) {
  81. this.$store.commit('template/SET_CONDITION_OPTIONS', options)
  82. },
  83. setTemplateData(data) {
  84. this.$store.commit('template/SET_TEMPLATE_DATA', data)
  85. },
  86. //统一处理删除行
  87. deleteRow(index) {
  88. this.$refs.stepTableRef.deleteRow(index);
  89. },
  90. //获取版本号
  91. getVersionNum() {
  92. return this.formData.versionNum || "";
  93. },
  94. //统一处理blur事件,因为有效周期和过期日期是相关的,所以需要在有效周期失焦时更新过期日期
  95. onHandleBlur(fields) {
  96. const { key, effectivePeriodUnit, effectivePeriod, codeSTD, targetStartSolution } = fields;
  97. const { createTime } = this.formData;
  98. if (key === "effectivePeriod") {//统一处理有效周期失焦,计算失效事件,保证字段名不能变
  99. const start = moment(createTime);
  100. const end = start.add(Number(effectivePeriod), effectivePeriodUnit).format("YYYY-MM-DD HH:mm:ss");
  101. this.$refs.stepFormPackageRef.updateFormData("expireDate", end);
  102. } else if (key === "codeSTD") {//起始编号STD失焦时,更新stepDataSource
  103. const arr = Array.from({ length: codeSTD }, (item, index) => ({
  104. actSolutionVolumePrecision: 3,//小数点精度默认为3
  105. actSolutionConcentrationPrecision: 3,//小数点精度默认为3
  106. targetDiluentVolumePrecision: 3,//小数点精度默认为3
  107. targetStartSolutionVolumePrecision: 3,//小数点精度默认为3
  108. targetSolutionCode: `STD${Number(codeSTD) - index}`
  109. }));
  110. this.$refs.stepTableRef.updateDataSource(arr);
  111. } else if (key === "targetStartSolution") {//起始溶液体积失焦时,更新目标溶液预计浓度
  112. const arr = this.$refs.stepTableRef.getDataSource();
  113. arr.forEach((item, rowIndex) => {
  114. this.updateTargetStartSolutionVolume(rowIndex, item, targetStartSolution);
  115. })
  116. }
  117. },
  118. //统一处理table失焦事件
  119. onHandleTableBlur(params) {
  120. const { rowIndex, colKey, value, item } = params;
  121. console.log(rowIndex, colKey, value, item, "params")
  122. if (colKey === "targetSolutionVolume" || colKey === "targetSolutionConcentration" || colKey === "targetStartSolutionVolumePrecision" || colKey === "targetDiluentVolumePrecision") {
  123. const volume = this.$refs.stepFormPackageRef.getFormDataByKey("targetStartSolution") || 0;
  124. if (volume) {
  125. this.updateTargetStartSolutionVolume(rowIndex, item, volume);
  126. }
  127. }
  128. },
  129. //更新起始溶液体积时,更新目标溶液预计浓度
  130. updateTargetStartSolutionVolume(rowIndex, item, volume) {
  131. const precision = item.targetStartSolutionVolumePrecision || 0;
  132. const concentration = item.targetSolutionConcentration || 0;
  133. const targetVolume = item.targetSolutionVolume || 0;
  134. //目标溶液预计浓度:(目标溶液预计体积 乘以 起始溶液浓度)除以 起始溶液体积
  135. const result = ((concentration * targetVolume) / volume).toFixed(precision);
  136. this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetStartSolutionVolume: result });
  137. if (targetVolume) {
  138. //预设稀释液体积:目标溶液预计体积 减去 源溶液预计体积;
  139. const precision1 = item.targetDiluentVolumePrecision || 0;
  140. const result1 = (targetVolume - result).toFixed(precision1);
  141. this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetDiluentVolume: result1 });
  142. }
  143. }
  144. },
  145. }