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

115 lines
4.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. handler(v) {
  14. if (v) {
  15. let n = { ...v };
  16. if (v.bdnr) {
  17. this.formData = { ...n, ...JSON.parse(v.bdnr) };
  18. }
  19. this.templateDetail = n;
  20. this.setTemplateData(n);
  21. }
  22. }
  23. }
  24. },
  25. data() {
  26. return {
  27. formData: {},
  28. templateDetail: {}
  29. }
  30. },
  31. mounted() {
  32. // this.setTemplateStatus("actFill");
  33. this.setTemplateStatus(this.fillType);
  34. },
  35. unmounted() {
  36. this.setTemplateStatus("");
  37. this.setTemplateData({});
  38. },
  39. methods: {
  40. //试验配制条件options
  41. getDictOptions(dictType) {
  42. return this.dict.type[dictType] || [];
  43. },
  44. setTemplateStatus(status) {
  45. this.$store.commit('template/SET_TEMPLATE_STATUS', status)
  46. },
  47. setConditionOptions(options) {
  48. this.$store.commit('template/SET_CONDITION_OPTIONS', options)
  49. },
  50. setTemplateData(data) {
  51. this.$store.commit('template/SET_TEMPLATE_DATA', data)
  52. },
  53. //统一处理删除行
  54. deleteRow(index) {
  55. this.$refs.stepTableRef.deleteRow(index);
  56. },
  57. //获取版本号
  58. getVersionNum() {
  59. return this.formData.versionNum || "";
  60. },
  61. //统一处理blur事件,因为有效周期和过期日期是相关的,所以需要在有效周期失焦时更新过期日期
  62. onHandleBlur(fields) {
  63. const { key, effectivePeriodUnit, effectivePeriod, codeSTD, targetStartSolution } = fields;
  64. const { createTime } = this.formData;
  65. if (key === "effectivePeriod") {//统一处理有效周期失焦,计算失效事件,保证字段名不能变
  66. const start = moment(createTime);
  67. const end = start.add(Number(effectivePeriod), effectivePeriodUnit).format("YYYY-MM-DD HH:mm:ss");
  68. this.$refs.stepFormPackageRef.updateFormData("expireDate", end);
  69. } else if (key === "codeSTD") {//起始编号STD失焦时,更新stepDataSource
  70. const arr = Array.from({ length: codeSTD }, (item, index) => ({
  71. actSolutionVolumePrecision: 3,//小数点精度默认为3
  72. actSolutionConcentrationPrecision: 3,//小数点精度默认为3
  73. targetDiluentVolumePrecision: 3,//小数点精度默认为3
  74. targetStartSolutionVolumePrecision: 3,//小数点精度默认为3
  75. targetSolutionCode: `STD${Number(codeSTD) - index}`
  76. }));
  77. this.$refs.stepTableRef.updateDataSource(arr);
  78. } else if (key === "targetStartSolution") {//起始溶液体积失焦时,更新目标溶液预计浓度
  79. const arr = this.$refs.stepTableRef.getDataSource();
  80. arr.forEach((item, rowIndex) => {
  81. this.updateTargetStartSolutionVolume(rowIndex, item, targetStartSolution);
  82. })
  83. }
  84. },
  85. //统一处理table失焦事件
  86. onHandleTableBlur(params) {
  87. const { rowIndex, colKey, value, item } = params;
  88. console.log(rowIndex, colKey, value, item, "params")
  89. if (colKey === "targetSolutionVolume" || colKey === "targetSolutionConcentration" || colKey === "targetStartSolutionVolumePrecision" || colKey === "targetDiluentVolumePrecision") {
  90. const volume = this.$refs.stepFormPackageRef.getFormDataByKey("targetStartSolution") || 0;
  91. if (volume) {
  92. this.updateTargetStartSolutionVolume(rowIndex, item, volume);
  93. }
  94. }
  95. },
  96. //更新起始溶液体积时,更新目标溶液预计浓度
  97. updateTargetStartSolutionVolume(rowIndex, item, volume) {
  98. const precision = item.targetStartSolutionVolumePrecision || 0;
  99. const concentration = item.targetSolutionConcentration || 0;
  100. const targetVolume = item.targetSolutionVolume || 0;
  101. //目标溶液预计浓度:(目标溶液预计体积 乘以 起始溶液浓度)除以 起始溶液体积
  102. const result = ((concentration * targetVolume) / volume).toFixed(precision);
  103. this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetStartSolutionVolume: result });
  104. if (targetVolume) {
  105. //预设稀释液体积:目标溶液预计体积 减去 源溶液预计体积;
  106. const precision1 = item.targetDiluentVolumePrecision || 0;
  107. const result1 = (targetVolume - result).toFixed(precision1);
  108. this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetDiluentVolume: result1 });
  109. }
  110. }
  111. },
  112. }