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

390 lines
12 KiB

  1. import moment from 'moment'
  2. import { getLatestSn } from '@/api/template';
  3. import { sj_subpackage, sj_startConfiguration, sj_configurationCompleted } from '@/api/business/sj/sj';
  4. export default {
  5. dicts: [
  6. 'business_pztj',
  7. 'business_cctj',
  8. 'business_nddw',
  9. 'business_tjdw',
  10. 'business_yxqdw',
  11. 'business_rqcz',
  12. 'business_sp_jmdyzqdyp', //色谱-编号-准确度与精密度
  13. 'business_sp_nbgzy', //色谱-编号-内标工作液
  14. 'business_sp_zkgzy', //色谱-编号-质控工作液
  15. 'business_sp_bqgzy', //色谱-编号-标曲工作液
  16. 'business_sp_bzqxzkypzbb', //色谱-编号-标准曲线/质控样品制备表
  17. 'business_sp_tqhsl', //色谱-编号-提取回收率
  18. 'business_sp_qxwdx', //色谱-编号-全血稳定性
  19. 'business_sp_cbyhgzywdx', //色谱-编号-储备液和工作液稳定性
  20. 'business_sp_rxjzxy', //色谱-编号-溶血基质效应
  21. 'business_sp_jzxy', //色谱-编号-基质效应
  22. 'business_sp_xzxytyx', //色谱-编号-选择性与特异性
  23. 'business_sp_zdybs', //色谱-编号-最大样本数
  24. 'business_sp_xskkx', //色谱-编号-稀释可靠性
  25. 'business_sp_cbydb' //色谱-编号-储备液对比
  26. ],
  27. props: {
  28. templateData: {
  29. type: Object,
  30. default: () => { }
  31. }
  32. },
  33. watch: {
  34. templateData: {
  35. immediate: true,
  36. deep: true,
  37. handler(v) {
  38. if (v) {
  39. const {
  40. studySubjectId,
  41. studyId,
  42. studyMc,
  43. studySn,
  44. templateMc,
  45. templateMcEn,
  46. templateSn,
  47. startDate,
  48. bdmc,
  49. endDate,
  50. id
  51. } = v
  52. if (v.resource) {
  53. //试验试剂信息
  54. this.resource = JSON.parse(v.resource)
  55. }
  56. if (v.yqResource) {
  57. //仪器信息
  58. this.yqResource = JSON.parse(v.yqResource)
  59. }
  60. if (v.bdnr) {
  61. this.formData = {
  62. ...JSON.parse(v.bdnr),
  63. studySubjectId,
  64. studyId,
  65. studyMc,
  66. studySn,
  67. templateMc,
  68. templateMcEn,
  69. templateSn,
  70. startDate,
  71. bdmc,
  72. endDate,
  73. id
  74. }
  75. } else {
  76. this.formData = {
  77. studySubjectId,
  78. studyId,
  79. studyMc,
  80. studySn,
  81. templateMc,
  82. templateMcEn,
  83. templateSn,
  84. startDate,
  85. bdmc,
  86. endDate,
  87. id
  88. }
  89. }
  90. const { effectivePeriod, effectivePeriodUnit, expireDate } =
  91. this.formData
  92. //实际填报的时候,如果有了开始时间,并且有有效周期,但是没有失效日,就计算失效日为开始时间+有效周期
  93. if (
  94. startDate &&
  95. this.fillType === 'actFill' &&
  96. effectivePeriod &&
  97. effectivePeriodUnit &&
  98. !expireDate
  99. ) {
  100. const start = moment(startDate)
  101. const unit = effectivePeriodUnit === '天' ? 'days' : 'hours'
  102. const end = start
  103. .add(Number(effectivePeriod), unit)
  104. .format('YYYY-MM-DD HH:mm:ss')
  105. this.formData = { ...this.formData, expireDate: end }
  106. }
  107. console.log(this.formData, 'formData from templateData')
  108. this.setTemplateData(v)
  109. }
  110. }
  111. }
  112. },
  113. data() {
  114. return {
  115. formData: {},
  116. templateDetail: {},
  117. resource: [], //试验试剂信息
  118. yqResource: [], //仪器信息
  119. yqResourceTmp: [], //仪器信息提交用
  120. resourceTmp:[],//试验试剂信息提交用
  121. sysjColumns: [
  122. { label: 'template.common.reagentName', prop: "mc" },//名称
  123. { label: 'template.common.reagentCode', prop: "bh" },//编号
  124. { label: 'template.common.reagentNo', prop: "ph" },//批号 试剂,供试品才有
  125. { label: 'template.common.concentration', prop: "nd" },//浓度
  126. { label: 'template.common.source', prop: "source" },//来源
  127. { label: 'template.common.reagentExpireDate', prop: "sxrq" },//失效日期
  128. ],
  129. yqsColumns: [
  130. { label: 'template.common.instrumentName', prop: "mc" },//仪器名称
  131. { label: 'template.common.instrumentModel', prop: "xh" },//仪器型号
  132. { label: 'template.common.instrumentCode', prop: "bh" },//仪器编号
  133. { label: 'template.common.nextTestDate', prop: "jzrq" },//下次测试/校准/检定日期
  134. ],
  135. }
  136. },
  137. mounted() { },
  138. unmounted() {
  139. this.setTemplateData({})
  140. },
  141. methods: {
  142. //开始配置
  143. //postData: {bh: '123456'}
  144. async startConfigRequest(postData) {
  145. const res = await sj_startConfiguration(postData)
  146. if (res.code === 200) {
  147. this.$message.success('开始配置成功')
  148. } else {
  149. this.$message.error('开始配置失败')
  150. }
  151. },
  152. //完成配置
  153. async configCompleteRequest(postData) {
  154. const res = await sj_configurationCompleted(postData)
  155. if (res.code === 200) {
  156. this.$message.success('完成配置成功')
  157. } else {
  158. this.$message.error('完成配置失败')
  159. }
  160. },
  161. //分装
  162. async subPackageRequest(postData) {
  163. const res = await sj_subpackage(postData)
  164. if (res.code === 200) {
  165. this.$message.success('分装成功')
  166. } else {
  167. this.$message.error('分装失败')
  168. }
  169. },
  170. //获取打印配置
  171. getBasePrintConfig(data = {}) {
  172. const { printCode, type, row = {} } = data;
  173. const { stepStorageCondition, startDate, expireDate } = this.formData;;
  174. const { nickName, name } = this.$store.getters;
  175. const lang = this.$i18n.locale;
  176. const printConfig = {
  177. "品名": "暂时还不知道品名是哪个字段",
  178. "存储条件": stepStorageCondition,
  179. "配制日期": moment(startDate).format("YYYY-MM-DD"),
  180. "有效期至": moment(expireDate).format("YYYY-MM-DD HH:mm"),
  181. "配置者": lang === "zh_CN" ? nickName : name,
  182. //type==="subPackage"从分装打印过来的,
  183. //type==="row" 从列表上点过来的
  184. "编号": type === "subPackage" ? printCode : (row.targetSolutionCode + row.subTargetSolutionCode),
  185. }
  186. return printConfig
  187. },
  188. async getLatestSn(count = 1) {
  189. const res = await getLatestSn({ count })
  190. if (res.code === 200) {
  191. return res.data
  192. }
  193. return null
  194. },
  195. getResource() {
  196. return this.resourceTmp
  197. },
  198. getYqResource() {
  199. return this.yqResourceTmp
  200. },
  201. //根据ref数组获取直接formData
  202. getFilledFormDataByRefs(refArr = []) {
  203. let result = {}
  204. refArr.map((ref) => {
  205. const refData = this.$refs[ref]?.getFilledFormData() || {}
  206. for (const [key, value] of Object.entries(refData)) {
  207. let index = 0
  208. // 如果当前键是可能重复的字段,且结果对象中已经存在该键,则添加索引后缀
  209. if (
  210. (key === 'headerSelectFields' || key === 'stepTableFormData') &&
  211. result.hasOwnProperty(key)
  212. ) {
  213. // 为重复字段生成带索引的键名,从1开始(因为第一个组件不需要后缀)
  214. const newKey = `${key}_${++index}`
  215. result[newKey] = value
  216. } else {
  217. // 正常合并其他字段
  218. result[key] = value
  219. }
  220. }
  221. })
  222. return result
  223. },
  224. //统一校验form表单是否填写
  225. async validFormFields(refArr = []) {
  226. let result = {}
  227. const refs = refArr.map((ref) => {
  228. let refData = {}
  229. if (this.$refs[ref][0]) {
  230. refData = this.$refs[ref][0]?.getFormData() || {}
  231. } else {
  232. refData = this.$refs[ref]?.getFormData() || {}
  233. }
  234. return refData
  235. })
  236. const validFormData = await Promise.all(refs).catch((err) => {
  237. // this.$message.error(err);
  238. if (err.errorType && err.errorType === 'step') {
  239. this.$message.error('请添加步骤')
  240. return
  241. }
  242. this.$message.error('表单内容未填完,请填写后再提交')
  243. })
  244. if (validFormData) {
  245. validFormData.forEach((item) => {
  246. for (const [key, value] of Object.entries(item)) {
  247. let index = 0
  248. // 如果当前键是可能重复的字段,且结果对象中已经存在该键,则添加索引后缀
  249. if (
  250. (key === 'headerSelectFields' || key === 'stepTableFormData') &&
  251. result.hasOwnProperty(key)
  252. ) {
  253. // 为重复字段生成带索引的键名,从1开始(因为第一个组件不需要后缀)
  254. const newKey = `${key}_${++index}`
  255. result[newKey] = value
  256. } else {
  257. // 正常合并其他字段
  258. result[key] = value
  259. }
  260. }
  261. })
  262. return result
  263. }
  264. return false
  265. },
  266. //试验配制条件options
  267. getDictOptions(dictType) {
  268. return this.dict.type[dictType] || []
  269. },
  270. setTemplateData(data) {
  271. this.$store.commit('template/SET_TEMPLATE_DATA', data)
  272. },
  273. //统一处理删除行
  274. deleteRow(index) {
  275. this.$refs.stepTableRef.deleteRow(index)
  276. },
  277. //统一处理blur事件,因为有效周期和过期日期是相关的,所以需要在有效周期失焦时更新过期日期
  278. onHandleBlur(fields) {
  279. const {
  280. key,
  281. effectivePeriodUnit,
  282. effectivePeriod,
  283. codeSTD,
  284. targetStartSolution
  285. } = fields
  286. const { startDate } = this.formData
  287. if (key === 'codeSTD') {
  288. //起始编号STD失焦时,更新stepDataSource
  289. const arr = Array.from({ length: codeSTD }, (item, index) => ({
  290. actSolutionVolumePrecision: 3, //小数点精度默认为3
  291. actSolutionConcentrationPrecision: 3, //小数点精度默认为3
  292. targetDiluentVolumePrecision: 3, //小数点精度默认为3
  293. targetStartSolutionVolumePrecision: 3, //小数点精度默认为3
  294. targetSolutionCode: `STD${Number(codeSTD) - index}`
  295. }))
  296. this.$refs.stepTableRef.updateDataSource(arr)
  297. } else if (key === 'targetStartSolution') {
  298. //起始溶液体积失焦时,更新目标溶液预计浓度
  299. const arr = this.$refs.stepTableRef?.getDataSource()
  300. arr.forEach((item, rowIndex) => {
  301. this.updateTargetStartSolutionVolume(
  302. rowIndex,
  303. item,
  304. targetStartSolution
  305. )
  306. })
  307. }
  308. },
  309. //统一处理table失焦事件
  310. onHandleTableBlur(params) {
  311. const { rowIndex, colKey, value, item } = params
  312. if (
  313. colKey === 'targetSolutionVolume' ||
  314. colKey === 'targetSolutionConcentration' ||
  315. colKey === 'targetStartSolutionVolumePrecision' ||
  316. colKey === 'targetDiluentVolumePrecision'
  317. ) {
  318. const volume =
  319. this.$refs.stepFormPackageRef?.getFormDataByKey(
  320. 'targetStartSolution'
  321. ) || 0
  322. if (volume) {
  323. this.updateTargetStartSolutionVolume(item, volume)
  324. }
  325. } else if (
  326. colKey === 'actStartSolutionVolume' ||
  327. colKey === 'actDiluentVolume'
  328. ) {
  329. //实际起始溶液体积和实际目标溶液体积
  330. const targetAcSolution =
  331. this.$refs.stepFormPackageRef?.getFormDataByKey('targetAcSolution') ||
  332. 0 //获取实际起始溶液浓度
  333. if (targetAcSolution) {
  334. const { actVol, actNd } = this.updateSjmbrynd(item, targetAcSolution);
  335. this.$refs.stepTableRef?.updateDataSourceByRowIndex(rowIndex, { actSolutionVolume: actVol })
  336. this.$refs.stepTableRef?.updateDataSourceByRowIndex(rowIndex, { actSolutionConcentration: actNd })
  337. }
  338. }
  339. },
  340. //计算并更新实际目标溶液浓度 先计算实际目标溶液体积再计算实际目标溶液浓度
  341. updateSjmbrynd(item, targetAcSolution) {
  342. //实际源溶液浓度÷(实际终体积÷源溶液加入体积);
  343. const precision = item.actSolutionConcentrationPrecision || 0
  344. const volPrecision = item.actSolutionVolumePrecision || 0
  345. //实际稀释液体积
  346. const actDiluentVolume = item.actDiluentVolume || 0
  347. const actStartSolutionVolume = item.actStartSolutionVolume || 0
  348. //实际高源溶液加入体积+实际稀释液加入体积
  349. const actVol = (
  350. Number(actStartSolutionVolume) + Number(actDiluentVolume)
  351. ).toFixed(volPrecision)
  352. //实际目标溶液体积
  353. // item.actSolutionVolume = actVol
  354. //实际目标溶液浓度
  355. const actNd = (
  356. targetAcSolution /
  357. actStartSolutionVolume /
  358. actVol
  359. ).toFixed(precision)
  360. const nd = actNd === 'Infinity' ? 0 : actNd
  361. console.log(actNd, targetAcSolution, actStartSolutionVolume, actVol, "actNd")
  362. // item.actSolutionConcentration = actNd === 'Infinity' ? 0 : actNd
  363. return { actVol, actNd: nd }
  364. },
  365. //更新起始溶液体积时,计算目标溶液预计浓度
  366. updateTargetStartSolutionVolume(item, volume) {
  367. const precision = item.targetStartSolutionVolumePrecision || 0
  368. const concentration = item.targetSolutionConcentration || 0
  369. const targetVolume = item.targetSolutionVolume || 0
  370. //目标溶液预计浓度:(目标溶液预计体积 乘以 起始溶液浓度)除以 起始溶液体积
  371. const result = ((concentration * targetVolume) / volume).toFixed(
  372. precision
  373. )
  374. item.targetStartSolutionVolume = result
  375. // this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetStartSolutionVolume: result });
  376. if (targetVolume) {
  377. //预设稀释液体积:目标溶液预计体积 减去 源溶液预计体积;
  378. const precision1 = item.targetDiluentVolumePrecision || 0
  379. const result1 = (targetVolume - result).toFixed(precision1)
  380. item.targetDiluentVolume = result1
  381. // this.$refs.stepTableRef.updateDataSourceByRowIndex(rowIndex, { targetDiluentVolume: result1 });
  382. }
  383. }
  384. }
  385. }