<template>
  <div>
    <vxe-modal
      :value="isShow"
      show-footer
      title="值班管理"
      show-confirm-button
      :width="600"
      :height="400"
      esc-closable
      :fullscreen="$store.getters.device === 'mobile'"
      @input="e => $emit('update:isShow',e)"
    >
      <el-form ref="elForm" :model="form" :rules="rules" label-position="top" label-width="100">
        <el-form-item label="日期" prop="date" required>
          <el-date-picker v-model="form.date" style="width: 100%;" value-format="yyyy-MM-dd" />
        </el-form-item>
        <el-form-item label="值班人员" prop="user_id">
          <user-picker v-model="form.user_id" style="width: 100%;" />
        </el-form-item>
        <el-form-item label="带班领导" prop="leader_id">
          <user-picker v-model="form.leader_id" style="width: 100%;" />
        </el-form-item>
        <el-form-item label="带班领导人员状态" prop="leader_status">
          <el-select v-model="form.leader_status" style="width: 100%;">
            <el-option :value="0" label="未值班" />
            <el-option :value="1" label="已完成值班" />
          </el-select>
        </el-form-item>
        <el-form-item label="值班人员状态" prop="status">
          <el-select v-model="form.status" style="width: 100%;">
            <el-option :value="0" label="未值班" />
            <el-option :value="1" label="已完成值班" />
          </el-select>
        </el-form-item>
        <el-form-item label="说明" prop="remark">
          <el-input v-model="form.remark" type="textarea" :autosize="{ minRows: 2 }" />
        </el-form-item>
      </el-form>

      <template #footer>
        <el-button type="primary" :loading="loading" @click="submit">确认</el-button>
      </template>
    </vxe-modal>
  </div>
</template>

<script>
import UserPicker from "@/components/UserPicker/index.vue";
import { save } from '@/api/onDutySchedules'
export default {
  components: {
    UserPicker
  },
  props: {
    isShow: {
      type: Boolean,
      default: false,
      required: true
    },
  },
  data() {
    return {
      loading: false,
      form: {
        date: '',
        user_id: '',
        leader_id: '',
        leader_status: 0,
        status: 0,
        remark: ''
      },
      rules: {
        date: [
          { required: true, message: '请选择日期' }
        ],
        type: [
          { required: true, message: '请选择类型' }
        ]
      }
    }
  },
  computed: {},
  methods: {
    submit() {
      this.$refs['elForm'].validate(async valid => {
        if (valid) {
          this.loading = true
          try {
            await save(this.form)
            this.$message.success('新增成功')
            this.$emit('refresh')
            this.$emit('update:isShow', false)
            this.loading = false
            this.$refs['elForm'].resetFields()
          } catch (err) {
            this.loading = false
          }
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
