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

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