Browse Source

型号搜索完成

yangc 7 years ago
parent
commit
f0e64e55e2

+ 9 - 0
components/applyPurchase/SeekProduct.vue

@@ -83,6 +83,15 @@
         type: Object,
         default: {}
       }
+    },
+    watch: {
+      'showObj.show': {
+        handler: function (val) {
+          if (val) {
+            this.emptyForm()
+          }
+        }
+      }
     }
   }
 </script>

+ 6 - 6
components/main/Search.vue

@@ -3,8 +3,8 @@
     <div class="input-group">
       <template v-if="!isPcb">
         <div class="type">
-          <span class="type-item" :class="{active: newSearchType == 'code'}" @click="setNewSearchType('code')">型号</span>
-          <span class="type-item" :class="{active: newSearchType == 'kind'}" @click="setNewSearchType('kind')">物料名称</span>
+          <span class="type-item" :class="{active: newSearchType == 'component'}" @click="setNewSearchType('component')">型号</span>
+          <span class="type-item" :class="{active: newSearchType == 'product'}" @click="setNewSearchType('product')">物料名称</span>
           <span class="type-item" :class="{active: newSearchType == 'store'}" @click="setNewSearchType('store')">卖家</span>
           <span class="type-item" :class="{active: newSearchType == 'brand'}" @click="setNewSearchType('brand')">品牌</span>
         </div>
@@ -100,7 +100,7 @@
         click_flag: false,
         searchType: 'product',
         // 新版搜索控制变量
-        newSearchType: 'code'
+        newSearchType: 'component'
       }
     },
     computed: {
@@ -150,13 +150,13 @@
       placeholderByType () {
         let type
         switch (this.newSearchType) {
-          case 'code':
+          case 'component':
             type = '型号'
             break
           case 'brand':
             type = '品牌'
             break
-          case 'kind':
+          case 'product':
             type = '物料名称'
             break
           case 'store':
@@ -238,7 +238,7 @@
             this.$router.push({path: '/pcb/search?w=' + encodeURIComponent(this.keyword)})
           } else {
             if (this.searchType === 'product') {
-              this.$router.push({path: '/search?w=' + encodeURIComponent(this.keyword)})
+              this.$router.push({path: `/search?w=${encodeURIComponent(this.keyword)}&type=${this.newSearchType}`})
             } else if (this.searchType === 'store') {
               this.$router.push({path: '/searchStore?w=' + encodeURIComponent(this.keyword)})
             }

+ 25 - 11
components/search/ForwardGoodsList.vue

@@ -11,40 +11,40 @@
         </tr>
       </thead>
       <tbody>
-        <tr>
+        <tr v-for="item in forwardGood.components">
           <td>
             <div class="line">
               <span class="title inline-block">原厂型号</span>
-              <span class="content inline-block">asdasdad</span>
+              <span class="content inline-block" :title="item.code" v-text="item.code || '-'"></span>
             </div>
             <div class="line">
               <span class="title inline-block">品牌</span>
-              <span class="content inline-block">asdasdad</span>
+              <span class="content inline-block" :title="item.brand.nameEn">{{item.brand.nameEn || '-'}}</span>
             </div>
           </td>
           <td class="single">
             <div class="line">
               <span class="title inline-block">卖家</span>
-              <span class="content inline-block">asdasdad</span>
+              <span class="content inline-block" :title="item.storeName">{{item.storeName || '-'}}</span>
             </div>
           </td>
           <td>
             <div class="line">
               <span class="title inline-block">物料名称(类目)</span>
-              <span class="content inline-block">asdasdad</span>
+              <span class="content inline-block" :title="item.kind.nameCn">{{item.kind.nameCn || '-'}}</span>
             </div>
             <div class="line">
               <span class="title inline-block">单位</span>
-              <span class="content inline-block">asdasdad</span>
+              <span class="content inline-block" :title="item.unit">{{item.unit || '-'}}</span>
             </div>
           </td>
           <td class="single">
             <div class="line">
               <span class="title inline-block">规格</span>
-              <span class="content inline-block text-ellipse">asdasdad</span>
+              <span class="content inline-block" :title="item.spec">{{item.spec || '-'}}</span>
             </div>
           </td>
-          <td><button @click="goSeek()">立即询价</button></td>
+          <td><button @click="authenticateInterceptor(goSeek(item))">立即询价</button></td>
         </tr>
       </tbody>
     </table>
@@ -65,8 +65,20 @@
     components: {
       SeekProduct
     },
+    computed: {
+      goods () {
+        return this.$store.state.searchData.searchList.listNew.data
+      },
+      forwardGood () {
+        return this.goods ? this.goods.futures : {}
+      }
+    },
     methods: {
-      goSeek: function () {
+      goSeek: function (item) {
+        this.productItem.cmpCode = item.code
+        this.productItem.brand = item.brand.nameEn
+        this.productItem.prodName = item.kind.nameCn
+        this.productItem.spec = item.spec
         this.showSeekObj.show = true
       }
     }
@@ -110,12 +122,12 @@
             }
             .title {
               color: #2496f1;
-              width: 27%;
+              width: 30%;
               text-align: right;
               vertical-align: top;
             }
             .content {
-              width: 73%;
+              width: 70%;
               padding-left: 10px;
               vertical-align: top;
               word-break: break-all;
@@ -133,6 +145,8 @@
             background: #2e91f0;
             border: none;
             outline: none;
+            display: block;
+            margin: 0 auto;
           }
         }
       }

+ 2 - 2
components/search/GoodList.vue

@@ -226,10 +226,10 @@
     },
     computed: {
       good_lists () {
-        return this.$store.state.searchData.searchList.lists
+        return this.$store.state.searchData.searchList.listNew.data
       },
       good_list () {
-        return this.good_lists.data
+        return this.good_lists.stock
       },
       total_count () {
         return Math.min(this.good_list.total, 100 * this.pageSize)

+ 2 - 21
components/search/ResultTitle.vue

@@ -3,36 +3,17 @@
     搜索"<span class="text-inverse" >{{keyword}}</span>"
     <!--<span v-if="status != 1">暂无此型号</span>-->
     <span>,为您找到
-    <span class="text-num" v-text="good_list.total"></span> 个<span v-if="status == 2">相关</span>信息
+    <span class="text-num" v-text="count || 0"></span> 个<span v-if="status == 2">相关</span>信息
     </span>:
   </div>
 </template>
 <script>
   export default{
-    props: ['keyword', 'page'],
+    props: ['keyword', 'page', 'count'],
     data () {
       return {
         status: 1
       }
-    },
-    computed: {
-      good_lists () {
-        return this.$store.state.searchData.searchList.lists
-      },
-      good_list () {
-//        if (this.page === 1) {
-//          if (this.good_lists.data.components && this.good_lists.data.components.length > 0) {
-//            if (this.keyword.toUpperCase() === this.good_lists.data.components[0].code.toUpperCase()) {
-//              this.status = 1
-//            } else {
-//              this.status = 2
-//            }
-//          } else {
-//            this.status = 3
-//          }
-//        }
-        return this.good_lists.data
-      }
     }
   }
 </script>

+ 23 - 12
pages/search/_keyword.vue

@@ -1,7 +1,7 @@
 <template>
 <div class="container" id="searchResult">
   <!--<detail-brand></detail-brand>-->
-  <result-title :keyword="key" :page="nowPage"></result-title>
+  <result-title :keyword="key" :page="nowPage" :count="count"></result-title>
   <!--  <kind @kindFilterEvent="listenKindFilter"
           @brandFilterEvent="listenBrandFilter"
           @typeFilterEvent="listenTypeFilter"
@@ -9,10 +9,10 @@
           @crnameFlagEvent="listenCrnameFlag"
     ></kind>-->
   <div class="search-result-type">
-    <span class="inline-block" :class="{active: resultType == 'current'}" @click="setResultType('current')">现货(5条)</span>
-    <span class="inline-block" :class="{active: resultType == 'forward'}" @click="setResultType('forward')">期货(5条)</span>
+    <span class="inline-block" :class="{active: resultType == 'current'}" @click="setResultType('current')">现货({{stockTotal}}条)</span>
+    <span class="inline-block" :class="{active: resultType == 'forward'}" @click="setResultType('forward')">期货({{futureTotal}}条)</span>
   </div>
-  <template v-if="searchType == 'code'">
+  <template v-if="searchType == 'component'">
     <good-list v-if="resultType === 'current'"
                @pageEvent="listenPage"
                @sortEvent="listenSort"
@@ -21,6 +21,9 @@
     ></good-list>
     <forward-goods-list v-else></forward-goods-list>
   </template>
+  <template v-if="searchType == 'product'">
+    123
+  </template>
 </div>
 </template>
 <script>
@@ -31,7 +34,7 @@
     data () {
       return {
         key: this.$route.query.w,
-        pageSize: 15,
+        pageSize: 10,
         nowPage: 1,
         sorting: {},
         filter: {},
@@ -46,11 +49,7 @@
     },
     fetch ({store, route}) {
       return Promise.all([
-        store.dispatch('searchData/searchForKinds', {collectList: 'goods_kind', keyword: route.query.w, paramJSON: {}}),
-        store.dispatch('searchData/searchForBrands', {collectList: 'goods_brand', keyword: route.query.w, paramJSON: {}}),
-        store.dispatch('searchData/searchForList', {count: 15, filter: {}, keyword: route.query.w, page: 1, sorting: {}}),
-        store.dispatch('searchData/searchForStoreType', {collectList: 'goods_store_type', keyword: route.query.w, paramJSON: {}}),
-        store.dispatch('searchData/searchForCrname', {collectList: 'goods_crname', keyword: route.query.w, paramJSON: {}})
+        store.dispatch('searchData/searchForListNew', {count: 10, filter: {}, keyword: route.query.w, page: 1, type: route.query.type || 'component'})
       ])
     },
     components: {
@@ -70,7 +69,19 @@
     },
     computed: {
       searchType () {
-        return this.$route.query.searchType || 'code'
+        return this.$route.query.type || 'component'
+      },
+      goods () {
+        return this.$store.state.searchData.searchList.listNew.data
+      },
+      stockTotal () {
+        return this.goods.stock.total || 0
+      },
+      futureTotal () {
+        return this.goods.futures.total || 0
+      },
+      count () {
+        return this.stockTotal + this.futureTotal
       }
     },
     methods: {
@@ -88,7 +99,7 @@
         if (this.sorting === {}) {
           this.sorting = {}
         }
-        this.$store.dispatch('searchData/searchForList', {count: this.pageSize, filter: this.filter, keyword: this.$route.query.w, page: this.nowPage, sorting: this.sorting})
+        this.$store.dispatch('searchData/searchForListNew', {count: this.pageSize, filter: this.filter, keyword: this.$route.query.w, page: this.nowPage, sorting: this.sorting, type: this.searchType})
       },
       reloadKind: function () {
         if (!this.filter.goods_kindId) {

+ 8 - 1
plugins/mixin.js

@@ -100,7 +100,7 @@ Vue.mixin({
       }
     },
     login: function (url) {
-      this.$router.push(`/auth/login${url ? '?returnUrl=' + url : ''}`)
+      this.$router.push(`/auth/login${url ? '?returnUrl=' + encodeURIComponent(url) : ''}`)
     },
     goStoreApply: function () {
       if (this.user.logged) {
@@ -128,6 +128,13 @@ Vue.mixin({
     },
     authorityInterceptor: function (url, callback) {
       this.baseUtils.getAuthority(this, url, callback, this.isMobile)
+    },
+    authenticateInterceptor: function (callback) {
+      if (this.user.logged) {
+        callback.call(this)
+      } else {
+        this.login(window.location.href)
+      }
     }
   },
   filters: {

+ 10 - 0
store/searchData.js

@@ -118,6 +118,16 @@ export const actions = {
       }, err => {
         commit('searchHistory/GET_SEARCH_HISTORY_FAILURE', err)
       })
+  },
+  // 获取搜索历史
+  searchForListNew ({ commit }, params = {}) {
+    commit('searchList/REQUEST_LIST_NEW', params)
+    return axios.get(`/search/201819`, {params})
+      .then(response => {
+        commit('searchList/GET_LIST_NEW_SUCCESS', response.data)
+      }, err => {
+        commit('searchList/GET_LIST_NEW_FAILURE', err)
+      })
   }
 }
 

+ 14 - 0
store/searchData/searchList.js

@@ -2,6 +2,10 @@ export const state = () => ({
   lists: {
     fetching: false,
     data: []
+  },
+  listNew: {
+    fetching: false,
+    data: []
   }
 })
 
@@ -15,5 +19,15 @@ export const mutations = {
   GET_LIST_SUCCESS (state, result) {
     state.lists.fetching = false
     state.lists.data = result
+  },
+  REQUEST_LIST_NEW (state) {
+    state.listNew.fetching = true
+  },
+  GET_LIST_NEW_FAILURE (state) {
+    state.listNew.fetching = false
+  },
+  GET_LIST_NEW_SUCCESS (state, result) {
+    state.listNew.fetching = false
+    state.listNew.data = result
   }
 }

+ 1 - 1
utils/mixin.js

@@ -337,8 +337,8 @@ export const seekProduct = {
         this.$http.post('/inquiry/buyer/save', inquiry)
           .then(res => {
             this.$message.success('发布成功')
-            this.hasDialog = false
             this.emptyForm()
+            this.showObj.show = false
           }, error => {
             console.log(error)
             this.$message.error('发布失败')