userModal.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <div>
  3. <el-input :placeholder="attrs.placeholder" :value="userValue.userName" @clear="clearValue" size="small" class="myinpuy-with-select" clearable>
  4. <el-button slot="append" icon="el-icon-more" @click="value = true"></el-button>
  5. </el-input>
  6. <vxe-modal v-model="value" id="userDialogModal" v-loading="load" width="900px" height="80%" @show="show" show-zoom resize transfer show-footer>
  7. <template #title>
  8. <span>选择用户</span>
  9. </template>
  10. <template #default>
  11. <module-view :propConfig="config" ref="view" @pagination="getList" @onRefresh="getList" @resert="queryList" @search="queryList" />
  12. </template>
  13. <template #footer>
  14. <div class="btn">
  15. <el-button plain size="small" @click="value = false">取消</el-button>
  16. <el-button type="primary" size="small" @click="confirm">确定</el-button>
  17. </div>
  18. </template>
  19. </vxe-modal>
  20. </div>
  21. </template>
  22. <script lang="ts">
  23. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  24. import { listUser } from '@/api/system/user'
  25. import VueViews from '@/benyun/compVue/VueViews'
  26. @Component
  27. export default class UserModal extends VueViews {
  28. value=false;
  29. load=false;
  30. isSearch=false
  31. timeNum = 0;
  32. userValue:any={};
  33. config:any={
  34. attr:{
  35. calculateH:true
  36. },
  37. search:{
  38. attr:{
  39. size:'small',
  40. },
  41. columns:[
  42. [{
  43. span:10,
  44. label:'用户名称',
  45. prop:'userName',
  46. component:'by-input',
  47. labelWidth:'120px',
  48. compConfig:{
  49. attr:{
  50. clearable:true
  51. }
  52. }
  53. },{
  54. span:10,
  55. label:'部门',
  56. prop:'deptId',
  57. component:'select-tree',
  58. labelWidth:'120px',
  59. compConfig:{
  60. attr:{
  61. clearable:true,
  62. retConfig:{
  63. deptId:'id',
  64. deptName:'label'
  65. },
  66. label:'label',
  67. },
  68. request:{
  69. url:'/system/dept/treeselect',
  70. method:"GET"
  71. }
  72. }
  73. }]
  74. ]
  75. },
  76. tool:{
  77. tools:{
  78. search:true,
  79. refresh:true
  80. }
  81. },
  82. table:{
  83. attr:{
  84. size:'mini',
  85. radio:true,
  86. seq:true,
  87. align:'center',
  88. triggerRowCheck:'row',
  89. pageSize:10
  90. },
  91. columns:[{
  92. title:'用户名称',
  93. field:'userName'
  94. },{
  95. title:'用户昵称',
  96. field:'nickName'
  97. },{
  98. title:'部门',
  99. field:'deptName',
  100. formatField:(row:any) =>{
  101. if(row.dept?.deptName){
  102. return row.dept.deptName
  103. }else{
  104. return '';
  105. }
  106. }
  107. }]
  108. }
  109. }
  110. @Watch('propValue')
  111. propValueChange(v:any){
  112. this.setValue(v);
  113. }
  114. mounted(){
  115. }
  116. //分页
  117. pagination(){
  118. if(this.isSearch){
  119. this.queryList();
  120. }else{
  121. this.getList()
  122. }
  123. }
  124. show(){
  125. this.getList();
  126. }
  127. //列表请求(只有分页,不包含搜素条件)
  128. getList(){
  129. if(!this.$refs.view){
  130. if(this.timeNum > 5){
  131. return
  132. }
  133. setTimeout(()=>{
  134. this.getList()
  135. },500)
  136. this.timeNum ++;
  137. return
  138. }
  139. this.isSearch = false;
  140. let data = (this.$refs.view as any).getPage();
  141. delete data.total;
  142. this.requestList(data);
  143. }
  144. //列表请求(包含分页和搜素条件)
  145. queryList(){
  146. this.isSearch = true;
  147. let data = (this.$refs.view as any).getQuery();
  148. delete data.total;
  149. this.requestList(data);
  150. }
  151. requestList(data:any){
  152. this.load = true;
  153. listUser(data).then((res:any) => {
  154. this.load = false;
  155. (this.$refs.view as any).setTableValue(res.rows);
  156. let page = {
  157. total: res.data.total //总条数
  158. };
  159. (this.$refs.view as any).setPage(page)
  160. }).catch(()=>{
  161. this.load = false;
  162. })
  163. }
  164. //获取已选中表格数据
  165. getSelectdata(){
  166. let data:Array<any>=[];
  167. if(this.$refs.view){
  168. data = (this.$refs.view as any).getSelectData()
  169. }
  170. return data;
  171. }
  172. //确定
  173. confirm(){
  174. let data:Array<any>=this.getSelectdata();
  175. if(data.length == 0){
  176. this.$message('请选择用户!')
  177. return
  178. }
  179. this.userValue.userId = data[0].userId;
  180. this.userValue.userName = data[0].userName;
  181. this.value = false;
  182. this.onChange();
  183. }
  184. onChange(){
  185. this.$emit('onChange',this.userValue);
  186. }
  187. setValue(v:any){
  188. this.userValue.userName = v;
  189. if(this.parentValue){
  190. this.userValue.userId = this.parentValue.userId;
  191. }
  192. }
  193. // 清空数据
  194. clearValue(){
  195. this.userValue = {};
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. </style>