<template>
  <!-- 随访审核 -->
  <div id="audit-detail">
    <div class="audit-detail_header p-24">
      <div class="left">
        <span>当前审核</span>
        <span class="f-b">【{{medicalCombination}}】【剩余{{mcCount}}】</span>
      </div>
      <div class="right">
        <el-button class="btn" @click="$router.go(-1)">返回</el-button>
      </div>
    </div>
    <div class="table-content p-24">
      <!-- <component :is="curComponent" :formEdit="formEdit"></component> -->
      <follow-review :form="formEdit"></follow-review>
    </div>
    <div class="choose-handle p-24">
      <span v-if="!editStatus">请选择审核结果:</span>
      <div class="btn_group">
        <el-button
          v-for="(item, index) in btnGroup"
          :key="index"
          type="primary"
          class="p-btn"
          size="medium"
          @click="showDialog(item.value)"
        >{{ item.text }}</el-button>
        <span v-if="editStatus" class="op">驳回修改建议:胃镜图片不合规</span>
      </div>
    </div>
    <public-dialog ref="editDialog" @onSubmit="onSubmit" @onCancel="onCancel">
      <!-- 修改审核结果 优先触发提示 -->
      <template v-if="!confirmStatus" slot="content">
        <div class="title">温馨提示</div>
        <div class="content">
          <div class="showTips">
            该病例已经审核【驳回修改】，需要改为{{
            btnGroup[curBtn - 1] ? btnGroup[curBtn - 1].text : ""
            }}吗
          </div>
        </div>
        <div class="btn">
          <el-button type="primary" :loading="loading" @click="onCancel">否</el-button>
          <el-button type="primary" :loading="loading" @click="editSubmit">是</el-button>
        </div>
      </template>
    </public-dialog>
    <public-dialog ref="publicDialog" @onSubmit="onSubmit" @onCancel="onCancel">
      <!-- 审核结果回显 -->
      <template v-if="!confirmStatus" slot="content">
        <div class="title">{{ btnGroup[curBtn - 1] ? btnGroup[curBtn - 1].text : "" }}</div>
        <div class="content">
          <div v-if="curBtn != 1" class="noPass">
            <el-form
              ref="form"
              label-position="top"
              :model="form"
              :rules="rules"
              label-width="100px"
              class="demo-ruleForm"
            >
              <el-form-item :label="curBtn == 2 ? '不合格原因' : '驳回修改建议'" prop="reson">
                <el-input
                  v-model="form.reson"
                  type="textarea"
                  :placeholder="
                    curBtn == 2 ? '请填写不合格原因' : '请填写驳回修改建议'
                  "
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="btn">
          <el-button type="primary" :loading="loading" @click="onSubmit">确 定</el-button>
        </div>
      </template>
      <!-- 提交后结果 -->
      <template v-if="confirmStatus" slot="content">
        <div class="title">{{ btnGroup[curBtn - 1].text }}</div>
        <div class="content">
          <div v-if="curBtn == 1" class="pass">该病例审核合格成功！</div>
          <div v-if="curBtn != 1" class="noPass">
            <!-- 不合格和驳回 -->
            <div class="label">{{ curBtn == 2 ? "不合格原因" : "驳回修改建议" }}</div>
            <div class="reson">{{ form.reson }}</div>
          </div>
        </div>
        <div v-if="curBtn != 1" class="showTips">该病例审核{{ curBtn == 2 ? "不合格原因" : "驳回修改建议" }}提交成功！</div>
        <div class="btn">
          <el-button type="primary" @click="nextExample">下一例</el-button>
        </div>
      </template>
    </public-dialog>
  </div>
</template>
<script>
import publicDialog from "./components/publicDialog.vue"
import followReview from "./components/followReview.vue"
import { getFollowUnCheckDetail } from "@/api/followup"
export default {
  components: { publicDialog, followReview },
  data() {
    return {
      medicalCombination:'无锡市人民医院医联体',
      mcCount:7,
      editStatus: false, //进入的状态是第一次审核还是修改审核,false为第一次,true为修改
      formEdit:{
        name:"djksh",
        contact_phone:"12345678",
        is_accept:"0",
        gas_exam:"15",
        G_17:"5"
      },//填报数据
      form: {},
      rules: {
        reson: [{ required: true, message: "请填写", trigger: "blur" }],
      },
      btnGroup: [
        {
          text: "合格",
          value: 1,
        },
        {
          text: "不合格",
          value: 2,
        },
        {
          text: "驳回修改",
          value: 3,
        },
      ],
      loading: false,
      curBtn: 0,
      curComponent: "followReview",
      confirmStatus: false,
    }
  },
  watch: {},
  created() {
    this.getDetail()
  },
  computed:{
    unionId(){
      return this.$route.query.id
    }
  },
  methods: {
    showDialog(val) {
      this.curBtn = val
      if (!this.editStatus) {
        if (this.curBtn == 1) {
          // 走接口，保存合格
          this.confirmStatus = true
        } else if (this.curBtn == 2) {
          this.rules.reson[0].message = "请输入不合格原因"
        } else {
          this.rules.reson[0].message = "请输入驳回修改建议"
        }
        this.$refs.publicDialog.dialogVisible = true
      } else {
        this.$refs.editDialog.dialogVisible = true
      }
    },
    onSubmit() {
      this.loading = true
      // 切换文本
      if (this.curBtn != 1) {
        this.$refs.form.validate((valid) => {
          if (valid) {
            // alert("submit!")
            // 保存成功，回显,调用接口

            // 回调
            this.confirmStatus = true
          } else {
            console.log("error submit!!")
            return false
          }
        })
      }

      this.loading = false
      // this.$refs.publicDialog.dialogVisible = true
    },
    onCancel() {
      this.confirmStatus = false
      if (this.curBtn != 1) {
        this.form = {}
      }
      this.$refs.editDialog.dialogVisible = false
      this.$refs.publicDialog.dialogVisible = false
      if (this.$refs.form) {
        this.$refs.form.clearValidate()
      }
    },
    editSubmit() {
      // this.$refs.editDialog.dialogVisible = false
      if (this.curBtn == 1) {
        // 走接口，保存合格
        this.confirmStatus = true
      } else if (this.curBtn == 2) {
        this.rules.reson[0].message = "请输入不合格原因"
      } else {
        this.rules.reson[0].message = "请输入驳回修改建议"
      }
      this.$refs.publicDialog.dialogVisible = true
    },
    nextExample() {
      this.onCancel()
    },
    async getDetail(){
      this.loading = true
      let res = await getFollowUnCheckDetail(this.unionId)
      if(res.code==1){
        this.formEdit=res.data[0]
      }
      this.loading = false
    },
  },
}
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  border-top: none;
  text-align: center;
  .tips {
    font-size: 16px;
  }
}
.p-24 {
  padding: 0 24px;
}
.f-b {
  font-weight: bold;
  font-size: 14px;
}

#audit-detail {
  // padding: 22px 24px;
  .audit-detail_header {
    height: 65px;
    border-bottom: 1px solid #f3f3f3;
    line-height: 65px;
    display: flex;
    justify-content: space-between;
    .right {
      .btn {
        width: 80px;
        height: 32px;
        border-radius: 4px;
      }
    }
  }
  .choose-handle {
    width: 100%;
    height: 72px;
    line-height: 72px;
    font-size: 14px;
    font-family: AlibabaPuHuiTiM;
    color: #333333;
    box-shadow: 0px 1px 0px 0px rgba(0, 0, 0, 0.1);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    .btn_group {
      margin-left: 24px;
      ::v-deep .p-btn {
        width: 100px;
        border-radius: 4px;
      }
    }
  }
}
.title {
  height: 26px;
  font-size: 22px;
  font-family: AlibabaPuHuiTiM;
  color: rgba(0, 0, 0, 0.8);
  line-height: 26px;
}
.content {
  margin: 58px;
  .pass {
    font-size: 18px;
    font-family: AlibabaPuHuiTiM;
    color: #30b9a6;
    letter-spacing: 1px;
  }
}
.btn {
  margin-top: 20px;
  .el-button {
    width: 100px;
    height: 32px;
  }
}
::v-deep .el-form-item__label {
  width: 100%;
  text-align: left;
}
.reson {
  margin-top: 20px;
}
.showTips {
  color: #4e68ff;
}
.op {
  font-size: 14px;
  font-family: AlibabaPuHuiTiR;
  color: #fa6400;
  margin-left: 20px;
}
.table-content {
  padding-top: 20px;
  padding-bottom: 20px;
}
</style>
