CheckAndEditModel.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. :line-id="model.lineId"
  47. dict-code="substation"
  48. />
  49. </a-form-model-item>
  50. <a-form-model-item label="行别" prop="xingbie">
  51. <j-dict-select-tag
  52. v-model="model.xingbie"
  53. type="radioButton"
  54. dict-code="xingbie"
  55. />
  56. </a-form-model-item>
  57. <a-form-model-item label="支柱号" prop="pillarCode">
  58. <a-input v-model="model.pillarCode" />
  59. </a-form-model-item>
  60. <a-form-model-item label="开始公里标" prop="startMarker">
  61. <a-input-number v-model="model.startMarker" style="width: 100%" />
  62. </a-form-model-item>
  63. <a-form-model-item label="结束公里标" prop="endMarker">
  64. <a-input-number v-model="model.endMarker" style="width: 100%" />
  65. </a-form-model-item>
  66. <a-form-model-item label="锈蚀部位" prop="rustPosition">
  67. <a-input v-model="model.rustPosition" />
  68. </a-form-model-item>
  69. <a-form-model-item label="风险源" prop="riskSource">
  70. <a-input v-model="model.riskSource" />
  71. </a-form-model-item>
  72. <a-form-model-item label="采取措施" prop="measures">
  73. <a-textarea v-model="model.measures" :max-length="300" :rows="4" />
  74. </a-form-model-item>
  75. <a-form-model-item label="备注" prop="remark">
  76. <a-textarea v-model="model.remark" :max-length="300" :rows="4" />
  77. </a-form-model-item>
  78. </a-form-model>
  79. </j-modal>
  80. </template>
  81. <script>
  82. import { getAction, httpAction } from '@/api/request'
  83. import JModal from '@/components/JModal'
  84. export default {
  85. name: 'CheckAndEditModel',
  86. components: {
  87. JModal
  88. },
  89. data() {
  90. return {
  91. stationShow: false,
  92. lineShow: false,
  93. substationShow: false,
  94. treeData: [],
  95. labelCol: { span: 4 },
  96. wrapperCol: { span: 19 },
  97. dataSource: [],
  98. title: '',
  99. visible: false,
  100. isCheck: false,
  101. model: {},
  102. validatorRules: {
  103. deptId: [{ required: true, message: '请选择' }],
  104. lineId: [{ required: true, message: '请选择' }],
  105. stationId: [{ required: true, message: '请选择' }],
  106. substationId: [{ required: true, message: '请选择' }],
  107. pillarCode: [{ required: true, message: '请输入' }],
  108. xingbie: [{ required: true, message: '请输入' }],
  109. startMarker: [{ required: true, message: '请输入' }],
  110. endMarker: [{ required: true, message: '请输入' }],
  111. rustPosition: [{ required: true, message: '请输入' }],
  112. riskSource: [{ required: true, message: '请输入' }],
  113. measures: [{ required: true, message: '请输入' }],
  114. remark: [{ required: true, message: '请输入' }]
  115. },
  116. url: {
  117. add: '/business/baseinfo/base/prevent/rust/add',
  118. edit: '/business/baseinfo/base/prevent/rust/update',
  119. tree: '/system/dept/treeSelect'
  120. }
  121. }
  122. },
  123. watch: {
  124. 'model.deptId': {
  125. immediate: true,
  126. handler: function(newV, oldV) {
  127. this.lineShow = false
  128. this.stationShow = false
  129. this.$nextTick(() => {
  130. this.lineShow = true
  131. this.stationShow = true
  132. })
  133. }
  134. },
  135. 'model.lineId': {
  136. immediate: true,
  137. handler: function(newV, oldV) {
  138. this.stationShow = false
  139. this.substationShow = false
  140. this.$nextTick(() => {
  141. this.stationShow = true
  142. this.substationShow = true
  143. })
  144. }
  145. }
  146. },
  147. created() {
  148. this.loadTree()
  149. },
  150. methods: {
  151. lineChange() {
  152. this.model.stationId = undefined
  153. this.model.substationId = undefined
  154. },
  155. deptChange() {
  156. this.model.lineId = undefined
  157. this.model.stationId = undefined
  158. this.model.substationId = undefined
  159. },
  160. loadTree() {
  161. this.treeData = []
  162. getAction(this.url.tree).then((res) => {
  163. if (res.code === 200) {
  164. this.treeData = res.data
  165. }
  166. })
  167. },
  168. add() {
  169. this.model = { lineId: null, stationId: null, substationId: null }
  170. this.visible = true
  171. },
  172. edit(record) {
  173. this.model = Object.assign({}, record, { substationId: record.substationId ? record.substationId : null })
  174. this.visible = true
  175. },
  176. close(isSubmit) {
  177. if (isSubmit) {
  178. this.checkData()
  179. } else {
  180. this.visible = false
  181. }
  182. },
  183. checkData() {
  184. this.$refs.form.validate(valid => {
  185. if (valid) {
  186. this.saveData()
  187. } else {
  188. return false
  189. }
  190. })
  191. },
  192. saveData() {
  193. let url, type
  194. if (!this.model.id) {
  195. url = this.url.add
  196. type = 'post'
  197. } else {
  198. url = this.url.edit
  199. type = 'put'
  200. }
  201. httpAction(url, this.model, type).then((res) => {
  202. if (res.code === 200) {
  203. this.$message.success(res.msg)
  204. this.$emit('ok')
  205. this.visible = false
  206. } else {
  207. console.log(res)
  208. }
  209. })
  210. }
  211. }
  212. }
  213. </script>