<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="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="money">
        <el-input v-model="form.money" ></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input type="textarea" v-model="form.remarks"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {
  getdepositcode,
  gethisusertoalive,
  adddeposit
}from "@/api/deposit";
export default {
  data() {
    return {
      form: {
        remarks:"",
        code:"",
        patient_name:"",
        money:"",
      },
      users:[],//可用患者列表
      trial_status:0,
      //表单验证规则
      rules: {
        patient_name:[{
          required:true,message:"患者姓名不能为空",trigger: "change"
        }],
        money:[{
          required:true,message:"押金金额不能为空",trigger: "change"
        }],
      },
    };
  },
  created(){
    // this.getusername()
  },
  methods:{
    getcode(){
      var params = {}
      getdepositcode(params).then((res) => {
        if(res.data.state == 1){
          this.form.code = res.data.data.list;
        }
      })
    },
    //获取患者列表
    getusername(){
      var params = {};
      gethisusertoalive(params).then((res) =>{
        if (res.data.state == 1){
          this.users = res.data.data.list;
        }
      })
    },
    //提交
    subfrom(){
      // console.log("========")
      // this.$parent.$parent.pli();
      // console.log("子组件",this.$parent.$parent)
      // console.log("========")
      var params = {
        code: this.form.code,
        his_patient_id: this.form.patient_name,
        deposit: this.form.money,
        remarks: this.form.remarks,
        trial_status: this.trial_status,
      }
      adddeposit(params).then((res) =>{
        if (res.data.state == 1){
          this.$message.success("添加成功");
          // this.closePop();
          this.$parent.$parent.pli();
          this.$parent.$parent.search();
        }else {
          this.$message.error("新增失败：" + res.data.msg);
        }

      })
    },
    handleSelect(item){
      this.form.patient_name = item.id
    },
    //审核通过
    examine(){
      this.trial_status = 1
    },
    //清除表单数据
    closePop(){
      // alert("清除");
      this.form.patient_name = "";
      this.form.remarks = "";
      this.form.money = "";
      this.trial_status = 0;
    },
  },
};
</script>

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

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