<template>
  <div class="code">
    <!-- <div class="code-item flex-vertical-center-l">
            <span>处方签和病历打印：</span>
            <div class="input">
                <el-radio-group v-model="sign.value">
                    <el-radio label="0">是</el-radio>
                    <el-radio label="1">否</el-radio>

                </el-radio-group>
            </div>
    </div>-->
    <div class="code-item flex-vertical-center-l">
      <span>医共体启用：</span>
      <div class="input">
        <el-radio-group v-model="doctorbody.value">
          <el-radio label="0">是</el-radio>
          <el-radio label="1">否</el-radio>
        </el-radio-group>
      </div>
    </div>
    <div class="code-item flex-vertical-center-l">
      <span>药贴计算方式：</span>
      <div class="input">
        <el-select v-model="way.value" placeholder="请选择">
          <el-option label="方式一" value="0"></el-option>
          <el-option label="方式二" value="1"></el-option>
          <el-option label="方式三" value="2"></el-option>
        </el-select>
      </div>
    </div>
    <div class="code-item flex-vertical-center-l">
      <span>审核流程：</span>
      <div class="input">
        <el-radio-group v-model="audit.value">
          <el-radio label="0">开启</el-radio>
          <el-radio label="1">关闭</el-radio>
        </el-radio-group>
      </div>
    </div>
    <div class="code-item flex-vertical-center-l">
      <span>支付流程：</span>
      <div class="input">
        <el-radio-group v-model="pay.value">
          <el-radio label="0">开启</el-radio>
          <el-radio label="1">关闭</el-radio>
        </el-radio-group>
      </div>
    </div>
    <div class="code-item flex-vertical-center-l">
      <span>诊疗首页配置：</span>
      <div class="input">
        <el-select v-model="diagnosisF.value" placeholder="请选择">
          <el-option label="电子病例页" value="0"></el-option>
          <el-option label="智能辨证页" value="1"></el-option>
          <el-option label="智能开方页" value="2"></el-option>
          <el-option label="知识库(名医医案)" value="3"></el-option>
        </el-select>
      </div>
    </div>
    <div class="code-item flex-vertical-center-l">
      <span>登录跳转配置：</span>
      <div class="input">
        <el-select v-model="defaultHomePage.value" placeholder="请选择">
          <el-option label="患者就诊" value="/index/todaypatients"></el-option>
          <el-option label="知识库(名医医案)" value="/index/doctorcaseBefore"></el-option>
        </el-select>
      </div>
    </div>
    <div class="code-item flex-vertical-center-l">
      <span>知识库转方按钮：</span>
      <div class="input">
        <el-radio-group v-model="transitionPr.value">
          <el-radio label="0">显示</el-radio>
          <el-radio label="1">不显示</el-radio>
        </el-radio-group>
      </div>
    </div>
    <div class="code-item flex-vertical-center-l">
      <span>知识库打印按钮：</span>
      <div class="input">
        <el-radio-group v-model="showPrintHTML.value">
          <el-radio label="0">显示</el-radio>
          <el-radio label="1">不显示</el-radio>
        </el-radio-group>
      </div>
    </div>
    <!-- <div class="code-item flex-vertical-center-l">
            <span>诊断页配置：</span>
            <div class="input">
                <el-radio-group v-model="diagnosis.value">
                    <el-radio label="0">显示</el-radio>
                    <el-radio label="1">不显示</el-radio>

                </el-radio-group>
            </div>
    </div>-->

    <div class="save flex-center" v-if="$route.query.pid" @click="saveDBParams">保存</div>
  </div>
</template>
<script>
import { getDoctorBodyPar, saveDBParams } from "@/api/system.js";
export default {
  data() {
    return {
      sign: {
        key: "print"
      }, // 处方签
      doctorbody: {
        key: "organizationEnable"
      }, // 医共体
      way: {
        key: "countMenthod"
      }, // 计算方式
      audit: {
        key: "automaticReview"
      }, // 自动审核
      pay: {
        key: "isPay"
      },
      diagnosisF: {
        key: "diagnosisHomePage"
      }, // 诊疗首页
      diagnosis: {
        key: "diagnosisPage"
      }, // 诊断
      transitionPr: {
        key: "transitionPr"
      }, // 转方
      showPrintHTML: {
        key: "showPrintHTML"
      }, // 打印
      defaultHomePage: {
        key: "defaultHomePage"
      }, // 登录默认首页
      type: "add"
    };
  },
  created() {
    this.getDoctorBodyPar();
  },
  methods: {
    // 保存 医共体详细信息
    async saveDBParams() {
      let paramList = [
        this.defaultHomePage,
        this.transitionPr,
        this.showPrintHTML,
        this.sign,
        this.doctorbody,
        this.way,
        this.audit,
        this.pay,
        this.diagnosisF,
        this.diagnosis
      ];

      let params = {
        organizationid: this.$route.query.pid,
        paramList
      };

      const loading = this.$loading({
        lock: true,
        text: "正在提交",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });

      let res = await saveDBParams(params).catch(err => {
        loading.close();
      });
      if (res.ResultCode == 0) {
        loading.close();
        this.$message({
          showClose: true,
          message: "提交成功",
          type: "success"
        });
        setTimeout(() => {
          this.$router.back();
        }, 2000);
      }
    },
    // 获取详细信息
    async getDoctorBodyPar() {
      let params = {
        organizationid: this.$route.query.pid
      };
      let res = await getDoctorBodyPar(params);
      if (res.ResultCode == 0) {
        if (res.Data.length > 0) {
          this.type = "edit";

          // 处方签
          let print = res.Data.filter(item => {
            return item.key == "print";
          });
          this.sign = {
            key: print[0].key,
            value: print[0].value,
            pid: this.$route.query.pid
          };
          //医共体启用
          let organizationEnable = res.Data.filter(item => {
            return item.key == "organizationEnable";
          });

          this.doctorbody = {
            key: organizationEnable[0].key,
            value: organizationEnable[0].value,
            pid: this.$route.query.pid
          };
          // 计算方式
          let countMenthod = res.Data.filter(item => {
            return item.key == "countMenthod";
          });
          this.way = {
            key: countMenthod[0].key,
            value: countMenthod[0].value,
            pid: this.$route.query.pid
          };
          // 自动审核
          let automaticReview = res.Data.filter(item => {
            return item.key == "automaticReview";
          });

          this.audit = {
            key: automaticReview[0].key,
            value: automaticReview[0].value,
            pid: this.$route.query.pid
          };
          //支付
          let isPay = res.Data.filter(item => {
            return item.key == "isPay";
          });
          this.pay = {
            key: isPay[0].key,
            value: isPay[0].value,
            pid: this.$route.query.pid
          };
          //诊疗首页
          let diagnosisHomePage = res.Data.filter(item => {
            return item.key == "diagnosisHomePage";
          });
          this.diagnosisF = {
            key: diagnosisHomePage[0].key,
            value: diagnosisHomePage[0].value,
            pid: this.$route.query.pid
          };
          //诊断页显示
          let diagnosisPage = res.Data.filter(item => {
            return item.key == "diagnosisPage";
          });
          this.diagnosis = {
            key: diagnosisPage[0].key,
            value: diagnosisPage[0].value,
            pid: this.$route.query.pid
          };
          // 转方
          let transitionPr = res.Data.filter(item => {
            return item.key === "transitionPr";
          });
          this.transitionPr = {
            key: transitionPr[0] ? transitionPr[0].key : 'transitionPr',
            value: transitionPr[0] ? (transitionPr[0].value || '0') : '0',
            pid: this.$route.query.pid
          };
          // 打印
          let showPrintHTML = res.Data.filter(item => {
            return item.key === "showPrintHTML";
          });
          this.showPrintHTML = {
            key: showPrintHTML[0] ? showPrintHTML[0].key : 'showPrintHTML',
            value: showPrintHTML[0] ? (showPrintHTML[0].value || '1') : '1',
            pid: this.$route.query.pid
          };
          // 登录首页配置
          let defaultHomePage = res.Data.filter(item => {
            return item.key === "defaultHomePage";
          });
          this.defaultHomePage = {
            key: defaultHomePage[0].key,
            value: defaultHomePage[0].value || '/index/todaypatients',
            pid: this.$route.query.pid
          };
        }
      }
    }
  }
};
</script>

<style lang="scss" scoped>
@import "../../style/common.scss";

.code {
  padding: 33px 46px;
  background: #fff;
  border-radius: 5px;

  .code-item {
    margin-bottom: 30px;

    span {
      display: inline-block;
      width: 150px;
      text-align: right;
    }
  }

  .save {
    width: 76px;
    height: 36px;
    background: #5386f6;
    border-radius: 4px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #ffffff;
    cursor: pointer;
  }
}
</style>