orderSearch.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <view class="page">
  3. <u-sticky zIndex="999" customNavHeight="0">
  4. <view class="header dis a-c j-s">
  5. <u-icon name="arrow-left" color="#333" size="18" :bold="true" style="margin-right: 20rpx;"
  6. @click="back"></u-icon>
  7. <u-search placeholder="搜索" v-model="pageRequest[fieldName]" bgColor="#f7f7f7"
  8. :style="{ '--arrow-margin': arrowMargin }" class="search-wrapper"
  9. :actionStyle="{position: 'absolute',right:'20px',background:'#FDE935',padding:'8rpx 24rpx',boxSiting:'border-box',borderRadius:'100rpx'}"
  10. :actionText="搜索" search-icon="arrow-down" searchIconColor="#333" :searchIconSize="11"
  11. @search="search" @custom="search" @clear="clear">
  12. <template #label>
  13. <uni-cloudPopup :text="cloudPopupName" color="#666" size="14" :buttons="cloudPopupList"
  14. direction="bottom" @click="cloudPopupChange"></uni-cloudPopup>
  15. </template>
  16. </u-search>
  17. </view>
  18. </u-sticky>
  19. <!-- 搜索历史记录 -->
  20. <view class="historyRecords ">
  21. <view class=" dis a-c j-s ">
  22. <text class="title">历史搜索</text>
  23. <u-icon name="trash" color="#666" size="20" @click="clearHistory"></u-icon>
  24. </view>
  25. <view class="content dis a-c f-wrap ">
  26. <view class="item" v-for="(item,index) in historySearchList" :key="index" @click="change(item)">
  27. {{item.content}}
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. cloudPopupName: "车牌号", //搜索字段name
  38. fieldName: "licenseNo", //搜索字段
  39. cloudPopupNameHeight: 0,
  40. arrowMargin: '0', // 默认值
  41. pageRequest: {}, //查询的默认条件
  42. // 搜索字段
  43. cloudPopupList: [
  44. "车牌号",
  45. "投保人姓名",
  46. "投保人手机号",
  47. "被保人姓名",
  48. "被保人手机号",
  49. ],
  50. cloudPopupList1: [{
  51. label: "车牌号",
  52. value: 'licenseNo',
  53. },
  54. {
  55. label: "投保人姓名",
  56. value: 'policyholder',
  57. },
  58. {
  59. label: "投保人手机号",
  60. value: 'policyholderMobile',
  61. }, {
  62. label: "被保人姓名",
  63. value: 'insured',
  64. },
  65. {
  66. label: "被保人手机号",
  67. value: 'insuredMobile',
  68. }
  69. ],
  70. // 历史搜索
  71. historySearchList: []
  72. }
  73. },
  74. onShow() {
  75. },
  76. async onLoad(options) {
  77. if (options.search) {
  78. let info = JSON.parse(options.search);
  79. this.cloudPopupName = info.cloudPopupName || '车牌号';
  80. this.fieldName = info.fieldName || 'licenseNo';
  81. this.pageRequest = info;
  82. }
  83. await this.getHistorySearch(); //查询历史搜索
  84. },
  85. async mounted() {
  86. // 获取左侧下拉组件宽度
  87. const query = uni.createSelectorQuery();
  88. query.select('.u-tooltip').boundingClientRect((rect) => {
  89. this.arrowMargin = `${rect.width+5}px`;
  90. }).exec();
  91. },
  92. methods: {
  93. // 查询搜索记录
  94. async getHistorySearch() {
  95. let res = await this.$http.get(`/order/searchHistory/getHistory`);
  96. if (res.code == 200) {
  97. this.historySearchList = res.data;
  98. }
  99. },
  100. back() {
  101. uni.navigateBack(-1)
  102. },
  103. // 切换搜索字段
  104. cloudPopupChange(value) {
  105. this.cloudPopupName = value;
  106. this.$nextTick(() => { //切换字段获取动态宽度
  107. const query = uni.createSelectorQuery();
  108. query.select('.u-tooltip').boundingClientRect((rect) => {
  109. this.arrowMargin = `${rect.width+5}px`;
  110. }).exec();
  111. })
  112. switch (value) {
  113. case '车牌号':
  114. this.fieldName = "licenseNo";
  115. break;
  116. case '投保人姓名':
  117. this.fieldName = "policyholder";
  118. break;
  119. case '投保人手机号':
  120. this.fieldName = "policyholderMobile";
  121. break;
  122. case '被保人姓名':
  123. this.fieldName = "insured"
  124. break;
  125. case '被保人手机号':
  126. this.fieldName = "insuredMobile";
  127. break;
  128. }
  129. },
  130. async search(value) {
  131. if (value) {
  132. let res = await this.$http.get(
  133. `/order/searchHistory/saveHistory?groupType=${this.fieldName}&content=${value}`);
  134. }
  135. this.getHistorySearch();
  136. let pages = getCurrentPages(); //获取所有页面栈实例列表
  137. let prevPage = pages[pages.length - 2]; //上一页页面实例
  138. prevPage.$vm.cloudPopupName = this.cloudPopupName; //搜索字段
  139. prevPage.$vm.fieldName = this.fieldName; //搜索字段Field
  140. prevPage.$vm.pageRequest[this.fieldName] = value; //订单列表检索条件赋值
  141. prevPage.$vm.SearchText = value; //搜索框回显
  142. uni.navigateBack({ //uni.navigateTo跳转的返回,默认1为返回上一级
  143. delta: 1
  144. });
  145. },
  146. // 清空搜索框输入值
  147. clear() {
  148. for (let key in this.pageRequest) {
  149. if (key != 'pages' && key != 'size') {
  150. this.pageRequest[key] = "";
  151. }
  152. }
  153. },
  154. //清空历史搜索
  155. async clearHistory() {
  156. let res = await this.$http.get(`/order/searchHistory/clearAllHistory`);
  157. if (res.code == 200) {
  158. this.getHistorySearch();
  159. uni.showToast({
  160. icon: "none",
  161. title: "已清空"
  162. })
  163. }
  164. },
  165. async change(item) {
  166. let res = await this.$http.get(
  167. `/order/searchHistory/saveHistory?groupType=${item.groupType}&content=${item.content}`);
  168. this.getHistorySearch();
  169. let pages = getCurrentPages(); //获取所有页面栈实例列表
  170. let prevPage = pages[pages.length - 2]; //上一页页面实例
  171. prevPage.$vm.cloudPopupName = this.cloudPopupList1.find(val => val.value == item.groupType)
  172. .label; //搜索字段
  173. prevPage.$vm.fieldName = item.groupType; //搜索字段Field
  174. prevPage.$vm.pageRequest[item.groupType] = item.content; //订单列表检索条件赋值
  175. prevPage.$vm.SearchText = item.content; //搜索框回显
  176. uni.navigateBack({ //uni.navigateTo跳转的返回,默认1为返回上一级
  177. delta: 1
  178. });
  179. },
  180. }
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. ::v-deep {
  185. .u-search__content {
  186. padding-right: 150rpx !important;
  187. }
  188. .u-tooltip {
  189. position: absolute;
  190. .u-tooltip__wrapper__popup {
  191. top: 20rpx;
  192. }
  193. }
  194. }
  195. .search-wrapper ::v-deep .uicon-arrow-down {
  196. margin-left: var(--arrow-margin) !important;
  197. font-weight: bold !important;
  198. }
  199. .page {
  200. background-color: #f8f8f8;
  201. height: 100vh;
  202. }
  203. .header {
  204. padding: 116rpx 30rpx 16rpx;
  205. box-sizing: border-box;
  206. background-color: #FFFFFF;
  207. width: 100%;
  208. border-bottom: 1rpx solid #eee;
  209. .fieldLabel {
  210. font-size: 28rpx;
  211. color: #333;
  212. margin-right: 10rpx;
  213. }
  214. }
  215. .historyRecords {
  216. background-color: #FFFFFF;
  217. height: calc(100vh - 200rpx);
  218. width: 100%;
  219. padding: 30rpx;
  220. box-sizing: border-box;
  221. .title {
  222. font-size: 30rpx;
  223. color: #333;
  224. font-weight: bold;
  225. }
  226. .content {
  227. margin-top: 20rpx;
  228. gap: 20rpx;
  229. .item {
  230. padding: 10rpx 16rpx;
  231. box-sizing: border-box;
  232. background: #F8F8F8;
  233. border-radius: 4rpx 4rpx 4rpx 4rpx;
  234. font-size: 26rpx;
  235. color: #666;
  236. }
  237. }
  238. }
  239. </style>