SimpleFilterPanel.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <div :key="'simple-filter-panel-' + windowNo + '-tabIndex-' + tabIndex">
  3. <div>
  4. <div class="input-group">
  5. <div class="input-group-addon m-input-group-addon" @click="clearSearchCondition">
  6. <span
  7. class="fa fa-list-ul"
  8. :class="{ 'red-icon': (searchText != null && searchText.length > 0)}"
  9. />
  10. </div>
  11. <input
  12. id="simple-filter-panel-input"
  13. autocomplete="off"
  14. :value="searchText"
  15. type="text"
  16. class="form-control"
  17. :placeholder="$t('lang.simpleFilterPanel.inputCondition')"
  18. :readonly="disabled == true"
  19. @input="$emit('update:searchText', $event.target.value)"
  20. @keydown.enter="commonSearchOk"
  21. @focus="showHistoryQueryCondition=true"
  22. />
  23. <div
  24. class="input-group-addon m-input-group-addon1"
  25. @click="$emit('showComplexFilterPanel')"
  26. >
  27. <span class="glyphicon glyphicon-list-alt" />
  28. </div>
  29. <div
  30. class="input-group-addon m-input-group-addon"
  31. @click="commonSearchOk"
  32. >
  33. <span class="glyphicon glyphicon-search" />
  34. </div>
  35. </div>
  36. <div style="position:relative">
  37. <ul
  38. v-if="showHistoryQueryCondition && conditions.length > 0 && (disabled == null || disabled == false)"
  39. v-click-outside="onClickOutside"
  40. class="select-history"
  41. >
  42. <li
  43. v-for="item in conditions"
  44. :key="'history-query-condition-' + item.id"
  45. @click="selectCommonHistoryQueryCondition(item)"
  46. >
  47. <span>{{ item.condition }}</span>
  48. <i
  49. class="fa fa-times"
  50. @click="deleteHistoryQueryById($event, item.id)"
  51. />
  52. </li>
  53. <li
  54. v-if="conditions.length>0"
  55. class="btn-clear-records"
  56. >
  57. <a
  58. type="button"
  59. @click="deleteHistoryQuery()"
  60. >
  61. {{ $t('lang.simpleFilterPanel.clearHistoryRecord') }}
  62. </a>
  63. </li>
  64. </ul>
  65. </div>
  66. </div>
  67. </div>
  68. </template>
  69. <script>
  70. import Common from '../../common/Common.js';
  71. import HistoryQueryResource from '../../api/system/HistoryQueryResource.js';
  72. import vClickOutside from 'click-outside-vue3';
  73. import { Notify, Uuid } from 'pc-component-v3';
  74. export default {
  75. directives: {
  76. clickOutside: vClickOutside.directive,
  77. },
  78. components: {
  79. },
  80. props: {
  81. /**
  82. * CURD窗口编号
  83. */
  84. windowNo: {
  85. type: String,
  86. default: null,
  87. },
  88. /**
  89. * 页签顺序号
  90. */
  91. tabIndex: {
  92. type: Number,
  93. default: null,
  94. },
  95. /**
  96. * 过滤方案
  97. */
  98. filterSchema: {
  99. type: Object,
  100. default: null,
  101. },
  102. /**
  103. * 简单过滤方案只读
  104. */
  105. disabled: {
  106. type: Boolean,
  107. default: false,
  108. },
  109. /**
  110. * 搜索的文本
  111. */
  112. searchText: {
  113. type: String,
  114. default: '',
  115. },
  116. },
  117. emits: ['simpleSearch', 'showComplexFilterPanel', 'update:searchText'],
  118. data: function () {
  119. return {
  120. showHistoryQueryCondition: false,
  121. conditions: [],
  122. simpleFilterHistoryQueryNumber: 10, //简单查询显示记录数
  123. };
  124. },
  125. watch: {
  126. /**
  127. * 切换窗口(页签Id发生改变)的时候重新加载数据
  128. */
  129. showHistoryQueryCondition: {
  130. handler: function (newValue, oldValue) {
  131. if(newValue === true){
  132. this.getHistoryQueries();
  133. }
  134. },
  135. },
  136. },
  137. methods: {
  138. /**
  139. * 简单查询
  140. */
  141. commonSearchOk: function () {
  142. var _self = this;
  143. if (this.disabled === true) {
  144. return;
  145. }
  146. if (this.filterSchema == undefined || this.filterSchema.filterSchemaSimpleLines == undefined) {
  147. Notify.error('错误:未定义过滤方案', '请联系系统管理员定义过滤方案', false);
  148. return;
  149. }
  150. var historyQuery = {
  151. type: 'SimpleFilter',
  152. condition: _self.searchText,
  153. queryName: '',
  154. windowNo: _self.windowNo,
  155. tabIndex: _self.tabIndex,
  156. };
  157. HistoryQueryResource.save(historyQuery).then(successData => {
  158. _self.getHistoryQueries();
  159. }, errorData => {
  160. Common.processException(errorData);
  161. });
  162. this.showHistoryQueryCondition = false;
  163. this.$emit('simpleSearch');
  164. },
  165. /**
  166. * 选择了历史查询条件
  167. */
  168. selectCommonHistoryQueryCondition: function (item) {
  169. this.$emit('update:searchText', item.condition);
  170. this.showHistoryQueryCondition = false;
  171. this.commonSearchOk();
  172. },
  173. /**
  174. * 清空搜索条件
  175. */
  176. clearSearchCondition: function () {
  177. this.showHistoryQueryCondition = false;
  178. this.$emit('update:searchText', '');
  179. this.$emit('simpleSearch');
  180. },
  181. /**
  182. * 获取查询历史条件
  183. */
  184. getHistoryQueries: function () {
  185. var _self = this;
  186. _self.conditions = [];
  187. if(_self.windowNo == null
  188. || _self.windowNo === ''
  189. || _self.tabIndex == null
  190. || _self.tabIndex === ''){
  191. return;
  192. }
  193. HistoryQueryResource.listByCondition('SimpleFilter', _self.simpleFilterHistoryQueryNumber, _self.windowNo, _self.tabIndex).then(successData => {
  194. _self.conditions = successData;
  195. }, errorData => {
  196. Common.processException(errorData);
  197. });
  198. },
  199. /**
  200. * 删除查询历史条件
  201. */
  202. deleteHistoryQuery: function () {
  203. var _self = this;
  204. HistoryQueryResource.deleteByType('SimpleFilter', _self.windowNo, _self.tabIndex).then(successData => {
  205. _self.getHistoryQueries();
  206. _self.showHistoryQueryCondition = false;
  207. _self.$emit('update:searchText', '');
  208. }, errorData => {
  209. Common.processException(errorData);
  210. });
  211. },
  212. /**
  213. * 根据id删除查询历史条件
  214. */
  215. deleteHistoryQueryById: function (event, id) {
  216. event.stopPropagation();
  217. var _self = this;
  218. HistoryQueryResource.deleteById('SimpleFilter', id).then(successData => {
  219. _self.getHistoryQueries();
  220. _self.showHistoryQueryCondition = false;
  221. }, errorData => {
  222. Common.processException(errorData);
  223. });
  224. },
  225. /**
  226. * 当点击'历史查询条件列表'以外的DOM,隐藏'历史查询条件列表'
  227. */
  228. onClickOutside: function(e){
  229. if(e.srcElement != null && e.srcElement.id == 'simple-filter-panel-input'){
  230. return;
  231. }
  232. this.showHistoryQueryCondition = false;
  233. },
  234. },
  235. };
  236. </script>
  237. <style scoped>
  238. .m-input-group-addon {
  239. cursor: pointer;
  240. }
  241. .m-input-group-addon1 {
  242. cursor: pointer;
  243. border-left: none;
  244. }
  245. .red-icon {
  246. color: red;
  247. }
  248. .select-history {
  249. background: #fff;
  250. border: 1px solid #ccc;
  251. width: calc(100% - 118px);
  252. height: 150px;
  253. overflow-x: hidden;
  254. margin-left: 40px;
  255. position: absolute;
  256. list-style: none;
  257. z-index: 999;
  258. text-align: left;
  259. font-size: 14px;
  260. border-radius: 4px;
  261. box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
  262. cursor: pointer;
  263. padding-left: 0px;
  264. z-index: 1002;
  265. }
  266. .select-history > li {
  267. display: block;
  268. padding: 3px 5px 3px 10px;
  269. clear: both;
  270. font-weight: 400;
  271. line-height: 1.42857143;
  272. color: #333;
  273. white-space: nowrap;
  274. height: 25px;
  275. }
  276. .select-history > li > span {
  277. float: left;
  278. }
  279. .select-history > li > i {
  280. float: right;
  281. }
  282. .select-history > li:hover {
  283. color: #262626;
  284. text-decoration: none;
  285. background-color: #f5f5f5;
  286. }
  287. .fa-times {
  288. float: right;
  289. margin-right: 15px;
  290. }
  291. .f:hover {
  292. height: 120%;
  293. width: 120%;
  294. }
  295. .delete {
  296. font-size: 800px;
  297. color: blue;
  298. float: right;
  299. }
  300. #deleteHistory {
  301. color: blue;
  302. }
  303. .btn-clear-records {
  304. cursor: pointer;
  305. }
  306. </style>