userSelect.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <span class="select-component" style="display:inline-flex;width: 100%;">
  3. <el-select
  4. v-model.trim="value"
  5. size="small"
  6. :placeholder="configuration.placeholder"
  7. style="border-right: none;width: 100%"
  8. :disabled="disabled?disabled:false"
  9. :multiple="configuration.multiple?configuration.multiple:false"
  10. :clearable="configuration.clearable?configuration.clearable:false"
  11. :collapse-tags="configuration.collapseTags?configuration.collapseTags:false"
  12. filterable
  13. remote
  14. @change="changeName()"
  15. :remote-method="remoteMethod"
  16. >
  17. <el-option
  18. v-for="item in configuration.dicData.length !== 0?dicData.length !== 0?dicData:configuration.dicData:dicData"
  19. :key="item.id"
  20. :label="item.realName"
  21. :value="item.realName"
  22. @click.native="getRow(item)"
  23. />
  24. </el-select>
  25. <el-button slot="append" icon="el-icon-search" size="mini" @click="dialogVisible = true"
  26. :disabled="disabled?disabled:false"></el-button>
  27. <el-dialog
  28. v-dialogdrag
  29. title="用户"
  30. :fullscreen="dialogFull"
  31. :visible.sync="dialogVisible"
  32. class="el-dialogDeep"
  33. append-to-body
  34. width="80%">
  35. <template slot="title">
  36. <span class="el-dialog__title">
  37. <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
  38. 用户
  39. </span>
  40. <div style="float: right" class="avue-crud__dialog__menu" @click="dialogFull? dialogFull=false: dialogFull=true">
  41. <i class="el-icon-full-screen"></i>
  42. </div>
  43. </template>
  44. <el-row style="height: 0">
  45. <el-col :span="5">
  46. <div class="box">
  47. <el-scrollbar>
  48. <basic-container>
  49. <avue-tree :option="treeOption" :data="treeData" @node-click="nodeClick"/>
  50. </basic-container>
  51. </el-scrollbar>
  52. </div>
  53. </el-col>
  54. <el-col :span="19">
  55. <basic-container>
  56. <avue-crud :option="option"
  57. :data="dataList"
  58. ref="crud"
  59. v-model="form"
  60. :page.sync="page"
  61. :table-loading="loadings"
  62. :before-close="beforeClose"
  63. @search-change="searchChange"
  64. @search-reset="searchReset"
  65. @refresh-change="refreshChange"
  66. @selection-change="selectionChange"
  67. @on-load="onLoad"
  68. @saveColumn="saveColumn"
  69. @tree-load="treeLoad">
  70. </avue-crud>
  71. </basic-container>
  72. </el-col>
  73. </el-row>
  74. <span slot="footer" class="dialog-footer">
  75. <el-button @click="dialogVisible = false">取 消</el-button>
  76. <el-button type="primary" @click="confirmSelection"
  77. :disabled="configuration.multipleChoices === true?false:selection.length === 1?false:true">确 定</el-button>
  78. </span>
  79. </el-dialog>
  80. </span>
  81. </template>
  82. <script>
  83. import option from "./configuration/userOption.json";
  84. import { getList } from "@/api/system/user";
  85. import { getDeptLazyTree} from "@/api/system/dept";
  86. export default {
  87. name: "index",
  88. props: {
  89. disabled: Boolean,
  90. value: String,
  91. configuration: Object,
  92. },
  93. model: {
  94. prop: 'value',
  95. event: 'returnBack'
  96. },
  97. data() {
  98. return {
  99. dialogFull: false,
  100. loadings:false,
  101. form: {},
  102. dicData: [],
  103. dialogVisible: false,
  104. value: '',
  105. option: option,
  106. parentId: 0,
  107. dataList: [],
  108. selection: [],
  109. treeOption: {
  110. nodeKey: 'id',
  111. lazy: true,
  112. treeLoad: function (node, resolve) {
  113. const parentId = (node.level === 0) ? 0 : node.data.id;
  114. getDeptLazyTree(parentId).then(res => {
  115. resolve(res.data.data.map(item => {
  116. return {
  117. ...item,
  118. leaf: !item.hasChildren
  119. }
  120. }))
  121. });
  122. },
  123. addBtn: false,
  124. menu: false,
  125. size: 'small',
  126. props: {
  127. labelText: '标题',
  128. label: 'title',
  129. value: 'value',
  130. children: 'children'
  131. }
  132. },
  133. page: {
  134. pageSize: 10,
  135. pagerCount: 5,
  136. total: 0,
  137. },
  138. // 远程模糊查找loading
  139. loading: false,
  140. queryParams: {
  141. size: 10,
  142. current: 1
  143. },
  144. }
  145. },
  146. async created() {
  147. this.remoteMethod()
  148. },
  149. methods: {
  150. changeName(){
  151. this.$emit('returnBack', this.value)
  152. let optionList = this.configuration.dicData.length !== 0?this.dicData.length !== 0?this.dicData:this.configuration.dicData:this.dicData;
  153. let value ;
  154. optionList.map(item =>{
  155. if(item.realName === this.value){
  156. value = {
  157. id : item.id,
  158. deptId : item.deptId
  159. }
  160. }
  161. })
  162. this.$emit('value',value)
  163. },
  164. getRow(row) {
  165. this.$emit('getRow', row)
  166. },
  167. //刷新触发
  168. refreshChange() {
  169. this.page = {
  170. pageSize: 10,
  171. pagerCount: 5,
  172. total: 0,
  173. }
  174. },
  175. //确认导出触发
  176. confirmSelection() {
  177. this.dicData = []
  178. if (this.configuration.multipleChoices === true) {
  179. let value = []
  180. for (let item in this.selection) {
  181. this.dicData.push({realName: this.selection[item].realName})
  182. value.push(this.selection[item].realName)
  183. }
  184. this.value = value
  185. } else {
  186. this.dicData.push({realName: this.selection[0].realName})
  187. this.value = this.selection[0].realName
  188. }
  189. this.$emit('returnRow', this.selection)
  190. this.$emit('returnBack', this.value)
  191. this.dialogVisible = false
  192. this.$emit('receiveList',this.dicData)
  193. let value = {
  194. id : this.selection[0].id,
  195. deptId : this.selection[0].deptId
  196. } ;
  197. this.$emit('value',value)
  198. this.selection = []
  199. },
  200. //选中触发
  201. selectionChange(selection) {
  202. this.selection = selection
  203. },
  204. nodeClick(data) {
  205. this.treeDeptId = data.id;
  206. this.page.currentPage = 1;
  207. this.onLoad(this.page);
  208. },
  209. //查询全部
  210. initData() {
  211. getList().then(res => {
  212. const column = this.findObject(this.option.column, "parentId");
  213. column.dicData = res.data.data.records;
  214. });
  215. },
  216. //新增子项触发
  217. handleAdd(row) {
  218. this.parentId = row.id;
  219. const column = this.findObject(this.option.column, "parentId");
  220. column.value = row.id;
  221. column.addDisabled = true;
  222. this.$refs.crud.rowAdd();
  223. },
  224. //点击新增时触发
  225. beforeClose(done) {
  226. this.parentId = "";
  227. const column = this.findObject(this.option.column, "parentId");
  228. column.value = "";
  229. column.addDisabled = false;
  230. done();
  231. },
  232. //点击搜索按钮触发
  233. searchChange(params, done) {
  234. this.treeDeptId = '';
  235. this.page.currentPage = 1;
  236. this.onLoad(this.page, params);
  237. done()
  238. },
  239. //搜索重置按钮触发
  240. searchReset() {
  241. this.treeDeptId = '';
  242. this.onLoad(this.page);
  243. },
  244. onLoad(page, params = {parentId: 0}) {
  245. this.loadings = true;
  246. getList(page.currentPage, page.pageSize, params,this.treeDeptId).then(res => {
  247. this.dataList = res.data.data.records
  248. this.page.total = res.data.data.total
  249. if (this.page.total) {
  250. this.option.height = window.innerHeight - 500;
  251. } else {
  252. this.option.height = window.innerHeight - 200;
  253. }
  254. }).finally(()=>{
  255. this.loadings = false
  256. })
  257. },
  258. //树桩列点击展开触发
  259. treeLoad(tree, treeNode, resolve) {
  260. const deptId = tree.id;
  261. this.loadings = true;
  262. getList(1, 10,deptId).then(res => {
  263. resolve(res.data.data.records);
  264. }).finally(()=>{
  265. this.loadings = false
  266. });
  267. },
  268. // 远程模糊查找
  269. remoteMethod(query) {
  270. if (query) {
  271. this.loading = true;
  272. let params = {
  273. realName: query
  274. }
  275. getList(1, 10, params).then(res => {
  276. this.dicData = res.data.data.records
  277. this.loading = false;
  278. });
  279. } else {
  280. this.loading = true
  281. this.queryParams = {
  282. size: 10,
  283. current: 1
  284. }
  285. getList(1, 10).then(res => {
  286. this.dicData = []
  287. this.configuration.dicData.forEach((e,index) => {
  288. res.data.data.records.forEach(item => {
  289. if (e.realName == item.realName) {
  290. this.configuration.dicData.splice(index, 1)
  291. }
  292. })
  293. })
  294. this.configuration.dicData = this.configuration.dicData.concat(res.data.data.records)
  295. // this.configuration.dicData = res.data.data.records
  296. this.removeRepeat()
  297. this.loading = false;
  298. });
  299. }
  300. },
  301. // 去重
  302. removeRepeat() {
  303. let obj = []
  304. this.configuration.dicData = this.configuration.dicData.reduce((current,next) => {
  305. obj[next.realName] ? '': obj[next.realName] = true && current.push(next)
  306. return current
  307. }, [])
  308. },
  309. //列保存触发
  310. async saveColumn() {
  311. const inSave = await this.saveColumnData(
  312. this.getColumnName(49),
  313. this.option
  314. );
  315. if (inSave) {
  316. this.$message.success("保存成功");
  317. //关闭窗口
  318. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  319. }
  320. },
  321. }
  322. };
  323. </script>
  324. <style scoped lang="scss">
  325. .el-dialogDeep {
  326. ::v-deep .el-dialog {
  327. .el-dialog__body, .el-dialog__footer {
  328. padding-bottom: 0 !important;
  329. padding-top: 0 !important;
  330. }
  331. }
  332. }
  333. </style>