<template>
  <el-dialog width="854px" class="registerDialog" :title="titles" :visible.sync="visibility"
             :close-on-click-modal="isClose"
             :close-on-press-escape="isClose">

    <el-form :model="form" :rules="rules" ref="formValue" label-width="100px">
      <el-form-item label="患者姓名：" prop="name" :validate-event="is_Name">
        <el-autocomplete
          class="checkSearch"
          popper-class="my-autocomplete"
          v-model="form.name"
          :fetch-suggestions="querySearchAsync"
          :trigger-on-focus="false"
          placeholder="请输入病人名字"
          @select="handleSelect"
          style="width:160px;"
        >
          <i class="el-icon-search el-input__icon" slot="suffix"></i>
          <template slot-scope="{ item }">
            <div class="name">{{ item.name }}</div>
          </template>
        </el-autocomplete>
      </el-form-item>

      <el-form-item label="性别：" prop="gender" :validate-event="is_Name">
        <el-select v-model="form.gender" placeholder="请选择" style="width:100%;">
          <el-option
            v-for="item in sex"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>


      </el-form-item>

      <el-form-item label="年龄：" prop="age" :validate-event="is_Name">
        <el-input v-model="form.age"></el-input>
      </el-form-item>


      <el-form-item label="出生日期：" prop="birthday" :validate-event="is_Name">
        <el-date-picker v-model="form.birthday" type="date" format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd" placeholder="选择日期" style="width:100%;"></el-date-picker>
      </el-form-item>

      <el-form-item label="手机号码：" prop="phone">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>


      <!--<el-form-item label="医疗类别：">-->
      <!--<el-select v-model="form.medical_care" placeholder="请选择" style="width:100%;">-->
      <!--<el-option-->
      <!--v-for="(item,index) in medical_care"-->
      <!--:key="index"-->
      <!--:label="item.label"-->
      <!--:value="item.value">-->
      <!--</el-option>-->
      <!--</el-select>-->
      <!--</el-form-item>-->


      <el-form-item label="证件类型：" prop="certificates" :validate-event="is_Name">
        <el-select v-model="form.certificates" placeholder="请选择" style="width:100%;">
          <el-option
            v-for="item in certificates"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="证件号码：" prop="id_card" :validate-event="is_Name">
        <el-input v-model="form.id_card"></el-input>
      </el-form-item>


      <el-form-item label="参保地：">
        <el-select v-model="form.insuplc_admdvs" placeholder="请选择" style="width:100%;">
          <el-option
              v-for="item in InsuplcAdmdvs"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>



      <el-form-item label="结算类型：">
        <el-select v-model="form.settlement_value" placeholder="请选择" style="width:100%;">
          <el-option
            v-for="item in settlement"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="社保类型：">
        <el-select v-model="form.social_type" placeholder="请选择" style="width:100%;">
          <el-option
            v-for="item in medicalCare"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="读卡类型：" prop="id_card_type" :validate-event="is_Name">
        <el-select v-model="form.id_card_type" placeholder="请选择">
          <el-option
            v-for="item in IDCardTypes"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item class="specialFormItem" label="医保卡号：">
        <div style="display:flex;">
          <el-input v-model="form.medical_insurance_card"></el-input>
          <el-button style="margin-left:10px;" type="primary" @click="reading">读卡</el-button>

        </div>
      </el-form-item>

      <el-form-item label="挂号类型：" :validate-event="is_Name" >
        <el-select v-model="form.register" placeholder="请选择" style="width:100%;">
          <el-option
            v-for="item in register"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="救助人群类型：" :validate-event="is_Name">
        <el-select v-model="form.mdtrt_type" placeholder="请选择" style="width:100%;">
          <el-option
            v-for="item in mdtrt"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="挂号费：">
        <el-input v-model="form.registration_fee"></el-input>
      </el-form-item>
      <el-form-item label="诊疗费：">
        <el-input v-model="form.medical_expenses"></el-input>
      </el-form-item>

      <el-form-item label="医生：" prop="doctor">
        <el-select v-model="form.doctor" placeholder="请选择">
          <el-option
            v-for="(item,index) in doctors"
            :key="index"
            :label="item.user_name"
            :value="item.admin_user_id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="科室：" prop="department">
        <el-select v-model="form.department" placeholder="请选择">
          <el-option
            v-for="(item,index) in departments"
            :key="index"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>


<!--      <el-button style="margin-left:10px;" type="primary" @click="check11" >查普通门诊待遇</el-button>-->
<!--      <el-button style="margin-left:10px;" type="primary" @click="check14" >查门诊大病待遇</el-button>-->

    </el-form>

    <span slot="footer" class="dialog-footer">
    <el-button @click="cancel('formValue')">取 消</el-button>
    <el-button type="primary" @click="confirm('formValue')">挂 号</el-button>
  </span>
  </el-dialog>

</template>

<script>

  import { jsGetAge, uParseTime } from '@/utils/tools'
  import axios from 'axios'
  import { PostSearch } from '@/api/patient'

  import { getDictionaryDataConfig } from '@/utils/data'
  import cryptoJs from 'crypto-js'

  export default {

    name: 'registerDialog',

    data() {

      return {
        ws:null,
        registers: [
          { value: 11, label: '普通门诊' },
          { value: 1102, label: '新冠门诊' },
          // { value: 12, label: '门诊挂号' },
          // { value: 13, label: '急诊' },
          { value: 14, label: '门诊特殊病' },
          // { value: 15, label: '门诊统筹' },
          // { value: 16, label: '门诊慢性病' },
          // { value: 21, label: '普通住院' }
        ],
        medical_care: [
          { value: 11, label: '普通门诊' },
          { value: 12, label: '家庭通道' },
          { value: 13, label: '门诊大病' },
          { value: 14, label: '重疾特药' },
          { value: 15, label: '门诊慢病' },
          { value: 16, label: '门诊特检' },
          { value: 17, label: '健康体检' },
          { value: 18, label: '预防接种' },
          { value: 19, label: '门诊输血' },
          { value: 91, label: '新冠肺炎门诊' }
        ],

        form: {
          id: '',
          insuplc_admdvs:'',
          settlement_value: 1,
          medical_insurance_card: '',
          name: '',
          gender: '',
          certificates: 1,
          p_type: '',
          sick_type: '',
          diagnosis: '',
          medical_care: '',
          birthday: '',
          age: '',
          id_card: '',
          register: '',
          mdtrt_type:'',
          doctor: '',
          id_card_type: 1,
          department: '',
          registration_fee: '',
          medical_expenses: '',
          cost: '',
          phone: '',
          social_type: ''
        },
        IDCardTypes: [{
          value: 1,
          label: '社保卡'
        }, {
          value: 2,
          label: '身份证'
        }, {
          value: 3,
          label: '电子社保卡'
        }, {
          value: 4,
          label: '电子凭证'
        }],
        settlement: [
          { value: 1, label: '医保' },
          { value: 2, label: '自费' },
          { value: 3, label: '公费' },
          { value: 4, label: '农保' },
          { value: 5, label: '会员' },
          { value: 6, label: '职工' },
          { value: 7, label: '合同' },
          {value: 8, label: '医保自费'},

        ],
        InsuplcAdmdvs:[
        ],
        sex: [{
          value: 1,
          label: '男'
        }, {
          value: 2,
          label: '女'
        }],
        certificates: [{
          value: 1,
          label: '内地身份证'
        }, {
          value: 2,
          label: '社保卡'
        }, {
          value: 3,
          label: '护照'
        }, {
          value: 4,
          label: '军官证'
        }, {
          value: 5,
          label: '台胞证'
        }, {
          value: 6,
          label: '港澳地区身份证'
        }],
        medicalCare: [{
          value: 390,
          label: '城乡居民基本医疗保险'
        }, {
          value: 310,
          label: '职工基本医疗保险'
        }],mdtrt: [{
            value: "1",
            label: '新冠肺炎确诊患者'
          }, {
            value: "2",
            label: '其他国家突发公共事件'
          }, {
            value: "3",
            label: '新冠肺炎疑似患者'
          }, {
            value: "4",
            label: '无症状感染者'
          }
        ],
        register: [{
          value: 1,
          label: '普通'
        }, {
          value: 2,
          label: '主治'
        }, {
          value: 3,
          label: '主任'
        }, {
          value: 4,
          label: '免收诊金'
        }, {
          value: 5,
          label: '专家'
        }],
        rules: {
          name: [{ required: true, message: '患者姓名不能为空', trigger: 'blur' }],
          gender: [{ required: true, message: '患者性别不能为空', trigger: 'change' }],
          id_card: [{ required: true, message: '证件号码不能为空', trigger: 'blur' }],
          doctor: [{ required: true, message: '请选择医生', trigger: 'blur' }],
          department: [{ required: true, message: '请填写科室', trigger: 'blur' }],
          age: [{ required: true, message: '患者年龄不能为空', trigger: 'blur' }],
          birthday: [{ required: true, message: '患者出生日期不能为空', trigger: 'blur' }],
          certificates: [{ required: true, message: '证件类型不能为空', trigger: 'change' }],
          id_card_type: [{ required: true, message: '读卡类型不能为空', trigger: 'change' }],
          p_type: [{ required: true, message: '处方类型不能为空', trigger: 'change' }],
          // sick_type: [{ required: true, message: '大病类别不能为空', trigger: 'change' }],
          // diagnosis: [{ required: true, message: '诊断不能为空', trigger: 'change' }]
        },
        visibility: false,
        labelPosition: 'right',
        isClose: false,
        resetForm: {
          settlement_value: '',
          medical_insurance_card: '',
          name: '',
          gender: '',
          certificates: '',
          id_card_type: '',
          medical_care: '',
          birthday: '',
          age: '',
          id_card: '',
          register: '',
          doctor: '',
          department: '',
          registration_fee: '',
          medical_expenses: '',
          cost: '',
          phone: '',
          social_type: ''
        }

      }
    },
    props: {
      departments: {
        type: Array
      },
      doctors: {
        type: Array
      },
      titles: {
        type: String,
        default: ''
      },
      formValue: {
        type: Object
      },
      type: {
        type: Number,
        default: 1

      },
      isCreated: {
        type: Number,
        default: 1

      },
      sick: Array,
      diagnoses: Array
    },
    methods: {
      check11(){

        if(this.form.social_type == 0 || this.form.social_type == ''){
          this.$message.error("社保类型不能为空")
          return
        }
        var that = this
        let params={
          id_card_no: this.form.id_card_no,
          admin_user_id:this.$store.getters.xt_user.user.id,
          med_type: 11,
          insutype: this.form.social_type
        }
        axios.get('http://127.0.0.1:9532/api/treatment/check', {
          params: params,
          headers: {
            'Permission': 5
          }
        })
          .then(function(response) {
            if (response.data.state == 0) {
              that.$message.error(response.data.msg)
              that.loadingone = false
              return false
            } else {
              that.loadingone = false
              if (response.data.data.failed_code == -10) {
                // that.$message.error(response.data.data.msg)
                that.$confirm(response.data.data.msg, '医保错误信息', {
                  confirmButtonText: '确 定',
                  type: 'warning'
                }).then(() => {


                }).catch(() => {
                })
              } else {
                var result_desc = '';
                result_desc = response.data.data.msg
                that.$alert(result_desc, '结果', {
                  confirmButtonText: '确定',
                  callback: action => {
                    this.dialogFormVisible = false
                  }
                });
              }
            }
          })
          .catch(function(error) {
          })
      },
      check14(){
        if(this.form.social_type == 0 || this.form.social_type == ''){
          this.$message.error("社保类型不能为空")
          return
        }
        var that = this
        let params={
          id_card_no: this.form.id_card_no,
          admin_user_id:this.$store.getters.xt_user.user.id,
          med_type: "14",
          insutype: this.form.social_type
        }
        axios.get('http://127.0.0.1:9532/api/treatment/check', {
          params: params,
          headers: {
            'Permission': 5
          }
        })
          .then(function(response) {
            if (response.data.state == 0) {
              that.$message.error(response.data.msg)
              that.loadingone = false
              return false
            } else {
              that.loadingone = false
              if (response.data.data.failed_code == -10) {
                // that.$message.error(response.data.data.msg)
                that.$confirm(response.data.data.msg, '医保错误信息', {
                  confirmButtonText: '确 定',
                  type: 'warning'
                }).then(() => {


                }).catch(() => {
                })
              } else {
                var result_desc = '';
                result_desc = response.data.data.msg
                that.$alert(result_desc, '结果', {
                  confirmButtonText: '确定',
                  callback: action => {
                    this.dialogFormVisible = false
                  }
                });
              }
            }
          })
          .catch(function(error) {

          })

      },
      changeDoctor() {
        for (let i = 0; i < this.doctors.length; i++) {
          if (this.doctors[i].admin_user_id == this.form.doctor) {
            console.log(this.doctors[i].department_id)
            this.form.department = this.doctors[i].department_id
            if (this.form.department == 0) {

              this.form.department = ''
            }
          }
        }
      },
      handleSelect(val) {
        this.form.id = val.id
        this.form.name = val.name
        this.form.gender = val.gender
        this.form.birthday = uParseTime(val.birthday, '{y}-{m}-{d}')
        this.form.phone = val.phone
        this.form.id_card = val.id_card_no
        var thisLen = this.form.id_card.length
        var birth = ''
        if (thisLen == 15) {
          birth = '19' + this.form.id_card.substr(6, 6)
        } else {
          birth = this.form.id_card.substr(6, 8)
        }
        var births =
          birth.substr(0, 4) +
          '-' +
          birth.substr(4, 2) +
          '-' +
          birth.substr(6, 2)
        this.form.age = jsGetAge(births, '-')


        this.InsuplcAdmdvs = []
        var that = this
        let params={
          id_card_no: this.form.id_card,
          admin_user_id:this.$store.getters.xt_user.user.id,

        }
        axios.get('http://127.0.0.1:9532/zh/api/patient/info', {
          params: params,
          headers: {
            'Permission': 5
          }
        })
            .then(function(response) {
              if (response.data.state == 0) {
                that.$message.error(response.data.msg)
                that.loadingone = false
                return false
              } else {
                that.loadingone = false
                if (response.data.data.failed_code == -10) {
                  // that.$message.error(response.data.data.msg)
                  that.$confirm(response.data.data.msg, '医保错误信息', {
                    confirmButtonText: '确 定',
                    type: 'warning'
                  }).then(() => {

                  }).catch(() => {
                  })
                } else {

                  for(let i =0; i < response.data.data.info.output.insuinfo.length; i++){
                    that.InsuplcAdmdvs.push({
                      value:response.data.data.info.output.insuinfo[i].insuplc_admdvs,
                      label:response.data.data.info.output.insuinfo[i].insuplc_admdvs,
                    })

                  }


                  that.form.social_type = parseInt(response.data.data.insutype)
                }
              }
            })
            .catch(function(error) {

            })

      },
      querySearchAsync(keyword, cb) {
        let key = ''
        if (keyword != undefined) {
          key = keyword
        }
        let searchArray = []
        PostSearch(key).then(response => {
          if (response.data.state == 1) {
            searchArray = response.data.data.patient
            cb(searchArray)
          } else {
            cb([])
          }
        })
      },
      reading() {
        var that = this
        if (this.form.id_card_type.length == 0 || this.form.id_card_type == 0) {
          this.$message.error('请先选择读卡类型')
          return
        }
        let params = {
          'id_card_type': this.form.id_card_type,
          'admin_user_id': this.$store.getters.xt_user.user.id,
          'certificates':this.form.certificates,
        }

        if ((this.$store.getters.xt_user.org_id == 10387 && this.form.id_card_type ==  4) || (this.$store.getters.xt_user.org_id == 4 && this.form.id_card_type ==  4)) {
          try {
            //检测当前浏览器是否支持websocket模式
            window.WebSocket = window.WebSocket || window.MozWebSocket;
            if (!window.WebSocket){
              alert("WebSocket not supported by this browser");
              return;
            }
            this.ws = new WebSocket("ws://127.0.0.1:8899");//连接服务器
            var that = this
            this.ws.onopen = function(event){
              if (that.$store.getters.xt_user.org_id == 10387){
                that.ws.send("{\"url\":\"http://10.93.33.243:20001/localcfc/api/hsecfc/localQrCodeQuery\",\"indata\":{\"data\":{\"businessType\":\"01101\",\"deviceType\":\"\",\"officeId\":\"32760\",\"officeName\":\"肾内科\",\"operatorId\":\"admin\",\"operatorName\":\"罗佳菊\",\"orgId\":\"H43082200408\"},\"orgId\":\"H43082200408\",\"transType\":\"ec.query\"}}");
              }else if(that.$store.getters.xt_user.org_id == 10318){
                that.ws.send("{\"url\":\"http://igb.hsa.gdgov.cn/prd_nation_eccode/prd_eccode/localcfc/api/hsecfc/localQrCodeQuery\",\"indata\":{\"data\":{\"businessType\":\"01101\",\"deviceType\":\"\",\"officeId\":\"32760\",\"officeName\":\"肾内科\",\"operatorId\":\"admin\",\"operatorName\":\"邹刘阳\",\"orgId\":\"H44011701749\"},\"orgId\":\"H44011701749\",\"transType\":\"ec.query\"}}");
              }else if(that.$store.getters.xt_user.org_id == 4){
                that.ws.send("{\"url\":\"http://igb.hsa.gdgov.cn/prd_nation_eccode/prd_eccode/localcfc/api/hsecfc/localQrCodeQuery\",\"indata\":{\"data\":{\"businessType\":\"01101\",\"deviceType\":\"\",\"officeId\":\"32760\",\"officeName\":\"肾内科\",\"operatorId\":\"admin\",\"operatorName\":\"邹刘阳\",\"orgId\":\"H44011701749\"},\"orgId\":\"H44011701749\",\"transType\":\"ec.query\"}}");
              }
            };

            this.ws.onmessage = function(event){
              // alert("接收到服务器发送的数据：\r\n"+event.data);
              var newParams =  JSON.parse(event.data)
              console.log(newParams)
              console.log(newParams.data)
              console.log(newParams.data)
              console.log(newParams.data.ecToken)
              console.log(newParams.data.idNo)
              console.log(newParams.data.userName)
              console.log(newParams.data.insuOrg)

              newParams['ecToken'] = newParams.data.ecToken
              newParams['idNo'] = newParams.data.idNo
              newParams['userName'] = newParams.data.userName
              newParams['insuOrg'] = newParams.data.insuOrg

              newParams['id_card_type'] =  that.form.id_card_type
              newParams['admin_user_id'] = that.$store.getters.xt_user.user.id
              newParams['certificates'] = that.form.certificates
              axios.get('http://127.0.0.1:9532/api/readcard', {
                params: newParams
              })
                .then(function(response) {
                  if (response.data.state == 0) {
                    that.$message.error(response.data.msg)
                    return false
                  } else {
                    var patient = response.data.data.patient

                    if (that.form.id_card_type == 1) {
                      that.form.id = patient.id
                      that.form.name = patient.name
                      that.form.gender = patient.gender
                      that.form.age = patient.age
                      that.form.birthday = uParseTime(patient.birthday, '{y}-{m}-{d}')
                      that.form.phone = patient.phone
                      that.form.id_card = patient.id_card_no
                      that.form.medical_insurance_card = response.data.data.number
                      that.form.social_type = parseInt(response.data.data.insutype)


                    } else if (that.form.id_card_type == 2) {
                      that.form.id = patient.id
                      that.form.name = patient.name
                      that.form.gender = patient.gender
                      that.form.age = patient.age
                      that.form.birthday = uParseTime(patient.birthday, '{y}-{m}-{d}')
                      that.form.phone = patient.phone
                      that.form.id_card = patient.id_card_no
                    } else {
                      that.form.id = patient.id
                      that.form.name = patient.name
                      that.form.gender = patient.gender
                      that.form.age = patient.age
                      that.form.birthday = uParseTime(patient.birthday, '{y}-{m}-{d}')
                      that.form.phone = patient.phone
                      that.form.id_card = patient.id_card_no
                      that.form.social_type = parseInt(response.data.data.insutype)
                    }
                    that.$message({ message: '读卡成功', type: 'success' })
                  }
                })
                .catch(function(error) {

                })


            };
            this.ws.onclose = function(event){
              // alert("已经与服务器断开连接\r\n当前连接状态："+this.readyState);
            };
            this.ws.onerror = function(event){
              // if (this.flag!=1)
              // alert("WebSocket接收异常！");
            };
          } catch (ex) {
            alert(ex.message);
          }

        }else{
          axios.get('http://127.0.0.1:9532/api/readcard', {
            params: params
          })
            .then(function(response) {
              if (response.data.state == 0) {
                that.$message.error(response.data.msg)
                return false
              } else {
                var patient = response.data.data.patient

                if (that.form.id_card_type == 1) {
                  that.form.id = patient.id
                  that.form.name = patient.name
                  that.form.gender = patient.gender
                  that.form.age = patient.age
                  that.form.birthday = uParseTime(patient.birthday, '{y}-{m}-{d}')
                  that.form.phone = patient.phone
                  that.form.id_card = patient.id_card_no
                  that.form.medical_insurance_card = response.data.data.number
                  that.form.social_type = parseInt(response.data.data.insutype)


                } else if (that.form.id_card_type == 2) {
                  that.form.id = patient.id
                  that.form.name = patient.name
                  that.form.gender = patient.gender
                  that.form.age = patient.age
                  that.form.birthday = uParseTime(patient.birthday, '{y}-{m}-{d}')
                  that.form.phone = patient.phone
                  that.form.id_card = patient.id_card_no
                } else {
                  that.form.id = patient.id
                  that.form.name = patient.name
                  that.form.gender = patient.gender
                  that.form.age = patient.age
                  that.form.birthday = uParseTime(patient.birthday, '{y}-{m}-{d}')
                  that.form.phone = patient.phone
                  that.form.id_card = patient.id_card_no
                  that.form.social_type = parseInt(response.data.data.insutype)

                }
                that.$message({ message: '读卡成功', type: 'success' })
              }
            })
            .catch(function(error) {

            })
        }
      },
      // reading() {
      //   var that = this
      //   if (this.form.id_card_type.length == 0 || this.form.id_card_type == 0) {
      //     this.$message.error('请先选择读卡类型')
      //     return
      //   }
      //   let params = {
      //     'id_card_type': this.form.id_card_type,
      //     'admin_user_id': this.$store.getters.xt_user.user.id,
      //     'certificates':this.form.certificates,
      //   }
      //   axios.defaults.retry = 0
      //
      //   if(this.$store.getters.xt_user.org_id == 10387){
      //
      //     // 创建WebSocket实例并指定服务器地址
      //     this.socket = new WebSocket("ws://localhost:8899");
      //
      //     // 监听WebSocket事件
      //     this.socket.onopen = () => {
      //       console.log("WebSocket连接已建立");
      //     };
      //
      //     this.socket.onmessage = (event) => {
      //       console.log("收到消息:", event.data);
      //     };
      //
      //     this.socket.onclose = () => {
      //       console.log("WebSocket连接已关闭");
      //     };
      //   }
      //
      //
      //   axios.get('http://127.0.0.1:9532/api/readcard', {
      //     params: params
      //   })
      //     .then(function(response) {
      //       if (response.data.state == 0) {
      //         that.$message.error(response.data.msg)
      //         return false
      //       } else {
      //         var patient = response.data.data.patient
      //
      //         if (that.form.id_card_type == 1) {
      //           that.form.id = patient.id
      //           that.form.name = patient.name
      //           that.form.gender = patient.gender
      //           that.form.age = patient.age
      //           that.form.birthday = uParseTime(patient.birthday, '{y}-{m}-{d}')
      //           that.form.phone = patient.phone
      //           that.form.id_card = patient.id_card_no
      //           that.form.medical_insurance_card = response.data.data.number
      //           that.form.social_type = parseInt(response.data.data.insutype)
      //
      //
      //         } else if (that.form.id_card_type == 2) {
      //           that.form.id = patient.id
      //           that.form.name = patient.name
      //           that.form.gender = patient.gender
      //           that.form.age = patient.age
      //           that.form.birthday = uParseTime(patient.birthday, '{y}-{m}-{d}')
      //           that.form.phone = patient.phone
      //           that.form.id_card = patient.id_card_no
      //         } else {
      //           that.form.id = patient.id
      //           that.form.name = patient.name
      //           that.form.gender = patient.gender
      //           that.form.age = patient.age
      //           that.form.birthday = uParseTime(patient.birthday, '{y}-{m}-{d}')
      //           that.form.phone = patient.phone
      //           that.form.id_card = patient.id_card_no
      //           that.form.social_type = parseInt(response.data.data.insutype)
      //
      //         }
      //         that.$message({ message: '读卡成功', type: 'success' })
      //       }
      //     })
      //     .catch(function(error) {
      //
      //     })
      // },
      getDictionaryDataConfig(module, filed_name) {
        return getDictionaryDataConfig(module, filed_name)
      },
      show: function(doctors,departments) {
        this.visibility = true
        // this.form = Object.assign({}, this.resetForm)
        this.form.id = 0
        this.form.settlement_value = 1
        this.form.medical_insurance_card = ''
        this.form.name = ''
        this.form.gender = ''
        this.form.mdtrt_type=''
        this.form.medical_care = ''
        this.form.birthda = ''
        this.form.age = ''
        this.form.id_card = ''
        this.form.register = ''
        this.form.doctor = ''
        this.form.department = ''
        this.form.registration_fee = ''
        this.form.medical_expenses = ''
        this.form.cost = ''
        this.form.phone = ''
        this.form.social_type = ''
        this.form.insuplc_admdvs =''

        this.form.p_type = 14
        this.form.sick_type = this.sick[0].id
        this.form.diagnosis = this.diagnoses[0].id
        this.form.id_card_type = 2
        this.form.certificates = 1
        if (this.$store.getters.xt_user.org_id == 10188  || this.$store.getters.xt_user.org_id == 10217 || this.$store.getters.xt_user.org_id == 10191){
          this.form.id_card_type = 1
        }
        if (departments.length > 0) {
          this.form.department = departments[0].id
        }
        if (doctors.length > 0) {
          this.form.doctor = doctors[0].admin_user_id
        }

        // this.form.name = patientInfo.name
        // this.form.gender = patientInfo.gender
        // this.form.age = patientInfo.age
        // this.form.birthday = patientInfo.birthday
        // this.form.phone = patientInfo.phone
        // this.form.birthday = patientInfo.birthday
        // this.form.id_card = patientInfo.id_card_no
        // this.form.social_type = patientInfo.health_care_type
        // if( this.form.social_type == 0){
        //   this.form.social_type = ""
        // }

      },

      hide: function () {
        this.visibility = false
        this.$refs['formValue'].resetFields()
      }, cancel: function(formName) {
        this.$emit('cancel', this.getValue())
        this.$refs['formValue'].resetFields()
      },
      confirm: function(formName) {
        this.$refs['formValue'].validate((valid) => {
          if (valid) {
            let value = {}
            value = this.getValue()
            this.$emit('confirm', value)
          }
        })
      },
      getValue: function() {
        let form = {}
        form = this.form
        return form
      }
    }

  }
</script>

<style lang="scss" scoped>
  .registerDialog {

  .el-form {
    display: flex;
    flex-wrap: wrap;
  }

  .el-form-item {
    width: 50%;
  }

  }
</style>
