<template>
  <div>
    <el-dialog :title="title" :visible.sync="showDialog" width="1000px" :close-on-click-modal="false" @close="handleClose" append-to-body>
        <el-form :model="form" ref="form" label-width="100px" class="demo-ruleForm">
            <el-form-item label="检索内容" prop="searchCondition">
                <el-input
                    v-model="form.searchCondition"
                    autocomplete="off"
                    placeholder="请输入检索内容"
                ></el-input>
            </el-form-item>
            <el-form-item label="检索数据库" prop="searchBase">
                <el-input
                    v-model="form.searchBase"
                    autocomplete="off"
                    placeholder="请输入检索数据库"
                ></el-input>
            </el-form-item>
            <el-form-item label="检索数量" prop="allNum">
                <el-input-number v-model="form.allNum" controls-position="right" :min="0" style="width:100%" ></el-input-number>
            </el-form-item>
            <el-form-item label="检索人" prop="searchPerson">
                <el-input
                    v-model="form.searchPerson"
                    autocomplete="off"
                    placeholder="请输入检索人"
                ></el-input>
            </el-form-item>
            <el-form-item label="检索时间" prop="searchTime">
                <el-date-picker
                    v-model="form.searchTime"
                    type="date"
                    value-format="yyyyMMdd"
                    placeholder="选择检索时间"
                    style="width:100%"
                    >
                </el-date-picker>
            </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: {
    projectId:{
        default:0
    }
  },
  data() {
    return {
        title:'',
        showDialog:false,
        form:{},
        btnLoading:false
    };
  },
  watch: {},
  computed: {},
  created() {},
  mounted() {},
  methods: {
    open(form){
        if(form.id){
            this.title = '编辑检索记录'
        }else{
            this.title = '添加检索记录'
        }
        this.form = JSON.parse(JSON.stringify(form))
        this.showDialog =  true
    },
    handleClose(){
        this.showDialog = false
    },
    submit(){
        this.$refs.form.validate((valid) => {
            if (valid) {
                this.form.projectId = this.projectId
                this.btnLoading = true
                var a = '添加'
                if(this.form.id){
                    a = '编辑'
                }
                this.$api.addSearchRecord(this.form).then(response=>{
                    if(response.code == 200){
                        this.btnLoading = false
                        this.$message.success(a + '成功')
                        this.$emit('save',true)
                        this.handleClose()
                    }
                }).catch(error=>{
                    this.$message.error(a + '失败')
                    this.btnLoading = false
                })
            }
        })
    }
  },
};
</script>
<style lang="scss" scoped>
</style>