Step3.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. :customRow="clickThenCheck"
  8. ref="table"
  9. bordered
  10. class="u-edit-table"
  11. >
  12. <template slot="yangpinKeyId" slot-scope="text, record,index">
  13. <a-form-model-item :prop="'list.'+index+'.yangpinKeyId'" :rules="validatorRules.yangpinKeyId">
  14. <a-select :disabled="formDisabled" v-model="record.yangpinKeyId" allowClear :dropdownMatchSelectWidth="false" option-label-prop="label" @change="handleChange">
  15. <!-- 针对样品名称有相同的情况,做以下更改 -->
  16. <!-- <a-select-option v-for="d in yangpins" :key="d.sampleName"> -->
  17. <a-select-option v-for="d in yangpins" :key="d.key" :label="d.sampleName" :channel="d">
  18. <!-- <el-row>
  19. <el-col :span="12">{{ d.sampleName }}</el-col>
  20. <el-col :span="12">{{ d.sampleModelSpecification }}</el-col>
  21. </el-row> -->
  22. {{ d.sampleName +'——'+ d.sampleModelSpecification}}
  23. </a-select-option>
  24. </a-select>
  25. </a-form-model-item>
  26. </template>
  27. <template slot="sampleModelSpecification" slot-scope="text, record,index">
  28. <a-form-model-item :prop="'list.'+index+'.sampleModelSpecification'">
  29. <a-input disabled v-model="record.sampleModelSpecification" />
  30. </a-form-model-item>
  31. </template>
  32. <template slot="testItems" slot-scope="text, record,index">
  33. <a-form-model-item :prop="'list.'+index+'.testItems'" :rules="validatorRules.testItems">
  34. <a-input :disabled="formDisabled" v-model="record.testItems" />
  35. </a-form-model-item>
  36. </template>
  37. <template slot="standardRequirementQ" slot-scope="text, record,index">
  38. <a-form-model-item :prop="'list.'+index+'.standardRequirementQ'" :rules="validatorRules.standardRequirementQ">
  39. <!-- <j-multi-select-tag :disabled="formDisabled" v-model="record.standardRequirement" :dropdownMatchSelectWidth="false" dictCode="itdm_weituo_yiju,name,name" /> -->
  40. <!-- 为了解决下拉框显示不全的问题,原来的没有对应参数配置 -->
  41. <a-select
  42. :disabled="formDisabled"
  43. v-model="record.standardRequirementQ"
  44. allowClear
  45. optionFilterProp="label"
  46. :dropdownMatchSelectWidth="false"
  47. @change="handleDescCate"
  48. mode="multiple"
  49. >
  50. <a-select-option v-for="yj in yijuLists" :key="yj.name" :label="yj.name">
  51. {{ yj.name }}
  52. </a-select-option>
  53. </a-select>
  54. </a-form-model-item>
  55. </template>
  56. <template slot="judgementBasis" slot-scope="text, record,index">
  57. <a-form-model-item :prop="'list.'+index+'.judgementBasis'" :rules="validatorRules.judgementBasis">
  58. <a-input :disabled="formDisabled" v-model="record.judgementBasis" />
  59. </a-form-model-item>
  60. </template>
  61. <template slot="yijufile" slot-scope="text, record,index">
  62. <a-form-model-item :prop="'list.'+index+'.yijufile'" :rules="validatorRules.yijufile">
  63. <a-input :disabled="formDisabled" v-model="record.yijufile" />
  64. </a-form-model-item>
  65. </template>
  66. <template slot="beizhu" slot-scope="text, record,index">
  67. <a-form-model-item :prop="'list.'+index+'.beizhu'">
  68. <a-input :disabled="formDisabled" v-model="record.beizhu" />
  69. </a-form-model-item>
  70. </template>
  71. <template slot="operation" slot-scope="text, record">
  72. <span>
  73. <a-popconfirm :disabled="formDisabled" title="是否要删除此行?" @confirm="remove(record.key)">
  74. <a>删除</a>
  75. </a-popconfirm>
  76. </span>
  77. </template>
  78. </a-table>
  79. <a-button :disabled="formDisabled" style="width: 100%; margin-top: 16px; margin-bottom: 8px" type="dashed"
  80. icon="plus"
  81. @click="newMember">
  82. 新增试验信息
  83. </a-button>
  84. <a-form-item class="buttonAll">
  85. <div class="all">
  86. <a-button style="margin-left: 8px" @click="prevStep" class="next">上一步</a-button>
  87. <a-button v-if="!disabled" type="primary" style="margin-left: 8px" @click="submitForm" class="next">提交
  88. </a-button>
  89. </div>
  90. </a-form-item>
  91. </a-form-model>
  92. </template>
  93. <script>
  94. import {getAction} from '@/api/manage'
  95. export default {
  96. name: 'step3',
  97. props: {
  98. //表单禁用
  99. disabled: {
  100. type: Boolean,
  101. default: false,
  102. required: false
  103. }
  104. },
  105. data() {
  106. return {
  107. yangpins: {},
  108. count: 1,
  109. // 当前点击的是第几行
  110. clickIndex: -1,
  111. model: {
  112. list: []
  113. },
  114. description: '高级表单常见于一次性输入和提交大批量数据的场景。',
  115. loading: false,
  116. validatorRules: {
  117. yangpinKeyId: [
  118. { required: true, message: '请选择样品!' }
  119. ],
  120. testItems: [
  121. { required: true, message: '请输入检测标准!' }
  122. ]
  123. },
  124. yijuLists: [],
  125. // table
  126. columns: [
  127. {
  128. title: '样品名称',
  129. dataIndex: 'yangpinKeyId',
  130. key: 'yangpinKeyId',
  131. align: 'center',
  132. width: '12%',
  133. scopedSlots: { customRender: 'yangpinKeyId' }
  134. },
  135. {
  136. title: '规格型号',
  137. dataIndex: 'sampleModelSpecification',
  138. key: 'sampleModelSpecification',
  139. align: 'center',
  140. width: '12%',
  141. scopedSlots: { customRender: 'sampleModelSpecification' }
  142. },
  143. {
  144. title: '检测项目',
  145. dataIndex: 'testItems',
  146. key: 'testItems',
  147. align: 'center',
  148. width: '12%',
  149. scopedSlots: { customRender: 'testItems' }
  150. },
  151. {
  152. title: '检测依据',
  153. dataIndex: 'standardRequirementQ',
  154. key: 'standardRequirementQ',
  155. align: 'center',
  156. width: '15%',
  157. scopedSlots: { customRender: 'standardRequirementQ' }
  158. },
  159. {
  160. title: '判定依据',
  161. dataIndex: 'judgementBasis',
  162. key: 'judgementBasis',
  163. align: 'center',
  164. width: '15%',
  165. scopedSlots: { customRender: 'judgementBasis' }
  166. },
  167. {
  168. title: '检测依据文件',
  169. dataIndex: 'yijufile',
  170. key: 'yijufile',
  171. width: '12%',
  172. align: 'center',
  173. scopedSlots: { customRender: 'yijufile' }
  174. },
  175. {
  176. title: '备注',
  177. dataIndex: 'beizhu',
  178. key: 'beizhu',
  179. width: '7%',
  180. align: 'center',
  181. scopedSlots: { customRender: 'beizhu' }
  182. },
  183. {
  184. title: '操作',
  185. key: 'action',
  186. align: 'center',
  187. width: '5%',
  188. scopedSlots: { customRender: 'operation' }
  189. }
  190. ],
  191. data: []
  192. }
  193. },
  194. computed: {
  195. formDisabled() {
  196. return this.disabled
  197. },
  198. yangpinInfos() {
  199. return this.$store.getters.yangpinInfos
  200. },
  201. shiyanInfos() {
  202. return this.$store.getters.shiyanInfos
  203. },
  204. // count() {
  205. // return this.$store.getters.countSy
  206. // },
  207. },
  208. created() {
  209. this.getYijuLists()
  210. // console.log(JSON.parse(sessionStorage.getItem('yangpin')))
  211. // console.log(JSON.parse(sessionStorage.getItem('yangpinkz')))
  212. // const data = JSON.parse(sessionStorage.getItem('yangpinkz'))
  213. if (this.shiyanInfos.length > 0) {
  214. this.model.list = this.shiyanInfos.map((item, index) => {
  215. // console.log(!item.standardRequirement)
  216. // console.log(item.standardRequirement)
  217. if(!item.standardRequirement){
  218. item.standardRequirementQ = []
  219. } else {
  220. item.standardRequirementQ = item.standardRequirement.split(',')
  221. }
  222. item.key = (index+1) + ''
  223. item.editable = true
  224. return item
  225. })
  226. this.count = this.shiyanInfos.length + 1
  227. console.log(this.model.list)
  228. }else{
  229. this.newMember()
  230. }
  231. // console.log(2323,sessionStorage.getItem('yangpin'))
  232. // const yangpins = JSON.parse(sessionStorage.getItem('yangpin'))
  233. this.yangpins = this.yangpinInfos
  234. // this.count = sessionStorage.getItem('count1') != null ? Number(sessionStorage.getItem('count1')) : 1
  235. },
  236. methods: {
  237. // 获取所有依据列表
  238. getYijuLists(){
  239. getAction('/weituoyiju/itdmWeituoYiju/getAllList').then((res) => {
  240. // console.log(res)
  241. this.yijuLists = res.result
  242. })
  243. },
  244. // 获取当前点击行是哪儿一行
  245. clickThenCheck(record, index){
  246. return {
  247. on: {
  248. click: () => {
  249. // console.log(record, index)
  250. this.clickIndex = index
  251. }
  252. }
  253. }
  254. },
  255. // 获得选中项信息
  256. handleChange(value,optipn) {
  257. console.log(777,value,optipn);
  258. if(value){
  259. const a = optipn.data.attrs.channel
  260. // console.log(a)
  261. // 解决下拉选择后多个输入框显示-用$set,估计设置中间变量也能解决
  262. this.$set(this.model.list[this.clickIndex], 'sampleModelSpecification', a.sampleModelSpecification )
  263. this.$set(this.model.list[this.clickIndex], 'yangpinKeyId', a.sampleName )
  264. }
  265. },
  266. // 多选依据
  267. handleDescCate(value,optipn) {
  268. // console.log(value, optipn)
  269. // 这里用$set不好使
  270. // this.$set(this.model.list[this.clickIndex], 'standardRequirementQ', value)
  271. // 解决多选数据选择不回显--设置中间变量
  272. const newData = [...this.model.list];
  273. const target = newData[this.clickIndex];
  274. target.standardRequirementQ = value;
  275. this.model.list = newData;
  276. },
  277. newMember() {
  278. this.model.list.push({
  279. key: this.count + '',
  280. yangpinKeyId: '',
  281. testItems: '',
  282. standardRequirementQ: [], // 前端用来下拉选择的,直接standardRequirement赋值standardRequirement会有问题
  283. standardRequirement: '',
  284. judgementBasis: '',
  285. yijufile: '',
  286. beizhu: '',
  287. editable: true,
  288. isNew: true
  289. })
  290. this.count++
  291. // sessionStorage.setItem('count1', this.count)
  292. },
  293. remove(key) {
  294. const newData = this.model.list.filter(item => item.key !== key)
  295. this.model.list = newData
  296. },
  297. // saveRow(key) {
  298. // let target = this.model.list.filter(item => item.key === key)[0]
  299. // target.editable = false
  300. // target.isNew = false
  301. // },
  302. submitForm() {
  303. // sessionStorage.setItem('yangpinkz', JSON.stringify(this.model.list))
  304. this.$store.commit('SET_SHIYANINFO', this.model.list);
  305. this.$refs.form.validate(valid => {
  306. if (valid) {
  307. this.$emit('submitForm')
  308. }
  309. })
  310. },
  311. prevStep() {
  312. // sessionStorage.setItem('yangpinkz', JSON.stringify(this.model.list))
  313. // var newData = this.model.list.map(item => {
  314. // item.standardRequirement = item.standardRequirementQ.toString()
  315. // return item
  316. // })
  317. // this.model.list = newData
  318. for (let i = 0; i < this.model.list.length; i++) {
  319. const element = this.model.list[i];
  320. element.standardRequirement = element.standardRequirementQ.join(',')
  321. }
  322. this.$store.commit('SET_SHIYANINFO', this.model.list);
  323. this.$emit('prevStep')
  324. },
  325. }
  326. }
  327. </script>
  328. <style lang="less" scoped>
  329. .u-edit-table{
  330. margin-top: 12px;
  331. .ant-form-item{
  332. margin-bottom: 0;
  333. }
  334. /deep/.ant-table-tbody .ant-table-row td {
  335. padding-top: 2px !important;
  336. padding-bottom: 2px !important;
  337. }
  338. .ant-input{
  339. // padding: 0;
  340. border: none;
  341. }
  342. .ant-table-tbody > tr:hover:not(.ant-table-expanded-row):not(.ant-table-row-selected) .ant-input{
  343. background: #e6f7ff;
  344. }
  345. // .ant-input:hover{
  346. // background: #e6f7ff;
  347. // }
  348. .ant-input:focus{
  349. box-shadow: none;
  350. }
  351. /deep/.ant-select-selection{
  352. border: none;
  353. }
  354. /deep/.ant-select-selection:focus{
  355. box-shadow: none;
  356. }
  357. .ant-table-tbody > tr:hover:not(.ant-table-expanded-row):not(.ant-table-row-selected) .ant-select-selection{
  358. background: #e6f7ff;
  359. }
  360. }
  361. .card {
  362. margin-bottom: 24px;
  363. }
  364. .next {
  365. width: 35%;
  366. margin-left: 20px;
  367. margin-right: 20px;
  368. margin-top: 20px;
  369. }
  370. .buttonAll {
  371. width: 100%;
  372. align-items: center;
  373. justify-content: center;
  374. }
  375. .all {
  376. width: 100%;
  377. display: flex;
  378. align-items: center;
  379. justify-content: center;
  380. }
  381. </style>