Browse Source

后台数据为空时一级页面的处理

yangc 6 years ago
parent
commit
3a1f739339

+ 2 - 10
components/applyPurchase/PublishApply.vue

@@ -27,21 +27,13 @@
           lazyLoading: true,
           loop: true,
           prevButton: '.swiper-button-prev',
-          nextButton: '.swiper-button-next',
-          onTransitionStart: (swiper) => {
-            if (this.banners.data && this.banners.data.length && (swiper.activeIndex > this.banners.data.length)) {
-              swiper.activeIndex = 1
-            }
-            if (this.banners.data && this.banners.data.length && swiper.activeIndex <= 0) {
-              swiper.activeIndex = this.banners.data.length
-            }
-          }
+          nextButton: '.swiper-button-next'
         }
       }
     },
     computed: {
       banners () {
-        return this.$store.state.applyPurchase.purchaseBannerList.bannerList.data.data
+        return this.$store.state.applyPurchase.purchaseBannerList.bannerList.data.data || []
       }
     }
   }

+ 1 - 1
components/home/Carousel.vue

@@ -34,7 +34,7 @@
     },
     computed: {
       banners () {
-        if (this.$store.state.carousel.banners.data) {
+        if (this.$store.state.carousel.banners.data && this.$store.state.carousel.banners.data.data) {
           let banner = this.$store.state.carousel.banners.data.data.slice()
            banner.sort(function (a, b) {
              return a.contentId - b.contentId

+ 1 - 1
components/home/displayCard.vue

@@ -9,7 +9,7 @@
            </li>
          </ul>
          <ul class="list-unstyled">
-           <li ref="pingdanListWrapper" v-for="c in counts"  :style="'top: -' + 30 * timerIndex + 'px'" :class="{'top': isTop}">
+           <li ref="pingdanListWrapper" v-for="c in counts" v-if="c"  :style="'top: -' + 30 * timerIndex + 'px'" :class="{'top': isTop}">
              <span v-for="(item, index) in formatScrollNumber(c.count, c.logo)" class="count-distance" :class="'count' + index">{{item}}</span>
            </li>
          </ul>

+ 2 - 2
components/home/floor/Floor.vue

@@ -1,9 +1,9 @@
 <template>
   <div class="floor" :class="!isDefault ? 'normal-floor' : 'price-floor'">
     <h3><span v-if="!isDefault">F{{ floor.floorNumber }}&nbsp;{{ floor.name }}</span></h3>
-    <ul class="list-unstyled clearfix" :style="{borderColor: floor.items[0].backGroundColor || '#d8d8d8'}">
+    <ul class="list-unstyled clearfix" :style="{borderColor: floor.items[0] && floor.items[0].backGroundColor ? floor.items[0].backGroundColor : '#d8d8d8'}">
       <li v-for="(item, index) in floor.items" :key="index" class="floor-item" :class="item.size + (isDefault ? ' default-floor' : '')"
-          :style="{backgroundColor: item.backGroundColor || '#fff', borderColor: item.borderColor || floor.items[0].backGroundColor || '#d8d8d8'}">
+          :style="{backgroundColor: item.backGroundColor || '#fff', borderColor: item.borderColor || floor.items[0] && floor.items[0].backGroundColor ? floor.items[0].backGroundColor : '#d8d8d8'}">
         <img v-if="!item.isNull && item.size != 'large' && isDefault" src="/images/floor/specificPrice-home.png" alt="">
         <a v-if="!item.isNull" :href="item.hrefUrl" target="_blank">
           <img :src="item.pictureUrl" class="floor-item-img"/>

+ 4 - 3
components/home/floor/FloorBar.vue

@@ -1,8 +1,8 @@
 <template>
-  <ul class="floor-bar list-unstyled" :style="!visible?'opacity: 0;':'opacity: 1;'">
+  <ul class="floor-bar list-unstyled" :style="!visible?'opacity: 0;':'opacity: 1;'" v-if="floors.length">
     <li v-for="(floor, index) in floors" :key="index" class="floor-bar-item">
       <a @click="jumpFloor(index)"
-         :style="{backgroundColor: index==activeFloor?floor.items[0].backGroundColor:'#b7dfff'}">
+         :style="{backgroundColor: index == activeFloor && floor.items[0] ? floor.items[0].backGroundColor : '#b7dfff'}">
         <span>F{{ floor.floorNumber }}</span><br/>
         <span class="floor-item-name">{{ floor.name }}</span>
       </a>
@@ -16,7 +16,8 @@
     name: 'floor-bar',
     props: {
       floors: {
-        type: Array
+        type: Array,
+        default: () => []
       }
     },
     data () {

+ 14 - 7
components/home/floor/FloorList.vue

@@ -118,26 +118,33 @@
       }
     },
     computed: {
+      floorsData () {
+        if (this.$store.state.floor.list_v3.data && this.$store.state.floor.list_v3.data.data) {
+          return this.$store.state.floor.list_v3.data.data
+        } else {
+          return {}
+        }
+      },
       floorsF1 () {
-        return this.$store.state.floor.list_v3.data.data.home_floor_f1
+        return this.floorsData.home_floor_f1 || {}
       },
       floorsF2 () {
-        return this.$store.state.floor.list_v3.data.data.home_floor_f2
+        return this.floorsData.home_floor_f2 || {}
       },
       floorsF3 () {
-        return this.$store.state.floor.list_v3.data.data.home_floor_f3
+        return this.floorsData.home_floor_f3 || {}
       },
       floorsF4 () {
-        return this.$store.state.floor.list_v3.data.data.home_floor_f4
+        return this.floorsData.home_floor_f4 || {}
       },
       floorsF5 () {
-        return this.$store.state.floor.list_v3.data.data.home_floor_f5
+        return this.floorsData.home_floor_f5 || {}
       },
       expandF1 () {
-        return this.$store.state.floor.list_v3.data.data.home_expand_f1
+        return this.floorsData.home_expand_f1 || {}
       },
       expandF2 () {
-        return this.$store.state.floor.list_v3.data.data.home_expand_f2
+        return this.floorsData.home_expand_f2 || {}
       },
       floorsList () {
         let lists = []

+ 3 - 138
components/pcb/home/EnterpriseInfo.vue

@@ -6,7 +6,7 @@
           <div>
             <div class="introduce">
               <div><h4>企业简介</h4></div>
-              <p class="intro-content" v-if="storeInfo.enterprise.description">
+              <p class="intro-content" v-if="storeInfo.enterprise">
                 <span class="info" v-text="getIntro(storeInfo.enterprise.description)"></span>
                 <span class="look" @click="dialogVisible = true" v-if="showMore">查看更多 <img src="/images/store/home/angle-right.png" style="margin-top:-2px;"></span>
               </p>
@@ -42,7 +42,7 @@
           <span class="close" @click="dialogVisible = false">&times;</span>
         </div>
         <div class='content'>
-          <p v-if="storeInfo.enterprise.description">{{storeInfo.enterprise.description}}</p>
+          <p v-if="storeInfo.enterprise">{{storeInfo.enterprise.description}}</p>
           <p v-else class="empty-introduce">暂无简介</p>
         </div>
       </div>
@@ -128,142 +128,7 @@
             }
           })
         } else {
-          if (item) {
-            if (isBuy) {
-              this.$http.post('trade/order/buyNow', [{
-                uuid: item.comUuid,
-                batchCode: item.batchCode,
-                number: item.minBuyQty,
-                storeid: item.storeId,
-                storeUuid: item.storeUuid,
-                currencyName: item.currency,
-                minPackQty: item.minPackQty ? item.minPackQty : item.minBuyQty
-              }])
-                .then(response => {
-                  //        window.location.href = '/user#/order/pay/' + this.enidfilter(response.data.orderid)
-                  if (response.data.success) {
-                    if (response.data.message) {
-                      this.$message({
-                        message: response.data.message,
-                        type: 'success'
-                      })
-                      let _self = this
-                      window.setTimeout(function () {
-                        window.location.href = '/user#/order/pay/' + _self.enidfilter(response.data.data.orderid)
-                      }, 1000)
-                    } else {
-                      window.location.href = '/user#/order/pay/' + this.enidfilter(response.data.data.orderid)
-                    }
-                  } else {
-                    if (response.data.data && response.data.data.unvailable === 1) {
-                      this.$message.error('产品信息已失效,请刷新界面')
-                    } else {
-                      this.$message.error(response.data.message)
-                    }
-                  }
-                }, err => {
-                  console.log(err)
-                  if (item.minBuyQty > item.reserve) {
-                    this.$message.error('商品' + item.code + '的库存已经不满足起订量')
-                  }
-                })
-            } else {
-              // this.$store.dispatch('user/addCar', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
-              this.$http.post('trade/cart/add', {
-                uuid: item.comUuid,
-                batchCode: item.batchCode,
-                number: item.minBuyQty,
-                storeid: item.storeId,
-                storeUuid: item.storeUuid,
-                currencyName: item.currency,
-                minPackQty: item.minPackQty ? item.minPackQty : item.minBuyQty
-              })
-                .then(response => {
-                  if (response.data.success) {
-                    if (response.data.message) {
-                      this.$message({
-                        message: '添加购物车成功,但商品信息有更新',
-                        type: 'success'
-                      })
-                    } else {
-                      this.$message({
-                        message: '添加购物车成功',
-                        type: 'success'
-                      })
-                    }
-                  } else {
-                    this.$message.error(response.data.message)
-                  }
-                })
-            }
-          }
-        }
-      },
-      enidfilter: function (str) {
-        if (str) {
-          let encryptStr = '' // 最终返回的加密后的字符串
-          // 产生三位随机数
-          let num = ''
-          for (let i = 0; i < 3; i++) {
-            num += Math.floor(Math.random() * 10)
-          }
-          encryptStr += num // 产生3位随机数
-
-          // 16位加密
-          let tempspit = ''
-          let strspit = str.toString().toLowerCase()
-          if (strspit.match(/^[-+]?\d*$/) === null) { // 非整数字符,对每一个字符都转换成16进制,然后拼接
-            /**
-             * Unicode汉字、英文字母、数字的unicode范围
-             *汉字:[0x4e00,0x9fa5](或十进制[19968,40869])
-             *数字:[0x30,0x39](或十进制[48, 57])
-             *小写字母:[0x61,0x7a](或十进制[97, 122])
-             *大写字母:[0x41,0x5a](或十进制[65, 90]
-             * 'a'的Unicode编码:'&#97;',charCodeAt()的值是97
-             * '码'的Unicode编码:'\u7801', new String('码').charCodeAt()的值是30721,30721的16进制表示是7801
-             */
-            let s = strspit.split('')
-            for (let i = 0; i < s.length; i++) {
-              s[i] = s[i].charCodeAt() // 先转换成Unicode编码
-              s[i] = s[i].toString(16)
-              // 因为在服务器是每两位当做一个字符进行解析的,所以这里每个字符的Unicode编码范围必须在0——255之间。数字和大小写满足该要求,特殊字符则不一定,如果后续有特殊字符的要求,需要重写编码器和解码器
-              if (s[i].length === 1) {
-                s[i] = '0' + s[i]
-              }
-              tempspit = tempspit + s[i]
-            }
-            tempspit = tempspit + '{' + 1 // 1代表字符
-          } else { // 数字直接转换成16进制
-            strspit = parseInt(strspit)
-              .toString(16)
-            tempspit = strspit + '{' + 0 // 0代表纯数字
-          }
-
-          let temp = tempspit.split('{') // 对要加密的字符转换成16进制
-          let numLength = temp[0].length // 转换后的字符长度
-          numLength = numLength.toString(16) // 字符长度换算成16进制
-          if (numLength.length === 1) { // 如果是1,补一个0
-            numLength = '0' + numLength
-          } else if (numLength.length > 3) { // 转换后的16进制字符长度如果大于2位数,则返回,不支持
-            return ''
-          }
-          encryptStr += numLength
-          if (temp[1] === '0') {
-            encryptStr += 0
-          } else if (temp[1] === '1') {
-            encryptStr += 1
-          }
-          encryptStr += temp[0]
-          if (encryptStr.length < 20) { // 如果小于20位,补上随机数
-            // 产生三位随机数
-            let numtwo = ''
-            for (let i = 0; i < 20 - encryptStr.length; i++) {
-              numtwo += Math.floor(Math.random() * 10)
-            }
-            let ran = numtwo // 产生3位随机数
-            encryptStr += ran
-          }
-          return encryptStr
+          this.baseUtils.buyOrCar(true, null, this, item, '/user#/order/pay/')
         }
       }
     }

+ 1 - 1
components/provider/HotCommodity.vue

@@ -4,7 +4,7 @@
       <span>产品推荐</span>
       <img src="/images/original/line.png" alt=""/>
     </div>
-    <div v-if="hotComponents || hotComponents.length>0" class="hot-components">
+    <div v-if="hotComponents && hotComponents.length>0" class="hot-components">
       <div v-if="hotComponents.length<=2">
         <ul class="recommend-list clearfix">
           <li v-for="(component, index) in hotComponents.slice(0,2)" class="big">

+ 2 - 2
components/provider/ToggleStore.vue

@@ -96,8 +96,8 @@ export default {
       return this.$store.state.provider.stores.originalCount.data
     },
     count () {
-      let allCount =  this.$store.state.option.counter.data ? this.$store.state.option.counter.data : []
-      if (allCount) {
+      let allCount = this.$store.state.option.counter.data ? this.$store.state.option.counter.data : []
+      if (allCount && Array.isArray(allCount)) {
         allCount.forEach((value) => {
           if (value.item === '供应商') {
             this.supplierArr = value.count

+ 1 - 1
components/supplier/articleTwo.vue

@@ -13,7 +13,7 @@
             <p>暂无供应商推荐信息</p>
           </div>
         </div>
-        <ul class="list-unstyled">
+        <ul class="list-unstyled" v-if="list && list.content">
           <li v-for="item in list.content.slice(0,10)" @click="jumpResource(item.uu)">
             <div class="img">
               <img :src="item.enLogoUrl || '/images/all/default.png'">

+ 2 - 10
components/supplier/banner.vue

@@ -29,21 +29,13 @@
           lazyLoading: true,
           loop: true,
           prevButton: '.swiper-button-prev',
-          nextButton: '.swiper-button-next',
-          onTransitionStart: (swiper) => {
-            if (this.banners.data && this.banners.data.length && (swiper.activeIndex > this.banners.data.length)) {
-              swiper.activeIndex = 1
-            }
-            if (this.banners.data && this.banners.data.length && swiper.activeIndex <= 0) {
-              swiper.activeIndex = this.banners.data.length
-            }
-          }
+          nextButton: '.swiper-button-next'
         }
       }
     },
     computed: {
       banners () {
-        return this.$store.state.supplier.detail.banner.data.data
+        return this.$store.state.supplier.detail.banner.data.data || []
       }
     }
   }

+ 1 - 1
components/supplier/merchant.vue

@@ -16,7 +16,7 @@
         <a href="javascript:history.go(-1)"><i class="fa fa-reply" style="margin-right:5px;"></i>返回上一页</a>
       </div>
     </div>
-    <ul class="list-inline">
+    <ul class="list-inline" v-if="list && list.content">
       <li v-for="item in list.content.slice(0,8)" @click="jumpResource(item.enUU)" class="clearfix">
         <div class="img">
           <img :src="item.storeLogoUrl || item.logoUrl || '/images/all/default.png'">

+ 1 - 1
store/applyPurchase/purchaseManList.js

@@ -5,7 +5,7 @@ export const state = () => ({
   },
   purchaseManList: {
     fetching: false,
-    data: []
+    data: {}
   },
   purchaseManDetail: {
     fetching: false,