ItdmWeituoInfoForm.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <a-card :bordered="false">
  3. <a-steps class="steps" :current="currentTab">
  4. <a-step title="填写基本信息" />
  5. <a-step title="填写样品信息" />
  6. <a-step title="填写试验信息" />
  7. </a-steps>
  8. <div class="content">
  9. <step1 v-if="currentTab === 0" ref="data001" @nextStep="nextStep" :disabled="disabled"/>
  10. <step2 v-if="currentTab === 1" @prevStep="prevStep" ref="ypxx" @nextStep="nextStep" :disabled="disabled" />
  11. <step3 v-if="currentTab === 2" @submitForm="submitForm" ref="syxx" @prevStep="prevStep" :disabled="disabled" />
  12. </div>
  13. </a-card>
  14. </template>
  15. <script>
  16. import { httpAction, getAction, postAction } from '@api/manage'
  17. import { validateDuplicateValue } from '@/utils/util'
  18. import Step1 from './step/Step1'
  19. import Step2 from './step/Step2'
  20. import Step3 from './step/Step3'
  21. export default {
  22. name: 'ItdmWeituoInfoForm',
  23. components: {
  24. Step1,
  25. Step2,
  26. Step3
  27. },
  28. props: {
  29. //表单禁用
  30. disabled: {
  31. type: Boolean,
  32. default: false,
  33. required: false
  34. }
  35. },
  36. data() {
  37. return {
  38. currentTab: 0,
  39. weituomodel: {},
  40. model: {},
  41. labelCol: {
  42. xs: { span: 24 },
  43. sm: { span: 5 }
  44. },
  45. wrapperCol: {
  46. xs: { span: 24 },
  47. sm: { span: 16 }
  48. },
  49. confirmLoading: false,
  50. validatorRules: {},
  51. url: {
  52. add: '/weituo/itdmWeituoInfo/add',
  53. edit: '/weituo/itdmWeituoInfo/edit',
  54. queryById: '/weituo/itdmWeituoInfo/queryById'
  55. }
  56. }
  57. },
  58. computed: {
  59. formDisabled() {
  60. return this.disabled
  61. },
  62. baseInfos() {
  63. return this.$store.getters.baseInfos
  64. },
  65. yangpinInfos() {
  66. return this.$store.getters.yangpinInfos
  67. },
  68. shiyanInfos() {
  69. return this.$store.getters.shiyanInfos
  70. },
  71. },
  72. created() {
  73. //备份model原始值
  74. this.modelDefault = JSON.parse(JSON.stringify(this.model))
  75. },
  76. methods: {
  77. nextStep() {
  78. if (this.currentTab < 3) {
  79. this.currentTab += 1
  80. }
  81. },
  82. prevStep() {
  83. if (this.currentTab > 0) {
  84. this.currentTab -= 1
  85. }
  86. },
  87. add() {
  88. this.model = Object.assign({}, this.modelDefault)
  89. this.visible = true
  90. },
  91. edit(record) {
  92. const that = this
  93. const select = { id: record.id }
  94. getAction(this.url.queryById, select).then((res) => {
  95. if (res.success) {
  96. this.model.id = res.result.id
  97. // sessionStorage.setItem('data', JSON.stringify(res.result.data))
  98. // sessionStorage.setItem('yangpin', JSON.stringify(res.result.yangpins))
  99. // sessionStorage.setItem('yangpinkz', JSON.stringify(res.result.pinShiYans))
  100. this.$store.commit('SET_BASEINFO', res.result.data);
  101. this.$store.commit('SET_YANGPININFO', res.result.yangpins);
  102. this.$store.commit('SET_SHIYANINFO', res.result.pinShiYans);
  103. this.$store.commit('SET_COUNTYP', res.result.yangpins.length>0?res.result.yangpins.length>0:1);
  104. this.$store.commit('SET_COUNTSY', res.result.pinShiYans.length>0?res.result.pinShiYans.length>0:1);
  105. this.$refs.data001.init()
  106. } else {
  107. that.$message.warning(res.message)
  108. }
  109. })
  110. this.visible = true
  111. },
  112. submitForm() {
  113. const that = this
  114. // 触发表单验证
  115. // this.weituomodel = JSON.parse(sessionStorage.getItem('data'))
  116. // this.weituomodel.yangpins = JSON.parse(sessionStorage.getItem('yangpin'))
  117. // this.weituomodel.pinShiYans = JSON.parse(sessionStorage.getItem('yangpinkz'))
  118. // console.log(JSON.parse(sessionStorage.getItem('yangpinkz')))
  119. // var pinShiYans = JSON.parse(sessionStorage.getItem('yangpinkz'))
  120. this.weituomodel = this.baseInfos
  121. this.weituomodel.yangpins = this.yangpinInfos
  122. this.weituomodel.shiyanInfos = this.shiyanInfos.map(item => {
  123. item.standardRequirement = item.standardRequirementQ.join(',')
  124. return item
  125. })
  126. that.confirmLoading = true
  127. let httpurl = ''
  128. let method = ''
  129. if (!this.model.id) {
  130. httpurl += this.url.add
  131. method = 'post'
  132. } else {
  133. httpurl += this.url.edit
  134. method = 'put'
  135. this.weituomodel.id = this.model.id
  136. }
  137. console.log(this.weituomodel)
  138. httpAction(httpurl, this.weituomodel, method).then((res) => {
  139. if (res.success) {
  140. that.$message.success(res.message)
  141. that.$emit('ok')
  142. } else {
  143. that.$message.warning(res.message)
  144. }
  145. }).finally(() => {
  146. that.confirmLoading = false
  147. })
  148. },
  149. handleCategoryChange(value, backObj) {
  150. this.model = Object.assign(this.model, backObj)
  151. }
  152. }
  153. }
  154. </script>