CheckAndEditModel.vue 5.8 KB

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