companyStructureInfo-detail.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <style scoped>
  2. .user-panel {
  3. margin: 10px auto;
  4. }
  5. </style>
  6. <template>
  7. <el-dialog
  8. :visible.sync="showDialog"
  9. :title="title"
  10. :modal-append-to-body="true"
  11. append-to-body
  12. :close-on-click-modal="false"
  13. style="text-align: left"
  14. width="80%"
  15. @close="closeDialog"
  16. >
  17. <div class="user-panel" v-loading="loading">
  18. <el-form
  19. ref="form"
  20. :model="formModel"
  21. :rules="ruleValidate"
  22. :label-width="'150px'"
  23. inline
  24. >
  25. <el-form-item label="公司名称" prop="companyId">
  26. <el-select-tree
  27. size="mini"
  28. :props="companyProps"
  29. :options="companyResult"
  30. v-model="formModel.companyId"
  31. height="200"
  32. ></el-select-tree>
  33. </el-form-item>
  34. <el-form-item label="结构名称" prop="structureName">
  35. <el-input
  36. v-model="formModel.structureName"
  37. placeholder="请输入结构名称"
  38. style="width: 300px"
  39. ></el-input>
  40. </el-form-item>
  41. <el-form-item
  42. label="位置名称"
  43. prop="positionName"
  44. >
  45. <el-input
  46. v-model="formModel.positionName"
  47. placeholder="请输入位置名称"
  48. style="width: 300px"
  49. ></el-input>
  50. </el-form-item>
  51. <el-form-item label="父级" prop="parentId">
  52. <el-select-tree
  53. size="mini"
  54. :props="parentProps"
  55. :options="parentResult"
  56. v-model="formModel.parentId"
  57. height="200"
  58. ></el-select-tree>
  59. </el-form-item>
  60. <el-form-item label="备注信息" prop="remark">
  61. <el-input
  62. v-model="formModel.remark"
  63. placeholder="请输入备注信息"
  64. style="width: 300px"
  65. ></el-input>
  66. </el-form-item>
  67. </el-form>
  68. </div>
  69. <span slot="footer" class="dialog-footer">
  70. <el-button @click="closeDialog">取 消</el-button>
  71. <el-button type="primary" @click="handleSubmit" :loading="submitting"
  72. >确 定</el-button
  73. >
  74. </span>
  75. </el-dialog>
  76. </template>
  77. <script>
  78. import Constant from "@/constant";
  79. import companyStructureInfoApi from "@/api/base/companyStructureInfo";
  80. import companyInfoApi from "@/api/base/companyInfo";
  81. import SelectTree from "@/components/SelectTree";
  82. export default {
  83. props: ["businessKey", "title"],
  84. data() {
  85. return {
  86. formModel: {},
  87. ruleValidate: {
  88. companyId: [
  89. { required: true, message: "公司id不能为空", trigger: "blur" },
  90. ],
  91. structureName: [
  92. { required: true, message: "结构名称不能为空", trigger: "blur" },
  93. ],
  94. positionName: [
  95. {
  96. required: true,
  97. message: "位置名称(如:楼栋、单元、部门、工号)不能为空",
  98. trigger: "blur",
  99. },
  100. ],
  101. },
  102. showDialog: true,
  103. loading: false,
  104. submitting: false,
  105. companyResult: [],
  106. companyProps: {
  107. value: "id",
  108. label: "name",
  109. children: "children"
  110. },
  111. parentResult: [],
  112. parentProps: {
  113. value: "id",
  114. label: "structureName"
  115. },
  116. };
  117. },
  118. methods: {
  119. closeDialog() {
  120. this.$emit("close", false);
  121. },
  122. handleSubmit() {
  123. var self = this;
  124. this.$refs["form"].validate((valid) => {
  125. if (valid) {
  126. (function () {
  127. var id = self.formModel.id;
  128. if (id == null || id.length == 0) {
  129. return companyStructureInfoApi.add(self.formModel);
  130. } else {
  131. return companyStructureInfoApi.update(self.formModel);
  132. }
  133. })().then(function (response) {
  134. var jsonData = response.data;
  135. if (jsonData.result) {
  136. self.$message({
  137. message: "保存成功!",
  138. type: "success",
  139. });
  140. self.$emit("close", true);
  141. } else {
  142. self.$message({
  143. message: jsonData.message + "",
  144. type: "warning",
  145. });
  146. self.$emit("close", false);
  147. }
  148. });
  149. }
  150. });
  151. },
  152. },
  153. created() {
  154. var self = this;
  155. companyInfoApi.treeList().then(function(response) {
  156. var jsonData = response.data;
  157. if (jsonData.result) {
  158. self.companyResult = jsonData.data;
  159. }
  160. });
  161. companyStructureInfoApi.query().then(function(response) {
  162. var jsonData = response.data;
  163. if (jsonData.result) {
  164. self.parentResult = jsonData.data;
  165. }
  166. });
  167. // this.changePage(1);
  168. // this.loadTree();
  169. },
  170. mounted: function () {
  171. var self = this;
  172. (function () {
  173. if (self.businessKey.length == 0) {
  174. return companyStructureInfoApi.create();
  175. } else {
  176. return companyStructureInfoApi.edit(self.businessKey);
  177. }
  178. })()
  179. .then((response) => {
  180. var jsonData = response.data;
  181. self.loading = false;
  182. if (jsonData.result) {
  183. self.formModel = jsonData.data;
  184. } else {
  185. self.$message.error(jsonData.message + "");
  186. }
  187. })
  188. .catch((error) => {
  189. self.$message.error(error + "");
  190. });
  191. },
  192. components: {
  193. "el-select-tree": SelectTree
  194. },
  195. };
  196. </script>