CheckAndEditModel.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <j-modal
  3. :title="title"
  4. :width="700"
  5. :visible="visible"
  6. :mask-closable="false"
  7. cancel-text="关闭"
  8. @close="close"
  9. >
  10. <a-form-model ref="form" :label-col="labelCol" :wrapper-col="wrapperCol" :rules="validatorRules" :model="model">
  11. <a-form-model-item label="车间" prop="deptId">
  12. <a-tree-select
  13. v-model="model.deptId"
  14. :show-search="true"
  15. allow-clear
  16. tree-default-expand-all
  17. style="width: 100%"
  18. :tree-data="treeData"
  19. tree-node-filter-prop="label"
  20. :replace-fields="{children:'children', title:'label', key:'id', value: 'id' }"
  21. @change="deptChange"
  22. />
  23. </a-form-model-item>
  24. <a-form-model-item label="线路" prop="lineId">
  25. <j-list-select-tag
  26. v-if="lineShow"
  27. v-model="model.lineId"
  28. :dept-id="model.deptId"
  29. dict-code="line"
  30. @selectChange="lineChange"
  31. />
  32. </a-form-model-item>
  33. <a-form-model-item label="站场区间" prop="stationId">
  34. <j-list-select-tag
  35. v-if="stationShow"
  36. v-model="model.stationId"
  37. :line-id="model.lineId"
  38. :dept-id="model.deptId"
  39. dict-code="station"
  40. />
  41. </a-form-model-item>
  42. <a-form-model-item label="所别" prop="substationId">
  43. <j-list-select-tag
  44. v-if="substationShow"
  45. v-model="model.substationId"
  46. :dept-id="model.deptId"
  47. :line-id="model.lineId"
  48. dict-code="substation"
  49. />
  50. </a-form-model-item>
  51. <a-form-model-item label="行别" prop="xingbie">
  52. <j-dict-select-tag
  53. v-model="model.xingbie"
  54. type="radioButton"
  55. dict-code="xingbie"
  56. />
  57. </a-form-model-item>
  58. <a-form-model-item label="支柱号" prop="pillarCode">
  59. <a-input v-model="model.pillarCode" />
  60. </a-form-model-item>
  61. <a-form-model-item label="开始公里标" prop="startMarker">
  62. <a-input-number v-model="model.startMarker" style="width: 100%" />
  63. </a-form-model-item>
  64. <a-form-model-item label="结束公里标" prop="endMarker">
  65. <a-input-number v-model="model.endMarker" style="width: 100%" />
  66. </a-form-model-item>
  67. <a-form-model-item label="锈蚀部位" prop="rustPosition">
  68. <a-input v-model="model.rustPosition" />
  69. </a-form-model-item>
  70. <a-form-model-item label="风险源" prop="riskSource">
  71. <a-input v-model="model.riskSource" />
  72. </a-form-model-item>
  73. <a-form-model-item label="采取措施" prop="measures">
  74. <a-textarea v-model="model.measures" :max-length="300" :rows="4" />
  75. </a-form-model-item>
  76. <a-form-model-item label="备注" prop="remark">
  77. <a-textarea v-model="model.remark" :max-length="300" :rows="4" />
  78. </a-form-model-item>
  79. </a-form-model>
  80. </j-modal>
  81. </template>
  82. <script>
  83. import { getAction, httpAction } from '@/api/request'
  84. import JModal from '@/components/JModal'
  85. export default {
  86. name: 'CheckAndEditModel',
  87. components: {
  88. JModal
  89. },
  90. data() {
  91. return {
  92. stationShow: false,
  93. lineShow: false,
  94. substationShow: false,
  95. treeData: [],
  96. labelCol: { span: 4 },
  97. wrapperCol: { span: 19 },
  98. dataSource: [],
  99. title: '',
  100. visible: false,
  101. isCheck: false,
  102. model: {},
  103. validatorRules: {
  104. deptId: [{ required: true, message: '请选择' }],
  105. lineId: [{ required: true, message: '请选择' }],
  106. stationId: [{ required: true, message: '请选择' }],
  107. substationId: [{ required: true, message: '请选择' }],
  108. pillarCode: [{ required: true, message: '请输入' }],
  109. xingbie: [{ required: true, message: '请输入' }],
  110. startMarker: [{ required: true, message: '请输入' }],
  111. endMarker: [{ required: true, message: '请输入' }],
  112. rustPosition: [{ required: true, message: '请输入' }],
  113. riskSource: [{ required: true, message: '请输入' }],
  114. measures: [{ required: true, message: '请输入' }],
  115. remark: [{ required: true, message: '请输入' }]
  116. },
  117. url: {
  118. add: '/business/baseinfo/base/prevent/rust/add',
  119. edit: '/business/baseinfo/base/prevent/rust/update',
  120. tree: '/system/dept/treeSelect'
  121. }
  122. }
  123. },
  124. watch: {
  125. 'model.deptId': {
  126. immediate: true,
  127. handler: function(newV, oldV) {
  128. this.lineShow = false
  129. this.stationShow = false
  130. this.substationShow = false
  131. this.$nextTick(() => {
  132. this.lineShow = true
  133. this.stationShow = true
  134. this.substationShow = true
  135. })
  136. }
  137. },
  138. 'model.lineId': {
  139. immediate: true,
  140. handler: function(newV, oldV) {
  141. this.stationShow = false
  142. this.substationShow = false
  143. this.$nextTick(() => {
  144. this.stationShow = true
  145. this.substationShow = true
  146. })
  147. }
  148. }
  149. },
  150. created() {
  151. this.loadTree()
  152. },
  153. methods: {
  154. lineChange() {
  155. this.model.stationId = undefined
  156. this.model.substationId = undefined
  157. },
  158. deptChange() {
  159. this.model.lineId = undefined
  160. this.model.stationId = undefined
  161. this.model.substationId = undefined
  162. },
  163. loadTree() {
  164. this.treeData = []
  165. getAction(this.url.tree).then((res) => {
  166. if (res.code === 200) {
  167. this.treeData = res.data
  168. }
  169. })
  170. },
  171. add() {
  172. this.model = { lineId: null, stationId: null, substationId: null }
  173. this.visible = true
  174. },
  175. edit(record) {
  176. this.model = Object.assign({}, record, { substationId: record.substationId ? record.substationId : null })
  177. this.visible = true
  178. },
  179. close(isSubmit) {
  180. if (isSubmit) {
  181. this.checkData()
  182. } else {
  183. this.visible = false
  184. }
  185. },
  186. checkData() {
  187. this.$refs.form.validate(valid => {
  188. if (valid) {
  189. this.saveData()
  190. } else {
  191. return false
  192. }
  193. })
  194. },
  195. saveData() {
  196. let url, type
  197. if (!this.model.id) {
  198. url = this.url.add
  199. type = 'post'
  200. } else {
  201. url = this.url.edit
  202. type = 'put'
  203. }
  204. httpAction(url, this.model, type).then((res) => {
  205. if (res.code === 200) {
  206. this.$message.success(res.msg)
  207. this.$emit('ok')
  208. this.visible = false
  209. } else {
  210. console.log(res)
  211. }
  212. })
  213. }
  214. }
  215. }
  216. </script>