subAccountList.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div class="full-container-p24">
  3. <div style="display: flex; justify-content: space-between">
  4. <div style="display: flex">
  5. <el-input
  6. placeholder="请输入姓名/手机号"
  7. prefix-icon="el-icon-search"
  8. v-model="term"
  9. clearable
  10. style="height: 32px; width: 330px; line-height: 32px"
  11. ></el-input>
  12. <div class="seach-btn" @click="getSubAccountList">查询</div>
  13. </div>
  14. <el-button v-auth="'ADDACCOUNT'" type="primary" @click="showAddModal"
  15. >添加账号</el-button
  16. >
  17. </div>
  18. <el-dialog
  19. v-model="visable"
  20. :title="accountId ? '修改角色' : '添加账号'"
  21. width="550px"
  22. @close="resetForm()"
  23. >
  24. <template v-slot:default>
  25. <div class="df jcc">
  26. <el-form
  27. :model="ruleForm"
  28. :rules="rules"
  29. ref="form"
  30. label-width="110px"
  31. label-position="left"
  32. >
  33. <el-form-item prop="name" label="姓名">
  34. <el-input style="width: 280px" v-model="ruleForm.name"></el-input>
  35. </el-form-item>
  36. <el-form-item prop="phone" label="手机号">
  37. <el-input
  38. style="width: 280px"
  39. v-model="ruleForm.phone"
  40. ></el-input>
  41. </el-form-item>
  42. <el-form-item prop="deptId" label="部门">
  43. <el-select
  44. style="width: 280px"
  45. v-model="ruleForm.deptId"
  46. placeholder="请选择部门"
  47. @change="getRoleSelect"
  48. >
  49. <el-option
  50. v-for="item in departmentSelect"
  51. :key="item"
  52. :label="item.value"
  53. :value="item.key"
  54. />
  55. </el-select>
  56. </el-form-item>
  57. <el-form-item v-if="ruleForm.deptId" prop="roleId" label="角色">
  58. <el-select
  59. style="width: 280px"
  60. v-model="ruleForm.roleId"
  61. placeholder="请选择角色"
  62. >
  63. <el-option
  64. v-for="item in roleSelect"
  65. :key="item"
  66. :label="item.value"
  67. :value="item.key"
  68. />
  69. </el-select>
  70. </el-form-item>
  71. </el-form>
  72. </div>
  73. </template>
  74. <template v-slot:footer>
  75. <div class="dialog-footer">
  76. <el-button @click="resetForm">取 消</el-button>
  77. <el-button type="primary" @click="addSubAccount(ruleForm)">
  78. 确 定
  79. </el-button>
  80. </div>
  81. </template>
  82. </el-dialog>
  83. <div style="margin-top: 24px">
  84. <el-table :data="tableData" stripe style="width: 100%">
  85. <el-table-column
  86. type="index"
  87. label="序号"
  88. min-width="40"
  89. align="center"
  90. ></el-table-column>
  91. <el-table-column
  92. prop="userName"
  93. label="姓名"
  94. min-width="80"
  95. align="center"
  96. ></el-table-column>
  97. <el-table-column
  98. prop="phone"
  99. label="手机号"
  100. min-width="100"
  101. align="center"
  102. ></el-table-column>
  103. <el-table-column
  104. prop="password"
  105. label="密码"
  106. min-width="80"
  107. align="center"
  108. ></el-table-column>
  109. <el-table-column
  110. prop="deptName"
  111. label="部门"
  112. min-width="80"
  113. align="center"
  114. ></el-table-column>
  115. <el-table-column
  116. prop="roleName"
  117. label="角色权限"
  118. min-width="80"
  119. align="center"
  120. ></el-table-column>
  121. <el-table-column
  122. v-auth="'ADDACCOUNT'"
  123. label="操作"
  124. min-width="120"
  125. align="center"
  126. >
  127. <template v-slot="scope">
  128. <div class="df aic jcsa">
  129. <!-- <el-switch
  130. v-model="scope.row.accountStatus"
  131. active-color="#13ce66"
  132. inactive-color="#ff4949"
  133. active-text="启用"
  134. inactive-text="禁用"
  135. :active-value="1"
  136. :inactive-value="0"
  137. />
  138. <div
  139. style="
  140. color: red;
  141. margin-left: 10px;
  142. font-size: 14px;
  143. text-decoration: underline;
  144. cursor: pointer;
  145. "
  146. >
  147. 删除
  148. </div> -->
  149. <el-button
  150. @click="showUpdateModal(scope.row)"
  151. size="small"
  152. type="primary"
  153. >修改角色权限</el-button
  154. >
  155. </div>
  156. </template>
  157. </el-table-column>
  158. </el-table>
  159. <div style="width: 100%; text-align: right; margin-top: 43px">
  160. <el-pagination
  161. background
  162. layout="prev, pager, next"
  163. :total="total"
  164. @current-change="pageChange"
  165. ></el-pagination>
  166. </div>
  167. </div>
  168. </div>
  169. </template>
  170. <script setup>
  171. import api from "../../apis/fetch";
  172. import { ref, onMounted, reactive } from "vue";
  173. import { ElNotification, ElMessageBox } from "element-plus";
  174. import store from "../../store/index";
  175. let tableData = ref([]);
  176. let currentPage = ref(1);
  177. let total = ref(0);
  178. let term = ref("");
  179. let loginAccountId = ref(0);
  180. let accountId = ref("");
  181. let ruleForm = ref({
  182. name: "",
  183. phone: "",
  184. roleId: "",
  185. deptId: "",
  186. });
  187. const rules = reactive({
  188. name: [
  189. {
  190. required: true,
  191. message: "请填写名称",
  192. trigger: "blur",
  193. },
  194. ],
  195. phone: [
  196. {
  197. required: true,
  198. message: "请填写手机号",
  199. trigger: "blur",
  200. },
  201. ],
  202. roleId: [
  203. {
  204. required: true,
  205. message: "请选择角色",
  206. trigger: "blur",
  207. },
  208. ],
  209. deptId: [
  210. {
  211. required: true,
  212. message: "请选择部门",
  213. trigger: "blur",
  214. },
  215. ],
  216. });
  217. function showAddModal() {
  218. visable.value = true;
  219. ruleForm.value = {
  220. name: "",
  221. phone: "",
  222. roleId: "",
  223. deptId: "",
  224. };
  225. }
  226. async function getSubAccountList() {
  227. let res = await api.getSubAccountList({
  228. term: term.value,
  229. currentPage: currentPage.value,
  230. size: 10,
  231. loginAccountId: loginAccountId.value,
  232. });
  233. if (res.data.status == 0) {
  234. tableData.value = res.data.result;
  235. for (let i of tableData.value) {
  236. if (i.roleId == 0) {
  237. i.roleId = "";
  238. }
  239. }
  240. total.value = res.data.total;
  241. } else {
  242. tableData.value = [];
  243. total.value = 0;
  244. }
  245. }
  246. function pageChange(e) {
  247. currentPage.value = e;
  248. getSubAccountList();
  249. }
  250. let visable = ref(false);
  251. let form = ref(null);
  252. async function addSubAccount() {
  253. let postData = {
  254. ...ruleForm.value,
  255. loginAccountId: loginAccountId.value,
  256. };
  257. if (accountId.value) {
  258. postData.accountId = accountId.value;
  259. }
  260. let res = await api[accountId.value ? "updateSubAccount" : "addSubAccount"](
  261. postData
  262. );
  263. let status = res.data.status == 0;
  264. ElNotification({
  265. title: status ? "成功" : "失败",
  266. duration: 1500,
  267. message: res.data.msg,
  268. type: status ? "success" : "error",
  269. });
  270. store.dispatch("GetBasePermissionData", localStorage.loginAccountId);
  271. store.dispatch("GetUserPermission", localStorage.loginAccountId);
  272. resetForm();
  273. getSubAccountList();
  274. }
  275. function resetForm() {
  276. visable.value = false;
  277. accountId.value = "";
  278. form.value.resetFields();
  279. }
  280. function showUpdateModal(item) {
  281. visable.value = true;
  282. accountId.value = item.id;
  283. ruleForm.value = {
  284. name: item.userName,
  285. phone: item.phone,
  286. deptId: item.deptId,
  287. roleId: item.roleId,
  288. };
  289. getRoleSelect();
  290. }
  291. let roleSelect = ref([]);
  292. async function getRoleSelect() {
  293. roleSelect.value = [];
  294. if (!ruleForm.value.deptId) return;
  295. let res = await api.getRoleSelect({
  296. loginAccountId: loginAccountId.value,
  297. deptId: ruleForm.value.deptId,
  298. });
  299. roleSelect.value = res.data.result;
  300. }
  301. let departmentSelect = ref([]);
  302. async function getDepartmentSelect() {
  303. let res = await api.getDepartmentSelect({
  304. loginAccountId: loginAccountId.value,
  305. });
  306. departmentSelect.value = res.data.result;
  307. }
  308. onMounted(() => {
  309. loginAccountId.value = localStorage.loginAccountId;
  310. getSubAccountList();
  311. getDepartmentSelect();
  312. });
  313. </script>
  314. <style scoped>
  315. .seach-btn {
  316. display: inline-block;
  317. width: 60px;
  318. height: 38px;
  319. background: #0094fe;
  320. border-radius: 2px;
  321. font-size: 14px;
  322. font-family: PingFangSC-Regular, PingFang SC;
  323. font-weight: 400;
  324. color: #ffffff;
  325. text-align: center;
  326. line-height: 38px;
  327. margin-left: 10px;
  328. cursor: pointer;
  329. }
  330. </style>