MrShi
2 天以前 5e8f70caf25beb34657f34a7ee06e1e1ff541cdb
mini-program/pages/search/search.vue
@@ -2,7 +2,7 @@
   <view class="box">
      <view class="search">
         <u-search placeholder="请输入商品名称搜索" height="36" searchIconColor="#999999" borderColor="#EEEEEE"
            bgColor="#F9F9FB" :showAction="false" v-model="goodsName" @search="search" />
            bgColor="#F9F9FB" :showAction="false" v-model="goodsName" @search="search" @clear="goodsList = []" />
      </view>
      <view class="history" v-if="historyList && historyList.length > 0">
         <view class="history-title">历史搜索</view>
@@ -13,7 +13,7 @@
      <template v-if="isSearch">
         <view class="list">
            <image class="list-notfund" v-if="goodsList.length === 0" src="/static/images/default_search@2x.png" mode="widthFix"></image>
            <view class="commodity-item" v-for="(item, i) in goodsList" :key="i" v-else>
            <view class="commodity-item" v-for="(item, i) in goodsList" :key="i" v-else @click="jumpDetails(item.id)">
               <view class="commodity-item-image">
                  <image :src="item.imgurl" mode="widthFix"></image>
               </view>
@@ -32,18 +32,21 @@
                  </view>
                  <view class="commodity-item-shou">
                     <text>已售{{item.saleNum + item.realSaleNum}}</text>
                     <view class="commodity-item-shou-add">+</view>
                     <view class="commodity-item-shou-add" @click.stop="addCard(item)">+</view>
                  </view>
               </view>
            </view>
         </view>
      </template>
      <Login ref="login" />
   </view>
</template>
<script>
   import { mapState } from 'vuex'
   import Login from '@/components/login/login.vue'
   export default {
      components: { Login },
      computed: {
         ...mapState(['userInfo'])
      },
@@ -76,6 +79,26 @@
         this.getGoodsList()
      },
      methods: {
         addCard(e) {
            if (!this.userInfo) {
               this.$refs.login.open()
               return
            }
            this.$u.api.addCart({
               goodsId: e.id,
               goodsSkuId: e.goodsSkuResponseList[0].id,
               num: 1
            }).then(res => {
               if (res.code === 200) {
                  uni.showToast({ title: '添加成功', icon: 'success' })
               }
            })
         },
         jumpDetails(id) {
            uni.navigateTo({
               url: '/pages/details/details?id=' + id
            })
         },
         seleContent(val) {
            this.goodsName = val
            this.search()
@@ -91,6 +114,7 @@
            })
         },
         search() {
            if (!this.goodsName) return;
            if (!this.isSearch) {
               this.isSearch = true
            }
@@ -204,6 +228,7 @@
            .commodity-item-image {
               width: 100%;
               height: 336rpx;
               overflow: hidden;
               display: flex;
               align-items: center;
               justify-content: center;