index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="search-page white-wrap">
  3. <van-sticky>
  4. <view class="white-wrap" style="padding: 20rpx 34rpx 10rpx 34rpx;">
  5. <van-search use-left-icon-slot use-action-slot shape="round" focus :placeholder="placeholder" @change="onChange"
  6. @search="onSearch" custom-class="search-box" field-class="search-con">
  7. <view slot="left-icon">
  8. <image src="../static/search-icon.png" mode="aspectFill" class="search-icon"></image>
  9. </view>
  10. <view slot="action" @click="onSearch" class="search-btn">搜索</view>
  11. </van-search>
  12. </view>
  13. </van-sticky>
  14. <van-empty description="未找到搜索结果" :image="require('@/static/empty.png')" v-if="empty" />
  15. <view class="search-result" v-else>
  16. <view class="result-item flex" v-for="item in list" :key="item" @click="handleGoDetail(item)">
  17. <image src="../static/search-icon.png" mode="aspectFill" class="search-icon"></image>
  18. <view class="con van-ellipsis">{{item}}</view>
  19. <image src="../static/click-icon.png" mode="aspectFill" class="click-icon"></image>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import {apiCustomeSearch} from '@/api/approve/custome.js'
  26. import {apiContractSearch} from '@/api/approve/contract.js'
  27. import {apiSealSearch} from '@/api/approve/seal.js'
  28. export default {
  29. data() {
  30. return {
  31. value: '',
  32. placeholder: '',
  33. type: '',
  34. list: [],
  35. empty:false,
  36. }
  37. },
  38. onLoad(options) {
  39. this.type = options.type
  40. this.initPage(options.type)
  41. },
  42. methods: {
  43. // 初始化界面
  44. initPage(type) {
  45. let navBarTitle = ''
  46. switch (type) {
  47. case 'custome':
  48. navBarTitle = '客户审批'
  49. this.placeholder = '客户名称/社会信用码'
  50. break;
  51. case 'contract':
  52. navBarTitle = '合同审批'
  53. this.placeholder = '客户名称/社会信用码'
  54. break;
  55. case 'seal':
  56. navBarTitle = '用印审批'
  57. this.placeholder = '客户名称/社会信用码'
  58. break;
  59. }
  60. uni.setNavigationBarTitle({
  61. title: navBarTitle
  62. })
  63. },
  64. //跳转搜索结果页
  65. handleGoDetail(e) {
  66. // 如果是合同则跳转合同搜索结果页 否则跳转公共的搜索结果页
  67. if(this.type==='contract'){
  68. uni.navigateTo({
  69. url:"/pages-approve/contract/search?val="+e
  70. })
  71. }else{
  72. uni.navigateTo({
  73. url:`./result?type=${this.type}&val=${e}`
  74. })
  75. }
  76. },
  77. // 客户审批搜索
  78. async handleCustome() {
  79. const res = await apiCustomeSearch({
  80. Keyword: this.value,
  81. })
  82. if (res.code === 200) {
  83. this.list = res.data
  84. if(res.data.length===0){
  85. this.empty=true
  86. }else{
  87. this.empty=false
  88. }
  89. }
  90. },
  91. // 合同审批搜索
  92. async handleContract() {
  93. const res = await apiContractSearch({
  94. Keyword: this.value,
  95. })
  96. if (res.code === 200) {
  97. this.list = res.data
  98. if(res.data.length===0){
  99. this.empty=true
  100. }else{
  101. this.empty=false
  102. }
  103. }
  104. },
  105. //用印搜索
  106. async handleSeal(){
  107. const res=await apiSealSearch({
  108. Keyword: this.value,
  109. })
  110. if (res.code === 200) {
  111. this.list = res.data
  112. if(res.data.length===0){
  113. this.empty=true
  114. }else{
  115. this.empty=false
  116. }
  117. }
  118. },
  119. onChange(e) {
  120. this.value = e.detail
  121. },
  122. onSearch() {
  123. if(!this.value){
  124. uni.showToast({
  125. title:'请输入搜索关键字',
  126. icon:'none'
  127. })
  128. return
  129. }
  130. if (this.type === 'custome') {
  131. this.handleCustome()
  132. }
  133. if (this.type === 'contract') {
  134. this.handleContract()
  135. }
  136. if(this.type==='seal'){
  137. this.handleSeal()
  138. }
  139. }
  140. }
  141. }
  142. </script>
  143. <style lang="scss">
  144. .search-page {
  145. width: 100%;
  146. min-height: 100vh;
  147. // padding: 20rpx 34rpx;
  148. }
  149. .search-box {
  150. border: 1px solid #3385FF;
  151. padding: 0 !important;
  152. border-radius: 60rpx;
  153. background-color: #fff !important;
  154. }
  155. .search-con {
  156. background-color: #fff !important;
  157. }
  158. .van-search__content {
  159. background-color: #fff !important;
  160. padding-left: 30rpx !important;
  161. }
  162. .search-btn {
  163. position: relative;
  164. color: #3385FF;
  165. &::before {
  166. content: '';
  167. display: block;
  168. width: 1px;
  169. height: 60%;
  170. background-color: #D1D1D1;
  171. position: absolute;
  172. left: -16rpx;
  173. top: 20%;
  174. }
  175. }
  176. .search-icon {
  177. width: 40rpx;
  178. height: 40rpx;
  179. display: block;
  180. position: relative;
  181. top: 4rpx;
  182. margin-right: 20rpx;
  183. }
  184. .click-icon {
  185. width: 24rpx;
  186. height: 24rpx;
  187. }
  188. .search-result{
  189. padding: 20rpx 34rpx;
  190. }
  191. .result-item {
  192. align-items: center;
  193. padding: 20rpx 0;
  194. border-bottom: 1px solid #EBEBEB;
  195. .con {
  196. flex: 1;
  197. margin-right: 20rpx;
  198. }
  199. }
  200. </style>