lookImpowerSearch.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <!--
  2. =========================示例说明=========================
  3. <advanced-search :searchData="searchData"></advanced-search>
  4. import advancedSearch from "@/components/ZDcomponents/advancedSearch.vue"
  5. components: {
  6. addPage,
  7. advancedSearch
  8. },
  9. =========================必要参数=========================
  10. searchData:{
  11. buttonList:[//按钮数组没有则为空
  12. {
  13. name:"新增",//按钮名称 只有再状态 1 时需要
  14. type:"1", //按钮类型 1.按钮 2.导入 3.导出
  15. parameter:"add",//按钮字符用于返回方法时的判断
  16. hasPermi:['laboratory:gradeManage:add'] // 权限字段 如果没有则传空字符 hasPermi:"",
  17. },
  18. {
  19. name:"导入",//按钮名称 只有再状态 1 时需要
  20. type:"2", //按钮类型 1.按钮 2.导入 3.导出
  21. parameter:"import",//按钮字符用于返回方法时的判断
  22. hasPermi:['laboratory:gradeManage:import'] // 权限字段 如果没有则传空字符 hasPermi:"",
  23. },
  24. {
  25. name:"导出",//按钮名称 只有再状态 1 时需要
  26. type:"3", //按钮类型 1.按钮 2.导入 3.导出
  27. parameter:"export",//按钮字符用于返回方法时的判断
  28. hasPermi:['laboratory:gradeManage:export'] // 权限字段 如果没有则传空字符 hasPermi:"",
  29. }
  30. ],
  31. searchList:[//搜索数组
  32. {
  33. name:"名称",//描述名称
  34. key:"name",//键名 用于返回数据
  35. value:"",//内容 用于组件内绑定数据
  36. placeholder:"请输入名称",//输入提示
  37. level:"1",//1.普通搜索 2.高级搜索 普通搜索默认会在高级搜索时显示
  38. type:"1",//类型 1.input 2.select 3.TimePicker
  39. universal:'10',//通用参数 input时为最大长度 //TimePicker时可不传
  40. universal:[ //通用参数 select时为列表数据 //TimePicker时可不传
  41. {label:"全部",value:""},{label:"开启",value:"1"},{label:"关闭",value:"0"},
  42. ],
  43. labelWidth:'100px',//label-width宽度 可传可不传 不传时为默认宽度
  44. width:'200',//el-form-item 长度 可传可不传 不传时input/select默认180长度 TimePicker默认240长度
  45. }
  46. ]
  47. }
  48. =========================必要方法=========================
  49. //父组件必要此方法用于接收参数
  50. searchClick(type,data){
  51. if(type == 1){ //type 1.查询
  52. this.queryParams = JSON.parse(JSON.stringify(data));
  53. this.queryParams.pageNum = 1;
  54. this.queryParams.pageSize = 20;
  55. this.getList();
  56. }else if(type == 2){ //type 1.重置
  57. this.queryParams = {
  58. pageNum : 1,
  59. pageSize:20,
  60. };
  61. this.getList();
  62. }else if(type == 'add'){ //type 其他 自定义按钮
  63. this.clickPageType(2);
  64. }else if(type == 'import'){ //如果按钮类型是2或者3 这里data也会返回数据
  65. console.log('data',data)
  66. }else if(type == 'export'){ //如果按钮类型是2或者3 这里data也会返回数据
  67. console.log('data',data)
  68. }
  69. },
  70. -->
  71. <template>
  72. <div class="advancedSearchMaxBigBox">
  73. <el-form ref="queryForm" :inline="true" v-if="!searchState">
  74. <el-form-item :label="item.name" :label-width="item.labelWidth?item.labelWidth:'px'" prop="searchValue" v-for="item in searchData.searchList" v-if="item.level == 1">
  75. <el-input v-if="item.type == 1" v-model="item.value" :maxlength="item.universal" :placeholder="item.placeholder" clearable
  76. :style="item.width?'width:'+item.width+'px;':'width: 180px;'"/>
  77. <el-select v-if="item.type == 2" v-model="item.value" :placeholder="item.placeholder" clearable
  78. :style="item.width?'width:'+item.width+'px;':'width: 180px;'">
  79. <el-option :key="minItem.value" :label="minItem.label" :value="minItem.value" v-for="minItem in item.universal"></el-option>
  80. </el-select>
  81. <el-date-picker v-if="item.type == 3" v-model="item.value" :clearable="false" value-format="yyyy-MM-dd"
  82. :style="item.width?'width:'+item.width+'px;':'width: 240px;'"
  83. type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
  84. </el-date-picker>
  85. </el-form-item>
  86. <el-form-item>
  87. <p class="inquire-button-one" @click="buttonClick(1)">查询</p>
  88. <p class="reset-button-one" @click="buttonClick(2)">重置</p>
  89. </el-form-item>
  90. <el-form-item>
  91. <p class="advanced-button" @click="stateSwitch">高级搜索</p>
  92. </el-form-item>
  93. <el-form-item style="float: right" v-for="item in searchData.buttonList" >
  94. <p v-if="item.type == 1 && !item.hasPermi" class="inquire-button-one" style="width:120px;" @click="buttonClick(item.parameter)">{{item.name}}</p>
  95. <p v-if="item.type == 1 && item.hasPermi" class="inquire-button-one" v-hasPermi="item.hasPermi" style="width:120px;" @click="buttonClick(item.parameter)">{{item.name}}</p>
  96. <div style="float: right;" v-if="item.type == 2">
  97. <el-dropdown @command="commandButton" v-hasPermi="item.hasPermi">
  98. <div class="form-dropdown-box">
  99. <img src="@/assets/ZDimages/personnelManagement/icon_jzgxx_dr.png">
  100. <p>导入</p>
  101. <img src="@/assets/ZDimages/personnelManagement/icon_jzggl_xljt.png">
  102. </div>
  103. <el-dropdown-menu slot="dropdown">
  104. <el-dropdown-item style="border-bottom:1px solid #E0E0E0;margin:0 10px;color:#333;" :command="{item:item,command:1}">下载模板</el-dropdown-item>
  105. <el-dropdown-item style="margin:0 10px;color:#666;" :command="{item:item,command:2}">导入数据</el-dropdown-item>
  106. </el-dropdown-menu>
  107. </el-dropdown>
  108. </div>
  109. <div style="float: right; " v-if="item.type == 3">
  110. <el-dropdown @command="commandButton" v-hasPermi="item.hasPermi">
  111. <div class="form-dropdown-box">
  112. <img src="@/assets/ZDimages/personnelManagement/icon_jzgxx_sc.png">
  113. <p>导出</p>
  114. <img src="@/assets/ZDimages/personnelManagement/icon_jzggl_xljt.png">
  115. </div>
  116. <el-dropdown-menu slot="dropdown">
  117. <el-dropdown-item style="border-bottom:1px solid #E0E0E0;margin:0 10px;color:#333;" :command="{item:item,command:1}">导出全部数据</el-dropdown-item>
  118. <el-dropdown-item style="margin:0 10px;color:#666;" :command="{item:item,command:2}">导出选中数据</el-dropdown-item>
  119. </el-dropdown-menu>
  120. </el-dropdown>
  121. </div>
  122. </el-form-item>
  123. </el-form>
  124. <el-form ref="queryForm" :inline="true" v-if="searchState">
  125. <el-form-item :label="item.name" :label-width="item.labelWidth?item.labelWidth:'px'" prop="searchValue" v-for="item in searchData.searchList" >
  126. <el-input v-if="item.type == 1" v-model="item.value" :maxlength="item.universal" :placeholder="item.placeholder" clearable
  127. :style="item.width?'width:'+item.width+'px;':'width: 180px;'"/>
  128. <el-select v-if="item.type == 2" v-model="item.value" :placeholder="item.placeholder" clearable
  129. :style="item.width?'width:'+item.width+'px;':'width: 180px;'">
  130. <el-option :key="minItem.value" :label="minItem.label" :value="minItem.value" v-for="minItem in item.universal"></el-option>
  131. </el-select>
  132. <el-date-picker v-if="item.type == 3" v-model="item.value" :clearable="false" value-format="yyyy-MM-dd"
  133. :style="item.width?'width:'+item.width+'px;':'width: 240px;'"
  134. type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
  135. </el-date-picker>
  136. </el-form-item>
  137. </el-form>
  138. <div class="advanced-max-big-box" v-if="searchState">
  139. <div class="left-advanced-box"></div>
  140. <div class="center-advanced-box">
  141. <p class="inquire-button-one" @click="buttonClick(1)">查询</p>
  142. <p class="reset-button-one" @click="buttonClick(2)">重置</p>
  143. </div>
  144. <div class="right-advanced-box">
  145. <span class="ordinary-button" @click="stateSwitch">普通搜索</span>
  146. </div>
  147. <div v-for="item in searchData.buttonList">
  148. <p v-if="item.type == 1" class="inquire-button-one"
  149. v-hasPermi="item.hasPermi" style="width:120px;float: right;" @click="buttonClick(item.parameter)">{{item.name}}</p>
  150. <div style="float: right;" v-if="item.type == 2">
  151. <el-dropdown @command="commandButton" v-hasPermi="item.hasPermi">
  152. <div class="form-dropdown-box">
  153. <img src="@/assets/ZDimages/personnelManagement/icon_jzgxx_dr.png">
  154. <p>导入</p>
  155. <img src="@/assets/ZDimages/personnelManagement/icon_jzggl_xljt.png">
  156. </div>
  157. <el-dropdown-menu slot="dropdown">
  158. <el-dropdown-item style="border-bottom:1px solid #E0E0E0;margin:0 10px;color:#333;" :command="{item:item,command:1}">下载模板</el-dropdown-item>
  159. <el-dropdown-item style="margin:0 10px;color:#666;" :command="{item:item,command:2}">导入数据</el-dropdown-item>
  160. </el-dropdown-menu>
  161. </el-dropdown>
  162. </div>
  163. <div style="float: right; " v-if="item.type == 3">
  164. <el-dropdown @command="commandButton" v-hasPermi="item.hasPermi">
  165. <div class="form-dropdown-box">
  166. <img src="@/assets/ZDimages/personnelManagement/icon_jzgxx_sc.png">
  167. <p>导出</p>
  168. <img src="@/assets/ZDimages/personnelManagement/icon_jzggl_xljt.png">
  169. </div>
  170. <el-dropdown-menu slot="dropdown">
  171. <el-dropdown-item style="border-bottom:1px solid #E0E0E0;margin:0 10px;color:#333;" :command="{item:item,command:1}">导出全部数据</el-dropdown-item>
  172. <el-dropdown-item style="margin:0 10px;color:#666;" :command="{item:item,command:2}">导出选中数据</el-dropdown-item>
  173. </el-dropdown-menu>
  174. </el-dropdown>
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. </template>
  180. <script>
  181. export default {
  182. name: "advancedSearch",
  183. props:{
  184. searchData:{}
  185. },
  186. data() {
  187. return {
  188. searchState:false,
  189. }
  190. },
  191. created() {
  192. },
  193. mounted(){
  194. },
  195. methods: {
  196. //普通/高级状态切换
  197. stateSwitch(){
  198. this.searchState = !this.searchState;
  199. },
  200. //导出/导入按钮
  201. commandButton(data){
  202. this.$parent.searchClick(data.item.parameter,data.command);
  203. },
  204. //按钮方法
  205. buttonClick(type){
  206. let self = this;
  207. if(type == '1'){
  208. //查找
  209. let obj = {};
  210. for(let i=0;i<self.searchData.searchList.length;i++){
  211. if(self.searchState){
  212. //高级搜索
  213. obj[self.searchData.searchList[i].key] = self.searchData.searchList[i].value;
  214. }else{
  215. //普通搜索
  216. if(self.searchData.searchList[i].level == '1'){
  217. obj[self.searchData.searchList[i].key] = self.searchData.searchList[i].value;
  218. }
  219. }
  220. }
  221. self.$parent.searchClick(type,obj);
  222. }else if(type == '2'){
  223. //返回
  224. for(let i=0;i<self.searchData.searchList.length;i++){
  225. self.searchData.searchList[i].value = '';
  226. }
  227. self.$parent.searchClick(type);
  228. }else{
  229. self.$parent.searchClick(type);
  230. }
  231. },
  232. }
  233. }
  234. </script>
  235. <style lang="scss" scoped>
  236. .advancedSearchMaxBigBox{
  237. margin:0 20px;
  238. .advanced-button{
  239. margin:0 20px;
  240. cursor: pointer;
  241. line-height:40px;
  242. font-weight:500;
  243. font-size:14px;
  244. color:#0183FA;
  245. }
  246. .advanced-max-big-box{
  247. display: flex;
  248. padding-bottom:20px;
  249. padding-right:10px;
  250. font-size:14px;
  251. .left-advanced-box{
  252. flex:1;
  253. }
  254. .center-advanced-box{
  255. }
  256. .right-advanced-box{
  257. flex:1;
  258. .ordinary-button{
  259. margin:0 20px;
  260. cursor: pointer;
  261. line-height:40px;
  262. font-weight:500;
  263. font-size:14px;
  264. color:#0183FA;
  265. }
  266. }
  267. }
  268. .form-dropdown-box{
  269. display: flex;
  270. margin:0;
  271. padding:0 10px;
  272. cursor: pointer;
  273. height:40px;
  274. img:nth-child(1){
  275. width:16px;
  276. height:16px;
  277. margin-top:12px;
  278. }
  279. p{
  280. width:47px;
  281. text-align: center;
  282. font-size:14px;
  283. margin:0;
  284. line-height:40px;
  285. }
  286. img:nth-child(3){
  287. width:10px;
  288. height:6px;
  289. margin-top:17px;
  290. }
  291. }
  292. }
  293. </style>
  294. <style lang="scss">
  295. .advancedSearchMaxBigBox{
  296. .el-range-editor--medium.el-input__inner{
  297. height:40px;
  298. }
  299. }
  300. </style>