index.vue 7.9 KB

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