SearchAutoCompleteWidget.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <div
  3. v-if="show"
  4. class="div-autoComplete"
  5. :style="{ left: realLeftComputed }"
  6. >
  7. <div class="table-responsive">
  8. <table class="table table-bordered table-hover">
  9. <thead>
  10. <tr>
  11. <td
  12. v-for="item in infoWindowDto.infoGridFields"
  13. :key="'td-info-grid-field-' + item.fieldName"
  14. align="center"
  15. width="100px"
  16. height="40px"
  17. >
  18. {{ item.name }}
  19. </td>
  20. </tr>
  21. </thead>
  22. <tbody>
  23. <tr
  24. v-for="(item1, index) in infoWindowData.dataList"
  25. :key="'tr-' + item1.id"
  26. height="40px"
  27. :class="{'select-tr': index == selectIndex}"
  28. @click="selectNode(item1)"
  29. >
  30. <td
  31. v-for="item2 in infoWindowDto.infoGridFields"
  32. :key="'tr-' + item1.id + '-td-' + item2.fieldName"
  33. align="center"
  34. >
  35. {{ (item1.data[item2.fieldName] == undefined) ? "" : item1.data[item2.fieldName].displayValue[0] }}
  36. </td>
  37. </tr>
  38. </tbody>
  39. </table>
  40. </div>
  41. <div class="clearfix" />
  42. </div>
  43. </template>
  44. <script>
  45. import Common from '../../common/Common.js';
  46. export default {
  47. name: 'SearchAutoCompleteWidget',
  48. props: {
  49. /**
  50. * 是否显示自动提示列表
  51. */
  52. 'show':{
  53. type: Boolean,
  54. default: false,
  55. },
  56. 'infoWindowNo':{
  57. type: String,
  58. default: null,
  59. },
  60. 'leftPosition':{
  61. type: Number,
  62. default: null,
  63. },
  64. 'whereClauseSource':{
  65. type: Object,
  66. default: null,
  67. },
  68. 'parentModelData': {
  69. type: Object,
  70. default: null,
  71. },
  72. 'modelData': {
  73. type: Object,
  74. default: null,
  75. },
  76. },
  77. emits: ['selectData', 'update:show'],
  78. data: function () {
  79. return {
  80. infoWindowDto: {},
  81. infoWindowData: {},
  82. selectIndex: -1,
  83. realLeft: {},
  84. isSearchWidget: true,
  85. };
  86. },
  87. computed: {
  88. realLeftComputed: function () {
  89. return (((this.realLeft > 0) ? this.realLeft : 0) + 'px');
  90. },
  91. },
  92. watch: {
  93. infoWindowData: function (val) {
  94. var _self = this;
  95. if (val.dataList != undefined && val.dataList.length > 0) {
  96. _self.$emit('update:show', true);
  97. } else {
  98. _self.$emit('update:show', false);
  99. }
  100. },
  101. /**
  102. * 距离左侧的距离
  103. * @param {[type]} currentValue [description]
  104. * @param {[type]} oldValue [description]
  105. * @return {[type]} [description]
  106. */
  107. leftPosition: function (currentValue, oldValue) {
  108. var _self = this;
  109. console.log('initialLeft changed: ' + currentValue);
  110. _self.realLeft = currentValue;
  111. console.log('realLeft2:' + _self.realLeft);
  112. },
  113. },
  114. mounted: function () {
  115. },
  116. methods: {
  117. /**
  118. * 向下
  119. * @return {void}
  120. */
  121. selectDown: function () {
  122. var _self = this;
  123. var length = _self.infoWindowData.dataList.length;
  124. if (_self.selectIndex < (length - 1)) {
  125. _self.selectIndex++;
  126. }
  127. },
  128. /**
  129. * 向上
  130. * @return {void}
  131. */
  132. selectUp: function () {
  133. var _self = this;
  134. var length = _self.infoWindowData.dataList.length;
  135. if (_self.selectIndex > 0) {
  136. _self.selectIndex--;
  137. }
  138. },
  139. /**
  140. * 获取当前数据 供外部调用
  141. * @return {Object} ModelData
  142. */
  143. getSelectData: function () {
  144. var _self = this;
  145. if (_self.selectIndex < 0) {
  146. return undefined;
  147. }
  148. var data = _self.infoWindowData.dataList[_self.selectIndex];
  149. return data;
  150. },
  151. /**
  152. * 获取第一行数据
  153. */
  154. getFirstData: function () {
  155. var _self = this;
  156. if (_self.infoWindowData != null && _self.infoWindowData.dataList != null && _self.infoWindowData.dataList.length > 0) {
  157. return _self.infoWindowData.dataList[0];
  158. }
  159. return null;
  160. },
  161. /**
  162. * 查询InfoWindowDto
  163. * @return {void}
  164. */
  165. getInfoWindowDto: function (resolve, reject) {
  166. var _self = this;
  167. $.ajax({
  168. url: Common.getApiURL('InfoWindowResource/uniqueByNo'),
  169. type: 'GET',
  170. dataType: 'json',
  171. data: { 'infoWindowNo': _self.infoWindowNo },
  172. beforeSend: function (request) {
  173. Common.addTokenToRequest(request);
  174. },
  175. success: function (data) {
  176. _self.infoWindowDto = data;
  177. resolve();
  178. },
  179. error: function (XMLHttpRequest, textStatus, errorThrown) {
  180. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  181. reject();
  182. },
  183. });
  184. },
  185. /**
  186. * 根据条件初始化查询
  187. * @param {String} text 查询条件
  188. * @return {void}
  189. */
  190. initSearch: function (text) {
  191. var _self = this;
  192. if (text != undefined) {
  193. if (_self.infoWindowDto == undefined || _self.infoWindowDto.infoGridFields == undefined) {
  194. new Promise(_self.getInfoWindowDto).then(function (value) {
  195. // success
  196. _self.getInfoWindowData(text);
  197. }, function (error) {
  198. // error
  199. });
  200. } else {
  201. _self.getInfoWindowData(text);
  202. }
  203. } else {
  204. _self.$emit('update:show', false);
  205. }
  206. },
  207. /**
  208. * 选择节点
  209. * @return {void}
  210. */
  211. selectNode: function (data) {
  212. this.$emit('selectData', data);
  213. },
  214. /**
  215. * 查询infoWindowData
  216. * @return {void}
  217. */
  218. getInfoWindowData: function (text) {
  219. var _self = this;
  220. var infoQueryParam = {
  221. infoWindowNo: _self.infoWindowNo,
  222. start: 0,
  223. length: 10,
  224. sortClause: '',
  225. infoFilterFieldValues: text,
  226. whereClauseSource: _self.whereClauseSource,
  227. modelData: _self.modelData,
  228. parentModelData: _self.parentModelData,
  229. isSearchWidget: _self.isSearchWidget,
  230. };
  231. $.ajax({
  232. url: Common.getApiURL('InfoWindowResource/queryInfoWindowDataSimple'),
  233. type: 'post',
  234. dataType: 'json',
  235. beforeSend: function (request) {
  236. Common.addTokenToRequest(request);
  237. },
  238. contentType: 'application/json',
  239. data: JSON.stringify(infoQueryParam),
  240. success: function (data) {
  241. _self.infoWindowData = data;
  242. _self.selectIndex = -1;
  243. },
  244. error: function (XMLHttpRequest, textStatus, errorThrown) {
  245. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  246. },
  247. });
  248. },
  249. },
  250. };
  251. </script>
  252. <style scoped>
  253. .div-autoComplete {
  254. position: absolute;
  255. z-index: 999;
  256. background-color: #fff;
  257. border: 1px #e5e5e5 solid;
  258. padding: 15px 15px 0px 15px;
  259. box-shadow: 0 0 5px rgba(81, 203, 238, 1);
  260. /*width: 300px;*/
  261. /*height: 300px;*/
  262. /*max-height: 400px;*/
  263. max-width: 800px;
  264. min-width: 400px;
  265. /*overflow: auto;*/
  266. top: 32px;
  267. }
  268. .no-padding-left {
  269. padding-left: 0px !important;
  270. }
  271. .select-tr {
  272. background-color: #eee;
  273. }
  274. </style>