index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <template>
  2. <div class="role pagePadding">
  3. <ex-table
  4. v-loading="loading"
  5. v-if=" powers.some((i) => i == '001')"
  6. :table="table"
  7. :data="tableData"
  8. :columns="columns"
  9. :page="pageInfo"
  10. :size="size"
  11. @page-curr-change="handlePageChange"
  12. @page-size-change="handleSizeChange"
  13. @screen-reset="
  14. pageInfo.curr = 1;
  15. searchList();
  16. "
  17. @screen-submit="
  18. pageInfo.curr = 1;
  19. searchList();
  20. "
  21. >
  22. <template #table-header="{}">
  23. <div style="width: 100%">
  24. <el-row>
  25. <el-col :span="24" style="padding: 0 0 0 80px">
  26. <el-col :span="3" style="width: 120px">
  27. <el-select
  28. v-model="parmValue.status"
  29. filterable
  30. clearable
  31. :size="searchSize"
  32. placeholder="角色状态"
  33. style="width: 100%"
  34. @change="
  35. pageInfo.curr = 1;
  36. parmValue.page = 1;
  37. searchList();
  38. "
  39. >
  40. <el-option
  41. v-for="item in statusList"
  42. :key="'status' + item.code"
  43. :label="item.name"
  44. :value="item.code"
  45. />
  46. </el-select>
  47. </el-col>
  48. <el-col :span="3" style="width: 130px; padding: 0 0 0 10px">
  49. <el-select
  50. :size="searchSize"
  51. v-model="parmValue.level"
  52. filterable
  53. placeholder="角色等级"
  54. style="width: 100%"
  55. @change="
  56. pageInfo.curr = 1;
  57. parmValue.page = 1;
  58. searchList();
  59. "
  60. >
  61. <el-option
  62. v-for="item in roleLevel"
  63. :key="'ruleid' + item.code"
  64. :label="item.name"
  65. :value="item.code"
  66. />
  67. </el-select>
  68. </el-col>
  69. <el-col :span="3" style="width: 150px; padding: 0 0 0 10px">
  70. <el-input
  71. :size="searchSize"
  72. v-model="parmValue.role_name"
  73. :maxlength="40"
  74. placeholder="角色名称"
  75. />
  76. </el-col>
  77. <el-col :span="3" style="width: 54px">
  78. <el-button
  79. type="primary"
  80. class="fr"
  81. :size="searchSize"
  82. icon="el-icon-search"
  83. @click="searchList"
  84. />
  85. </el-col>
  86. <el-col
  87. :span="3"
  88. style="width: 66px"
  89. >
  90. <el-button
  91. type="warning"
  92. class="fr"
  93. :size="searchSize"
  94. @click="restSearch"
  95. >
  96. 重置
  97. </el-button>
  98. </el-col>
  99. <el-col
  100. :span="3"
  101. style="width: 66px; float: right"
  102. >
  103. <el-button
  104. type="primary"
  105. :size="searchSize"
  106. style="float: right"
  107. @click="searchList"
  108. >
  109. 刷新
  110. </el-button></el-col
  111. >
  112. <el-col
  113. :span="3"
  114. style="width: 66px; float: right"
  115. v-if="powers.some((i) => i == '003')"
  116. >
  117. <el-button
  118. :size="searchSize"
  119. type="success"
  120. style="float: right"
  121. @click="openModal('add', false)"
  122. >
  123. 添加
  124. </el-button>
  125. </el-col>
  126. </el-col>
  127. </el-row>
  128. </div>
  129. </template>
  130. <template #status="{ scope }">
  131. <el-tag
  132. :size="tablebtnSize"
  133. :type="scope.row.status == '0' ? 'warning' : ''"
  134. v-text="
  135. (statusOptions.find((item) => item.id == scope.row.status) || {})
  136. .label || '--'
  137. "
  138. ></el-tag>
  139. </template>
  140. <template #operation="{ scope }">
  141. <el-tooltip
  142. v-if="powers.some((i) => i == '007')"
  143. effect="dark"
  144. content="详情"
  145. placement="top"
  146. >
  147. <i
  148. class="el-icon-view tb-icon"
  149. @click="openModal(scope.row.id, true)"
  150. ></i>
  151. </el-tooltip>
  152. <el-tooltip
  153. v-if="powers.some((i) => i == '005')"
  154. effect="dark"
  155. content="修改"
  156. placement="top"
  157. >
  158. <i
  159. class="el-icon-edit tb-icon"
  160. @click="openModal(scope.row.id, false)"
  161. ></i>
  162. </el-tooltip>
  163. <el-tooltip
  164. v-if="
  165. powers.some((i) => i == '004') && scope.row.status === '1'
  166. "
  167. effect="dark"
  168. content="禁用"
  169. placement="top"
  170. >
  171. <i
  172. class="el-icon-video-pause tb-icon"
  173. @click="changeStatus(scope.row.id, scope.row.status)"
  174. ></i>
  175. </el-tooltip>
  176. <el-tooltip
  177. v-if="
  178. powers.some((i) => i == '004') && scope.row.status === '0'
  179. "
  180. effect="dark"
  181. content="启用"
  182. placement="top"
  183. >
  184. <i
  185. class="el-icon-video-play tb-icon"
  186. @click="changeStatus(scope.row.id, scope.row.status)"
  187. ></i>
  188. </el-tooltip>
  189. </template>
  190. </ex-table>
  191. <no-auth v-else></no-auth>
  192. <!-- 弹窗 新增/修改 -->
  193. <add-edit
  194. :id="modelId"
  195. :show-model="showModel"
  196. :is-detail="isDetail"
  197. @refresh="searchList"
  198. @cancel="showModel = false"
  199. />
  200. </div>
  201. </template>
  202. <script>
  203. import addEdit from "./addEdit";
  204. import asyncRequest from "@/apis/service/interest/role";
  205. import {statusList} from "@/assets/js/statusList";
  206. import roleLevel from "@/assets/js/roleLevel";
  207. import mixinPage from "@/mixins/elPaginationHandle";
  208. import resToken from "@/mixins/resToken";
  209. import { mapGetters } from "vuex";
  210. export default {
  211. name: "role",
  212. mixins: [mixinPage, resToken],
  213. components: {
  214. addEdit,
  215. },
  216. computed: {
  217. //组件SIZE设置
  218. ...mapGetters(["tablebtnSize", "searchSize", "size"]),
  219. powers() {
  220. const tran =
  221. this.$store.getters.btnList.find((i) => i.menu_route == "role") ||
  222. {};
  223. const { action } = tran ?? {};
  224. return action ?? [];
  225. },
  226. },
  227. data() {
  228. return {
  229. statusList: statusList,
  230. roleLevel: roleLevel,
  231. loading: true,
  232. showModel: false,
  233. isDetail: false,
  234. modelId: 0,
  235. parmValue: {
  236. loginName: "", // 账户
  237. fullName: "", // 姓名
  238. type: 2, // 用户类型(1运营人员 2物业人员)
  239. page: 1, // 页码
  240. size: 15, // 每页显示条数
  241. },
  242. // 状态
  243. statusOptions: [
  244. { id: 0, label: "禁用" },
  245. { id: 1, label: "启用" },
  246. ],
  247. // 角色等级
  248. authOptions: [
  249. { id: "1", label: "管理员" },
  250. { id: "2", label: "非管理员" },
  251. ],
  252. // 表格 - 数据
  253. tableData: [],
  254. // 表格 - 参数
  255. table: {
  256. stripe: true,
  257. border: true,
  258. _defaultHeader_: ["setcol"],
  259. },
  260. // 表格 - 分页
  261. pageInfo: {
  262. size: 15,
  263. curr: 1,
  264. total: 0,
  265. },
  266. // 表格 - 列参数
  267. columns: [
  268. {
  269. prop: "role_name",
  270. label: "角色名称",
  271. },
  272. {
  273. prop: "level",
  274. label: "角色等级",
  275. _format_: (d) => {
  276. return (
  277. this.authOptions.find((item) => {
  278. return item.id == d.level;
  279. }) || {}
  280. ).label;
  281. },
  282. },
  283. {
  284. prop: "addtime",
  285. label: "创建时间",
  286. sortable: true,
  287. },
  288. {
  289. prop: "status",
  290. label: "状态",
  291. sortable: true,
  292. _slot_: "status",
  293. },
  294. {
  295. prop: "",
  296. label: "操作",
  297. fixed: "right",
  298. _noset_: true,
  299. _slot_: "operation",
  300. },
  301. ],
  302. };
  303. },
  304. mounted() {
  305. this.searchList();
  306. },
  307. methods: {
  308. restSearch() {
  309. // 表格 - 分页
  310. this.pageInfo = {
  311. size: 15,
  312. curr: 1,
  313. total: 0,
  314. };
  315. this.parmValue = {
  316. status: "", // 账户
  317. level: "", // 姓名
  318. role_name: "",
  319. page: 1, // 页码
  320. size: 15, // 每页显示条数
  321. };
  322. this.searchList();
  323. },
  324. // 新建/编辑/详情
  325. openModal(id, isDetail) {
  326. this.showModel = true;
  327. this.modelId = id;
  328. this.isDetail = isDetail;
  329. },
  330. /**
  331. * 启用/禁用
  332. * @param {String} id id
  333. * @param {String} status 0-禁用 1-启用
  334. */
  335. async changeStatus(id, status) {
  336. await this.$confirm(`确定要改为${status === "1" ? "禁用" : "启用"}?`, {
  337. confirmButtonText: "确定",
  338. cancelButtonText: "取消",
  339. type: "warning",
  340. })
  341. .then(async () => {
  342. const model = {
  343. roleid: id,
  344. status: status === "1" ? "0" : "1",
  345. };
  346. const res = await asyncRequest.status(model);
  347. if (res && res.code === 0) {
  348. this.$notify.success({
  349. title: "状态修改成功",
  350. message: "",
  351. });
  352. this.searchList();
  353. } else if (res && res.code >= 100 && res.code <= 104) {
  354. await this.logout();
  355. } else {
  356. this.$message.warning(res.message);
  357. }
  358. })
  359. .catch(() => {
  360. console.log("取消");
  361. });
  362. },
  363. // 刷新表格
  364. async searchList() {
  365. this.loading = true;
  366. const res = await asyncRequest.list(this.parmValue);
  367. if (res && res.code === 0 && res.data) {
  368. this.tableData = res.data.list;
  369. // this.tableData.map((v1) => {
  370. // v1.addtime = v1.addtime.replace(".000", "");
  371. // return v1;
  372. // });
  373. this.pageInfo.total = Number(res.data.count);
  374. } else if (res && res.code >= 100 && res.code <= 104) {
  375. await this.logout();
  376. } else {
  377. this.tableData = [];
  378. this.pageInfo.total = 0;
  379. }
  380. this.loading = false;
  381. },
  382. },
  383. };
  384. </script>
  385. <style lang="scss" scoped>
  386. </style>