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

233 lines
6.4 KiB

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