Step3.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
  3. <a-table
  4. :columns="columns"
  5. :dataSource="model.list"
  6. :pagination="false"
  7. >
  8. <template slot="yangpinKeyId" slot-scope="text, record,index">
  9. <a-form-model-item :prop="'list.'+index+'.yangpinKeyId'" :rules="validatorRules.yangpinKeyId">
  10. <a-select :disabled="formDisabled" v-model="record.yangpinKeyId">
  11. <a-select-option v-for="d in yangpins" :key="d.sampleName">
  12. {{ d.sampleName }}
  13. </a-select-option>
  14. </a-select>
  15. </a-form-model-item>
  16. </template>
  17. <template slot="testItems" slot-scope="text, record,index">
  18. <a-form-model-item :prop="'list.'+index+'.testItems'" :rules="validatorRules.testItems">
  19. <a-input :disabled="formDisabled" v-model="record.testItems" />
  20. </a-form-model-item>
  21. </template>
  22. <template slot="standardRequirement" slot-scope="text, record,index">
  23. <a-form-model-item :prop="'list.'+index+'.standardRequirement'" :rules="validatorRules.standardRequirement">
  24. <j-multi-select-tag :disabled="formDisabled" v-model="record.standardRequirement"
  25. dictCode="itdm_weituo_yiju,name,name" />
  26. </a-form-model-item>
  27. </template>
  28. <template slot="judgementBasis" slot-scope="text, record,index">
  29. <a-form-model-item :prop="'list.'+index+'.judgementBasis'" :rules="validatorRules.judgementBasis">
  30. <a-input :disabled="formDisabled" v-model="record.judgementBasis" />
  31. </a-form-model-item>
  32. </template>
  33. <template slot="yijufile" slot-scope="text, record,index">
  34. <a-form-model-item :prop="'list.'+index+'.yijufile'" :rules="validatorRules.yijufile">
  35. <a-input :disabled="formDisabled" v-model="record.yijufile" />
  36. </a-form-model-item>
  37. </template>
  38. <template slot="beizhu" slot-scope="text, record,index">
  39. <a-form-model-item :prop="'list.'+index+'.beizhu'">
  40. <a-input :disabled="formDisabled" v-model="record.beizhu" />
  41. </a-form-model-item>
  42. </template>
  43. <template slot="operation" slot-scope="text, record">
  44. <span>
  45. <a-popconfirm :disabled="formDisabled" title="是否要删除此行?" @confirm="remove(record.key)">
  46. <a>删除</a>
  47. </a-popconfirm>
  48. </span>
  49. </template>
  50. </a-table>
  51. <a-button :disabled="formDisabled" style="width: 100%; margin-top: 16px; margin-bottom: 8px" type="dashed"
  52. icon="plus"
  53. @click="newMember">
  54. 新增试验信息
  55. </a-button>
  56. <a-form-item class="buttonAll">
  57. <div class="all">
  58. <a-button style="margin-left: 8px" @click="prevStep" class="next">上一步</a-button>
  59. <a-button v-if="!disabled" type="primary" style="margin-left: 8px" @click="submitForm" class="next">提交
  60. </a-button>
  61. </div>
  62. </a-form-item>
  63. </a-form-model>
  64. </template>
  65. <script>
  66. export default {
  67. name: 'step3',
  68. props: {
  69. //表单禁用
  70. disabled: {
  71. type: Boolean,
  72. default: false,
  73. required: false
  74. }
  75. },
  76. data() {
  77. return {
  78. yangpins: {},
  79. count: 1,
  80. model: {
  81. list: []
  82. },
  83. description: '高级表单常见于一次性输入和提交大批量数据的场景。',
  84. loading: false,
  85. validatorRules: {
  86. yangpinKeyId: [
  87. { required: true, message: '请选择样品!' }
  88. ],
  89. testItems: [
  90. { required: true, message: '请输入检测项目!' }
  91. ]
  92. },
  93. // table
  94. columns: [
  95. {
  96. title: '样品名称',
  97. dataIndex: 'yangpinKeyId',
  98. key: 'yangpinKeyId',
  99. align: 'center',
  100. width: '15%',
  101. scopedSlots: { customRender: 'yangpinKeyId' }
  102. },
  103. {
  104. title: '检测项目',
  105. dataIndex: 'testItems',
  106. key: 'testItems',
  107. align: 'center',
  108. width: '15%',
  109. scopedSlots: { customRender: 'testItems' }
  110. },
  111. {
  112. title: '检测依据',
  113. dataIndex: 'standardRequirement',
  114. key: 'standardRequirement',
  115. align: 'center',
  116. width: '20%',
  117. scopedSlots: { customRender: 'standardRequirement' }
  118. },
  119. {
  120. title: '判定依据',
  121. dataIndex: 'judgementBasis',
  122. key: 'judgementBasis',
  123. align: 'center',
  124. width: '25%',
  125. scopedSlots: { customRender: 'judgementBasis' }
  126. },
  127. {
  128. title: '检测依据文件',
  129. dataIndex: 'yijufile',
  130. key: 'yijufile',
  131. width: '15%',
  132. align: 'center',
  133. scopedSlots: { customRender: 'yijufile' }
  134. },
  135. {
  136. title: '备注',
  137. dataIndex: 'beizhu',
  138. key: 'beizhu',
  139. width: '15%',
  140. align: 'center',
  141. scopedSlots: { customRender: 'beizhu' }
  142. },
  143. {
  144. title: '操作',
  145. key: 'action',
  146. align: 'center',
  147. scopedSlots: { customRender: 'operation' }
  148. }
  149. ],
  150. data: []
  151. }
  152. },
  153. computed: {
  154. formDisabled() {
  155. return this.disabled
  156. }
  157. },
  158. created() {
  159. const data = JSON.parse(sessionStorage.getItem('yangpinkz'))
  160. if (data != null) {
  161. this.model.list=data
  162. }
  163. console.log(sessionStorage.getItem('yangpin'))
  164. const yangpins = JSON.parse(sessionStorage.getItem('yangpin'))
  165. if (yangpins != null) {
  166. this.yangpins = yangpins
  167. console.log(this.yangpins)
  168. }
  169. this.count = sessionStorage.getItem('count1') != null ? Number(sessionStorage.getItem('count1')) : 1
  170. },
  171. methods: {
  172. newMember() {
  173. this.model.list.push({
  174. key: this.count + '',
  175. yangpinKeyId: '',
  176. testItems: '',
  177. standardRequirement: '',
  178. judgementBasis: '',
  179. yijufile: '',
  180. beizhu: '',
  181. editable: true,
  182. isNew: true
  183. })
  184. this.count++
  185. sessionStorage.setItem('count1', this.count)
  186. },
  187. remove(key) {
  188. const newData = this.model.list.filter(item => item.key !== key)
  189. this.model.list = newData
  190. },
  191. saveRow(key) {
  192. let target = this.model.list.filter(item => item.key === key)[0]
  193. target.editable = false
  194. target.isNew = false
  195. },
  196. handleChange(value, key, column) {
  197. const newData = [...this.model.list]
  198. const target = newData.filter(item => key === item.key)[0]
  199. if (target) {
  200. target[column] = value
  201. this.model.list = newData
  202. }
  203. },
  204. submitForm() {
  205. sessionStorage.setItem('yangpinkz', JSON.stringify(this.model.list))
  206. this.$refs.form.validate(valid => {
  207. if (valid) {
  208. this.$emit('submitForm')
  209. }
  210. })
  211. },
  212. prevStep() {
  213. sessionStorage.setItem('yangpinkz', JSON.stringify(this.model.list))
  214. this.$emit('prevStep')
  215. }
  216. }
  217. }
  218. </script>
  219. <style lang="less" scoped>
  220. .card {
  221. margin-bottom: 24px;
  222. }
  223. .next {
  224. width: 35%;
  225. margin-left: 20px;
  226. margin-right: 20px;
  227. margin-top: 20px;
  228. }
  229. .buttonAll {
  230. width: 100%;
  231. align-items: center;
  232. justify-content: center;
  233. }
  234. .all {
  235. width: 100%;
  236. display: flex;
  237. align-items: center;
  238. justify-content: center;
  239. }
  240. </style>