index.vue 7.4 KB

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