<!--
 * @Description: file content
 * @Version: 2.0
 * @Author: ljl
 * @Date: 2022-06-16 09:49:18
 * @LastEditors: ljl
 * @LastEditTime: 2022-08-02 15:19:56
 * @FilePath: \zyypt-ssb-vue_alipay\src\views\relativeInfo.vue
-->
<template>
  <div>
    <div id="main">
      <div class="title" v-if="relativeInfo.JLS == 0">您尚未添加亲属</div>
      <div class="title" v-else>已添加亲属列表</div>
      <van-cell-group inset v-if="relativeInfo.JLS != 0">
        <van-cell
          v-for="item in relativeInfo.MXXQ"
          :key="item.id"
          :title="item.QSXM"
          :label="item.QSZJHM"
          is-link
          :to="'/?idcard=' + item.QSZJHM + '&name=' + item.QSXM"
        >
          <van-button
            color="#8b614d"
            plain
            size="mini"
            class="jiebang"
            @click.stop="unbind(item.id)"
            >解除绑定</van-button
          >
        </van-cell>
        <!-- <van-cell title="张琳" label="120225199712142370" is-link>
          <van-button
            color="#8b614d"
            plain
            size="mini"
            class="jiebang"
            @click="unbind()"
            >解除绑定</van-button
          >
        </van-cell> -->
      </van-cell-group>
      <div class="bottomInfo">
        <div class="info" @click="toApply()">
          <p>老人信息</p>
          <p>(年满60周岁以上老人)</p>
        </div>
        <div class="info" @click="toApply()">
          <p>子女信息</p>
          <p>(未满18周岁子女)</p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Vue from "vue";
import { Dialog, Toast, Button, Icon, Cell, CellGroup } from "vant";
// 全局注册
Vue.use(Dialog).use(Toast).use(Button).use(Icon).use(Cell).use(CellGroup);
import { removeCookies } from "@/utils/auth";
import { setParamLog, getRelatives, UnbindRelatives } from "@/api/index";
export default {
  name: "RelativeInfo",
  data() {
    return {
      relativeInfo: {
        JLS: 0,
        MXXQ: [],
      },
      queryInfo: {},
    };
  },
  created() {
    removeCookies("relativeInfo");
    this.queryInfo = this.$route.query;
    this.getRelatives();
  },
  methods: {
    getRelatives() {
      setParamLog({ type: "alipay", service: "getRelatives" });
      getRelatives({ type: "alipay", ZJHM: this.queryInfo.ZJHM }).then(
        (res) => {
          if (res.code == 0) {
            this.relativeInfo = res.data;
          }
        }
      );
    },
    //解除绑定
    unbind(id) {
      Dialog.confirm({
        message: "确定要解绑当前亲属吗？",
        confirmButtonColor: "#8b614d",
        overlay: true,
      })
        .then(() => {
          setParamLog({ type: "alipay", service: "UnbindRelatives" });
          UnbindRelatives({ type: "alipay", id }).then((res) => {
            if (res.code == 0) {
              Toast.success("解绑成功");
              this.getRelatives();
            }
          });
        })
        .catch(() => {});
    },

    toApply() {
      this.$router.push({ name: "AddRelative", query: this.queryInfo });
      // this.$router.push({ name: "ApplyNotice", query: this.queryInfo });
    },
  },
};
</script>
<style lang="scss" scoped>
#main {
  padding: 10px 0px;
  text-align: left;
  font-family: "PingFang SC-Regular";
  .title {
    text-align: left;
    font-family: "PingFang SC-Medium";
    font-size: 18px;
    margin: 20px 0 20px 15px;
  }
  .van-cell-group {
    box-shadow: 0px 0px 10px 1px rgba(184, 160, 115, 0.3);
  }
  .van-cell__title span {
    font-size: 16px;
  }
  .van-cell__label {
    // font-family: "Avenir-Roman";
    font-family: "Avenir-Medium";
    color: #999999;
    font-size: 14px;
  }
  .jiebang {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 40px;
    border-radius: 4px;
    font-size: 14px;
  }
  .jiebang:hover {
    background: #8b614d;
    color: #fff !important;
  }
  .van-cell__right-icon {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
  }
  .bottomInfo {
    height: 75px;
    display: flex;
    text-align: center;
    justify-content: center;
    margin-top: 30px;
    .info {
      width: 150px;
      background: linear-gradient(270deg, #b9916a 0%, #e4c995 100%);
      border-radius: 4px;
      height: 100%;
      flex-direction: column;
      display: flex;
      justify-content: center;
      color: #fff;
      font-family: "PingFang SC-Medium";
      p:nth-child(1) {
        padding-bottom: 10px;
        font-size: 18px;
      }
      p:nth-child(2) {
        font-size: 12px;
      }
    }
    .info:nth-child(1) {
      margin-right: 20px;
    }
  }
}
</style>