<template>
  <div>
    <el-dialog  :title="title" :visible.sync="showDialog" width="1000px" :close-on-click-modal="false"  :before-close="handleClose" append-to-body>
        <el-form :model="form"  ref="form" label-width="80px" label-position="left">
            <el-form-item label="内容" prop="content">
                <div>
                    <my-RichText v-model="form.content" placeholder="请输入内容"></my-RichText>
                </div>
            </el-form-item>
            <el-form-item label="选择特征" prop="featureIds">
                <div>
                    <el-select v-model="form.featureIds" multiple placeholder="请选择" style="width:100%">
                        <el-option v-for="item in features" :key="item.featureId" :label="`特征${item.featureOrder}`" :value="item.featureId"></el-option>
                    </el-select>
                </div>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" :loading="btnLoading" @click="submit" >确 定</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  components: {},
  props: {
    ifSecondInvalid:{
        default:false
    }
  },
  data() {
    return {
        title:'批量添加',
        showDialog:false,
        btnLoading:false,
        form:{},
        features:[],
        field:null,
        titles:{
            invalidReasonDetail1:'无效理由详情',
            presentOpinions1:'答辩意见',
            invalidReasonDetail2:'第二次无效理由详情',
            presentOpinions2:'第二次答辩意见',
            rbOpinions:'复审委意见',
            rbDecisionKey:'复审委要点提炼',
        }
    };
  },
  watch: {},
  computed: {},
  created() {},
  mounted() {},
  methods: {
    open(type,features){
        this.field = type
        this.features = features
        console.log(this.features)
        var str = '批量添加'
        this.title = str + this.titles[type]
        this.showDialog = true
    },
    handleClose(){
        this.form = {}
        this.showDialog = false
    },
    submit(){
        var ids = []
        for(var i=0;i<this.form.featureIds.length;i++){
            var data = this.features.find(item=>{
                return item.featureId == this.form.featureIds[i]
            }).featureHistories.filter(item1=>{
                if(this.ifSecondInvalid){
                    return item1
                }else{
                    return item1.featureGen!=2
                }
                
            })
            var id = data[data.length-1].id
            ids.push(id)
        }
        var params = {
            ids:ids,
            fieldList:[{ 
                field:this.field,
                value:this.form.content,
            }]
        }
        this.$api.updateGroupFeatureMessage(params).then(response=>{
            if(response.code == 200){
                this.$message.success('编辑成功')
                this.$emit('save',true)
                this.handleClose()
            }
        }).catch(error=>{
            this.$message.error('编辑失败')
        })
    },
  },
};
</script>
<style lang="scss" scoped>
</style>