subAccountList.vue 8.8 KB

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