<template>
  <div class="app-container">
      <el-form ref="form" :model="form"  label-width="180px">
        
        <el-form-item label="所在单位" prop="deptName" >
          <el-input v-model="form.deptName" placeholder="请输入单位名称" />
        </el-form-item>
        <el-form-item label="姓名" prop="name" >
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="gender" >
          <el-select v-model="form.gender" placeholder="请选择">
            <el-option
              v-for="item in genderList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="身份证号" prop="idcard" >
          <el-input v-model="form.idcard" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="联系方式" prop="phone" >
          <el-input v-model="form.phone" placeholder="请输入手机号码" />
        </el-form-item>

        <el-divider ></el-divider>
        <el-form-item label="入住医院全称" prop="inHospitalName" >
          <el-input v-model="form.inHospitalName" placeholder="请输入入住医院全称" />
        </el-form-item>
        <el-form-item label="住院日期" prop="inHospitalTime" >
          <el-date-picker
          type="datetime"
            v-model="form.inHospitalTime"
            style="width: 240px"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            placeholder="请选择"
          ></el-date-picker>
        
        </el-form-item>
        <el-form-item label="所患疾病" prop="diseaseCode" >
          <el-select v-model="form.diseaseCode" placeholder="请选择">
            <el-option
              v-for="item in approveStatusList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-divider ></el-divider>
        
        <el-form-item label="会员住院慰问申请表" prop="content" >
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="会员住院慰问金汇总申请表" prop="content" >
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="基层工会慰问申请表" prop="content" >
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="工会会员在职证明" prop="content" >
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="公示" prop="content" >
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="身份证复印件" prop="content" >
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="工会会员卡复印件" prop="content" >
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="住院病案首页复印件" prop="content" >
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="诊断证明复印件" prop="content" >
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="工伤证明（仅限工伤非必填）" prop="content" >
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="手术记录（仅限部分疾病非必填）" prop="content" >
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
      </el-form>
      
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
    
    
  </div>
</template>

<script>
import { list, getConfig, del, add, saveOrUpdate, refreshCache, sendEmail, doApprove } from "@/api/business/inhospital";

export default {
  name: "Config",
  dicts: ['sys_yes_no','sys_normal_disable'],
  props: {
    form: {
      type: Object
    }
  },
  data() {
    return {
      dialogVisible: false,
      dialogImageUrl: '',
      approveStatusList:[{
        label: '待审批',
        value: 0
      },{
        label: '审批中',
        value: 3
      },{
        label: '已审批',
        value: 1
      }],
      genderList:[{
        label: '男',
        value: 0
      },{
        label: '女',
        value: 1
      },{
        label: '未知',
        value: 3
      }]
    };
  },
  created() {
  },
  methods: {
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    changeShifouInhospital(val){
      if(val == 'Y'){

      }else{
        this.$alert('因不符合重病住院关爱慰问要求，未住院会员无法申报此项慰问金', '说明', {
          confirmButtonText: '确定',
          callback: action => {
            
          }
        });
      }
    },
    handleSubmitApply(){
      this.open = true;
      this.$alert('对符合慰问条件，患本办法规定范围内的38种指定重大疾病且每年首次住院的工会会员，给予一次性2000元慰问金，对每年首次因其他疾病住院的工会会员给予500元慰问金。', '说明', {
          confirmButtonText: '确定',
          callback: action => {
            
          }
        });
    },
    /** 查询参数列表 */
    getList() {
      this.loading = true;
      if(this.queryParams.approveStatus == 0){
        this.queryParams. type = 'approve'
      }else{
        this.queryParams. type = 'apply'
      }
      list(this.queryParams).then(response => {
          this.configList = response.records;
          
          this.total = response.total;
          this.loading = false;
        }
        );
      
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        docId: undefined,
        title: undefined,
        
        url: undefined,
        content: undefined,
        // isTop: '0', 
        // orderNum: '0'
      };
      this.resetForm("form");
    },
    handleGetApplyTpl(){
      this.openApplyTpl = true;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加文章";
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.configId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const configId = row.docId
      // getDetail(configId).then(response => {
        // this.form = response.data;
        this.form  = row;
        this.open = true;
        this.title = "修改文章";
      // });
    },
    
    handleLook(row){
      this.drawer = true;
      this.form =row;
      
    },
    submitFormApplyTpl(){
      this.$refs["formApplyTpl"].validate(valid => {
        if (valid) {
          if (this.form.docId != undefined) {
            sendEmail({
              toEmail:this.formApplyTpl.email,
              moduleCode: 'zyww' //住院慰问
            }).then(response => {
              this.$modal.msgSuccess(response.data);
              this.openApplyTpl = false;
              // this.getList();
            });
      
            
          }
        }
      });
    },
    cancelApplyTpl(){
      this.openApplyTpl = false;
      this.formApplyTpl.docId = null;
      this.formApplyTpl.email = null;
    },
    /** 提交按钮 */
    submitForm: function() {
      let that = this;
      this.$refs["form"].validate(valid => {
        if (valid) {
          saveOrUpdate(this.form).then(response => {
            if(response.data){
              this.$modal.msgSuccess(that.form.applyFormId ? "修改成功":"新增成功");
              this.open = false;
              this.getList();
            }else{
              this.$modal.msgSuccess(that.form.applyFormId ? "修改失败":"新增失败");
            }
              
            });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      // const configIds = row.id || this.ids;
      this.$modal.confirm('是否确认删除该条记录？').then(function() {
          return del({
            docId: row.docId
          });
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/config/export', {
        ...this.queryParams
      }, `config_${new Date().getTime()}.xlsx`)
    },
    /** 刷新缓存按钮操作 */
    handleRefreshCache() {
      refreshCache().then(() => {
        this.$modal.msgSuccess("刷新成功");
      });
    },
    approve(row){
      let that = this;
      this.$confirm('请确认该条信息是否通过审核?', '提示', {
        distinguishCancelAndClose: true,
        confirmButtonText: '通过',
        cancelButtonText: '不通过',
      }).then(() => {
        doApprove({
          applyFormId: row.applyFormId,
          optFlag:1
        }).then(res=>{
          this.$modal.msgSuccess(res.data);
        })
      }).catch(action  => {
        if(action == 'cancel'){
          doApprove({
            applyFormId: row.applyFormId,
            optFlag:2
          }).then(res=>{
            this.$modal.msgSuccess(res.data);
          })
        }
        
      })
      
    }
  }
};
</script>
