<template>
  <div class="white_bg burt-container">
    <a-form-model ref="form" layout="vertical" :model="form">
      <a-row :gutter="30">
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="客户信息">
            <a-input v-model="form.patientNo" placeholder="请输入客户信息" allow-clear />
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="客户姓名">
            <a-input v-model="form.patientNo" placeholder="请输入客户姓名" allow-clear />
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="出生日期">
            <a-date-picker allow-clear v-model="form.firstEnrollmentTime" placeholder="请选择出生日期" value-format="YYYY-MM-DD 00:00:00" />
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="保险公司">
            <a-select v-model="form.payorCode" placeholder="请选择保险公司" allowClear>
              <a-select-option v-for="item in companyOptions" :key="item.id" :value="item.payorCode">
                {{ item.longName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="保单号码">
            <a-input v-model="form.patientNo" placeholder="请输入保单号码" allow-clear />
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="主治医生">
            <a-select v-model="form.payorCode" placeholder="请选择主治医生" allowClear>
              <a-select-option v-for="item in companyOptions" :key="item.id" :value="item.payorCode">
                {{ item.longName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="预授权项目">
            <a-select v-model="form.authProject" placeholder="请选择预授权项目" allowClear>
              <a-select-option v-for="(item) in ProjectList" :key="item.id" :value="item.descCh">{{item.descCh}}</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="预计治疗时间">
            <a-date-picker allow-clear v-model="form.firstEnrollmentTime" placeholder="请选择预计治疗时间" value-format="YYYY-MM-DD 00:00:00" />
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="预计治疗费用">
            <div class="flex input-div">
              <a-input v-model="form.patientNo" placeholder="请输入费用" type="number" />
              <a-select v-model="form.authProject" style="width:85px;">
                <a-select-option v-for="(item) in MoneyUnitOptions" :key="item.value" :value="item.value">{{item.name}}</a-select-option>
              </a-select>
            </div>
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="初诊日期">
            <a-date-picker allow-clear v-model="form.firstEnrollmentTime" placeholder="请选择初诊日期" value-format="YYYY-MM-DD 00:00:00" />
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="治疗目的">
            <a-select v-model="form.authProject" placeholder="请选择治疗目的">
              <a-select-option value="1">疾病</a-select-option>
              <a-select-option value="2">事故</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="治疗方案">
            <a-select v-model="form.authProject" placeholder="请选择治疗方案">
              <a-select-option value="1">疾病</a-select-option>
              <a-select-option value="2">事故</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="诊断">
            <a-input v-model="form.patientNo" placeholder="请输入诊断" allow-clear />
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="病历资料">
            <a-upload name="file" :multiple="false" :showUploadList="true"
              :fileList="form.bingli"
              :customRequest="(file)=>uploadFile(file, 1)"
              :beforeUpload="beforeUpload"
              :remove="(file)=>removeFile(file, 1)">
              <a-button type="primary"> <Icon name="ssiupload" :size="18" />上传病历 </a-button>
            </a-upload>
          </a-form-model-item>
        </a-col>
      </a-row>
      <!--费用明细-->
      <a-row>
        <FeeDetail :ProjectList="ProjectList" />
      </a-row>
      <a-row :gutter="30" class="footer-body">
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="申请状态">
            <a-select v-model="form.authProject" placeholder="请选择申请状态">
              <a-select-option v-for="(item) in ApplyStatusOptions" :key="item.value" :value="item.value">{{item.name}}</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="批准次数/金额">
            <a-input v-model="form.patientNo" placeholder="请输入批准次数/金额" allow-clear />
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="拒绝原因">
            <a-select v-model="form.authProject" placeholder="请选择拒绝原因">
              <a-select-option v-for="(item,i) in ProjectList" :key="i" :value="item.refcd">{{item.descCh}}</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :lg="6" :sm="12">
          <a-form-model-item label="补充材料">
            <a-upload name="file" :multiple="false" :showUploadList="true"
              :fileList="form.supplementalResultUrl"
              :customRequest="(file)=>uploadFile(file, 2)"
              :remove="(file)=>removeFile(file, 2)">
              <a-button type="primary"> <Icon name="ssiupload" :size="18" />上传材料</a-button>
            </a-upload>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :lg="24" :sm="12" class="none-label">
          <a-form-model-item label="button">
            <a-button type="primary" @click="saveEvt">
              <Icon name="ssibaocun" :size="14" />保存
            </a-button>
            </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
  </div>
</template>

<script>
import {MoneyUnitOptions,ApplyStatusOptions} from '@/utils/utilsdictOptions';
import FeeDetail from './components/feeDetail.vue';
export default{
  data(){
    return{
      MoneyUnitOptions,
      ApplyStatusOptions,
      form: {
        bingli: [],
        supplementalResultUrl: [], //补充材料
      },
      companyOptions: [],  //保险公司
      ProjectList: [], //预授权项目
      rejectReason: [], //拒绝原因
    }
  },
  components: {
    FeeDetail,
  },
  created(){
    this._getCompanyOptions();
    this.getRefcdByRefgrp();
  },
  methods: {
    // 获取保险公司下拉选项
    _getCompanyOptions() {
      this.$apis.GETCOMPANYOPTIONS().then((res) => {
        this.companyOptions = res.content || [];
      });
    },
    // 获取码表
    getRefcdByRefgrp() {
      //预授权项目
      this.$apis.GETREFCDBYREFGRP({
        modid: "CI",
        refgrp: "AUTH_PROJECT"
      }).then((res) => {
        this.ProjectList = res.content || [];
      });
      //拒绝原因
      this.$apis.GETREFCDBYREFGRP({
        modid: "CI",
        refgrp: "REJECT_REASON"
      }).then((res) => {
        this.rejectReason = res.content || [];
      });
    },
    //上传之前
    beforeUpload(){
      if(this.form.bingli.length >= 5){
        this.$message.warning('不能超过5个文件');
        return false;
      }
      return true;
    },
    /**删除文件
     * type  1:上传病历  2:补充材料
     * **/
    removeFile(file, type){
      if(type == 2){
        this.form.supplementalResultUrl = [];
      }else{
        let index;
        this.form.bingli.forEach((item, i) => {
          if (item.uid == file.uid) {
            index = i;
          }
        });
        this.form.bingli.splice(index, 1);
      }
      return true;
    },
    /**上传文件
     * type  1:上传病历  2:补充材料
     * **/
    uploadFile(fileData, type){
      let formData = new FormData();
      formData.append("file", fileData.file);
      this.$apis.UPLOADIMG(formData)
      .then((res)=>{
        fileData.onSuccess();
        let tmp =  {
          uid: Math.random()*10000,
          name: res.title,
          status: 'done',
          url: res.url,
        }
        if(type==2){
          this.form.supplementalResultUrl = [tmp];
        }else{
          this.form.bingli.push(tmp);
        }
        this.$forceUpdate();
      })
    },
    //保存
    saveEvt(){
      
    }
  }
}
</script>

<style lang="less" scoped>
.footer-body{
  margin-top: 25px;
}
</style>