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

186 lines
4.7 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. getStepData: { default: () => null },
  8. getMybh: { default: () => null }
  9. },
  10. dicts: [
  11. 'business_tjdw',
  12. 'business_czhj',
  13. 'business_rqcz',
  14. 'business_zldw',
  15. 'business_yqscdw',
  16. 'business_zsdw',
  17. 'business_wddw',
  18. 'business_ccwz',
  19. 'business_ggdw',
  20. 'business_hjxx',
  21. 'business_zzzc',
  22. 'business_step_pcr',
  23. 'business_fycx',
  24. 'business_step_pcrfxyp',
  25. 'business_cctj'
  26. ],
  27. props: {
  28. formData: {
  29. type: Object,
  30. default: () => ({})
  31. },
  32. stepIndex: {
  33. type: String,
  34. default: ''
  35. }
  36. },
  37. data() {
  38. return {
  39. uuid: getuuid(),
  40. fzInfo: {},
  41. }
  42. },
  43. mounted() {
  44. EventBus.$on('dialogSubPackageSubmit', (data) => {
  45. this.onSubPackageSubmit(data)
  46. })
  47. EventBus.$on('subPackageDialogPrintTag', (data) => {
  48. this.onPrintTag(data)
  49. })
  50. },
  51. destroyed() {
  52. EventBus.$off('dialogSubPackageSubmit')
  53. EventBus.$off('subPackageDialogPrintTag')
  54. },
  55. methods: {
  56. //回填编号 preField 前缀 updateField 需要更新的字段
  57. async handleBackfillCode(preField, updateField) {
  58. const updateValue = this.formData[updateField];
  59. if (this.templateFillType === 'actFill' && !updateValue) {
  60. const stepFormData = this.getFilledFormData();
  61. const preValue = stepFormData[preField];
  62. const result = await this.getLatestSn({
  63. pre: preValue,
  64. })
  65. this.$refs.stepFormPackageRef.updateFormData(updateField, result[0])
  66. this.justUpdateFilledFormData();
  67. }
  68. },
  69. justUpdateFilledFormData() {
  70. justUpdateFilledFormData();
  71. },
  72. //获取最新的多个编号
  73. async getLatestSnArr(params) {
  74. const res = await getLatestSnArr(params)
  75. if (res.code === 200) {
  76. return res.data
  77. }
  78. return []
  79. },
  80. async getLatestSn(params) {
  81. const defaultParams = {
  82. count: 1,
  83. type: 1,
  84. pre: ''
  85. }
  86. const finalParams = { ...defaultParams, ...params }
  87. const res = await getLatestSn(finalParams)
  88. if (res.code === 200) {
  89. return res.data
  90. }
  91. return []
  92. },
  93. // 打印标签
  94. onPrintTag(data) {
  95. this.$emit('printTag')
  96. },
  97. onSubPackageSubmit(data) {
  98. if (data.uuid === this.uuid) {
  99. delete data.uuid //删除uuid字段,不然会导致下次匹配的时候匹配到错误的uuid
  100. this.$refs.stepFormPackageRef.updateFormData('fzInfo', data)
  101. this.justUpdateFilledFormData();
  102. }
  103. },
  104. // 点击按钮
  105. onHandleClickButton(e, item, key) {
  106. const {
  107. buttonName = '',
  108. myCodeFields = [],
  109. maxVolumeField = '',
  110. maxVolumeUnitField = ''
  111. } = e
  112. if (buttonName === '分装') {
  113. const stepFormData = this.getFilledFormData()
  114. const fzInfo = stepFormData.fzInfo || this.formData.fzInfo;
  115. let fields = [],options = []
  116. let maxVolume, maxVolumeUnit;
  117. if (this.getMybh && this.getMybh()) {
  118. const { mybh,mybhOptions=[], maxVolume:max, maxVolumeUnit:unit } = this.getMybh()
  119. if((!mybh &&!mybhOptions.length) || !max || !unit){
  120. this.$message.warning('请先填写分装数据')
  121. return
  122. }
  123. options = mybhOptions
  124. fields.push(mybh)
  125. maxVolume = max || ''
  126. maxVolumeUnit = unit || ''
  127. } else {
  128. if (!myCodeFields.length || !maxVolumeField || !maxVolumeUnitField) {
  129. this.$message.warning('请配制分装参数')
  130. return
  131. }
  132. maxVolume = stepFormData[maxVolumeField]
  133. maxVolumeUnit = stepFormData[maxVolumeUnitField]
  134. myCodeFields.forEach((key) => {
  135. fields.push(stepFormData[key])
  136. })
  137. }
  138. EventBus.$emit('showSubPackageDialog', {
  139. mybh: fields.join(''),
  140. id: this.stepIndex,
  141. fzType: 'step',
  142. ...fzInfo,
  143. maxVolume,
  144. mybhOptions:options,
  145. maxVolumeUnit,
  146. uuid: this.uuid,
  147. })
  148. }
  149. },
  150. async getFormData() {
  151. const data = await this.$refs.stepFormPackageRef.getFormData();
  152. data.fzInfo = data.fzInfo || this.formData.fzInfo;
  153. return data
  154. },
  155. getFilledFormData() {
  156. const data = this.$refs.stepFormPackageRef?.getFilledFormData();
  157. data.fzInfo = data.fzInfo || this.formData.fzInfo;
  158. return data
  159. },
  160. getSjResource() {
  161. const data = this.$refs.stepFormPackageRef?.getSjResource();
  162. data.fzInfo = data.fzInfo || this.formData.fzInfo;
  163. return data
  164. },
  165. //试验配制条件options
  166. getDictOptions(dictType) {
  167. return this.dict.type[dictType] || []
  168. },
  169. resetRecord() {
  170. this.$refs.stepFormPackageRef.resetRecord()
  171. },
  172. //更新温层数据
  173. updateWcData(key, value) {
  174. const options = this.getDictOptions('business_ccwz')
  175. const selectedOption = options.find((item) => item.value === value)
  176. if (selectedOption) {
  177. this.$refs.stepFormPackageRef.updateFormData(key, [
  178. selectedOption.raw.remark
  179. ])
  180. }
  181. }
  182. }
  183. }