SearchAutoCompleteWidget.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <div
  3. v-show="isShowAuto"
  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. var Common = require('../../common/Common.js').default;
  46. export default {
  47. props: {
  48. 'infoWindowNo':{
  49. type: String,
  50. default: null,
  51. },
  52. 'leftPosition':{
  53. type: Number,
  54. default: null,
  55. },
  56. 'whereClause':{
  57. type: String,
  58. default: null,
  59. },
  60. 'parentModelData': {
  61. type: Object,
  62. default: null,
  63. },
  64. 'modelData': {
  65. type: Object,
  66. default: null,
  67. },
  68. },
  69. emits: ['selectData'],
  70. data: function () {
  71. return {
  72. infoWindowDto: {},
  73. infoWindowData: {},
  74. isShowAuto: false,
  75. selectIndex: -1,
  76. realLeft: {},
  77. isSearchWidget: true,
  78. };
  79. },
  80. computed: {
  81. realLeftComputed: function () {
  82. return (((this.realLeft > 0) ? this.realLeft : 0) + 'px');
  83. },
  84. },
  85. watch: {
  86. infoWindowData: function (val) {
  87. var _self = this;
  88. if (val.dataList != undefined && val.dataList.length > 0) {
  89. _self.isShowAuto = true;
  90. } else {
  91. _self.isShowAuto = false;
  92. }
  93. },
  94. /**
  95. * 距离左侧的距离
  96. * @param {[type]} currentValue [description]
  97. * @param {[type]} oldValue [description]
  98. * @return {[type]} [description]
  99. */
  100. leftPosition: function (currentValue, oldValue) {
  101. var _self = this;
  102. console.log('initialLeft changed: ' + currentValue);
  103. _self.realLeft = currentValue;
  104. console.log('realLeft2:' + _self.realLeft);
  105. },
  106. },
  107. mounted: function () {
  108. },
  109. methods: {
  110. /**
  111. * 向下
  112. * @return {void}
  113. */
  114. selectDown: function () {
  115. var _self = this;
  116. var length = _self.infoWindowData.dataList.length;
  117. if (_self.selectIndex < (length - 1)) {
  118. _self.selectIndex++;
  119. }
  120. },
  121. /**
  122. * 向上
  123. * @return {void}
  124. */
  125. selectUp: function () {
  126. var _self = this;
  127. var length = _self.infoWindowData.dataList.length;
  128. if (_self.selectIndex > 0) {
  129. _self.selectIndex--;
  130. }
  131. },
  132. /**
  133. * 获取当前数据 供外部调用
  134. * @return {Object} ModelData
  135. */
  136. getSelectData: function () {
  137. var _self = this;
  138. if (_self.selectIndex < 0) {
  139. return undefined;
  140. }
  141. var data = _self.infoWindowData.dataList[_self.selectIndex];
  142. return data;
  143. },
  144. /**
  145. * 获取第一行数据
  146. */
  147. getFirstData: function () {
  148. var _self = this;
  149. if (_self.infoWindowData != null && _self.infoWindowData.dataList != null && _self.infoWindowData.dataList.length > 0) {
  150. return _self.infoWindowData.dataList[0];
  151. }
  152. return null;
  153. },
  154. /**
  155. * 隐藏
  156. * @return {[type]} [description]
  157. */
  158. hide: function () {
  159. var _self = this;
  160. _self.isShowAuto = false;
  161. },
  162. /**
  163. * 是否可见
  164. * @return {Boolean} [description]
  165. */
  166. isVisible: function () {
  167. return this.isShowAuto;
  168. },
  169. /**
  170. * 查询InfoWindowDto
  171. * @return {void}
  172. */
  173. getInfoWindowDto: function (resolve, reject) {
  174. var _self = this;
  175. $.ajax({
  176. url: Common.getApiURL('InfoWindowResource/uniqueByNo'),
  177. type: 'GET',
  178. dataType: 'json',
  179. data: { 'infoWindowNo': _self.infoWindowNo },
  180. beforeSend: function (request) {
  181. Common.addTokenToRequest(request);
  182. },
  183. success: function (data) {
  184. _self.infoWindowDto = data;
  185. resolve();
  186. },
  187. error: function (XMLHttpRequest, textStatus, errorThrown) {
  188. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  189. reject();
  190. },
  191. });
  192. },
  193. /**
  194. * 生成查询条件
  195. * @param {String} text 查询条件
  196. * @return {Array}
  197. */
  198. getSimpleQueryCondition: function (text) {
  199. var _self = this;
  200. var values = [];
  201. if (_self.infoWindowDto.infoFilterFields != undefined) {
  202. _self.infoWindowDto.infoFilterFields.forEach(function (item) {
  203. if (item.displayType == 'TextEditor') {
  204. var value = {
  205. fieldName: item.fieldName,
  206. value1: text,
  207. };
  208. values.push(value);
  209. }
  210. });
  211. }
  212. return values;
  213. },
  214. /**
  215. * 根据条件初始化查询
  216. * @param {String} text 查询条件
  217. * @return {void}
  218. */
  219. initSearch: function (text) {
  220. var _self = this;
  221. if (text != undefined) {
  222. if (_self.infoWindowDto == undefined || _self.infoWindowDto.infoGridFields == undefined) {
  223. new Promise(_self.getInfoWindowDto).then(function (value) {
  224. // success
  225. _self.getInfoWindowData(text);
  226. }, function (error) {
  227. // error
  228. });
  229. } else {
  230. _self.getInfoWindowData(text);
  231. }
  232. } else {
  233. _self.isShowAuto = false;
  234. }
  235. },
  236. /**
  237. * 选择节点
  238. * @return {void}
  239. */
  240. selectNode: function (data) {
  241. this.$emit('selectData', data);
  242. },
  243. /**
  244. * 查询infoWindowData
  245. * @return {void}
  246. */
  247. getInfoWindowData: function (text) {
  248. var _self = this;
  249. var infoFilterFieldValues = _self.getSimpleQueryCondition(text);
  250. var infoQueryParam = {
  251. infoWindowNo: _self.infoWindowNo,
  252. start: 0,
  253. length: 10,
  254. sortClause: '',
  255. infoFilterFieldValues: infoFilterFieldValues,
  256. whereClause: _self.whereClause,
  257. modelData: _self.modelData,
  258. parentModelData: _self.parentModelData,
  259. isSearchWidget: _self.isSearchWidget,
  260. };
  261. $.ajax({
  262. url: Common.getApiURL('InfoWindowResource/queryInfoWindowDataSimple'),
  263. type: 'post',
  264. dataType: 'json',
  265. beforeSend: function (request) {
  266. Common.addTokenToRequest(request);
  267. },
  268. contentType: 'application/json',
  269. data: JSON.stringify(infoQueryParam),
  270. success: function (data) {
  271. _self.infoWindowData = data;
  272. _self.selectIndex = -1;
  273. },
  274. error: function (XMLHttpRequest, textStatus, errorThrown) {
  275. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  276. },
  277. });
  278. },
  279. },
  280. };
  281. </script>
  282. <style scoped>
  283. .div-autoComplete {
  284. position: absolute;
  285. z-index: 999;
  286. background-color: #fff;
  287. border: 1px #e5e5e5 solid;
  288. padding: 15px 15px 0px 15px;
  289. box-shadow: 0 0 5px rgba(81, 203, 238, 1);
  290. /*width: 300px;*/
  291. /*height: 300px;*/
  292. /*max-height: 400px;*/
  293. max-width: 800px;
  294. min-width: 400px;
  295. /*overflow: auto;*/
  296. top: 32px;
  297. }
  298. .no-padding-left {
  299. padding-left: 0px !important;
  300. }
  301. .select-tr {
  302. background-color: #eee;
  303. }
  304. </style>