export const PatentViewFieldJs = {
  data() {
    return {
      fields: [],
      patentViewField:[],
      viewSelected:'',
    }
  },
  mounted() {
    // if(!this.coordination){
      this.getPatentViewField()
    // }
    
  },
  methods: {
      // 请求显示栏位管理数据
      async getPatentViewField(refresh) {
        let params = {
          projectId: null,
          type: 'list',
          view: (this.queryParams.taskId + this.signPatentNo)?this.queryParams.taskId + this.signPatentNo:this.reportId ,
          refresh: refresh
      }
      // console.log(this.reportId,params);
      await this.$api.getUserSettingField(params).then(response=>{
        if(response.code == 200){
           this.patentViewField = response.data
           this.handleFields(this.patentViewField)
        }
      }).catch(error=>{
        this.fields = [
          {
            "key": "publicNo",
            "name": "公开号",
            "type": "list",
            "order": 0,
            "hidden": true
          },
          {
            "key": "name",
            "name": "标题",
            "type": "list",
            "order": 1,
            "hidden": true
          },
          {
            "key": "publicDate",
            "name": "公开日",
            "type": "list",
            "order": 0,
            "hidden": true
          },
          {
            "key": "simpleStatus",
            "name": "专利状态",
            "type": "list",
            "order": 0,
            "hidden": true
          },
          {
            "key": "applicant2",
            "name": "权利人",
            "type": "list",
            "order": 20,
            "hidden": true
          },
          {
            "key": "applicant4",
            "name": "申请人",
            "type": "list",
            "order": 22,
            "hidden": true
          }
        ]
      })
        // const { data } = await this.$api.getUserSettingField(params)
       
        // this.patentViewField = data.filter(item => {
        //   return item.type=='list'
        // })
        
      },
      // 显示栏位管理
      async handleFieldManage() {
        // await this.getPatentViewField()
        this.viewSelected =(this.queryParams.taskId + this.signPatentNo)?this.queryParams.taskId + this.signPatentNo:this.reportId
        // console.log(this.viewSelected);
        this.$refs.patentViewField.open(this.patentViewField,this.viewSelected)
      },
      updatePatentViewField(data) {
        this.patentViewField = data.filter(item => {
          return item.type=='list'
        })
       this.handleFields(this.patentViewField)
      },
      handleFields(patentViewField) {
        this.fields=[]
        this.fields=patentViewField.filter(item => {
          return item.hidden==false
        })
      },
    getColumnValue(row, column) {
      if (column.type !== 'list') {
        const field = row.field.find(item => item.id === parseInt(column.key))
        if (field) {
          // return field.selecteds
        }
      } else if (column.key === 'label') {
        return row.label.map(item => item.name)
      } else {
        const value = row[column.key]
        if (column.key === 'inventor' || column.key === 'agent') {
          return value.map(item => item.name)
        }
        if (column.key === 'applicant1') {
          return row.applicant.filter(a => a.dataType === 1).map(item => item.shortName)
        }
        if (column.key === 'applicant2') {
          return row.applicant.filter(a => a.dataType === 1).map(item => item.name)
        }
        if (column.key === 'applicant3') {
          return row.applicant.filter(a => a.dataType === 2).map(item => item.shortName)
        }
        if (column.key === 'applicant4') {
          return row.applicant.filter(a => a.dataType === 2).map(item => item.name)
        }
        if (column.key === 'simpleFamily') {
          return [row.family.simple.length]
        }
        if (column.key === 'inpadocFamily') {
          return [row.family.inpadoc.length]
        }
        if (column.key === 'patSnapFamily') {
          return [row.family.patSnap.length]
        }
        if (column.key === 'agency' && value) {
          return [value.name]
        }
        if (value instanceof Array) {
          return value
        } else if (typeof value === 'string' || typeof value === 'number') {
          return [value]
        }
        return ''
      }
    },
  },
}
