MrShi
18 小时以前 62b483cc627b0a5f7d626d6b333a3ef7c7c1f4f4
mini-program/pages/search/search.vue
@@ -4,10 +4,10 @@
         <u-search placeholder="请输入商品名称搜索" height="36" searchIconColor="#999999" borderColor="#EEEEEE"
            bgColor="#F9F9FB" :showAction="false" v-model="goodsName" @search="search" />
      </view>
      <view class="history">
      <view class="history" v-if="historyList && historyList.length > 0">
         <view class="history-title">历史搜索</view>
         <view class="history-list">
            <view class="history-list-item">支重轮</view>
            <view class="history-list-item" v-for="(item, index) in historyList" :key="index" @click="seleContent(item.content)">{{item.content}}</view>
         </view>
      </view>
      <template v-if="isSearch">
@@ -42,20 +42,54 @@
</template>
<script>
   import { mapState } from 'vuex'
   export default {
      computed: {
         ...mapState(['userInfo'])
      },
      data() {
         return {
            goodsName: '',
            goodsList: [],
            page: 1,
            next: true,
            isSearch: false
            isSearch: false,
            historyList: [],
            categoryId: null,
            applicableBrandId: null
         };
      },
      onLoad(option) {
         if (option.categoryId) {
            this.categoryId = option.categoryId
            this.isSearch = true
            this.getGoodsList()
         }
         if (option.applicableBrandId) {
            this.applicableBrandId = option.applicableBrandId
            this.isSearch = true
            this.getGoodsList()
         }
         this.gethistary()
      },
      onReachBottom() {
         this.getGoodsList()
      },
      methods: {
         seleContent(val) {
            this.goodsName = val
            this.search()
         },
         gethistary() {
            if (!this.userInfo) return
            this.$u.api.searchHistoryList({
               memberId: this.userInfo.id
            }).then(res => {
               if (res.code === 200) {
                  this.historyList = res.data
               }
            })
         },
         search() {
            if (!this.isSearch) {
               this.isSearch = true
@@ -73,10 +107,14 @@
               model: {
                  type: 0,
                  sortInfo: 3,
                  goodsName: this.goodsName
                  goodsName: this.goodsName,
                  memberId: this.userInfo.id,
                  categoryId: this.categoryId,
                  applicableBrandId: this.applicableBrandId
               }
            }).then(res => {
               if (res.code === 200) {
                  this.gethistary()
                  res.data.records.forEach(item => {
                     item.minPrice = item.minPrice.toFixed(2).split('.')
                  })
@@ -92,6 +130,11 @@
   }
</script>
<style>
   page {
      background-color: #F9F9FB;
   }
</style>
<style lang="scss" scoped>
   .box {
      width: 100%;
@@ -133,7 +176,7 @@
               margin-right: 24rpx;
               margin-bottom: 24rpx;
               &:last-child {
                  margin: 0 !important;
                  margin-right: 0 !important;
               }
            }
         }