personPopedom-detail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. :append-to-body="true"
  11. style="text-align: left"
  12. @close="closeDialog"
  13. :close-on-click-modal="false"
  14. >
  15. <div class="user-panel" v-loading="loading">
  16. <el-form
  17. ref="form"
  18. :model="formModel"
  19. :rules="ruleValidate"
  20. :label-width="'100px'"
  21. >
  22. <el-form-item label="单位" prop="companyId">
  23. <el-select-tree
  24. :props="props"
  25. :options="companyResult"
  26. v-model="formModel.companyId"
  27. size=""
  28. height="200"
  29. ></el-select-tree>
  30. </el-form-item>
  31. <el-form-item label="机构" prop="companyStructureId">
  32. <el-select-tree
  33. :props="companyStructureProps"
  34. :options="companyStructureResult"
  35. v-model="formModel.companyStructureId"
  36. height="200"
  37. size=""
  38. ></el-select-tree>
  39. </el-form-item>
  40. <el-form-item label="关联场景" prop="sceneId">
  41. <el-select v-model="sceneId" filterable placeholder="请选择">
  42. <el-option
  43. v-for="result in sceneData"
  44. :key="result.id"
  45. :label="result.sceneName"
  46. :value="result.id"
  47. ></el-option>
  48. </el-select>
  49. </el-form-item>
  50. <el-form-item label="服务公司" prop="serviceCompanyId" v-if="sceneId == '4'">
  51. <el-select-tree
  52. :props="props"
  53. :options="companyResult"
  54. v-model="formModel.serviceCompanyId"
  55. height="200"
  56. ></el-select-tree>
  57. </el-form-item>
  58. <el-form-item label="身份" prop="personRoleId">
  59. <el-select
  60. v-model="formModel.personRoleId"
  61. filterable
  62. placeholder="请选择"
  63. style="width: 280px"
  64. >
  65. <el-option
  66. v-for="role in personRoleResult"
  67. :key="role.id"
  68. :label="role.personRoleName"
  69. :value="role.id"
  70. ></el-option>
  71. </el-select>
  72. </el-form-item>
  73. <!-- <el-form-item label="展示的图标" prop="showIconId">
  74. <el-select
  75. v-model="formModel.showIconId"
  76. filterable
  77. multiple
  78. placeholder="请选择"
  79. style="width: 280px"
  80. >
  81. <el-option
  82. v-for="icon in iconResult"
  83. :key="icon.iconId"
  84. :label="icon.iconName"
  85. :value="icon.iconId"
  86. ></el-option>
  87. </el-select>
  88. </el-form-item> -->
  89. <el-form-item label="备注信息" prop="remark">
  90. <el-input
  91. v-model="formModel.remark"
  92. placeholder="请输入备注信息"
  93. style="width: 300px"
  94. ></el-input>
  95. </el-form-item>
  96. </el-form>
  97. </div>
  98. <span slot="footer" class="dialog-footer">
  99. <el-button @click="closeDialog">取 消</el-button>
  100. <el-button type="primary" @click="handleSubmit" :loading="submitting"
  101. >确 定</el-button
  102. >
  103. </span>
  104. </el-dialog>
  105. </template>
  106. <script>
  107. import Constant from "@/constant";
  108. import personPopedomApi from "@/api/base/personPopedom";
  109. import personRoleInfoApi from "@/api/base/personRoleInfo";
  110. import companyInfoApi from "@/api/base/companyInfo";
  111. import deviceInfoApi from "@/api/base/deviceInfo";
  112. import companyStructureInfoApi from "@/api/base/companyStructureInfo";
  113. import iconInfoApi from "@/api/base/iconInfo";
  114. import sceneInfoApi from "@/api/base/sceneInfo";
  115. import SelectTree from "@/components/SelectTree";
  116. import { Breadcrumb } from "element-ui";
  117. export default {
  118. components: {
  119. "el-select-tree": SelectTree,
  120. },
  121. props: ["businessKey", "title", "personId"],
  122. data() {
  123. return {
  124. formModel: { companyId: "" },
  125. ruleValidate: {
  126. companyId: [
  127. { required: true, message: "对应公司不能为空", trigger: "blur" },
  128. ],
  129. personRoleId: [
  130. { required: true, message: "对应角色不能为空", trigger: "blur" },
  131. ],
  132. },
  133. showDialog: true,
  134. loading: false,
  135. submitting: false,
  136. companyResult: [],
  137. treeData: [],
  138. props: {
  139. // 配置项(必选)
  140. value: "id",
  141. label: "name",
  142. children: "children",
  143. },
  144. personRoleResult: [],
  145. iconResult: [],
  146. companyStructureResult: [],
  147. companyStructureProps: {
  148. // 配置项(必选)
  149. value: "id",
  150. label: "structureName",
  151. children: "children",
  152. },
  153. sceneData: [],
  154. sceneId: "",
  155. oldPersonRoleId:"",
  156. };
  157. },
  158. created() {
  159. var self = this;
  160. companyInfoApi.list().then(function (response) {
  161. var jsonData = response.data;
  162. if (jsonData.result) {
  163. if (jsonData.data != null && jsonData.data != "") {
  164. self.companyResult = jsonData.data;
  165. }
  166. }
  167. });
  168. sceneInfoApi.list().then((response) => {
  169. var jsonData = response.data;
  170. this.sceneData = jsonData.data;
  171. });
  172. // var formData = new FormData();
  173. // formData.append("companyId", "c52b03cb-7526-4e8b-8b90-4f7a6a37b586");
  174. // personRoleInfoApi.listByCompanyId(formData).then(function (response) {
  175. // var jsonData = response.data;
  176. // if (jsonData.result) {
  177. // if (jsonData.data != null && jsonData.data != "") {
  178. // self.personRoleResult = jsonData.data;
  179. // }
  180. // }
  181. // });
  182. },
  183. watch: {
  184. "formModel.companyId": function (val, oldval) {
  185. if (val != null && val != "") {
  186. var self = this;
  187. if(self.oldPersonRoleId != ""){
  188. self.formModel.personRoleId = self.oldPersonRoleId;
  189. }else{
  190. self.formModel.personRoleId = "";
  191. self.oldPersonRoleId = "";
  192. }
  193. var formData = new FormData();
  194. formData.append("companyId", val);
  195. personRoleInfoApi.listByCompanyId(formData).then(function (response) {
  196. var jsonData = response.data;
  197. if (jsonData.result) {
  198. if (jsonData.data != null && jsonData.data != "") {
  199. self.personRoleResult = jsonData.data;
  200. }
  201. }
  202. });
  203. companyStructureInfoApi.list(formData).then(function (response) {
  204. var jsonData = response.data;
  205. if (jsonData.result) {
  206. if (jsonData.data != null && jsonData.data != "") {
  207. self.companyStructureResult = jsonData.data;
  208. }
  209. }
  210. });
  211. companyInfoApi.edit(val).then((response) => {
  212. var jsonData = response.data;
  213. if (jsonData.result) {
  214. self.sceneId = jsonData.data.sceneId;
  215. }
  216. });
  217. }
  218. },
  219. "sceneId": function (val, oldval) {
  220. if (val != null && val != "") {
  221. var self = this;
  222. var formData = new FormData();
  223. formData.append("sceneId", val);
  224. personRoleInfoApi.findBySceneId(formData).then(function (response) {
  225. var jsonData = response.data;
  226. if (jsonData.result) {
  227. if (jsonData.data != null && jsonData.data != "") {
  228. if(self.oldPersonRoleId != ""){
  229. self.formModel.personRoleId = self.oldPersonRoleId;
  230. }else{
  231. self.formModel.personRoleId = "";
  232. self.oldPersonRoleId = "";
  233. }
  234. self.personRoleResult = jsonData.data;
  235. }
  236. }
  237. });
  238. }
  239. },
  240. // "formModel.personRoleId": function (val, oldval) {
  241. // if (val != null && val != "") {
  242. // var self = this;
  243. // self.formModel.showIconId = "";
  244. // var formData = new FormData();
  245. // formData.append("roleId", val);
  246. // iconInfoApi.listByRoleId(formData).then(function (response) {
  247. // var jsonData = response.data;
  248. // if (jsonData.result) {
  249. // if (jsonData.data != null && jsonData.data != "") {
  250. // self.iconResult = jsonData.data;
  251. // }
  252. // }
  253. // });
  254. // }
  255. // },
  256. },
  257. methods: {
  258. closeDialog() {
  259. this.$emit("close", false);
  260. },
  261. handleSubmit() {
  262. var self = this;
  263. self.formModel.personId = self.personId;
  264. // if (
  265. // self.formModel.showIconId != null &&
  266. // self.formModel.showIconId != ""
  267. // ) {
  268. // var showIconId = self.formModel.showIconId.join(",");
  269. // self.formModel.showIconId = showIconId;
  270. // } else {
  271. // self.formModel.showIconId = "";
  272. // }
  273. if (
  274. self.formModel.companyStructureId != null &&
  275. self.formModel.companyStructureId == "0"
  276. ) {
  277. self.$message({
  278. message: "请选择下级机构",
  279. type: "warning",
  280. });
  281. self.formModel.companyStructureId == null;
  282. } else {
  283. this.$refs["form"].validate((valid) => {
  284. if (valid) {
  285. (function () {
  286. var id = self.formModel.id;
  287. if (id == null || id.length == 0) {
  288. return personPopedomApi.add(self.formModel);
  289. } else {
  290. return personPopedomApi.update(self.formModel);
  291. }
  292. })().then(function (response) {
  293. var jsonData = response.data;
  294. if (jsonData.result) {
  295. self.$message({
  296. message: "保存成功!",
  297. type: "success",
  298. });
  299. self.$emit("close", true);
  300. } else {
  301. self.$message({
  302. message: jsonData.message + "",
  303. type: "warning",
  304. });
  305. self.formModel.companyStructureId == null;
  306. self.$emit("close", false);
  307. }
  308. });
  309. }
  310. });
  311. }
  312. },
  313. },
  314. mounted: function () {
  315. var self = this;
  316. (function () {
  317. if (self.businessKey.length == 0) {
  318. return personPopedomApi.create();
  319. } else {
  320. return personPopedomApi.edit(self.businessKey);
  321. }
  322. })()
  323. .then((response) => {
  324. var jsonData = response.data;
  325. self.loading = false;
  326. if (jsonData.result) {
  327. self.formModel = jsonData.data;
  328. self.oldPersonRoleId = self.formModel.personRoleId;
  329. } else {
  330. self.$message.error(jsonData.message + "");
  331. }
  332. })
  333. .catch((error) => {
  334. self.$message.error(error + "");
  335. });
  336. },
  337. };
  338. </script>