<template>
  <my-dialog :print="print" title="UBM预约" :is-show="show" @handleSave="handleSave" @close="closeDialog">
    <el-form id="UBMOrder" ref="form" size="small" :model="form" label-width="90px">
      <el-form-item required label="选择患者:">
        <el-input v-model="form.patient" suffix-icon="el-icon-search" />
      </el-form-item>
      <div v-if="patientInfo" class="patientDetail">
        <div style="font-size: 16px;font-weight: bold">患者信息</div>
        <div class="detailItem">
          <div>登记号：{{ patientInfo.patientId }}</div>
          <div>电话：{{ patientInfo.patientPhone }}</div>
        </div>
        <div class="detailItem">
          <div>姓名：{{ patientInfo.patientName }}</div>
          <div>性别：{{ patientInfo.patientSex }}</div>
          <div>生日：{{ patientInfo.patientBirthday }}</div>
          <div>年龄：{{ patientInfo.patientAge }}</div>
          <div>来源：门诊/住院</div>
        </div>
      </div>
      <el-form-item label="负责医生:">
        <el-col :span="12">
          <el-select v-model="form.doctorId" placeholder="请选择">
            <el-option
              v-for="item in doctorList"
              :key="item.employeeId"
              :label="item.realName"
              :value="item.employeeId"
            />
          </el-select>
        </el-col>
        <el-col :span="12" style="display: flex;align-items: center">
          已开医嘱:
          <div class="radioItem" @click="form.docAdvice=true">
            <input :checked="form.docAdvice" type="radio">是
          </div>
          <div class="radioItem" @click="form.docAdvice=false">
            <input :checked="!form.docAdvice" type="radio">否
          </div>
        </el-col>
      </el-form-item>
      <el-form-item label="备注:">
        <el-input v-model="form.remark" autosize type="textarea" />
      </el-form-item>
      <div style="display: flex;padding:0 0 20px 20px">
        <el-col :span="10" style="display: flex;align-items: center">
          眼别:
          <div class="radioItem" @click="form.eyeLevel='OD'">
            <input :checked="form.eyeLevel==='OD'" type="radio">OD
          </div>
          <div class="radioItem" @click="form.eyeLevel='OS'">
            <input :checked="form.eyeLevel==='OS'" type="radio">OS
          </div>
          <div class="radioItem" @click="form.eyeLevel='OU'">
            <input :checked="form.eyeLevel==='OU'" type="radio">OU
          </div>
        </el-col>
        <el-col :span="7" style="display: flex;align-items: center">
          散瞳:
          <div class="radioItem" @click="form.mydriasis=true">
            <input :checked="form.mydriasis" type="radio">是
          </div>
          <div class="radioItem" @click="form.mydriasis=false">
            <input :checked="!form.mydriasis" type="radio">否
          </div>
        </el-col>
        <el-col :span="7" style="display: flex;align-items: center">
          缩瞳:
          <div class="radioItem" @click="form.miosis=!form.miosis">
            <input :checked="form.miosis" type="radio">是
          </div>
          <div class="radioItem" @click="form.miosis=!form.miosis">
            <input :checked="!form.miosis" type="radio">否
          </div>
        </el-col>
      </div>
      <el-form-item required label="预约时间:">
        <el-date-picker
          v-model="form.date"
          type="datetime"
          placeholder="选择日期时间"
        />
      </el-form-item>
    </el-form>
  </my-dialog>
</template>

<script>
import MyDialog from '@/page-subspecialty/views/modules/nurseManagement/myDialog.vue'

export default {
  name: 'UBMOrder',
  components: { MyDialog },
  props: {
    isShow: {
      type: Boolean,
      default: false
    },
    patientInfo: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      show: false,
      radio: '1',
      print: {
        id: 'UBMOrder'
      },
      form: {
        patient: '',
        doctor: '',
        docAdvice: '',
        remark: '',
        doctorId: '',
        eyeLevel: '',
        mydriasis: false,
        miosis: '',
        date: ''
      },
      doctorList: []
    }
  },
  watch: {
    isShow(val) {
      this.show = val
    },
    'patientInfo.id'() {
      this.$nextTick(() => {
        this.form.doctorId = this.patientInfo.doctorId
        this.form.doctorName = this.patientInfo.doctorName
        this.form.date = this.patientInfo.appointDate
      })
    }
  },
  created() {
    this.getDoctorList()
  },
  methods: {
    getDoctorList() {
      this.$http.get('/sys/user', { params: { position: '门诊医师' }}).then(data => {
        this.doctorList = data.data.data
      })
    },
    closeDialog(val) {
      this.$emit('close', val)
    },
    handleSave() {
      const params = {
        appointDate: this.$moment(this.form.date).format('YYYY-MM-DD HH:mm:ss'),
        doctorId: this.form.doctorId,
        doctorName: this.form.doctorName,
        patientId: this.patientInfo.patientId,
        patientName: this.patientInfo.patientName,
        id: this.patientInfo.id
      }
      this.$http.post('/appoint/updateAppointInfo', params).then(() => {
        this.$message.success('修改成功')
        this.$emit('editSuccess')
        this.closeDialog()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.radioItem{
  user-select: none;
  cursor: pointer;
  margin:0 8px;
  display: flex;
}
input{
  -webkit-appearance: checkbox !important;
  margin-right: 5px !important;
}
::v-deep .el-form-item__label{
  font-size: 14px;
}
::v-deep .el-form-item{
  margin-bottom: 16px;
}
::v-deep .el-radio{
  margin-right: 8px;
}
.patientDetail{
  border: 1px solid #6EB1FF;
  border-radius:  8px;
  background: #E8F5FF;
  padding: 16px;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.88);
  margin-bottom: 22px;
}
.detailItem{
  display:flex;
  margin: 8px 0;
  div{
    margin-right: 20px;
  }
}
</style>
