<!--
 * @Description: file content
 * @Version: 2.0
 * @Author: ljl
 * @Date: 2022-06-16 09:49:18
 * @LastEditors: ljl
 * @LastEditTime: 2022-12-12 17:07:11
 * @FilePath: \zyypt-ssb-vue_wechat\src\views\consultationRecord.vue
-->
<template>
  <div>
    <header>
      <div class="center">
        <div class="avatarImg">
          <img
            src="../assets/images/man.png"
            alt=""
            v-if="recordInfo.HZXB && recordInfo.HZXB == 1"
          />
          <img
            src="../assets/images/woman.png"
            alt=""
            v-else-if="recordInfo.HZXB && recordInfo.HZXB == 2"
          />
          <img src="../assets/images/avatar.png" alt="" v-else />
        </div>
        <div class="avatarInfo">
          <div class="name">
            <span>{{ info.name }}</span>
            <span @click="eye()" v-if="eyeLock"
              ><img src="../assets/images/openEye.png" alt=""
            /></span>
            <span @click="eye()" v-else
              ><img src="../assets/images/closeEye.png" alt=""
            /></span>
          </div>
          <div class="info">
            <span style="margin-left: 12px">{{
              recordInfo.HZXB != 1 && recordInfo.HZXB != 2
                ? "-"
                : recordInfo.HZXB == 1
                ? "男"
                : "女"
            }}</span>
            <span style="margin: 0 12px">|</span>
            <span style="font-family: 'PingFang SC-Regular'"
              >近三个月就诊记录</span
            >
          </div>
          <div class="relativeinfo" @click="toRelative()" v-if="isRelative">
            <img src="../assets/images/relative.png" alt="" />
            <span>亲属信息</span>
          </div>
        </div>
      </div>
      <div class="bottom">
        <div class="bottomInfo">
          <div class="info">
            <p>证件号码</p>
            <p>{{ info.idcard }}</p>
          </div>
          <div class="info">
            <p>最近就诊</p>
            <p v-if="recordInfo.JLS == 0">--</p>
            <p v-else>{{ getDate(recordInfo.MXXQ[0].KFRQ) }}</p>
          </div>
        </div>
      </div>
    </header>
    <div id="main">
      <div v-if="recordInfo.JLS == 0" class="nodata">暂无数据</div>
      <div v-else>
        <div
          class="record"
          @click="toDetails(item)"
          v-for="(item, index) in recordInfo.MXXQ"
          :key="index"
        >
          <div class="code">
            <p>处方状态：</p>
            <p v-if="item.CLZT == 0">待处理(已收费)</p>
            <p v-else-if="item.CLZT == 1">已审方</p>
            <p v-else-if="item.CLZT == 2">代煎机构已确认</p>
            <p v-else-if="item.CLZT == 5">已配方</p>
            <p v-else-if="item.CLZT == 6">已浸泡</p>
            <p v-else-if="item.CLZT == 7">已煎煮</p>
            <p v-else-if="item.CLZT == 8">已包装</p>
            <p v-else-if="item.CLZT == 9">已快递</p>
            <p v-else-if="item.CLZT == 10">已发车</p>
            <p v-else-if="item.CLZT == 11">已签收</p>
            <p v-else-if="item.CLZT == 12">代煎企业退回</p>
            <p v-else-if="item.CLZT == 13">医疗机构退回</p>
            <p v-else-if="item.CLZT == 99">处方信息处理出现异常</p>
          </div>
          <div class="info">
            <div class="outDiv">
              <div class="title">医疗机构</div>
              <div class="name">{{ item.YLJGMC }}</div>
            </div>
            <div class="outDiv">
              <div class="title">处方日期</div>
              <div class="name" style="font-family: 'Avenir-Medium'">
                {{ getDate(item.KFRQ) }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
</script>
<script>
import { getDate } from "@/mixins/format";
import { eye } from "@/mixins/eye";
import {
  getTestAccesstoken,
  setParamLog,
  getWeChatUser,
  getWechatService,
} from "@/api/index";
import { getCookies, setCookies } from "@/utils/auth";
export default {
  name: "ConsultationRecord",
  mixins: [getDate(), eye()],
  data() {
    return {
      recordInfo: {
        JLS: 0,
        HZXB: "",
        MXXQ: [],
      },
      isRelative: true,
    };
  },
  created() {
    let query = this.$route.query;
    if (query.idcard) {
      setCookies("relativeInfo", JSON.stringify(query));
      this.info = JSON.parse(JSON.stringify(query));
      this.eye("refresh");
      setParamLog({type:'wechat',service:'WX001'})
      getWechatService({
        Service: "WX001",
        ZJHM: query.idcard,
      }).then((res) => {
        this.recordInfo = res.data;
        if (!res.data.HZXB) {
          this.recordInfo.HZXB = "-";
        }
      });
      this.isRelative = false;
    } else {
      if (getCookies("myInfo")) {
        this.info = JSON.parse(getCookies("myInfo"));
      } else {
        this.info = false;
      }
      this.isRelative = true;
      if (this.info) {
        this.eye("refresh");
        setParamLog({type:'wechat',service:'WX001'})
        getWechatService({
          Service: "WX001",
          ZJHM: getCookies("idcard"),
        }).then((res) => {
          if (res.data) {
            this.recordInfo = res.data;
          }
        });
      } else {
        this.getFirstInfo(() => {
          this.info = JSON.parse(getCookies("myInfo"));
          this.eye("refresh");
          setParamLog({type:'wechat',service:'WX001'})
          getWechatService({
            Service: "WX001",
            ZJHM: getCookies("idcard"),
          }).then((res) => {
            if (res.data) {
              this.recordInfo = res.data;
            }
          });
        });
      }
    }
    //控制名称显隐
    // this.eye("refresh");
  },
  methods: {
    getUrlParms: function (name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var getHref = decodeURI(window.location.search);
      var r = getHref.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return null;
    },
    getFirstInfo(callback) {
      let accesstoken = this.getUrlParms("accesstoken");
      setParamLog({type:'wechat',service:'getWeChatUser'})
      getWeChatUser({ accesstoken: accesstoken }).then((res) => {
        setCookies("myInfo", JSON.stringify(res.data));
        setCookies("idcard", res.data.idcard);
        if (callback) callback();
      });
      // getTestAccesstoken().then((res) => {
      //   let accesstoken = res.result.data;
      // });
    },
    //亲属信息按钮
    toRelative() {
      this.$router.push({
        name: "RelativeInfo",
        query: {
          XM: JSON.parse(getCookies("myInfo")).name,
          ZJHM: getCookies("idcard"),
        },
      });
    },
    toDetails(item) {
      setCookies("tabId",0)
      this.$router.push({
        name: "PrescriptionDetails",
        query: {
          YNCFBH: item.YNCFBH,
          YLJGDM: item.YLJGDM,
          KFRQ: item.KFRQ,
          CFTS: item.CFTS ? item.CFTS : 0,
          YLJGMC: item.YLJGMC,
          sex: this.recordInfo.HZXB,
          zjhm:this.$route.query.idcard?this.$route.query.idcard:getCookies("idcard")
        },
      });
    },
  },
};
</script>
<style lang="scss" scoped>
header {
  width: 100%;
  // height: 270px;
  background-color: #cbb486;
  border-bottom-left-radius: 15px;
  border-bottom-right-radius: 15px;
  padding-bottom: 10px;
}
.center {
  // height: 80px;
  display: flex;
  padding: 10px 15px;
  position: relative;
}
.avatarImg {
  height: 100%;
  img {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    // margin-top: 15px;
  }
}
.avatarInfo {
  .name {
    color: #fff;
    font-size: 24px;
    height: 50px;
    display: flex;
    align-items: center;
    span {
      margin-left: 12px;
      font-weight: bolder;
    }
    img {
      width: 20px;
    }
  }
  .info {
    color: #fff;
    font-size: 12px;
  }
  .relativeinfo {
    position: absolute;
    top: 22px;
    right: 15px;
    width: 74px;
    padding: 3px 7px;
    display: flex;
    text-align: center;
    align-items: center;
    border-radius: 30px;
    background: linear-gradient(180deg, #eee5d2 0%, #fdfaf5 100%);
    font-family: "PingFang SC-Regular";
    color: #8b614d;
    font-size: 12px;
    img {
      width: 18px;
      margin-right: 5px;
    }
  }
}
.bottom {
  padding: 0 15px;
  height: 100px;
  .bottomInfo {
    background: rgba(111, 82, 38, 0.2);
    border-radius: 8px;
    width: 100%;
    height: 100%;
    display: flex;
    .info {
      width: 50%;
      height: 100%;
      flex-direction: column;
      display: flex;
      justify-content: center;
      color: #fff;
      font-family: "Avenir-Medium";
      p:nth-child(1) {
        padding-bottom: 20px;
        font-size: 12px;
        font-family: "PingFang SC-Regular";
      }
      p:nth-child(2) {
        font-size: 14px;
      }
    }
    .info:nth-child(1) {
      p {
        border-right: 2px solid;
      }
    }
  }
}
#main {
  padding: 10px 15px;
  font-family: "PingFang SC-Regular";
  .nodata {
    color: #7a7a7a;
    margin-top: 30px;
  }
  .record {
    margin-bottom: 15px;
    box-shadow: 0px 0px 10px 1px rgba(184, 160, 115, 0.3);
    border-radius: 8px;
    .code {
      display: flex;
      height: 50px;
      align-items: center;
      // justify-content: space-between;
      padding: 0 15px;
      border-bottom: 1px solid #e7e7e7;
      font-size: 14px;
      color: #000;
      text-align: left;
      line-height: 20px;

      p:nth-child(1) {
        width: 80px;
      }
      p:nth-child(2) {
        color: #8b614d;
        text-align: right;
      }
    }
    .info {
      display: flex;
      flex-direction: column;
      justify-content: center;
      text-align: left;
    }
    .outDiv:nth-child(1) {
      padding-top: 15px;
      line-height: 20px;
    }
    .outDiv:nth-child(2) {
      height: 40px;
      line-height: 40px;
    }
    .outDiv {
      display: flex;
      padding: 0px 15px;
      font-family: "PingFang SC-Regular";
      font-size: 14px;
      .title {
        width: 80px;
        text-align: left;
        color: #999999;
      }
      .name {
        color: #000;
        width: calc(100% - 80px);
      }
    }
  }
}
</style>