BaseForm.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 ref="sbInfoSelectModal" @selected="handleSbSelectd"/>
  67. <UpLoad ref="upLoad" @upLoad="handleUpLoadOk"/>
  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. name: item.sbName,
  143. no: item.sbNo,
  144. positionNo: item.positionNo
  145. }
  146. })
  147. },
  148. getUnusedUsers () {
  149. getUnusedUsers().then(res => {
  150. this.verityUserIdMap = res.data
  151. })
  152. },
  153. handleSbSelect () {
  154. this.$refs.sbInfoSelectModal.base()
  155. },
  156. handleSbSelectd (rows) {
  157. const sbInfoDTOS = rows.map(item => {
  158. return {
  159. id: item.id,
  160. name: item.name,
  161. no: item.no,
  162. positionNo: item.positionNo
  163. }
  164. })
  165. this.sbInfoDTOS = [...sbInfoDTOS, ...this.sbInfoDTOS]
  166. },
  167. handleUpLoad (record) {
  168. this.$refs.upLoad.base(record)
  169. },
  170. handleUpLoadOk () {
  171. },
  172. handleDelete (record) {
  173. this.sbInfoDTOS = this.sbInfoDTOS.filter(item => item.id !== record.id)
  174. },
  175. save () {
  176. const { form: { validateFieldsAndScroll } } = this
  177. // this.confirmLoading = true
  178. validateFieldsAndScroll((errors, values) => {
  179. if (errors) {
  180. Object.values(errors).map(item => {
  181. this.$message.error(item.errors[0].message)
  182. })
  183. this.confirmLoading = false
  184. return
  185. }
  186. values.sbInfoDTOS = this.sbInfoDTOS
  187. if (values.id) {
  188. values.saveFlag = true
  189. updataSbUnused(values).then(res => {
  190. this.$message.success('修改成功!')
  191. this.handleCancel()
  192. })
  193. } else {
  194. addSbUnused(values).then(res => {
  195. this.$message.success('创建成功!')
  196. this.handleCancel()
  197. })
  198. }
  199. })
  200. },
  201. handleCancel (values) {
  202. this.visible = false
  203. this.modal = {}
  204. this.sbInfoDTOS = []
  205. this.form.resetFields()
  206. this.$emit('ok', values)
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="less" scoped>
  212. .tooltip{
  213. font-size:20px;
  214. color:#ccc;
  215. &:hover {
  216. color:#2f54eb;
  217. }
  218. }
  219. </style>