SearchAutoCompleteWidget.vue 7.5 KB

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