<template>
  <el-dialog v-model="xianZhiShiJianDialog" title="设置医生可修改的时间">
    <el-form :model="info" label-width="120px">
      <el-form-item label="开始时间" prop="startTime">
        <el-date-picker type="datetime" placeholder="开始时间" v-model="info.startTime"></el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="startTime">
        <el-date-picker type="datetime" placeholder="开始时间" v-model="info.endTime"></el-date-picker>
      </el-form-item>
      <el-form-item label="设置人" prop="opIdName">
        <el-input disabled v-model="info.opIdName" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="设置时间" prop="opDate">
        <el-date-picker type="datetime" placeholder="开始时间" v-model="info.opDate" disabled></el-date-picker>
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="baoCunXianZhiShiJian">保存</el-button>
  </el-dialog>
</template>

<script>
import { ref, watch } from 'vue'
import { sheZhiShiJian, xianZhiShiJian } from '../../api/medical-insurance/si-setl-upload'
import { formatDatetime } from '../../utils/date'
import store from '@/store'

export default {
  name: 'XianZhiShiJian',
  setup(props, ctx) {
    const xianZhiShiJianDialog = ref(false)
    const info = ref({
      startTime: '',
      endTime: '',
      opId: '',
      opIdName: '',
      opDate: '',
    })

    const baoCunXianZhiShiJian = () => {
      sheZhiShiJian(formatDatetime(info.value.startTime), formatDatetime(info.value.endTime), store.state.user.info.code).then((res) => {
        xianZhiShiJianDialog.value = false
      })
    }

    watch(
      () => xianZhiShiJianDialog.value,
      () => {
        if (xianZhiShiJianDialog.value) {
          xianZhiShiJian().then((res) => {
            info.value = res
          })
        }
      }
    )

    return {
      xianZhiShiJianDialog,
      info,
      baoCunXianZhiShiJian,
    }
  },
}
</script>

<style scoped></style>
