<template>
  <div class="detail-container">
    <head-form
      title="行政许可"
      :form-data="formData"
      :query-params="queryParams"
      :total="tableDataTotal"
      @handle-search="handleSearch"
    />
    <skeleton style="margin-left:16px;" v-if="isSkeleton"></skeleton>
    <tables
      v-else
      :indexFixed="true"
      :tableLoading="tableLoading"
      :tableData="tableData"
      :forData="forData"
      :tableDataTotal="tableDataTotal"
      :queryParams="queryParams"
      @handle-current-change="handleCurrentChange"
    >
      <template slot="deciWritName" slot-scope="scope">
        <div v-html="scope.row.deciWritName"></div>
      </template>
      <template slot="content" slot-scope="scope">
        <div :class="[isOverHiddenFlag(scope.data.width, showList, scope.index, 0, scope.row.content)?'cell-span':'']" :style="{'-webkit-line-clamp': 2}">
          <div v-html="scope.row.content"></div>
          <span v-if="isOverHiddenFlag(scope.data.width, showList, scope.index, 0, scope.row.content)" @click="changeShowAll(scope.index, 0)">...<span style="color: #0081FF;">展开</span></span>
        </div>
      </template>
    </tables>

  </div>
</template>

<script>
import mixin from '../mixins/mixin'
import skeleton from '@/views/project/projectList/component/skeleton'
import {creditXzxkPage} from '@/api/detail/party-a/opport'
export default {
  name: 'Administrative',
  props: ['companyId'],
  mixins: [mixin],
  components: {
    skeleton
  },
  data() {
    return {
      isSkeleton:true,
      queryParams: {
        cid: this.companyId,
        pageNum: 1,
        pageSize: 20
      },
      forData: [
        {label: '许可决定日期', prop: 'deciTime', width: '110'},
        {label: '决定文书号', prop: 'deciWritNo', width: '200'},
        {label: '许可编号', prop: 'permitNo', width: '100'},
        {label: '决定文书名称', prop: 'deciWritName', width: '190', slot: true},
        {label: '许可内容', prop: 'content', width: '300', slot: true},
        {label: '有效期自', prop: 'valiBegin', width: '100'},
        {label: '有效期至', prop: 'valiEnd', width: '100'},
        {label: '行政许可类别', prop: 'permitType', width: '110'},
        {label: '许可机关', prop: 'office', width: '180'},
        {label: '行政许可机关统一社会信用代码', prop: 'officeCreditCode', width: '210'},
        {label: '数据来源单位', prop: 'dataSourceOffice', width: '110'},
        {label: '数据来源单位统一社会信用代码', prop: 'dataSourceOfficeCreditCode', width: '210'},
        {label: '来源', prop: 'dataSource', width: '80'}
      ],
      formData: [
        { type: 3, fieldName: 'keys', value: '', placeholder: '输入关键词查询', options: []},
      ],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0,
      showList:[]
    }
  },
  computed: {
  },
  created() {
    this.handleQuery()
  },
  methods: {
    async handleQuery(params) {
      this.tableLoading = true
      let param = params?params:this.queryParams
      let res = await creditXzxkPage(param)
      this.tableLoading = false
      if(res.code==200){
        this.isSkeleton = false;
        if(res.rows&&res.rows.length>0){
          res.rows.forEach(item => {
            item.smallContent = item.content.replace(/<.*?>/ig,"")
          })
        }
        this.tableData = res.rows
      }
      this.tableDataTotal = res.total
    },
    changeShowAll(row, column) {
      this.showList.push({
        row: row,
        column: column
      })
    },
    isOverHiddenFlag(data, showList, row, column, value) {
      if(value && this.getByteLen(value) > 88) {
        return !showList.some(item => item.row==row&&item.column==column)
      }else {
        return false
      }
    },
    /*getLenth(data) {
      return Math.floor(data / 6) * 2  //宽度（300） / 一个字符的宽度（6） * 行数（2）
    },*/
    getByteLen(val) {
      var len = 0
      for (var i = 0; i < val.length; i++) {
        var a = val.charAt(i)
        if (a.match(/[^\x00-\xff]/ig) != null){
          len += 2
        }else{
          len += 1
        }
      }
      /*if(val.match(/ /g)){
        len =len+Math.floor(val.match(/ /g).length/2)
      }*/
      return len
    }
  }
}
</script>
<style lang="scss" scoped>
.detail-container{
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
  .cell-span {
    display: inline-block;
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    cursor: pointer;

    >span {
      display: inline-block;
      width: 37px;
      position: absolute;
      right: 0;
      bottom: 0;
      background-color: #fff;
      z-index: 1;
    }
  }
}
</style>
