subAccountList.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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="visable = true"
  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="roleId" label="角色">
  43. <el-select
  44. style="width: 280px"
  45. v-model="ruleForm.roleId"
  46. placeholder="请选择角色"
  47. >
  48. <el-option
  49. v-for="item in roleSelect"
  50. :key="item"
  51. :label="item.value"
  52. :value="item.key"
  53. />
  54. </el-select>
  55. </el-form-item>
  56. </el-form>
  57. </div>
  58. </template>
  59. <template v-slot:footer>
  60. <div class="dialog-footer">
  61. <el-button @click="resetForm">取 消</el-button>
  62. <el-button type="primary" @click="addSubAccount(ruleForm)">
  63. 确 定
  64. </el-button>
  65. </div>
  66. </template>
  67. </el-dialog>
  68. <div style="margin-top: 24px">
  69. <el-table :data="tableData" stripe style="width: 100%">
  70. <el-table-column
  71. type="index"
  72. label="序号"
  73. min-width="40"
  74. align="center"
  75. ></el-table-column>
  76. <el-table-column
  77. prop="userName"
  78. label="姓名"
  79. min-width="80"
  80. align="center"
  81. ></el-table-column>
  82. <el-table-column
  83. prop="phone"
  84. label="手机号"
  85. min-width="100"
  86. align="center"
  87. ></el-table-column>
  88. <el-table-column
  89. prop="password"
  90. label="密码"
  91. min-width="80"
  92. align="center"
  93. ></el-table-column>
  94. <el-table-column
  95. prop="role_name"
  96. label="角色权限"
  97. min-width="80"
  98. align="center"
  99. ></el-table-column>
  100. <el-table-column label="操作" min-width="120" align="center">
  101. <template v-slot="scope">
  102. <div class="df aic jcsa">
  103. <!-- <el-switch
  104. v-model="scope.row.accountStatus"
  105. active-color="#13ce66"
  106. inactive-color="#ff4949"
  107. active-text="启用"
  108. inactive-text="禁用"
  109. :active-value="1"
  110. :inactive-value="0"
  111. />
  112. <div
  113. style="
  114. color: red;
  115. margin-left: 10px;
  116. font-size: 14px;
  117. text-decoration: underline;
  118. cursor: pointer;
  119. "
  120. >
  121. 删除
  122. </div> -->
  123. <el-button
  124. @click="showUpdateModal(scope.row)"
  125. size="small"
  126. type="primary"
  127. >修改角色权限</el-button
  128. >
  129. </div>
  130. </template>
  131. </el-table-column>
  132. </el-table>
  133. <div style="width: 100%; text-align: right; margin-top: 43px">
  134. <el-pagination
  135. background
  136. layout="prev, pager, next"
  137. :total="total"
  138. @current-change="pageChange"
  139. ></el-pagination>
  140. </div>
  141. </div>
  142. </div>
  143. </template>
  144. <script setup>
  145. import api from "../../apis/fetch";
  146. import { ref, onMounted, reactive } from "vue";
  147. import { ElNotification, ElMessageBox } from "element-plus";
  148. let tableData = ref([]);
  149. let currentPage = ref(1);
  150. let total = ref(0);
  151. let term = ref("");
  152. let loginAccountId = ref(0);
  153. let accountId = ref("");
  154. let ruleForm = ref({
  155. name: "",
  156. phone: "",
  157. roleId: "",
  158. });
  159. const rules = reactive({
  160. name: [
  161. {
  162. required: true,
  163. message: "请填写名称",
  164. trigger: "blur",
  165. },
  166. ],
  167. phone: [
  168. {
  169. required: true,
  170. message: "请填写手机号",
  171. trigger: "blur",
  172. },
  173. ],
  174. roleId: [
  175. {
  176. required: true,
  177. message: "请选择角色",
  178. trigger: "blur",
  179. },
  180. ],
  181. });
  182. async function getSubAccountList() {
  183. let res = await api.getSubAccountList({
  184. term: term.value,
  185. currentPage: currentPage.value,
  186. size: 10,
  187. loginAccountId: loginAccountId.value,
  188. });
  189. if (res.data.status == 0) {
  190. tableData.value = res.data.result;
  191. for (let i of tableData.value) {
  192. if (i.roleId == 0) {
  193. i.roleId = "";
  194. }
  195. }
  196. total.value = res.data.total;
  197. } else {
  198. tableData.value = [];
  199. total.value = 0;
  200. }
  201. }
  202. function pageChange(e) {
  203. currentPage.value = e;
  204. getSubAccountList();
  205. }
  206. let visable = ref(false);
  207. let form = ref(null);
  208. async function addSubAccount() {
  209. let postData = {
  210. ...ruleForm.value,
  211. loginAccountId: loginAccountId.value,
  212. };
  213. if (accountId.value) {
  214. postData.accountId = accountId.value;
  215. }
  216. let res = await api[accountId.value ? "updateSubAccount" : "addSubAccount"](
  217. postData
  218. );
  219. let status = res.data.status == 0;
  220. ElNotification({
  221. title: status ? "成功" : "失败",
  222. duration: 1500,
  223. message: res.data.msg,
  224. type: status ? "success" : "error",
  225. });
  226. resetForm();
  227. getSubAccountList();
  228. }
  229. function resetForm() {
  230. visable.value = false;
  231. accountId.value = "";
  232. form.value.resetFields();
  233. }
  234. function showUpdateModal(item) {
  235. visable.value = true;
  236. accountId.value = item.id;
  237. ruleForm.value = {
  238. name: item.userName,
  239. phone: item.phone,
  240. roleId: item.roleId,
  241. };
  242. }
  243. let roleSelect = ref([]);
  244. async function getRoleSelect() {
  245. let res = await api.getRoleSelect({
  246. loginAccountId: loginAccountId.value,
  247. });
  248. roleSelect.value = res.data.result;
  249. }
  250. onMounted(() => {
  251. loginAccountId.value = localStorage.loginAccountId;
  252. getSubAccountList();
  253. getRoleSelect();
  254. });
  255. </script>
  256. <style scoped>
  257. .seach-btn {
  258. display: inline-block;
  259. width: 60px;
  260. height: 38px;
  261. background: #0094fe;
  262. border-radius: 2px;
  263. font-size: 14px;
  264. font-family: PingFangSC-Regular, PingFang SC;
  265. font-weight: 400;
  266. color: #ffffff;
  267. text-align: center;
  268. line-height: 38px;
  269. margin-left: 10px;
  270. cursor: pointer;
  271. }
  272. </style>