search.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <view class="pageBg">
  3. <view class="top">
  4. <view class="head">
  5. <view class="search">
  6. <image class="search_icon" src="http://139.9.103.171:1888/img/image/search_icon.png"></image>
  7. <input class="search_input" :value="searchValue" @confirm="tapSearch(searchValue.length>0?searchValue:'')" @input="inputSearch" placeholder="请输入搜索的商品" placeholder-style="color:#B5B5B5;" @blur="searchBlur"/>
  8. <image v-if="searchValue" @tap="tapClearInput" class="search-close" src="http://139.9.103.171:1888/img/image/close2.png" mode="widthFix"></image>
  9. </view>
  10. <view @tap="tapSearch(searchValue.length>0?searchValue:'')" class="search_text">搜索</view>
  11. </view>
  12. <view class="condition" v-if="!showHistory">
  13. <view class="item" :class="{'active':curActive==0}" @tap="tapActive(0)">
  14. <view>默认</view>
  15. </view>
  16. <view class="item" :class="{'active':curActive==1}" @tap="tapActive(1)">
  17. <view>销量</view>
  18. <image v-if="curActive!=1" src="http://139.9.103.171:1888/img/image/sort_arrow_icon.png"></image>
  19. <block v-else>
  20. <image v-if="typeList[curActive].v==1" src="http://139.9.103.171:1888/img/image/sort_down_arrow.png"></image>
  21. <image v-else src="http://139.9.103.171:1888/img/image/sort_up_arrow.png"></image>
  22. </block>
  23. </view>
  24. <view class="item" :class="{'active':curActive==2}" @tap="tapActive(2)">
  25. <view>价格</view>
  26. <image v-if="curActive!=2" src="http://139.9.103.171:1888/img/image/sort_arrow_icon.png"></image>
  27. <block v-else>
  28. <image v-if="typeList[curActive].v==1" src="http://139.9.103.171:1888/img/image/sort_down_arrow.png"></image>
  29. <image v-else src="http://139.9.103.171:1888/img/image/sort_up_arrow.png"></image>
  30. </block>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="pre_tip_keyword" v-if="showHistory && history.length>0">
  35. <view class="top_height"></view>
  36. <view class="item_wrap">
  37. <view class="item_type">历史搜索</view>
  38. <view class="item_value_box">
  39. <view v-for="(item,idx) in history" :key="idx"
  40. class="item_value"
  41. @tap="tapSearch(item)">{{item.keyword}}</view>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="search_results" v-if="!showHistory">
  46. <view class="top_height"></view>
  47. <view v-if="emptyType==0" class="goods_list_result">
  48. <DtGoodsList :dataList="dataList"/>
  49. </view>
  50. <DtNoMore v-if="isNoMore" />
  51. <DtEmpty :type="emptyType" />
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import DtGoodsList from '../comps/dt_goods_list.vue'
  57. import DtEmpty from '../comps/dt_empty.vue'
  58. import DtNoMore from '../comps/dt_no_more.vue'
  59. export default {
  60. components: {
  61. DtGoodsList,
  62. DtEmpty,
  63. DtNoMore
  64. },
  65. data() {
  66. return {
  67. hisItem:{},
  68. searchValue: '',
  69. showHistory:true,
  70. memberId:'',
  71. dataList:[],
  72. history:[],
  73. hots:[], // 热门暂时没有接口
  74. curActive:0,
  75. typeList:{
  76. 0:null,
  77. 1:{
  78. k:'sales',
  79. t:3,
  80. v:1
  81. },
  82. 2:{
  83. k:'price',
  84. t:3,
  85. v:1
  86. }
  87. }, // 当 curActive->curType ===> 0->0 1,2->3
  88. }
  89. },
  90. methods: {
  91. tapActive(idx){
  92. this.curActive = idx
  93. if(idx==1 || idx==2){
  94. let typeList = this.typeList
  95. if(typeList[idx].v == 1){
  96. typeList[idx].v = -1
  97. }else{
  98. typeList[idx].v = 1
  99. }
  100. this.typeList = typeList
  101. }
  102. this.pageIndex = 0
  103. this.dataList.length = 0
  104. this.queryDataList()
  105. },
  106. tapClearInput(){
  107. this.searchValue = ''
  108. this.showHistory = true
  109. },
  110. inputSearch(e) {
  111. this.searchValue = e.detail.value;
  112. if(!this.searchValue){
  113. this.showHistory = true
  114. }
  115. },
  116. searchBlur(){
  117. },
  118. tapSearch(item){
  119. console.log(129,item)
  120. if(item && item.keyword){
  121. this.hisItem = item
  122. this.searchValue = item.keyword
  123. }else{
  124. this.hisItem = {}
  125. }
  126. // if(!this.searchValue || !this.searchValue.trim()){
  127. // this.$dialog.toast('请输入搜索关键字!')
  128. // return
  129. // }
  130. this.showHistory = false
  131. this.isNoMore = false
  132. this.pageIndex = 0
  133. this.dataList.length = 0
  134. this.queryDataList()
  135. },
  136. getParams(){
  137. let history = this.history.slice(0)
  138. let value = this.searchValue.trim()
  139. let baseParam = null
  140. if(value){
  141. let productCategoryId = ''
  142. let isInclude = -1
  143. let hisIdInclude = false
  144. for(let i=0,his;his = history[i]; i++){
  145. if(his.keyword.indexOf(value)!=-1 || value.indexOf(his.keyword)!=-1){
  146. isInclude = i
  147. if(his.id){
  148. productCategoryId = his.id || ''
  149. }else if(this.loadOptions.productCategoryId){
  150. productCategoryId = this.loadOptions.productCategoryId || ''
  151. his.id = this.loadOptions.productCategoryId
  152. }
  153. break;
  154. }else{
  155. if(this.loadOptions.productCategoryId == his.id){
  156. hisIdInclude = true
  157. }
  158. }
  159. }
  160. if(isInclude==-1){
  161. if(hisIdInclude){
  162. productCategoryId = ''
  163. }else{
  164. productCategoryId = this.loadOptions.productCategoryId
  165. }
  166. history.unshift({
  167. id: productCategoryId,
  168. keyword: value
  169. })
  170. if(history.length>10){
  171. history.splice(10,history.length-10)
  172. }
  173. }else{
  174. let aim = history.splice(isInclude,1)
  175. history.unshift(...aim)
  176. }
  177. if(productCategoryId){
  178. console.log(productCategoryId);
  179. baseParam = {
  180. k:'productCategory.id',
  181. t:1,
  182. v:parseInt(productCategoryId)
  183. }
  184. }else{
  185. baseParam = {
  186. k:'name',
  187. t:0,
  188. v:value
  189. }
  190. }
  191. this.history = history
  192. this.$storage.history = history
  193. }
  194. let param = this.typeList[this.curActive]
  195. let resParams = []
  196. if(param){
  197. resParams.unshift(param)
  198. }
  199. if(baseParam){
  200. resParams.unshift(baseParam)
  201. }
  202. return resParams
  203. },
  204. // 搜索
  205. async queryDataList(){
  206. let params = this.getParams()
  207. let resp = await this.$api.searchProduct({
  208. _isShowLoading:true,
  209. pageNo: this.pageIndex,
  210. pageSize: this.pageSize,
  211. memberId: this.memberId,
  212. params: params
  213. })
  214. let list = this.getDataList(resp)
  215. this.dataList = this.dataList.concat(list)
  216. },
  217. onLoadPage(options){
  218. wx.hideShareMenu();
  219. if(this.isLoad){
  220. this.placeholder = options.placeholder?options.placeholder:'请输入搜索的商品';
  221. this.memberId = this.$auth.getMemberId()
  222. this.history = this.$storage.history || []
  223. console.log(159,this.history)
  224. if(options.keyword){
  225. this.searchValue = options.keyword || ''
  226. this.showHistory = false
  227. this.queryDataList()
  228. }
  229. }
  230. if(this.isReach){
  231. this.queryDataList()
  232. }
  233. },
  234. },
  235. onReachBottom(){
  236. this.onReachBottomPage()
  237. },
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. .top {
  242. position: fixed;
  243. top: 0;
  244. left: 0;
  245. width: 100%;
  246. z-index: 100;
  247. .head {
  248. padding: 20upx 0 20upx 30upx;
  249. background: #fff;
  250. display: flex;
  251. align-items: center;
  252. .search {
  253. width: 588upx;
  254. height: 60upx;
  255. border-radius: 25px;
  256. display: flex;
  257. flex-direction: row;
  258. align-items: center;
  259. background: rgba(242, 242, 242, 1);
  260. font-size: 30upx;
  261. // border: 1upx solid #ccc;
  262. .search_icon {
  263. width: 26upx;
  264. height: 26upx;
  265. padding: 20upx;
  266. }
  267. .search_input {
  268. flex: 1;
  269. height: 65upx;
  270. padding-right: 20upx;
  271. font-size: 24upx;
  272. }
  273. .search-close{
  274. width:30upx;
  275. height:30upx;
  276. padding-right: 20upx;
  277. }
  278. }
  279. .search_text {
  280. font-size: 28upx;
  281. color: #333333;
  282. width: 122upx;
  283. text-align: center;
  284. }
  285. }
  286. .condition {
  287. margin-bottom: 20upx;
  288. display: flex;
  289. flex-direction: row;
  290. align-items: center;
  291. height: 68upx;
  292. justify-content: space-around;
  293. background: #fff;
  294. .item {
  295. font-size: 28upx;
  296. color: #333333;
  297. display: flex;
  298. flex-direction: row;
  299. align-items: center;
  300. flex: 1;
  301. justify-content: center;
  302. height: 100%;
  303. image {
  304. width: 11upx;
  305. height: 15upx;
  306. margin-left: 10upx;
  307. }
  308. }
  309. .active {
  310. color: $dt-color-primary;
  311. }
  312. }
  313. }
  314. .pre_tip_keyword {
  315. display: flex;
  316. flex-direction: column;
  317. padding: 30upx;
  318. background: #fff;
  319. .top_height {
  320. height: 105upx;
  321. }
  322. .item_wrap {
  323. display: flex;
  324. flex-direction: column;
  325. .item_type {
  326. font-size: 28upx;
  327. color: #999999;
  328. margin-bottom: 20upx;
  329. }
  330. .item_value_box {
  331. display: flex;
  332. flex-direction: row;
  333. flex-wrap: wrap;
  334. .item_value {
  335. margin-right: 20upx;
  336. margin-bottom: 20upx;
  337. padding: 8upx 20upx;
  338. font-size: 24upx;
  339. color: #333333;
  340. background-color: #F7F7F7;
  341. border-radius: 25px;
  342. }
  343. }
  344. .item_category_box {
  345. display: flex;
  346. flex-direction: row;
  347. flex-wrap: wrap;
  348. align-items: center;
  349. padding-bottom: 30upx;
  350. .item_category {
  351. width: 25%;
  352. display: flex;
  353. flex-direction: column;
  354. align-items: center;
  355. padding-top: 30upx;
  356. image {
  357. width: 80upx;
  358. height: 80upx;
  359. border-radius: 50%;
  360. }
  361. .item_text {
  362. margin-top: 10upx;
  363. font-size: 22upx;
  364. color: #353535;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. .search_results {
  371. .top_height {
  372. height: 165upx;
  373. }
  374. .goods_list_result {
  375. background: #fff;
  376. }
  377. .no_data_wrap {
  378. height: 100vh;
  379. display: flex;
  380. align-items: center;
  381. justify-content: center;
  382. }
  383. }
  384. </style>