<template>
  <div class="recipeAuditD">
    <div class="btn">
      <el-button size="small" type="primary" @click="$router.back()">返回</el-button>
    </div>
    <div class="container-detail flex flex-row-left flex-col-top">
      <div class="recipe-left" v-if="msg.patient">
        <div class="title flex flex-row-left flex-col-center">
          <img src="../../assets/new-icon/people.png" alt />
          <span>患者信息</span>
        </div>
        <div class="msg">
          <div class="msg-row flex flex-row-left flex-col-cneter">
            <div class="msg-item flex-plane-center-l">
              <span>姓名：</span>
              <div>{{msg.patient.name}}</div>
            </div>
            <div class="msg-item flex-plane-center-l">
              <span>性别：</span>
              <div>{{msg.patient.sex}}</div>
            </div>
            <div class="msg-item flex-plane-center-l">
              <span>年龄：</span>
              <div>{{msg.patient.age}}岁</div>
            </div>
          </div>
          <div class="msg-row flex flex-row-left flex-col-cneter">
            <div class="msg-item flex-plane-center-l">
              <span>备注：</span>
              <div>{{msg.patient.name}}</div>
            </div>
            <div class="msg-item flex-plane-center-l">
              <span>电话：</span>
              <div>{{msg.patient.phone}}</div>
            </div>
          </div>
          <div class="msg-item flex-plane-center-l">
            <span>身份证：</span>
            <div>{{msg.patient.idcard}}</div>
          </div>
          <div class="msg-item flex-plane-center-l">
            <span>地址：</span>
            <div>{{msg.patient.province}}{{msg.patient.city}}{{msg.patient.district}}{{msg.patient.detailadress}}</div>
          </div>
        </div>
        <div class="title flex flex-row-left flex-col-center">
          <img src="../../assets/new-icon/book.png" alt />
          <span>就诊信息</span>
        </div>
        <div class="msg">
          <div class="msg-row flex flex-row-left flex-col-center">
            <div class="msg-item flex-plane-center-l">
              <span>就诊日期：</span>
              <div>{{caseItem.treatmentTime}}</div>
            </div>

            <div class="msg-item flex-plane-center-l">
              <span>就诊科室：</span>
              <div>{{caseItem.clinic}}</div>
            </div>
          </div>

          <div class="msg-row flex flex-row-left flex-col-center">
            <div class="msg-item flex-plane-center-l">
              <span>就诊医生：</span>
              <div>{{caseItem.treatmentTime}}</div>
            </div>

            <div class="msg-item flex-plane-center-l">
              <span>就诊科室：</span>
              <div>{{caseItem.clinic}}</div>
            </div>
          </div>

          <div class="msg-row flex flex-row-left flex-col-center">
            <div class="msg-item flex-plane-center-l">
              <span>中医诊断：</span>
              <div>{{caseItem.tcmDiagnosis}}</div>
            </div>

            <div class="msg-item flex-plane-center-l">
              <span>治法：</span>
              <div>{{caseItem.treatment}}</div>
            </div>
          </div>
          <div class="msg-item flex-plane-center-l">
            <span>其他诊断：</span>
            <div>{{caseItem.chiefcomplaint}}</div>
          </div>
          <div class="msg-item flex-plane-center-l">
            <span>主诉：</span>
            <div>{{msg.electronicmedicalrecord?msg.electronicmedicalrecord.chiefcomplaint:''}}</div>
          </div>
          <div class="msg-item flex-plane-center-l">
            <span>现病史：</span>
            <div>{{msg.electronicmedicalrecord?msg.electronicmedicalrecord.historypresent:''}}</div>
          </div>
          <div class="msg-item flex-plane-center-l">
            <span>既往史：</span>
            <div>{{msg.electronicmedicalrecord?msg.electronicmedicalrecord.pasthistory:''}}</div>
          </div>
          <div class="msg-item flex-plane-center-l">
            <span>体格检查：</span>
            <div>{{msg.electronicmedicalrecord?msg.electronicmedicalrecord.physicalexamination:''}}</div>
          </div>
          <div class="msg-item flex-plane-center-l">
            <span>辅助检查：</span>
            <div>{{msg.electronicmedicalrecord?msg.electronicmedicalrecord.supplementaryexamination:''}}</div>
          </div>
          <!-- <div class="msg-item flex-plane-center-l">
                        <span>诊断：</span>
                        <div>{{msg.mainDiagnosis.diagnosis?msg.mainDiagnosis.diagnosis:msg.mainDiagnosis.namemedicine}}
                        </div>
                    </div>
                    <div class="msg-item flex-plane-center-l" v-if="!msg.mainDiagnosis.diagnosis">
                        <span>治法：</span>
                        <div>{{msg.mainDiagnosis.namemedicine}}</div>
          </div>-->
          <!-- <div class="msg-item flex-plane-center-l">
                        <span>处方类型：</span>
                        <div>中药处方</div>
          </div>-->
          <div class="msg-item flex flex-col-top">
            <span>报告图片：</span>
            <div>
              <el-image
                :preview-src-list="[item1]"
                style="width:100px;height:100px;margin-right:20px;"
                :src="item1"
                alt
                v-for="(item1,index1) in msg.electronicmedicalrecord.image1"
                :key="index1"
              />
            </div>
          </div>
        </div>
      </div>

      <div class="recipe-right" v-if="msg.patientprescription">
        <div
          class="title"
          v-if="msg.patientprescription[0].type==0"
        >{{msg.patientprescription[0].type==0?'中药处方':msg.patientprescription[0].type==1?'中成药方':'适宜技术处方'}}</div>
        <!-- v-for="item in id" :key="item" -->
        <div v-for="(item,index) in msg.patientprescription" :key="index">
          <div class="title" v-if="item.type==0">处方{{index+1}}</div>
          <!-- <div class="title" v-if="item.type==0">中药处方</div> -->
          <div
            class="title"
            v-else
          >{{msg.patientprescription[0].type==0?'中药处方':msg.patientprescription[0].type==1?'中成药方':'适宜技术处方'}}</div>
          <div class="right-msg">
            <div class="r-msg-item flex-plane-center-l">
              <span class="name">处方类型：</span>
              <div
                class="right flex-plane-center-l flex-wrap"
              >{{item.type==0?'中药处方':item.type==1?'中成药方':'适宜技术处方'}}</div>
            </div>
            <div class="r-msg-item flex-plane-center-l">
              <span class="name">处方明细：</span>
              <div class="right flex-plane-center-l flex-wrap">
                <span
                  v-for="item1 in item.myPatientDetailVos"
                  :key="item1.pid"
                >{{item1.name}}{{item1.num}}{{item1.unit}}</span>
              </div>
            </div>
            <div class="r-msg-item flex-plane-center-l">
              <span class="name">剂型：</span>
              <div class="right flex-plane-center-l flex-wrap">
                <span>{{item.dosageForm==0?'膏剂':item.dosageForm==1?'汤剂':item.dosageForm==2?'丸剂':'丹剂'}}</span>
              </div>
            </div>
            <div class="r-msg-item flex-plane-center-l" v-show="item.dosageForm==1">
              <span class="name">浓煎：</span>
              <div class="right flex-plane-center-l flex-wrap">
                <span>{{item.strongFried}}ml</span>
                <div class="r-msg-item flex-plane-center-l">
                  <span class="name">代煎：</span>
                  <div class="right flex-plane-center-l flex-wrap">
                    <span>{{item.agency}}</span>
                  </div>
                </div>
              </div>
            </div>
            <div class="r-msg-item flex-plane-center-l">
              <span class="name">用法：</span>
              <div class="right flex-plane-center-l flex-wrap">
                <span>{{item.usestrValue}}</span>
                <div class="r-msg-item flex-plane-center-l">
                  <span class="name">频次：</span>
                  <div class="right flex-plane-center-l flex-wrap">
                    <span>{{item.frequencyValue}}</span>
                  </div>
                </div>
                <div class="r-msg-item flex-plane-center-l">
                  <span class="name">帖数：</span>
                  <div class="right flex-plane-center-l flex-wrap">
                    <span>{{item.num}}</span>
                  </div>
                </div>
              </div>
            </div>
            <div class="r-msg-item flex-plane-center-l">
              <span class="name">嘱托：</span>
              <div class="right flex-plane-center-l flex-wrap">{{item.command}}</div>
            </div>
            <!-- <div class="r-msg-item flex-plane-center-l">
                            <span class="name">提示：</span>
                            <div class="right flex-plane-center-l flex-wrap">
                                提示文本
                            </div>
            </div>-->
            <div class="r-msg-item flex-plane-center-l">
              <span class="name">不宜同用：</span>
              <div class="right flex-plane-center-l flex-wrap">{{item.byty}}</div>
            </div>
            <div class="r-msg-item flex-plane-center-l">
              <span class="name">剂量超标：</span>
              <div class="right flex-plane-center-l flex-wrap">
                <div v-if="item.chao.length==0">无</div>
                <div v-else>
                  <span v-for="item1 in item.chao" :key="item1">{{item1}}</span>
                </div>
              </div>
            </div>
            <div class="r-msg-item flex-plane-center-l">
              <span class="name">病症禁忌：</span>
              <div class="right flex-plane-center-l flex-wrap">{{item.bzjj}}</div>
            </div>
            <div class="r-msg-item flex-plane-center-l" v-show="item.isdelivery==0">
              <span class="name">收货姓名：</span>
              <div class="right flex-plane-center-l flex-wrap">{{item.consigneeName}}</div>
            </div>
            <div class="r-msg-item flex-plane-center-l" v-show="item.isdelivery==0">
              <span class="name">收货电话：</span>
              <div class="right flex-plane-center-l flex-wrap">{{item.consigneePhone}}</div>
            </div>
            <div class="r-msg-item flex-plane-center-l" v-show="item.isdelivery==0">
              <span class="name">配送地址：</span>
              <div
                class="right flex-plane-center-l flex-wrap"
              >{{item.province}}{{item.city}}{{item.district}}{{item.address}}</div>
            </div>

            <div class="r-msg-item flex-plane-center-l" v-if="false">
              <div class="right flex-plane-center-l flex-wrap">
                <div
                  class="r-msg-item flex-plane-center-l"
                  v-if="item.dosageForm==1 && item.agency!=0"
                >
                  <span class="name">代煎费：</span>
                  <div class="right flex-plane-center-l flex-wrap">
                    <span>{{item.agency}}</span>
                  </div>
                </div>
                <div class="r-msg-item flex-plane-center-l" v-if="item.isdelivery==0">
                  <span class="name">配送费：</span>
                  <div class="right flex-plane-center-l flex-wrap">
                    <span>{{item.deliveryfree}}</span>
                  </div>
                </div>

                <div class="r-msg-item flex-plane-center-l" v-if="item.dosageForm==0">
                  <span class="name">制膏费：</span>
                  <div class="right flex-plane-center-l flex-wrap">
                    <span>{{item.markfree}}</span>
                  </div>
                </div>

                <div class="r-msg-item flex-plane-center-l" v-if="item.dosageForm==2">
                  <span class="name">特殊调配费：</span>
                  <div class="right flex-plane-center-l flex-wrap">
                    <span>{{item.deploymentfree}}</span>
                  </div>
                </div>
              </div>
            </div>

            <div class="r-msg-item flex-vertical-center-l" v-if="type!='find'">
              <span class="name">审核：</span>
              <div class="right flex-plane-center-l flex-wrap">
                <el-radio-group
                  v-model="item.revierwstate"
                  @change="stateC($event,index)"
                  :disabled="type=='find'"
                >
                  <el-radio label="0">通过</el-radio>
                  <el-radio label="1">未通过</el-radio>
                </el-radio-group>
              </div>
            </div>
            <div class="r-msg-item flex-vertical-center-l" v-else>
              <span class="name">审核：</span>
              <div class="right flex-plane-center-l flex-wrap">
                <div>{{item.revierwstate==0?'通过':'未通过'}}</div>
              </div>
            </div>
          </div>
        </div>

        <div class="save flex-center" @click="submit()" v-if="type=='edit'">保存</div>
      </div>
    </div>
  </div>
</template>
<script>
import {
  getRecipeAuditD,
  auditRecipe,
  getMedForRecipeA
} from "@/api/business.js";
import { getRecordDetail } from "@/api/diagnosis";
import { mapState, mapGetters, mapActions, mapMutations } from "vuex";
export default {
  data() {
    return {
      type: "edit",
      caseItem: null,
      radio: 0,
      ops: {
        vuescroll: {},
        scrollPanel: {},
        rail: {
          keepShow: true
        },
        bar: {
          hoverStyle: true,
          onlyShowBarOnScroll: false, //是否只有滚动的时候才显示滚动条
          background: "#C1C1C1", //滚动条颜色
          opacity: 0.5, //滚动条透明度
          "overflow-x": "hidden"
        }
      },
      msg: {}
    };
  },
  created() {
    if (this.$route.query.type) {
      this.type = this.$route.query.type;
    }
    this.getRecipeAuditD();
  },
  methods: {
    submit() {
      this.auditRecipe();
    },
    stateC(e, index) {
      this.msg.patientprescription[index].revierwstate = e;
    },
    async auditRecipe() {
      let reviewParam = [];
      this.msg.patientprescription.forEach(item => {
        let obj = {
          reviewState: item.revierwstate,
          pid: item.pid
        };
        reviewParam.push(obj);
      });
      let params = {
        reviewParam
      };
      const loading = this.$loading({
        lock: true,
        text: "正在保存",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      let res = await auditRecipe(params).catch(err => {
        loading.close();
      });
      if (res.ResultCode == 0) {
        loading.close();
        this.$message.success("保存成功");
        setTimeout(() => {
          this.$router.back();
        }, 3000);
      } else {
      }
    },
    async getRecipeAuditD() {
      let res = await getRecipeAuditD(this.$route.query.pid);
      if (res.ResultCode == 0) {
        res.Data.electronicmedicalrecord.image1 = res.Data
          .electronicmedicalrecord.image1
          ? res.Data.electronicmedicalrecord.image1.split(",")
          : [];
        this.msg = res.Data;
        this._getRecordDetail(res.Data.patientprescription[0].recordid);
        res.Data.patientprescription.forEach((item, index) => {
          let arr = [];
          item.detail.forEach(item1 => {
            arr.push(item1.platformdrugid);
          });
          this.getMedForRecipeA(arr.join(","), item.pid);
        });

        // this.msg.patientprescription.filter(item => {
        //     return item.revierwstate = '0'
        // })
      }
    },
    // 获取就诊详情
    async _getRecordDetail(id) {
      let res = await getRecordDetail({
        id: id
        // id: 'e68d293d-f1b7-4f6d-bed4-42b1aba6973e'
      });
      if (res.ResultCode == 0) {
        this.caseItem = res.Data;
      } else {
        this.$message.error(res.ResultInfo);
      }
    },
    // 获取合理用药信息
    async getMedForRecipeA(matids, recipeid) {
      let res = await getMedForRecipeA({
        matId: matids,
        // orgId: this.getuserinfo.organizationid
        preId: recipeid
      });
      if (res.ResultCode == 0) {
        this.msg.patientprescription.forEach((item, index) => {
          item.byty = "";
          item.bzjj = "";

          item.chao = [];
          if (item.pid == recipeid) {
            res.Data.forEach(item1 => {
              item1.matby = item1.matby.split(",");
              item.byty +=
                item1.matname + "不宜与" + item1.matby.join(",") + "同用。";
              item.bzjj += item1.matbzjj ? item1.matbzjj : "无" + "。";

              if (item1.matid == item.detail[index].platformdrugid) {
                if (item1.matmaxdosage < item.detail[index].dose) {
                  itme.chao.push(
                    `${item.detail[index].matname}${item.detail[index].dose}${
                      item.detail[index].unit
                    }(${item1.matmindosage - item1.matmaxdosage})`
                  );
                }
              }
            });
          }

          this.$set(this.msg.patientprescription, index, item);
        });
      }
    }
  },
  computed: {
    ...mapGetters(["getuserinfo"])
  }
};
</script>
<style lang="scss" scoped>
@import "../../style/common.scss";

.recipeAuditD {
  // height: 100%;
  // height: 70vh;

  .container-detail {
    margin-top: 5px;
    height: 76vh;
    overflow: hidden;
  }

  .recipe-left {
    height: 100%;
    overflow: auto;
    padding: 5px 5px;
    background: #ffffff;
    border-radius: 5px;
    // width: 575px;
    flex: 1;
    margin-right: 8px;
    // box-sizing: border-box;
    height: 100%;

    .title {
      margin-bottom: 10px;

      img {
        width: 24px;
        margin-right: 5px;
      }

      span {
        font-size: 16px;
        font-weight: 600;
      }
    }

    .back-btn {
      width: 74px;
      height: 36px;
      background: #5386f6;
      border-radius: 4px;
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #ffffff;
      margin-bottom: 34px;
      cursor: pointer;
    }

    .msg {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #333333;

      .msg-item {
        margin-bottom: 15px;
        flex: 1;
      }

      .msg-row {
        .msg-item {
          max-width: 300px;
        }
      }

      span {
        text-align-last: justify;
        width: 80px;
        text-align: justify;
      }

      div {
        flex: 1;
        overflow: hidden;
      }
    }
  }

  .recipe-right {
    width: 450px;
    height: 100%;
    padding: 33px 46px;
    background: #ffffff;
    border-radius: 5px;
    // flex: 1;
    overflow: auto;

    .title {
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #5386f6;
      margin-bottom: 15px;
    }

    .right-msg {
      .r-msg-item {
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: 500;
        // color: #5386F6;
        color: #333;

        margin-bottom: 15px;

        .name {
          text-align-last: justify;
          width: 80px;
          text-align: justify;
        }

        .right {
          flex: 1;
          overflow: hidden;
          white-space: pre-wrap;

          span {
            margin-right: 50px;
            margin-bottom: 15px;
          }
        }
      }
    }

    .save {
      width: 74px;
      height: 36px;
      background: #ffae45;
      border-radius: 4px;
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #ffffff;
      cursor: pointer;
      margin-top: 50px;
    }
  }
}

// 滚动条位置
.recipeAuditD ::v-deep .__bar-is-vertical {
  right: -1px !important;
}

// 隐藏横向滚动条
.recipeAuditD ::v-deep .__bar-is-horizontal {
  display: none !important;
}
</style>