userSelect.vue 10 KB

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