<template>
  <div class="industrialPolicy">
    <div class="peripheralBody">
      <van-tabs :active="active" @change="onChange">
<!--        <van-tab title="全部" :name="0"></van-tab>-->
        <van-tab :title="item.name" :name="item.id" v-for="(item,index) in typeList"></van-tab>
      </van-tabs>
      <div class="peripheralBox">
        <div class="peripheralItem" v-for="item in peripheralList" @tap="toDetail(item)">
            <span class="peripheralName">{{item.title}}</span>
          <div class="peripheralItemRow2">{{item.releaseTime}} &nbsp;|&nbsp; 园区管委会</div>
          <div class="tagBox">
             <span class="periTag" v-for="tag in item.policySmallName">{{tag}}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { policyList,getUserLocalStorageInfo,policyListAll } from "@/js_sdk/http.js";
export default {
  name: "peripheralService",
  data(){
    return{
      active: '',
      peripheralList:[
        {name:'关于入住企业规模发展奖励',type:['小类','大类']},
        {name:'关于入住企业规模发展奖励',type:['小类','大类']},
      ],
      typeList:[],
      userId:getUserLocalStorageInfo().userId,
      params: {
        pageNum: 1,
        pageSize: 10,
        policyBig: '', // auth.currUser().id
        groupId: '', // 园区
        status: 'published'
      },
    }
  },
  created(){
    this.selectPolicyType()
  },
  onPullDownRefresh() {
    this.peripheralList = []
    this.selectData()
    setTimeout(function () {
      uni.stopPullDownRefresh();
    }, 1000);
  },
  mounted() {
  },
  methods:{
    selectPolicyType() {
      policyListAll({}).then((res) => {
        console.log(res)
        if (res.data) {
          this.type = res.data
          this.typeList = []
          const list = []
          list.push({ id: '0', name: '全部' })
          res.data.forEach((item) => {
            if (item.type === 'big') {
              list.push({
                id: item.id,
                name: item.name,
              })
            }
          })
          this.typeList = list
        }
        this.onChange({detail:{
            name:''
          }})
      })
    },
    onChange(value) {
       console.log(value)
       this.peripheralList = []
       this.selectData(value.detail.name)
    },
    selectData(value) {
      const _this = this
      _this.params.policyBig = value
      policyList(_this.params).then((res) => {
        console.log(res)
        if (res.data) {
          res.data.forEach((res) => {
            const det = _this.getItemJson(res)
            console.log('det',det)
            const types = _this.type
            const smallNames = []
            types.forEach((i) => {
              if (det.policySmall){
                if (det.policySmall.search(i.id) !== -1) {
                  smallNames.push(i.name)
                }
              }
            })
            det.policySmallName = smallNames
            _this.peripheralList.push(det)
          })
        }
      })
    },
    toDetail(item) {
      uni.navigateTo({
        url:'/pages/subPackages/industrialPolicy/detail?id='+item.id
      })
    },
    getItemJson(item) {
      item.releaseTime = this.$common.transServDate(item.releaseTime)
      return item
    }
  }
}
</script>

<style lang="scss">
.industrialPolicy{
  .peripheralBody{
    background: white;
    margin-top: 24rpx;
    padding: 32rpx;
    box-sizing: border-box;
    height: 1424rpx;
    .peripheralBox{
      margin-top: 8rpx;
      .peripheralItem{
        width: 686rpx;
        height: 204rpx;
        box-sizing: border-box;
        border-radius: 16rpx;
        background: #F5F7FA;
        padding: 32rpx;
        margin-top: 24rpx;
          .peripheralName{
            color:#222222;
            font-size: 32rpx;
            font-weight: 600;
          }
        .peripheralItemRow2{
          color: #888888;
          font-size: 28rpx;
          margin-top: 14rpx;
        }
        .tagBox{
          display: flex;
          flex-wrap: wrap;
        }
        .periTag{
          display: flex;
          align-items: center;
          justify-content: center;
          width: 92rpx;
          height: 48rpx;
          background: rgba(3, 101, 249, 0.20);
          color: rgba(3, 101, 249, 1);
          border-radius: 8rpx;
          margin: 16rpx 16rpx 0 0;
          font-size: 24rpx;
        }
      }
    }
  }
}
</style>
