export const tableEdit = {
    data() {
        return {
            editedMessage:{}
        }
    },
    methods: {
         //双击单元格进行编辑
      cellDblclick(row, column, cell, event){
        var key = column.property
        var item = this.column.find(item=>{
          return item.field == key
        })
        if(row){
            if(this.editedMessage.field){
              return
            }
            if(!item.editable){
              // this.$message.warning('该栏位不可编辑')
              return
            }
            this.cell={
              rowId:row.id,
              columnId:column.id
            }
            this.editedMessage = {
              field:key,
              data: JSON.parse(JSON.stringify(row))
            }
            return
          }
      },
      cellClick(row, column, cell, event){
        
      },
      cancelEdit(){
        this.editedMessage={}
      },
      
    },
}
export const updateNoveltyCompareFile = {
  methods: {
    changeMessage(fieldObj,row,value){
        var field = fieldObj.field
        var message = this.$message({
          message: '信息保存中...',
          type: 'warning',
          duration:0
        });
        if(field == 'noveltyCompareRecordVOS'){
            var params = {
                markNoteText:value,
                projectId:this.projectId,
                patentNo:row.literatureNo,
            }
            if(row.noveltyCompareRecordVOS && row.noveltyCompareRecordVOS.length>0){
                var obj = row.noveltyCompareRecordVOS[0]
                params.id = obj.id
            }
            this.$api.editNoveltyMark(params).then(response=>{
                if(response.code == 200){
                    message.close()
                    this.$message.success('编辑成功')
                    if(params.id){
                        this.$set(row.noveltyCompareRecordVOS[0],'markNoteText',value)
                    }else{
                        params.id = response.data
                        if(!row.noveltyCompareRecordVOS){
                          this.$set(row,'noveltyCompareRecordVOS',[params])
                        }else{
                          row.noveltyCompareRecordVOS.push(params)
                        }
                        
                    }
                    this.cancelEdit()
                }
            }).catch(error=>{
                message.close()
                this.$message.error('编辑失败')
                if(this.$refs[field.field] && this.$refs[field.field][0]){
                    var fn = this.$refs[field.field][0] || this.$refs[field.field]
                    fn.setFocus()
                }
            })
            return
        }
        var params = {
            // ...row
            projectId:this.projectId,
            patentNo:row.literatureNo || row.patentNo,
            field:field,
            value:value
        }
        // params[field] = value
        this.$api.editCompareFileByProjectId(params).then(response=>{
            if(response.code == 200){
                message.close()
                this.$message.success('编辑成功')
                this.$set(row,field,value)
                this.cancelEdit()
            }
        }).catch(error=>{
          message.close()
          this.$message.error('编辑失败')
          if(this.$refs[field.field] && this.$refs[field.field][0]){
            var fn = this.$refs[field.field][0] || this.$refs[field.field]
            fn.setFocus()
          }
        })
        
    },
  },
}