BaseForm.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <a-modal
  3. :title="title"
  4. :width="800"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @cancel="handleCancel"
  8. >
  9. <a-card >
  10. <a-form :form="form">
  11. <row-list :col="1" v-show="false">
  12. <row-item>
  13. <a-form-item>
  14. <a-input v-decorator="['id']" type="hidden"/>
  15. </a-form-item>
  16. </row-item>
  17. </row-list>
  18. <row-list :col="2">
  19. <row-item >
  20. <a-form-item
  21. label="审核人"
  22. :labelCol="BaseTool.Constant.labelCol"
  23. :wrapperCol="BaseTool.Constant.wrapperCol"
  24. >
  25. <a-select :disabled="title=='编辑'" v-decorator="['verityUserId', { rules: [{required: true, message: '审核人不能为空'}]}]" placeholder="请选择">
  26. <a-select-option
  27. v-for="{userId,realName} in verityUserIdMap"
  28. :key="userId"
  29. :label="realName"
  30. :value="userId">{{ realName }}
  31. </a-select-option>
  32. </a-select>
  33. </a-form-item>
  34. </row-item>
  35. <row-item>
  36. <a-form-item
  37. label="备注"
  38. :labelCol="BaseTool.Constant.labelCol"
  39. :wrapperCol="BaseTool.Constant.wrapperCol"
  40. >
  41. <a-input v-decorator="['name', { rules: [{required: true, message: '备注不能为空'}]}]" placeholder="请填写备注" />
  42. </a-form-item>
  43. </row-item>
  44. </row-list>
  45. </a-form>
  46. <title-divider title="设备集合" width="90px"></title-divider>
  47. <a-button type="primary" @click="handleSbSelect">选择</a-button>
  48. <br>
  49. <br>
  50. <a-table
  51. :columns="columns"
  52. bordered
  53. :data-source="sbInfoDTOS"
  54. >
  55. <span slot="action" slot-scope="record">
  56. <a @click="handleDelete(record)">删除</a>
  57. <operation-button
  58. @click="handleUpLoad(record)"
  59. >上传图片</operation-button>
  60. </span>
  61. </a-table>
  62. </a-card>
  63. <template slot="footer">
  64. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  65. </template>
  66. <sb-info-select-modal v-if="visible" ref="sbInfoSelectModal" @selected="handleSbSelectd"/>
  67. <UpLoad ref="upLoad" />
  68. </a-modal>
  69. </template>
  70. <script>
  71. import pick from 'lodash.pick'
  72. import { addSbUnused, getUnusedUsers, updataSbUnused } from '@/api/idle-assets/idle-assets'
  73. import SbInfoSelectModal from './SbInfoSelectModal'
  74. import UpLoad from './UpLoad'
  75. export default {
  76. name: 'BaseForm',
  77. components: {
  78. SbInfoSelectModal,
  79. UpLoad
  80. },
  81. data () {
  82. return {
  83. form: this.$form.createForm(this),
  84. visible: false,
  85. title: '新增',
  86. modal: {},
  87. verityUserIdMap: [],
  88. sbInfoDTOS: [],
  89. confirmLoading: false,
  90. columns: [
  91. {
  92. title: '设备名称',
  93. dataIndex: 'name',
  94. key: 'name'
  95. },
  96. {
  97. title: '设备位号',
  98. dataIndex: 'positionNo',
  99. key: 'positionNo'
  100. },
  101. {
  102. title: '设备编号',
  103. dataIndex: 'no',
  104. key: 'no'
  105. },
  106. {
  107. title: '操作',
  108. key: 'action',
  109. width: '200px',
  110. fixed: 'right',
  111. checked: true,
  112. align: 'center',
  113. scopedSlots: { customRender: 'action' }
  114. }
  115. ]
  116. }
  117. },
  118. created () {
  119. // this.flagMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PROJECT_NEW_AND_OLD)
  120. this.getUnusedUsers()
  121. },
  122. methods: {
  123. base (record) {
  124. this.visible = true
  125. if (this.BaseTool.Object.isBlank(record)) {
  126. this.title = '新增'
  127. return
  128. }
  129. this.title = '编辑'
  130. this.modal = record
  131. const { form: { setFieldsValue } } = this
  132. this.$nextTick(() => {
  133. setFieldsValue(Object.assign(pick(record, [
  134. 'id',
  135. 'name',
  136. 'verityUserId'
  137. ])))
  138. })
  139. this.sbInfoDTOS = record.sbUnusedDetailVOS.map(item => {
  140. return {
  141. id: item.sbId,
  142. sbUnusedDetailId: item.id,
  143. name: item.sbName,
  144. no: item.sbNo,
  145. sbFileList: item.usedFileList,
  146. positionNo: item.positionNo
  147. }
  148. })
  149. },
  150. getUnusedUsers () {
  151. getUnusedUsers().then(res => {
  152. this.verityUserIdMap = res.data
  153. })
  154. },
  155. handleSbSelect () {
  156. this.$refs.sbInfoSelectModal.base()
  157. },
  158. handleSbSelectd (rows) {
  159. const sbInfoDTOS = rows.map(item => {
  160. if (this.sbInfoDTOS.length > 0 && this.sbInfoDTOS.find(sb => sb.id === item.id)) {
  161. return
  162. }
  163. return {
  164. id: item.id,
  165. name: item.name,
  166. no: item.no,
  167. positionNo: item.positionNo,
  168. sbFileList: []
  169. }
  170. })
  171. this.sbInfoDTOS = [...sbInfoDTOS, ...this.sbInfoDTOS].filter(item => item)
  172. },
  173. handleUpLoad (record) {
  174. this.$refs.upLoad.base(record)
  175. },
  176. handleUpLoadOk () {
  177. },
  178. handleDelete (record) {
  179. this.sbInfoDTOS = this.sbInfoDTOS.filter(item => item.id !== record.id)
  180. },
  181. save () {
  182. const { form: { validateFieldsAndScroll } } = this
  183. // this.confirmLoading = true
  184. validateFieldsAndScroll((errors, values) => {
  185. if (errors) {
  186. Object.values(errors).map(item => {
  187. this.$message.error(item.errors[0].message)
  188. })
  189. this.confirmLoading = false
  190. return
  191. }
  192. values.sbInfoDTOS = this.sbInfoDTOS
  193. if (values.id) {
  194. values.saveFlag = true
  195. updataSbUnused(values).then(res => {
  196. this.$message.success('修改成功!')
  197. this.handleCancel()
  198. })
  199. } else {
  200. addSbUnused(values).then(res => {
  201. this.$message.success('创建成功!')
  202. this.handleCancel()
  203. })
  204. }
  205. })
  206. },
  207. handleCancel (values) {
  208. this.visible = false
  209. this.modal = {}
  210. this.sbInfoDTOS = []
  211. this.form.resetFields()
  212. this.$emit('ok', values)
  213. }
  214. }
  215. }
  216. </script>
  217. <style lang="less" scoped>
  218. .tooltip{
  219. font-size:20px;
  220. color:#ccc;
  221. &:hover {
  222. color:#2f54eb;
  223. }
  224. }
  225. </style>