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

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