edit.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <!-- 用户编辑弹窗 -->
  2. <template>
  3. <el-dialog
  4. class="ele-dialog-form"
  5. :title="title"
  6. :visible.sync="visible"
  7. :before-close="handleClose"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. width="1000px"
  11. >
  12. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  13. <el-row>
  14. <el-col :span="8">
  15. <el-form-item
  16. label="工厂编码:"
  17. prop="code"
  18. style="margin-bottom: 22px"
  19. >
  20. <el-input
  21. clearable
  22. :maxlength="20"
  23. v-model="form.code"
  24. placeholder="请输入"
  25. />
  26. </el-form-item>
  27. </el-col>
  28. <el-col :span="8">
  29. <el-form-item
  30. label="工厂名称:"
  31. prop="name"
  32. style="margin-bottom: 22px"
  33. >
  34. <el-input
  35. clearable
  36. :maxlength="20"
  37. v-model="form.name"
  38. placeholder="请输入"
  39. />
  40. </el-form-item>
  41. </el-col>
  42. <el-col :span="8">
  43. <el-form-item
  44. label="所属公司:"
  45. prop="groupId"
  46. style="margin-bottom: 22px"
  47. >
  48. <ele-tree-select
  49. clearable
  50. :data="options.groupId"
  51. v-model="form.groupId"
  52. valueKey="id"
  53. labelKey="name"
  54. placeholder="请选择"
  55. default-expand-all
  56. />
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="16" style="margin-bottom: 22px">
  60. <el-form-item label="地址:" prop="location_city">
  61. <div class="location-warp">
  62. <el-cascader
  63. clearable
  64. style="width: 385px"
  65. v-model="form.location"
  66. :options="options.cityDataLabel"
  67. ></el-cascader>
  68. <el-input
  69. class="detail"
  70. clearable
  71. :maxlength="20"
  72. v-model="form.locationDetail"
  73. placeholder="请输入详细地址"
  74. />
  75. </div>
  76. </el-form-item>
  77. </el-col>
  78. <el-col :span="8" style="margin-bottom: 22px">
  79. <el-form-item label="状态:" prop="enabled">
  80. <div class="location-warp">
  81. <el-select
  82. v-model="form.enabled"
  83. v
  84. placeholder="请选择"
  85. style="width: 100%"
  86. >
  87. <el-option
  88. v-for="item in options.zt"
  89. :key="item.value"
  90. :label="item.label"
  91. :value="item.value"
  92. >
  93. </el-option>
  94. </el-select>
  95. </div>
  96. </el-form-item>
  97. </el-col>
  98. </el-row>
  99. </el-form>
  100. <template v-slot:footer>
  101. <el-button @click="handleClose">取消</el-button>
  102. <el-button type="primary" :loading="loading" @click="save">
  103. 保存
  104. </el-button>
  105. </template>
  106. </el-dialog>
  107. </template>
  108. <script>
  109. import { cityDataLabel } from 'ele-admin/packages/utils/regions';
  110. import { listOrganizations } from '@/api/system/organization';
  111. import { saveOrUpdate } from '@/api/factoryModel';
  112. export default {
  113. data() {
  114. const defaultForm = {
  115. id: '',
  116. code: '',
  117. name: '',
  118. groupId: '',
  119. locationDetail: '',
  120. location: [],
  121. enabled: 1,
  122. parentId: '',
  123. type: 1 // FACTORY(1, "工厂"), WORKSHOP_PLAN(2, "厂房"), WORKSHOP(3, "车间"), LINE(4, "厂线");
  124. };
  125. return {
  126. defaultForm,
  127. // 表单数据
  128. form: { ...defaultForm },
  129. // 表单验证规则
  130. rules: {
  131. code: [{ required: true, message: '请输入', trigger: 'blur' }],
  132. name: [{ required: true, message: '请输入', trigger: 'blur' }],
  133. groupId: [{ required: true, message: '请输入', trigger: 'blur' }]
  134. },
  135. visible: false,
  136. type: '', // add/edit
  137. loading: false,
  138. options: {
  139. zt: [
  140. {
  141. label: '生效',
  142. value: 1
  143. },
  144. {
  145. label: '未生效',
  146. value: 0
  147. }
  148. ],
  149. groupId: [],
  150. cityDataLabel
  151. }
  152. };
  153. },
  154. computed: {
  155. title() {
  156. switch (this.type) {
  157. case 'add':
  158. return '新增工厂';
  159. break;
  160. case 'edit':
  161. return '编辑工厂';
  162. break;
  163. default:
  164. break;
  165. }
  166. }
  167. },
  168. created() {
  169. this.getGs();
  170. },
  171. methods: {
  172. open(type, row) {
  173. this.type = type;
  174. this.visible = true;
  175. if (type == 'edit') {
  176. this.form.id = row.id;
  177. this.form.code = row.code;
  178. this.form.name = row.name;
  179. this.form.groupId = row.groupId;
  180. this.form.enabled = row.enabled;
  181. this.form.parentId = row.parentId;
  182. this.form.type = row.type;
  183. this.form.location = row.extInfo.location.split('/');
  184. this.form.locationDetail = row.extInfo.locationDetail;
  185. }
  186. },
  187. /* 保存编辑 */
  188. save() {
  189. this.$refs.form.validate((valid) => {
  190. if (!valid) {
  191. return false;
  192. }
  193. this.loading = true;
  194. const data = {
  195. code: this.form.code,
  196. name: this.form.name,
  197. groupId: this.form.groupId,
  198. enabled: this.form.enabled,
  199. parentId: this.form.groupId,
  200. type: this.form.type,
  201. extInfo: this.setLocation()
  202. };
  203. if (this.type == 'edit') {
  204. data.id = this.form.id;
  205. }
  206. console.log(data);
  207. saveOrUpdate(data)
  208. .then((msg) => {
  209. this.loading = false;
  210. this.$message.success(msg);
  211. this.handleClose();
  212. this.$emit('done');
  213. })
  214. .catch((e) => {
  215. this.loading = false;
  216. this.$message.error(e.message);
  217. });
  218. });
  219. },
  220. restForm() {
  221. this.$refs.form.clearValidate();
  222. this.form = { ...this.defaultForm };
  223. },
  224. handleClose() {
  225. this.restForm();
  226. this.visible = false;
  227. },
  228. // 获取公司数据
  229. getGs() {
  230. listOrganizations().then((list) => {
  231. console.log(list);
  232. this.options.groupId = this.$util.toTreeData({
  233. data: list,
  234. idField: 'id',
  235. parentIdField: 'parentId'
  236. });
  237. });
  238. },
  239. setLocation() {
  240. return {
  241. location: this.form.location.join('/'),
  242. locationDetail: this.form.locationDetail
  243. };
  244. }
  245. }
  246. };
  247. </script>
  248. <style lang="scss" scoped>
  249. .location-warp {
  250. display: flex;
  251. .detail {
  252. margin-left: 10px;
  253. }
  254. }
  255. </style>