<template>
  <el-dialog title="审核通过" :visible.sync="open" width="800px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <el-form-item label="服务时间段" prop="serviceTime">
          <el-date-picker v-model="form.serviceTime" placeholder="选择日期" type="daterange" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
        </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" :disabled="disabled" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {auditEntApi,getEntInfoByIdApi,updateEntInfoApi} from "@/api/admin/ent/ent"
  export default {
    data () {
      return {
        open: false,
        disabled: false,
        type: '',
        form: {
          serviceTime: [],
          authState: '2',
          endDate: '',
          startDate: ''
        },
        rules: {
          checkStatus: [
            {required: true, message: '请选择审核结果', trigger: 'change'}
          ],
          serviceTime: [
            {required: true, message: '请设置服务时间段', trigger: 'change'}
          ]
        }
      }
    },
    methods: {
      init(id,type) {
        this.open = true;
        this.form.id = id;
        this.type == type || ''
        if(this.type) {
          this.getData()
        }
      },
      getData() {
        this.loading = true
        getEntInfoByIdApi(this.form.id).then(res => {
          this.loading = false
          this.form = res.data || {}
          this.form.serviceDate = []
          if(this.form.startDate) {
            this.form.serviceDate[0] = this.form.startDate
            this.form.serviceDate[1] = this.form.endDate
          }
        })
      },
      submitForm() {
        this.$refs.form.validate(valid => {
          if (valid) {
            this.disabled = true
            auditEntApi(this.form).then(res => {
              this.disabled = false;
              if(res.code == 200) {          
                this.$message({
                  message: '审核通过成功',
                  type: 'success'
                });    
              }
              this.open = false;
              this.$emit('refreshData');
            })
          }
        })
      },
      cancel() {
        this.open = false
      },
    },
    watch: {
      "form.serviceTime"(val) {
        if(this.form.serviceTime) {
          this.form.startDate = this.form.serviceTime[0]
          this.form.endDate = this.form.serviceTime[1]
        }else {
          this.form.startDate = ''
          this.form.endDate = ''
        }
      }
    }
  }
</script>

<style>
</style>
