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

293 lines
8.5 KiB

  1. import { getuuid, justUpdateFilledFormData } from '@/utils/index.js'
  2. import { EventBus } from '@/utils/eventBus'
  3. import { getLatestSn, getLatestSnArr } from '@/api/template'
  4. import { getBalance, getPh } from '@/utils/tpph.js';
  5. export default {
  6. inject: {
  7. templateFillType: { default: 'preFill' },
  8. templateData: { default: {} },
  9. templateSn: { default: '' },
  10. getStepData: { default: () => null },
  11. getJcbData: { default: () => null },
  12. getMybh: { default: () => null },
  13. getMybhByIndex: { default: (index) => null }
  14. },
  15. dicts: [
  16. 'business_tjdw',
  17. 'business_czhj',
  18. 'business_rqcz',
  19. 'business_zldw',
  20. 'business_yqscdw',
  21. 'business_zsdw',
  22. 'business_wddw',
  23. 'business_ccwz',
  24. 'business_ggdw',
  25. 'business_hjxx',
  26. 'business_zzzc',
  27. 'business_step_pcr',
  28. 'business_fycx',
  29. 'business_step_pcrfxyp',
  30. 'business_cctj'
  31. ],
  32. props: {
  33. formData: {
  34. type: Object,
  35. default: () => ({})
  36. },
  37. stepIndex: {
  38. type: String,
  39. default: ''
  40. },
  41. formIndex: {
  42. type: Number,
  43. default: 0
  44. },
  45. formType: {
  46. type: String,
  47. default: ''
  48. },
  49. fieldItemLabel: {
  50. type: String,
  51. default: ''
  52. }
  53. },
  54. data() {
  55. return {
  56. uuid: getuuid(),
  57. fzInfo: {},
  58. localFormData: {},
  59. }
  60. },
  61. mounted() {
  62. EventBus.$on('dialogSubPackageSubmit', (data) => {
  63. this.onSubPackageSubmit(data)
  64. })
  65. EventBus.$on('subPackageDialogPrintTag', (data) => {
  66. this.onPrintTag(data)
  67. })
  68. },
  69. destroyed() {
  70. EventBus.$off('dialogSubPackageSubmit')
  71. EventBus.$off('subPackageDialogPrintTag')
  72. },
  73. methods: {
  74. //处理jcb更新
  75. commonHandleJcbUpdate() {
  76. this.localFormData = this.formData;
  77. if (!this.formData.jcb && this.templateFillType === 'actFill') {
  78. setTimeout(() => {
  79. const qbData = this.getQbData();
  80. this.localFormData = { ...this.localFormData, jcb: qbData };
  81. justUpdateFilledFormData();
  82. }, 3000);
  83. }
  84. },
  85. //获取取板数据
  86. getQbData() {
  87. let qbData = [];
  88. if (this.templateSn === "LBA003" || this.templateSn === "ADA003") {//只有lba003才会有取板步骤,所以检测板数据从取板数据里面获取;
  89. const stepData = this.getStepData() || [];
  90. const filterData = stepData.filter((item) => item.type === "qb");
  91. const allQbData = [];
  92. filterData.forEach((item) => {
  93. const { stepTableFormData = [] } = item.formData.qb || {};
  94. const parseData = JSON.parse(JSON.stringify(stepTableFormData));
  95. allQbData.push(...parseData);
  96. })
  97. qbData = [...new Map(allQbData.map(item => [item.mc, item])).values()]
  98. } else if (this.templateSn === "LBA002" || this.templateSn === "ADA002") {//lba002没有取板步骤,所以检测板数据从检测板数据里面获取;
  99. const { stepTableFormData = [] } = this.getJcbData() || {};
  100. qbData = stepTableFormData;
  101. }
  102. return { stepTableFormData: JSON.parse(JSON.stringify(qbData)) }
  103. },
  104. //回填编号 preField 前缀 updateField 需要更新的字段
  105. async handleBackfillCode(preField, updateField) {
  106. const updateValue = this.formData[updateField];
  107. if (this.templateFillType === 'actFill' && !updateValue) {
  108. const stepFormData = this.getFilledFormData();
  109. const preValue = stepFormData[preField];
  110. const result = await this.getLatestSn({
  111. pre: preValue,
  112. })
  113. this.$refs.stepFormPackageRef.updateFormData(updateField, result[0])
  114. this.justUpdateFilledFormData();
  115. }
  116. },
  117. justUpdateFilledFormData() {
  118. justUpdateFilledFormData();
  119. },
  120. //获取最新的多个编号
  121. async getLatestSnArr(params) {
  122. const res = await getLatestSnArr(params)
  123. if (res.code === 200) {
  124. return res.data
  125. }
  126. return []
  127. },
  128. async getLatestSn(params) {
  129. const defaultParams = {
  130. count: 1,
  131. type: 1,
  132. pre: ''
  133. }
  134. const finalParams = { ...defaultParams, ...params }
  135. const res = await getLatestSn(finalParams)
  136. if (res.code === 200) {
  137. return res.data
  138. }
  139. return []
  140. },
  141. // 打印标签
  142. onPrintTag(data) {
  143. this.$emit('printTag')
  144. },
  145. onSubPackageSubmit(data) {
  146. if (data.uuid === this.uuid) {
  147. delete data.uuid //删除uuid字段,不然会导致下次匹配的时候匹配到错误的uuid
  148. this.$refs.stepFormPackageRef.updateFormData('fzInfo', data)
  149. this.justUpdateFilledFormData();
  150. }
  151. },
  152. onBeforeSaveRecord(params) {
  153. const { callback, item } = params
  154. const { buttonName } = item;
  155. if (buttonName === '获取值') {
  156. const { dataSource, yqCode } = item;
  157. const stepFormData = this.getFilledFormData()
  158. if (dataSource === "tp" || dataSource === "ph") {//电子天平或PH测量仪
  159. const yq = stepFormData[yqCode] || "";
  160. const obj = {
  161. tp:"请选择电子天平",
  162. ph:"请选择PH测量仪"
  163. }
  164. if (!yq) {
  165. callback.prevent(obj[dataSource])
  166. }
  167. }
  168. }
  169. },
  170. // 点击按钮
  171. async onHandleClickButton(e, item, key,signData) {
  172. const {
  173. buttonName = '',
  174. myCodeFields = [],
  175. maxVolumeField = '',
  176. maxVolumeUnitField = ''
  177. } = e
  178. if (buttonName === '分装') {
  179. const stepFormData = this.getFilledFormData()
  180. const fzInfo = stepFormData.fzInfo || this.formData.fzInfo;
  181. let fields = [], options = []
  182. let maxVolume, maxVolumeUnit;
  183. if (this.getMybh || this.getMybhByIndex) {//某些表单的步骤需要分装表单上的数据
  184. let result = {};
  185. if (this.getMybh) {
  186. result = this.getMybh()
  187. } else if (this.getMybhByIndex) {
  188. result = this.getMybhByIndex(this.formIndex, this.formType)
  189. }
  190. const { mybh, mybhOptions = [], maxVolume: max, maxVolumeUnit: unit } = result
  191. // if ((!mybh && !mybhOptions.length) || !max || !unit) {
  192. // this.$message.warning('请先填写分装数据')
  193. // return
  194. // }
  195. options = mybhOptions
  196. fields.push(mybh)
  197. maxVolume = max || ''
  198. maxVolumeUnit = unit || ''
  199. } else {
  200. if (!myCodeFields.length || !maxVolumeField || !maxVolumeUnitField) {
  201. this.$message.warning('请配制分装参数')
  202. return
  203. }
  204. maxVolume = stepFormData[maxVolumeField]
  205. maxVolumeUnit = stepFormData[maxVolumeUnitField]
  206. myCodeFields.forEach((key) => {
  207. fields.push(stepFormData[key])
  208. })
  209. }
  210. EventBus.$emit('showSubPackageDialog', {
  211. mybh: fields.join(''),
  212. id: this.stepIndex,
  213. fzType: 'step',
  214. ...fzInfo,
  215. maxVolume,
  216. mybhOptions: options,
  217. maxVolumeUnit,
  218. uuid: this.uuid,
  219. })
  220. } else if (buttonName === '获取值') {
  221. const { dataSource, dwField = "", fillField,fillDwField = "", yqCode } = e;
  222. const stepFormData = this.getFilledFormData()
  223. const yqInfo = stepFormData[`yqInfo_${yqCode}`] || {};
  224. if (dataSource === "tp") {//电子天平
  225. const dw = stepFormData[dwField] || "";
  226. const oldValue = stepFormData[fillDwField] || "";
  227. const result = await getBalance({ yq: yqInfo, dw });
  228. if (result.success) {
  229. const value = dw?result.value:`${result.value}${result.unit}`
  230. if(fillDwField){//需要回填的单位字段
  231. this.$refs.stepFormPackageRef.updateFormData(fillField, value)
  232. this.$refs.stepFormPackageRef.updateFormData(fillDwField, result.unit,{isUpdateRecord:true,signData,record:{
  233. oldValue,
  234. inputValue:result.value+result.unit
  235. }})
  236. }else{
  237. this.$refs.stepFormPackageRef.updateFormData(fillField, value,{isUpdateRecord:true,signData})
  238. }
  239. } else {
  240. this.$message.error(result.message || "获取值失败");
  241. }
  242. }else if(dataSource === "ph"){
  243. const result = await getPh({ yq: yqInfo });
  244. if (result.success) {
  245. this.$refs.stepFormPackageRef.updateFormData(fillField, result.value,{isUpdateRecord:true,signData})
  246. } else {
  247. this.$message.error(result.message || "获取值失败");
  248. }
  249. }
  250. }
  251. },
  252. async getFormData() {
  253. const data = await this.$refs.stepFormPackageRef.getFormData();
  254. data.fzInfo = data.fzInfo || this.formData.fzInfo;
  255. return data
  256. },
  257. getFilledFormData() {
  258. const data = this.$refs.stepFormPackageRef?.getFilledFormData();
  259. data.fzInfo = data.fzInfo || this.formData.fzInfo;
  260. return data
  261. },
  262. getSjResource() {
  263. const data = this.$refs.stepFormPackageRef?.getSjResource();
  264. data.fzInfo = data.fzInfo || this.formData.fzInfo;
  265. return data
  266. },
  267. //试验配制条件options
  268. getDictOptions(dictType) {
  269. return this.dict.type[dictType] || []
  270. },
  271. resetRecord() {
  272. this.$refs.stepFormPackageRef.resetRecord()
  273. },
  274. //更新温层数据
  275. updateWcData(key, value) {
  276. const options = this.getDictOptions('business_ccwz')
  277. const selectedOption = options.find((item) => item.value === value)
  278. if (selectedOption) {
  279. this.$refs.stepFormPackageRef.updateFormData(key, [
  280. selectedOption.raw.remark
  281. ])
  282. }
  283. }
  284. }
  285. }