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

686 lines
25 KiB

  1. import moment from 'moment'
  2. import { getLatestSn, getLatestSnArr } from '@/api/template';
  3. import { isValueEmpty, getStringWidth } from '@/utils/index';
  4. import { isCommonUnit } from "@/utils/conTools";
  5. import { sj_subpackage, sj_startConfiguration, sj_configurationCompleted } from '@/api/business/sj/sj';
  6. import { convertConcentration } from "@/utils/conConverter";//浓度单位转换
  7. import { volumeConverter } from "@/utils/volConverter";//体积单位转换
  8. import * as XLSX from 'xlsx'
  9. import { EventBus } from "@/utils/eventBus";
  10. export default {
  11. dicts: [
  12. 'business_pztj',
  13. 'business_cctj',
  14. 'business_nddw',
  15. 'business_tjdw',
  16. 'business_zldw',
  17. 'business_yxqdw',
  18. 'business_rqcz',
  19. 'business_sp_jmdyzqdyp', //色谱-编号-准确度与精密度
  20. 'business_sp_nbgzy', //色谱-编号-内标工作液
  21. 'business_sp_zkgzy', //色谱-编号-质控工作液
  22. 'business_sp_bqgzy', //色谱-编号-标曲工作液
  23. 'business_sp_bzqxzkypzbb', //色谱-编号-标准曲线/质控样品制备表
  24. 'business_sp_tqhsl', //色谱-编号-提取回收率
  25. 'business_sp_qxwdx', //色谱-编号-全血稳定性
  26. 'business_sp_cbyhgzywdx', //色谱-编号-储备液和工作液稳定性
  27. 'business_sp_rxjzxy', //色谱-编号-溶血基质效应
  28. 'business_sp_jzxy', //色谱-编号-基质效应
  29. 'business_sp_xzxytyx', //色谱-编号-选择性与特异性
  30. 'business_sp_zdybs', //色谱-编号-最大样本数
  31. 'business_sp_xskkx', //色谱-编号-稀释可靠性
  32. 'business_sp_cbydb', //色谱-编号-储备液对比
  33. 'business_pcr_gzy', // PCR-编号-工作液
  34. 'business_lba_jg', // LBA006-结果
  35. 'business_cftj', // 存放条件
  36. 'business_yplx', // 样品类型
  37. 'business_sydd', // 毒理-Ames实验地点
  38. 'business_dl_ameswrqk', // 毒理-Ames污染情况
  39. 'business_dl_amescltj', // 毒理-Ames处理条件
  40. 'business_dl_amesbjjt', // 毒理-Ames背景菌苔
  41. 'business_dl_amescdqk', // 毒理-Ames沉淀情况
  42. 'business_dl_xbmc', // 毒理-Ames细胞名称
  43. 'business_dl_qsxjbltj', // 毒理-暴露条件
  44. 'business_rylx', // 溶液类型
  45. 'business_xbzb', // 细胞组别
  46. 'business_xblx', // 细胞类型
  47. 'business_pytj', // 毒理-培养条件
  48. 'business_fstj', // 毒理-复苏条件
  49. 'business_dsfs', //动技-递送方式
  50. 'business_knj', //动技-抗凝剂
  51. 'business_fhlr', //动技-复核内容
  52. 'business_fhfw', //动技-复核范围
  53. 'business_dwzs', // 动物种属
  54. 'business_cjdd', // 采集地点
  55. 'business_zpdd', // 制片地点
  56. 'business_cjbw', // 制片部位
  57. 'business_qywz', // 取样位置
  58. 'business_lba_ptjhbzqx_zkpx', // LBA-编号-配体结合分析标准曲线LBA005-质控平行
  59. 'business_lba_bqpx', //LBA-编号-配体结合分析标准曲线LBA005-标曲平行
  60. 'business_lba_ptjhfxyp', // LBA-编号-配体结合分析方法学样品制备表LBA007
  61. 'business_ada_kyktzkyp', // ADA-编号-抗药抗体质控样品配制记录表ADA005
  62. 'business_ada_kyktffxyp', // ADA-编号-抗药抗体方法学样品制备表ADA007
  63. 'business_dl_uav', // 毒理-紫外照射操作记录表-UVA-DL023
  64. 'business_pcr_fxffypzbb', //PCR-编号-分析方法学样品制备表
  65. ],
  66. props: {
  67. templateData: {
  68. type: Object,
  69. default: () => { }
  70. }
  71. },
  72. watch: {
  73. templateData: {
  74. immediate: true,
  75. deep: true,
  76. handler(v) {
  77. if (v) {
  78. const {
  79. studySubjectId,
  80. studyId,
  81. studyMc,
  82. studySn,
  83. templateMc,
  84. templateMcEn,
  85. templateId,
  86. templateSn,
  87. startDate,
  88. bdmc,
  89. endDate,
  90. id
  91. } = v
  92. if (v.resource) {
  93. //type 类型:1:试剂;3:给药制剂;5:麻精药;7:供试品 9:细胞;11:细菌
  94. //试验试剂信息 试剂
  95. // this.resource = _.filter(JSON.parse(v.resource), function (o) {
  96. // return o.type == 1 || o.elnType == 1
  97. // })
  98. // //试验物资信息 供试品、给药制剂、麻精药
  99. // this.resourceWz = _.filter(JSON.parse(v.resource), function (o) {
  100. // return o.type == 3 || o.type == 5 || o.type == 7 || o.elnType == 3|| o.elnType == 5 || o.elnType == 7
  101. // })
  102. //试验试剂信息
  103. this.resourceSj = _.filter(JSON.parse(v.resource), function (o) {
  104. return o.type == 1 || o.elnType == 1
  105. })
  106. //供试品信息
  107. this.resourceGsp = _.filter(JSON.parse(v.resource), function (o) {
  108. return o.type == 7 || o.elnType == 7
  109. })
  110. //给药制剂信息
  111. this.resourceGyzj = _.filter(JSON.parse(v.resource), function (o) {
  112. return o.type == 3 || o.elnType == 3
  113. })
  114. //麻精药信息
  115. this.resourceMjy = _.filter(JSON.parse(v.resource), function (o) {
  116. return o.type == 5 || o.elnType == 5
  117. })
  118. }
  119. if (v.yqResource) {
  120. //仪器信息
  121. this.yqResource = JSON.parse(v.yqResource)
  122. }
  123. this.product = v.product || null
  124. if (v.bdnr) {
  125. this.formData = {
  126. ...JSON.parse(v.bdnr),
  127. studySubjectId,
  128. studyId,
  129. studyMc,
  130. studySn,
  131. templateMc,
  132. templateMcEn,
  133. templateId,
  134. templateSn,
  135. startDate,
  136. bdmc,
  137. endDate,
  138. id
  139. }
  140. } else {
  141. this.formData = {
  142. studySubjectId,
  143. studyId,
  144. studyMc,
  145. studySn,
  146. templateMc,
  147. templateMcEn,
  148. templateId,
  149. templateSn,
  150. startDate,
  151. bdmc,
  152. endDate,
  153. id
  154. }
  155. }
  156. const { effectivePeriod, effectivePeriodUnit, expireDate } =
  157. this.formData
  158. //实际填报的时候,如果有了开始时间,并且有有效周期,但是没有失效日,就计算失效日为开始时间+有效周期
  159. if (
  160. startDate &&
  161. this.fillType === 'actFill' &&
  162. effectivePeriod &&
  163. effectivePeriodUnit &&
  164. !expireDate
  165. ) {
  166. let end;
  167. if (startDate === "NA") {
  168. end = "NA";
  169. } else {
  170. const start = moment(startDate)
  171. const unit = effectivePeriodUnit === '天' ? 'days' : 'hours'
  172. end = start
  173. .add(Number(effectivePeriod), unit)
  174. .format('YYYY-MM-DD HH:mm:ss')
  175. }
  176. this.formData = { ...this.formData, expireDate: end }
  177. }
  178. console.log(this.formData, 'formData from templateData')
  179. this.setTemplateData(v)
  180. }
  181. }
  182. }
  183. },
  184. data() {
  185. return {
  186. formData: {},
  187. templateDetail: {},
  188. product: null,//产物:1:试剂;3:给药制剂;5:麻精药
  189. resource: [], //试验试剂信息--弃用
  190. resourceWz: [], //物资信息--弃用
  191. resourceSj: [],//试验试剂信息
  192. resourceGsp: [],//供试品信息
  193. resourceGyzj: [],//给药制剂信息
  194. resourceMjy: [],//麻精药信息
  195. yqResource: [], //仪器信息
  196. jcbList: [], //检测板信息
  197. xbxj: [], //细胞细菌信息
  198. resourceTmp: [],//试验试剂信息提交用
  199. yqResourceTmp: [], //仪器信息提交用
  200. jcbListTmp: [], //检测板信息提交用
  201. xbxjTmp: [],//细胞细菌信息提交用
  202. sjColumns: [
  203. { label: 'template.common.reagentName', prop: "mc" },//名称
  204. { label: 'template.common.reagentCode', prop: "bh" },//编号
  205. { label: 'template.common.reagentNo', prop: "ph" },//批号 试剂,供试品才有
  206. { label: 'template.common.concentration', prop: "ndz" },//浓度
  207. { label: 'template.common.source', prop: "ly" },//来源
  208. { label: 'template.common.reagentExpireDate', prop: "sxrq" },//失效日期
  209. ],
  210. gspColumns: [
  211. { label: 'template.common.wzName', prop: "mc" },//名称
  212. { label: 'template.common.wzCode', prop: "bh" },//编号
  213. { label: 'template.common.reagentNo', prop: "ph" },//批号 试剂,供试品才有
  214. { label: 'template.common.wzSource', prop: "ly" },//来源
  215. { label: 'template.common.wzConcentration', prop: "ndz" },//浓度
  216. { label: 'template.common.wzExpireDate', prop: "sxrq" },//失效日期
  217. ],
  218. gyzjColumns: [
  219. { label: 'template.common.wzName', prop: "mc" },//名称
  220. { label: 'template.common.wzCode', prop: "bh" },//编号
  221. { label: 'template.common.wzSource', prop: "ly" },//来源
  222. { label: 'template.common.wzConcentration', prop: "ndz" },//浓度
  223. { label: 'template.common.wzExpireDate', prop: "sxrq" },//失效日期
  224. ],
  225. mjyColumns: [
  226. { label: 'template.common.wzName', prop: "mc" },//名称
  227. { label: 'template.common.wzCode', prop: "bh" },//编号
  228. { label: 'template.common.wzSource', prop: "ly" },//来源
  229. { label: 'template.common.wzConcentration', prop: "ndz" },//浓度
  230. { label: 'template.common.wzExpireDate', prop: "sxrq" },//失效日期
  231. ],
  232. //弃用
  233. sysjColumns: [
  234. { label: 'template.common.reagentName', prop: "mc" },//名称
  235. { label: 'template.common.reagentCode', prop: "bh" },//编号
  236. { label: 'template.common.reagentNo', prop: "ph" },//批号 试剂,供试品才有
  237. { label: 'template.common.concentration', prop: "ndz" },//浓度
  238. { label: 'template.common.source', prop: "ly" },//来源
  239. { label: 'template.common.reagentExpireDate', prop: "sxrq" },//失效日期
  240. ],
  241. //弃用
  242. sywzColumns: [
  243. { label: 'template.common.wzName', prop: "mc" },//名称
  244. { label: 'template.common.wzCode', prop: "bh" },//编号
  245. { label: 'template.common.wzSource', prop: "ly" },//来源
  246. { label: 'template.common.wzConcentration', prop: "ndz" },//浓度
  247. { label: 'template.common.wzExpireDate', prop: "sxrq" },//失效日期
  248. ],
  249. yqColumns: [
  250. { label: 'template.common.instrumentName', prop: "mc" },//仪器名称
  251. { label: 'template.common.instrumentModel', prop: "xh" },//仪器型号
  252. { label: 'template.common.instrumentCode', prop: "bh" },//仪器编号
  253. { label: 'template.common.nextTestDate', prop: "jzrq" },//下次测试/校准/检定日期
  254. ],
  255. }
  256. },
  257. mounted() { },
  258. unmounted() {
  259. this.setTemplateData({})
  260. },
  261. methods: {
  262. // 只是更新已填写的表单数据,不触发校验
  263. justUpdateFilledFormData() {
  264. const params = {
  265. type: "fieldChanged",
  266. newRecord: null,
  267. resourceList: null,
  268. }
  269. EventBus.$emit('onModifyRecord', params,)
  270. },
  271. //试剂弹窗确认前
  272. onBeforeReagentSubmit(data) {
  273. const { selectData, callback, key, formFields } = data;
  274. const { subTargetStartSolution } = formFields;
  275. //判断选择的浓度单位和预制的浓度单位是否一致
  276. if (key === "subStartSolution" && !isCommonUnit(selectData.row.nddw, [subTargetStartSolution])) {//选择起始源溶液需要同步更新table的变更记录。
  277. callback.prevent('浓度单位与预制不符,请重新选择或申请废止并重新预制。');
  278. }
  279. },
  280. getFormDataByTemplateData() {
  281. let o = {};
  282. const { bdnr } = this.templateData
  283. if (bdnr) {
  284. o = JSON.parse(bdnr)
  285. }
  286. return o;
  287. },
  288. //开始配置
  289. //postData: {bh: '123456'}
  290. async startConfigRequest(postData) {
  291. const res = await sj_startConfiguration(postData)
  292. if (res.code === 200) {
  293. this.$message.success('开始配置成功')
  294. } else {
  295. this.$message.error('开始配置失败')
  296. }
  297. },
  298. //完成配置
  299. async configCompleteRequest(postData) {
  300. const res = await sj_configurationCompleted(postData)
  301. if (res.code === 200) {
  302. this.$message.success('完成配置成功')
  303. } else {
  304. this.$message.error('完成配置失败')
  305. }
  306. },
  307. //分装
  308. async subPackageRequest(postData) {
  309. const res = await sj_subpackage(postData)
  310. if (res.code === 200) {
  311. this.$message.success('分装成功')
  312. } else {
  313. this.$message.error('分装失败')
  314. }
  315. },
  316. //获取打印配置
  317. getBasePrintConfig(data = {}) {
  318. const { printCode, type, row = {} } = data;
  319. const { stepStorageCondition, startDate, expireDate } = this.formData;;
  320. const { nickName, name } = this.$store.getters;
  321. const lang = this.$i18n.locale;
  322. const printConfig = {
  323. "品名": "暂时还不知道品名是哪个字段",
  324. "存储条件": stepStorageCondition,
  325. "配制日期": moment(startDate).format("YYYY-MM-DD"),
  326. "有效期至": moment(expireDate).format("YYYY-MM-DD HH:mm"),
  327. "配置者": lang === "zh_CN" ? nickName : name,
  328. //type==="subPackage"从分装打印过来的,
  329. //type==="row" 从列表上点过来的
  330. "编号": type === "subPackage" ? printCode : (row.targetSolutionCode + row.subTargetSolutionCode),
  331. }
  332. return printConfig
  333. },
  334. async getLatestSn(count = 1) {
  335. const res = await getLatestSn({ count })
  336. if (res.code === 200) {
  337. return res.data
  338. }
  339. return []
  340. },
  341. //获取最新的多个编号
  342. async getLatestSnArr(params) {
  343. const res = await getLatestSnArr(params)
  344. if (res.code === 200) {
  345. return res.data
  346. }
  347. return []
  348. },
  349. getResource() {
  350. return this.resourceTmp
  351. },
  352. getYqResource() {
  353. return this.yqResourceTmp
  354. },
  355. getJcbList() {
  356. return this.jcbListTmp
  357. },
  358. getXbxj() {
  359. return this.xbxjTmp
  360. },
  361. //根据ref数组获取直接formData
  362. getFilledFormDataByRefs(refArr = []) {
  363. let result = {}
  364. refArr.map((ref) => {
  365. const refData = this.$refs[ref]?.getFilledFormData() || {}
  366. for (const [key, value] of Object.entries(refData)) {
  367. let index = 0
  368. // 如果当前键是可能重复的字段,且结果对象中已经存在该键,则添加索引后缀
  369. if (
  370. (key === 'headerSelectFields' || key === 'stepTableFormData') &&
  371. result.hasOwnProperty(key)
  372. ) {
  373. // 为重复字段生成带索引的键名,从1开始(因为第一个组件不需要后缀)
  374. const newKey = `${key}_${++index}`
  375. result[newKey] = value
  376. } else {
  377. // 正常合并其他字段
  378. result[key] = value
  379. }
  380. }
  381. })
  382. return result
  383. },
  384. //统一校验form表单是否填写
  385. async validFormFields(refArr = []) {
  386. let result = {}
  387. const refs = refArr.map((ref) => {
  388. let refData = {}
  389. if (this.$refs[ref]) {
  390. if (this.$refs[ref][0]) {
  391. refData = this.$refs[ref][0]?.getFormData() || {}
  392. } else {
  393. refData = this.$refs[ref]?.getFormData() || {}
  394. }
  395. }
  396. return refData
  397. })
  398. const validFormData = await Promise.all(refs).catch((err) => {
  399. // this.$message.error(err);
  400. if (err.errorType && err.errorType === 'step') {
  401. this.$message.error('请添加步骤')
  402. return
  403. }
  404. this.$message.error('表单内容未填完,请填写后再提交')
  405. })
  406. if (validFormData) {
  407. validFormData.forEach((item) => {
  408. for (const [key, value] of Object.entries(item)) {
  409. let index = 0
  410. // 如果当前键是可能重复的字段,且结果对象中已经存在该键,则添加索引后缀
  411. if (
  412. (key === 'headerSelectFields' || key === 'stepTableFormData') &&
  413. result.hasOwnProperty(key)
  414. ) {
  415. // 为重复字段生成带索引的键名,从1开始(因为第一个组件不需要后缀)
  416. const newKey = `${key}_${++index}`
  417. result[newKey] = value
  418. } else {
  419. // 正常合并其他字段
  420. result[key] = value
  421. }
  422. }
  423. })
  424. return result
  425. }
  426. return false
  427. },
  428. //试验配制条件options
  429. getDictOptions(dictType) {
  430. return this.dict.type[dictType] || []
  431. },
  432. setTemplateData(data) {
  433. this.$store.commit('template/SET_TEMPLATE_DATA', data)
  434. },
  435. //统一处理删除行
  436. deleteRow(index, ref) {
  437. if (ref) {
  438. this.$refs[ref].deleteRow(index);
  439. return;
  440. }
  441. this.$refs.stepTableRef.deleteRow(index)
  442. },
  443. //统一处理浓度校验异常
  444. onCommonVerifyNdException(formFields, data) {
  445. const { callback, rowIndex, key, dataSource } = data;
  446. const keys = [
  447. 'actStartSolutionVolume',
  448. 'actDiluentVolume',
  449. ]
  450. if (keys.includes(key)) {
  451. const { targetAcSolution } = formFields;
  452. if (rowIndex === 0) {//第一行的浓度取选择的溶液,
  453. if (isValueEmpty(targetAcSolution)) {
  454. callback.prevent("请先选择起始源溶液")
  455. }
  456. } else {
  457. //非第一行的浓度取上一行的浓度
  458. const prevItem = dataSource[rowIndex - 1]
  459. const prevConcentration = prevItem.actSolutionConcentration;
  460. if (!prevConcentration) {
  461. callback.prevent("请先计算上一行的实际目标溶液浓度")
  462. }
  463. }
  464. }
  465. },
  466. //统一处理blur事件,因为有效周期和过期日期是相关的,所以需要在有效周期失焦时更新过期日期
  467. onHandleBlur(fields) {
  468. const {
  469. key,
  470. codeSTD,
  471. targetStartSolution,
  472. subTargetStartSolution,//预设起始源溶液浓度单位
  473. } = fields
  474. const { startDate } = this.formData
  475. if (key === 'codeSTD') {
  476. //起始编号STD失焦时,更新stepDataSource
  477. const arr = Array.from({ length: codeSTD }, (item, index) => ({
  478. actSolutionVolumePrecision: 3, //小数点精度默认为3
  479. actSolutionConcentrationPrecision: 3, //小数点精度默认为3
  480. targetDiluentVolumePrecision: 3, //小数点精度默认为3
  481. targetStartSolutionVolumePrecision: 3, //小数点精度默认为3
  482. targetSolutionCode: `CA-WS-STD${Number(codeSTD) - index}`
  483. }))
  484. this.$refs.stepTableRef.updateDataSource(arr)
  485. } else if (key === 'targetStartSolution' || key === 'subTargetStartSolution') {
  486. //起始溶液体积失焦时,更新目标溶液预计浓度
  487. const arr = this.$refs.stepTableRef?.getDataSource();
  488. const { headerSelectFields } = this.$refs.stepTableRef?.getFilledFormData();
  489. const params = {
  490. subTargetStartSolution,
  491. headerSelectFields
  492. }
  493. arr.forEach((item, rowIndex) => {
  494. this.updateTargetStartSolutionVolume(
  495. item,
  496. targetStartSolution,
  497. params
  498. )
  499. })
  500. }
  501. },
  502. //批量更新目标起始源溶液体积
  503. batchUpdateTargetStartSolutionVolume(arr, startConcentration, params) {
  504. arr.forEach((item, rowIndex) => {
  505. this.updateTargetStartSolutionVolume(
  506. item,
  507. startConcentration,
  508. params
  509. )
  510. })
  511. },
  512. //统一处理table失焦事件
  513. onHandleTableBlur(params) {
  514. const { rowIndex, colKey, value, item, dataSource, headerSelectFields } = params
  515. if (
  516. colKey === 'targetSolutionVolume' ||
  517. colKey === 'targetSolutionConcentration' ||
  518. colKey === 'targetStartSolutionVolumePrecision' ||
  519. colKey === 'targetDiluentVolumePrecision'
  520. ) {
  521. const volume =
  522. this.$refs.stepFormPackageRef?.getFormDataByKey(
  523. 'targetStartSolution'
  524. )
  525. const subTargetStartSolution =
  526. this.$refs.stepFormPackageRef?.getFormDataByKey(
  527. 'subTargetStartSolution'
  528. )
  529. const params = {
  530. subTargetStartSolution: subTargetStartSolution,
  531. headerSelectFields
  532. }
  533. if (isValueEmpty(volume)) {
  534. this.$message.error('请先选择预设起始源溶液浓度')
  535. } else {
  536. this.updateTargetStartSolutionVolume(item, volume, params)
  537. }
  538. } else if (
  539. colKey === 'actStartSolutionVolume' ||
  540. colKey === 'actDiluentVolume'
  541. ) {
  542. //实际起始溶液体积和实际目标溶液体积
  543. const { targetAcSolution, subTargetAcSolutionUnit } =
  544. this.$refs.stepFormPackageRef?.getFilledFormData() //获取实际起始溶液浓度
  545. const { headerSelectFields } = this.$refs.stepTableRef?.getFilledFormData();
  546. const p = {
  547. targetStartSolutionUnit: subTargetAcSolutionUnit,
  548. headerSelectFields
  549. }
  550. let initNd = 0;
  551. if (rowIndex === 0) {
  552. initNd = targetAcSolution;
  553. } else {
  554. initNd = dataSource[rowIndex - 1].actSolutionConcentration;
  555. }
  556. if (isValueEmpty(initNd)) {
  557. this.$message.error('请先选择起始源溶液')
  558. return
  559. } else {
  560. const volResult = this.updateSjmbrynd(item, initNd, p)
  561. if (!volResult) {
  562. return
  563. }
  564. this.$refs.stepTableRef?.updateDataSourceByRowIndex(rowIndex, { actSolutionVolume: volResult.actVol, actSolutionConcentration: volResult.actNd }, "blur")
  565. }
  566. }
  567. },
  568. //计算目标溶液浓度
  569. calcNd(item, targetAcSolution, params) {
  570. console.log(params, "ppp")
  571. // debugger
  572. //targetStartSolutionUnit(实际起始源溶液浓度单位)
  573. const { targetStartSolutionUnit, headerSelectFields } = params;
  574. //actStartSolutionVolumeUnit(实际起始源溶液体积单位)actSolutionVolumeUnit(实际目标溶液体积单位)
  575. //actDiluentVolumeUnit(实际稀释液体积单位)actSolutionConcentrationUnit(实际目标溶液浓度单位)
  576. const { actStartSolutionVolumeUnit, actSolutionVolumeUnit, actDiluentVolumeUnit, actSolutionConcentrationUnit } = headerSelectFields;
  577. //实际源溶液浓度÷(实际终体积÷源溶液加入体积);
  578. const precision = item.actSolutionConcentrationPrecision
  579. const volPrecision = item.actSolutionVolumePrecision;
  580. //实际稀释液体积
  581. const actDiluentVolume = item.actDiluentVolume
  582. //实际起始源溶液体积
  583. const actStartSolutionVolume = item.actStartSolutionVolume
  584. if (isValueEmpty(actStartSolutionVolume) || isValueEmpty(actDiluentVolume) || isValueEmpty(targetStartSolutionUnit)) {
  585. return false
  586. }
  587. const converActDiluentVolume = volumeConverter.convert(actDiluentVolume + actDiluentVolumeUnit, actSolutionVolumeUnit)
  588. const converActStartSolutionVolume = volumeConverter.convert(actStartSolutionVolume + actStartSolutionVolumeUnit, actSolutionVolumeUnit)
  589. //实际源溶液加入体积+实际稀释液加入体积
  590. const actVol = (
  591. Number(converActDiluentVolume) + Number(converActStartSolutionVolume)
  592. ).toFixed(volPrecision)
  593. const targetStartVolUnit = actSolutionConcentrationUnit.split("/")[1];//先按照预设目标溶液浓度的单位标准
  594. const converActVol = volumeConverter.convert(actVol + actSolutionVolumeUnit, targetStartVolUnit)
  595. const converActDiluentVolume1 = volumeConverter.convert(actStartSolutionVolume + actStartSolutionVolumeUnit, targetStartVolUnit)
  596. const converTargetAcSolution = convertConcentration.convert(targetAcSolution + targetStartSolutionUnit, actSolutionConcentrationUnit)
  597. // 实际目标溶液浓度 = 实际源溶液浓度÷(实际终体积÷源溶液加入体积);
  598. const actNd = (
  599. parseFloat(converTargetAcSolution) / (
  600. parseFloat(converActVol) / parseFloat(converActDiluentVolume1)
  601. )
  602. ).toFixed(precision)
  603. const nd = actNd === 'Infinity' ? 0 : Number(actNd)
  604. console.log(actNd, targetAcSolution, actStartSolutionVolume, actVol, "actNd")
  605. // item.actSolutionConcentration = actNd === 'Infinity' ? 0 : actNd
  606. return { actVol: Number(actVol), actNd: nd }
  607. },
  608. //计算并更新实际目标溶液浓度 先计算实际目标溶液体积再计算实际目标溶液浓度
  609. updateSjmbrynd(item, targetAcSolution, params) {
  610. return this.calcNd(item, targetAcSolution, params)
  611. },
  612. //更新起始溶液体积时,计算预设起始溶液体积和预设稀释液体积
  613. updateTargetStartSolutionVolume(item, volume, unitParams) {
  614. const precision = item.targetStartSolutionVolumePrecision || 0
  615. const concentration = item.targetSolutionConcentration
  616. const targetVolume = item.targetSolutionVolume
  617. const { subTargetStartSolution, headerSelectFields } = unitParams
  618. const { targetSolutionConcentrationUnit, targetSolutionVolumeUnit, targetStartSolutionVolumeUnit, targetDiluentVolumeUnit } = headerSelectFields
  619. if (
  620. isValueEmpty(concentration) ||
  621. isValueEmpty(targetVolume) ||
  622. isValueEmpty(subTargetStartSolution) ||
  623. isValueEmpty(targetSolutionConcentrationUnit) ||
  624. isValueEmpty(targetSolutionVolumeUnit) ||
  625. isValueEmpty(targetStartSolutionVolumeUnit) ||
  626. isValueEmpty(targetDiluentVolumeUnit)
  627. ) {
  628. return;
  629. }
  630. const targetStartVolUnit = targetSolutionConcentrationUnit.split("/")[1];//先按照预设目标溶液浓度的单位标准
  631. //将起始溶液浓度转换为和预设目标溶液浓度一样的单位再计算;
  632. const converStartCon = convertConcentration.convert(volume + subTargetStartSolution, targetSolutionConcentrationUnit)
  633. //将预设目标溶液体积转换为和预设目标溶液浓度单位的分母一样的单位再计算;如:预设目标溶液浓度单位为mg/mL,预设目标溶液体积单位为uL,则将预设目标溶液体积转换为mL
  634. const convertTargetVol = volumeConverter.convert(targetVolume + targetSolutionVolumeUnit, targetStartVolUnit)
  635. //预设起始溶液体积:(目标溶液预计浓度 乘以 目标溶液预计体积)除以 起始溶液浓度
  636. const result = Number((concentration * convertTargetVol) / converStartCon)
  637. //根据预设起始溶液体积单位转换计算后的数据
  638. const convertYsVol = volumeConverter.convert(result + targetStartVolUnit, targetStartSolutionVolumeUnit)
  639. item.targetStartSolutionVolume = Number(convertYsVol.toFixed(
  640. precision
  641. ))
  642. // this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetStartSolutionVolume: result });
  643. if (targetVolume) {
  644. //预设稀释液体积:目标溶液预计体积 减去 源溶液预计体积;
  645. const precision1 = item.targetDiluentVolumePrecision || 0;
  646. //将预设目标溶液体积转换为和预设起始溶液体积单位一样的单位再计算;
  647. const convertTargetVol1 = volumeConverter.convert(targetVolume + targetSolutionVolumeUnit, targetStartSolutionVolumeUnit)
  648. const result1 = (convertTargetVol1 - convertYsVol)
  649. item.targetDiluentVolume = Number(volumeConverter.convert(result1 + targetStartSolutionVolumeUnit, targetDiluentVolumeUnit).toFixed(precision1))
  650. // this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetDiluentVolume: result1 });
  651. }
  652. },
  653. // 导出excel模板
  654. exportExcel(headerArray, title = '导出模板') {
  655. this.$modal.loading()
  656. const ws = XLSX.utils.aoa_to_sheet([headerArray]);
  657. const colWidths = headerArray.map(cell => getStringWidth(cell) + 2);
  658. ws['!cols'] = colWidths.map(width => ({ wch: width }));
  659. const wb = XLSX.utils.book_new();
  660. XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
  661. XLSX.writeFile(wb, `${title}.xlsx`);
  662. this.$modal.closeLoading()
  663. },
  664. }
  665. }