瀏覽代碼

feat: add company shortname

cuiyalong 4 年之前
父節點
當前提交
82584497a7

+ 1 - 0
src/web/staticres/frontRouter/pc/collection/css/index-pc.css

@@ -141,6 +141,7 @@
 .c-tab-container .j-icon {
     width: 16px;
     height: 16px;
+    background-position: center;
 }
 .c-tab-container .icon-box {
     padding: 0 10px;

+ 35 - 0
src/web/staticres/js/ent-search-index-pc.js

@@ -392,6 +392,7 @@ var vm = new Vue({
             })
         },
         setListStateAndCheckPower: function (res) {
+            var _this = this
             if (res.data) {
                 if (res.data.total) {
                     if (this.power) {
@@ -402,6 +403,9 @@ var vm = new Vue({
                 }
 
                 if (res.data.list) {
+                    res.data.list.forEach(function (d) {
+                        d.company_shortname = _this.getShortName(d.company_name)
+                    })
                     if (this.power) {
                         this.listState.list = res.data.list || []
                     } else {
@@ -457,6 +461,37 @@ var vm = new Vue({
             var arr = ['default', 'blue', 'orange', 'green']
             var randomIndex = utils.getRandomNumber(0, arr.length - 1)
             return 'bgc-' + arr[randomIndex]
+        },
+        getShortName: function (comName) {
+            var areaMap = chinaMapJSON || []
+            var shortname = comName
+            // 1. 循环省份城市进行替换
+            areaMap.forEach(function (item) {
+                var p = item.name.replace(/[省市]/, '')
+                if (shortname.indexOf(p) !== -1) {
+                    shortname = shortname.replace(item.name, '').replace(p, '')
+                    console.log(p + ' -> \'\'')
+                }
+                item.city.forEach(function (iitem) {
+                    var c = iitem.name.replace(/[省市]/, '')
+                    if (shortname.indexOf(c) !== -1) {
+                        shortname = shortname.replace(iitem.name, '').replace(c, '')
+                        console.log(c + ' -> \'\'')
+                    }
+                    iitem.area.forEach(function (iiitem) {
+                        if (shortname.indexOf(iiitem) !== -1) {
+                            shortname = shortname.replace(iiitem, '')
+                            console.log(iiitem + ' -> \'\'')
+                        }
+                    })
+                })
+            })
+            var matchRes = shortname.match(/[\u4e00-\u9fa5]{4}/gm)
+            var shortname = matchRes ? matchRes[0] : shortname.slice(0, 4)
+            if (shortname.length < 4) {
+                shortname = shortname.slice(0, 4)
+            }
+            return shortname
         }
     }
 })