<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="申请编号">
        <span>{{form.code}}</span>
      </el-form-item>
      <el-form-item label="患者名称" prop="patient_name">
        <!--        <el-input v-model="form.patient_name"></el-input>-->
        <el-select v-model="form.patient_name" clearable filterable placeholder="请输入患者名称" @select="handleSelect" @change="updateconfig"><!--@change="updateconfig1(h1)"-->
          <el-option
            v-for="item in users"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="押金余额" prop="decote">
        <span>{{decote}}</span>
      </el-form-item>
      <el-form-item label="退款金额" prop="money">
        <el-input v-model="form.money"></el-input>元
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {
  gethisuser,
  idtobalance,
  changerefund
}from "@/api/deposit";
export default {
  data() {
    return {
      id:"",
      form: {
        remarks:"",
        code:"",//编号
        patient_name:"",//患者名称
        money:0//退款金额
      },
      users:[],//可用患者列表
      trial_status:0,//审核
      decote:0,//押金余额
      rules: {
        patient_name:[{
          required:true,message:"患者姓名不能为空",trigger: "change"
        }],
        money:[{
          required:true,message:"退款金额不能为空",trigger: "change"
        }],
      },
    };
  },
  methods:{
    //获取信息
    getinformation(data,type){
      this.form.code = data.deposit_code;
      this.form.patient_name = data.his_patient_id;
      this.form.money = data.deposit;
      this.trial_status = data.trial_status,
      this.id = data.id;
    },
    //获取患者列表
    getusername(){
      console.log("decote获取患者列表",this.decote)
      var params = {};
      gethisuser(params).then((res) =>{
        if (res.data.state == 1){
          this.users = res.data.data.list;
        }
      })
    },
    //获取用户押金余额
    updateconfig(){
      console.log("this.name",this.form.patient_name);
      var params = {
        his_patient_id: this.form.patient_name,
      }
      idtobalance(params).then((res) => {
        if (res.data.state == 1){
          this.decote = res.data.data.list;
        }
      })
    },
    handleSelect(item){
      this.form.patient_name = item.id;

    },

    //提交
    subfrom(){
      var params = {
        id: this.id,
        code: this.form.code,
        his_patient_id: this.form.patient_name,
        deposit: this.form.money,
        trial_status: this.trial_status,
      }
      changerefund(params).then((res) =>{
        if (res.data.state == 1){
          this.$message.success("保存成功");
          // this.closePop();
          this.$parent.$parent.pli02();
          this.$parent.$parent.search();
        }else {
          this.$message.error("保存失败：" + res.data.msg);
        }
      })
    },
    //审核通过
    examine(){
      if(this.trial_status == 1){
        // alert("已审核")
        this.$message.success("已审核");
      }
      this.trial_status = 1

    },
    //清除表单数据
    closePop(){
      // alert("清除");
      this.form.patient_name = "";
      this.form.remarks = "";
      this.form.money = 0;
      this.trial_status = 0;
      this.decote = 0;
    },
  }
};
</script>

<style scoped>
.el-input{
  width: 50%;
}

.el-textarea{
  width: 65%;
}
</style>
