index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template>
  2. <div class="bf-rolelist">
  3. <!-- 角色列表 -->
  4. <div class="cont">
  5. <div v-if="title" class="paren_header">
  6. <p class="manageTitle">{{ title }}</p>
  7. </div>
  8. <template v-if="dataList.length">
  9. <div :class="active ? 'bgActive' : 'bgActivecheckbox'" class="paren_content">
  10. <template v-if="!type">
  11. <el-row v-infinite-scroll="load" :infinite-scroll-distance="20" infinite-scroll-disabled="disabled" class="scCont scrollbar" :gutter="16">
  12. <el-checkbox-group @change="checkChange" v-model="checkList">
  13. <el-col :span="number" v-for="(item, index) in dataList" :key="index">
  14. <div @click="handleBg(item, index)" :class="active && msg === index ? 'bgColor' : ''" class="cide">
  15. <div class="cide_header">
  16. <p :title="item.name">{{ item.name }}</p>
  17. <el-checkbox :label="index"></el-checkbox>
  18. </div>
  19. </div>
  20. </el-col>
  21. </el-checkbox-group>
  22. </el-row>
  23. </template>
  24. <template v-if="total > 1">
  25. <p class="center" v-if="loading">加载中...</p>
  26. <p class="center" v-if="noMore">没有更多数据了~</p>
  27. </template>
  28. </div>
  29. </template>
  30. <template v-else-if="mainData.length">
  31. <div :class="active ? 'bgActive' : 'bgActivecheckbox'" class="paren_content">
  32. <template v-if="type">
  33. <el-row :gutter="16">
  34. <el-radio-group style="display: block" @change="radioChange" v-model="radio">
  35. <el-col :span="number" v-for="(item, index) in mainData" :key="index">
  36. <div @click.stop="handleBg(index)" :class="active && msg === index ? 'bgColor' : ''" class="cide">
  37. <div class="cide_header">
  38. <p>{{ item.name }}</p>
  39. <el-radio :label="index"></el-radio>
  40. </div>
  41. </div>
  42. </el-col>
  43. </el-radio-group>
  44. </el-row>
  45. </template>
  46. </div>
  47. </template>
  48. <template v-else>
  49. <NoData />
  50. </template>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import { GetAccountList } from "@/api/Account";
  56. import { GetRoleByGroup } from "@/api/AccountGroup";
  57. import { QueryRole } from "@/api/apiAuthority";
  58. import { GeneralDataReception, Query } from "@/api/dataIntegration";
  59. import NoData from "@/components/nodata";
  60. export default {
  61. props: {
  62. title: {
  63. type: String,
  64. default: "",
  65. },
  66. type: {
  67. type: Boolean,
  68. default: false,
  69. },
  70. number: {
  71. type: Number,
  72. default: 3,
  73. },
  74. active: {
  75. type: Boolean,
  76. default: false,
  77. },
  78. checkBoxList: {
  79. type: Array,
  80. default: () => [],
  81. },
  82. mainData: {
  83. type: Array,
  84. default: () => [],
  85. },
  86. radioCheck: {
  87. type: Number,
  88. default: 0,
  89. },
  90. imageSize: {
  91. type: Number,
  92. default: 200,
  93. },
  94. roleType: {
  95. type: String,
  96. default: "",
  97. },
  98. GroupIds: {
  99. type: Array,
  100. default: () => [],
  101. },
  102. },
  103. components: { NoData },
  104. data () {
  105. return {
  106. radio: null,
  107. checkList: [],
  108. dataList: [],
  109. arrsList: [],
  110. msg: null,
  111. pageSize: 100,
  112. pageNum: 1,
  113. total: "",
  114. loading: false,
  115. asyncData: [],
  116. };
  117. },
  118. watch: {
  119. radioCheck: {
  120. handler (num) {
  121. this.radio = num;
  122. },
  123. deep: true,
  124. },
  125. roleType: {
  126. handler (msg) {
  127. if (msg == "account") {
  128. this.getRoleData("account_id", "account_name");
  129. }
  130. if (msg == "roleByUpId") {
  131. this.getRoleDataByUpId("role_id");
  132. }
  133. if (msg == "onlyRole") {
  134. this.getRoleData("role_id", "role_name");
  135. }
  136. },
  137. deep: true,
  138. },
  139. dataList: {
  140. handler (arr) {
  141. if (arr && arr.length) {
  142. this.asyncData.push(true);
  143. }
  144. },
  145. deep: true,
  146. },
  147. checkBoxList: {
  148. handler (arr) {
  149. if (arr && arr.length) {
  150. this.asyncData.push(true);
  151. }
  152. // if (this.roleType == "roleByUpId") {
  153. // const datas = [];
  154. // this.dataList.forEach((item, index) => {
  155. // arr.forEach((p) => {
  156. // if (item.RoleId == p.RoleId) {
  157. // datas.push(index);
  158. // }
  159. // });
  160. // });
  161. // this.checkList = datas;
  162. // }
  163. },
  164. deep: true,
  165. },
  166. asyncData: {
  167. handler (arr) {
  168. if (arr && arr.length == 2) {
  169. if (this.roleType == "account") {
  170. this.checkBoxs("user_id");
  171. }
  172. if (this.roleType == "onlyRole" || this.roleType == "roleByUpId") {
  173. this.checkBoxs("role_id");
  174. }
  175. }
  176. },
  177. deep: true,
  178. },
  179. GroupIds: {
  180. handler () {
  181. this.getRoleDataByUpId();
  182. },
  183. deep: true,
  184. },
  185. },
  186. computed: {
  187. noMore () {
  188. return this.pageNum >= this.total;
  189. },
  190. disabled () {
  191. return this.loading || this.noMore;
  192. },
  193. },
  194. methods: {
  195. // 选中
  196. handleBg (item, i) {
  197. this.msg = i;
  198. this.$emit("checkClick", item);
  199. },
  200. //多选框
  201. checkChange (arr) {
  202. const datas = this.formatChecks(arr);
  203. // if (this.roleType == 'account') {
  204. // datas = this.formatChecks(arr, 'UserId');
  205. // }
  206. this.$emit("checkChange", datas);
  207. },
  208. //单选框
  209. radioChange (val) {
  210. this.$emit("radioChange", val);
  211. },
  212. //格式化选中回调
  213. formatChecks (arr, key) {
  214. const datas = [];
  215. // const ids = []
  216. this.dataList.forEach((item, index) => {
  217. arr.forEach((p) => {
  218. if (index == p) {
  219. datas.push(item);
  220. }
  221. });
  222. });
  223. // datas.forEach(item => {
  224. // ids.push(item[key])
  225. // })
  226. return datas;
  227. },
  228. //多选框默认选中
  229. checkBoxs (ids) {
  230. const datas = [];
  231. const type = typeof this.checkBoxList[0];
  232. if (type == "object") {
  233. this.dataList.forEach((item, index) => {
  234. this.checkBoxList.forEach((p) => {
  235. if (item[ids] == p[ids]) {
  236. datas.push(index);
  237. }
  238. });
  239. });
  240. } else {
  241. this.dataList.forEach((item, index) => {
  242. this.checkBoxList.forEach((p) => {
  243. if (item[ids] == p) {
  244. datas.push(index);
  245. }
  246. });
  247. });
  248. }
  249. this.checkList = datas;
  250. },
  251. checkRole () {
  252. const datas = [];
  253. this.dataList.forEach((item, index) => {
  254. this.checkBoxList.forEach((p) => {
  255. if (item.RoleId == p.RoleId) {
  256. datas.push(index);
  257. }
  258. });
  259. });
  260. this.checkList = datas;
  261. },
  262. //获取列表
  263. async getRoleData (ids, names) {
  264. try {
  265. this.loading = true;
  266. let result = null;
  267. const userId = sessionStorage.getItem("User_Id");
  268. if (this.roleType == "account") {
  269. result = await Query({
  270. id: DATACONTENT_ID.accountTableId,
  271. needPage: this.pageNum,
  272. dataContent: [userId],
  273. });
  274. }
  275. if (this.roleType == "onlyRole") {
  276. result = await Query({
  277. id: DATACONTENT_ID.roleTableNewId,
  278. needPage: this.pageNum,
  279. dataContent: [userId],
  280. });
  281. }
  282. if (result.code == 0) {
  283. const datas = result.returnData.listValues;
  284. const num = result.returnData.pages;
  285. this.arrsList.push(datas);
  286. const arrs = this.arrsList.flat();
  287. const msgs = _.unionBy(arrs, ids);
  288. msgs.forEach((item) => {
  289. item.name = item[names];
  290. });
  291. this.dataList = msgs;
  292. this.total = num;
  293. this.$emit("roleListChange", msgs);
  294. this.loading = false;
  295. } else {
  296. this.$message.error(result.message);
  297. this.loading = false;
  298. }
  299. } catch (error) {
  300. this.loading = false;
  301. }
  302. },
  303. //获取列表2
  304. async getRoleDataByUpId () {
  305. try {
  306. this.loading = true;
  307. const obj = {
  308. GroupIds: this.GroupIds,
  309. };
  310. const result = await GetRoleByGroup(obj);
  311. if (result.code === 0) {
  312. const datas = result.returnData;
  313. const msgs = [];
  314. if (datas.length) {
  315. datas.forEach((item) => {
  316. item.name = item.RoleName;
  317. if (item.IsSelected) {
  318. msgs.push(item);
  319. }
  320. });
  321. this.dataList = msgs;
  322. } else {
  323. this.dataList = msgs;
  324. }
  325. this.$emit("roleListChange", msgs);
  326. // this.checkBoxs(this.dataList, "RoleId");
  327. this.loading = false;
  328. } else {
  329. this.$message.error(result.message);
  330. this.loading = false;
  331. }
  332. } catch (error) {
  333. this.loading = false;
  334. }
  335. },
  336. //滚动加载数据
  337. load () {
  338. // this.pageNum += 1
  339. // if (this.roleType == 'account') {
  340. // this.getRoleData('UserId', 'UserName')
  341. // }
  342. // if (this.roleType == 'onlyRole') {
  343. // this.getRoleData('RoleId', 'RoleName')
  344. // }
  345. },
  346. },
  347. };
  348. </script>
  349. <style lang="scss" scoped>
  350. @import "./rolelist.scss";
  351. .paren_content {
  352. ::v-deep .el-radio__label {
  353. display: none;
  354. }
  355. ::v-deep .el-checkbox__label {
  356. display: none;
  357. }
  358. .scCont {
  359. height: 65vh;
  360. overflow-x: hidden;
  361. overflow-y: auto;
  362. }
  363. }
  364. </style>