<template>
  <div class="customer-service">
    <div class="nav">
      <van-icon
        name="arrow-left"
        size="20"
        class="nav-left"
        @click="handlerBack"
      />
      <span class="nav-title">专属客服</span>
    </div>
    <div class="panel-box">
      <div class="panel-content">
        <div class="title">客服二维码</div>
        <img :src="imageUrl" class="qrCode" alt="" />
        <div class="save-code">
          <p>保存二维码</p>
          <p>打开微信扫一扫添加客服</p>
          <!-- <p>请截图保存！</p> -->
        </div>
        <van-button @click="onSave">保存</van-button>
      </div>
    </div>
  </div>
</template>

<script>
import { getCustomer } from "@/api/customer";

export default {
  name: "CustomerService",
  data() {
    return {
      imageUrl: ""
    };
  },
  created() {
    this.getCustomerData();
  },
  mounted() {},
  methods: {
    onSave() {
      const url = this.imageUrl;
      this.$bridgeToAppFun.saveImage(url);
    },
    handlerBack() {
      try {
        this.$bridgeToAppFun.navigateBack();
      } catch {
        console.log("不能和App交互");
        this.$router.go(-1);
      }
    },
    handleUrl(urlName) {
      this.$router.push({ name: urlName });
    },
    getCustomerData() {
      let params = {
        userId: JSON.parse(localStorage.getItem("user")).userId
      };
      getCustomer(params).then(res => {
        if (res.code === 0) {
          this.imageUrl = process.env.VUE_APP_BASE_URL + res.data;
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
$white: #ffffff;
.customer-service {
  width: 100%;
  height: 298px;
  background-image: url("../assets/images/森林状态.png");
  background-size: cover;
  .nav {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    height: 46px;
    color: #fff;
    .nav-left {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 52px;
      height: 100%;
      line-height: 46px;
      text-align: center;
    }
    .nav-title {
      max-width: 60%;
      margin: 0 auto;
      font-weight: bold;
      font-size: 16px;
    }
  }
  .panel-box {
    height: calc(100vh - 86px);
    padding: 0 15px;
    margin-top: 15px;
    .panel-content {
      width: 100%;
      height: 100%;
      background-color: #ffffff;
      box-shadow: 0px 2px 12px 0px rgba(6, 0, 1, 0.04);
      border-radius: 4px;
      padding-top: 45px;
      box-sizing: border-box;
      .title {
        font-size: 18px;
        font-weight: normal;
        font-stretch: normal;
        line-height: 26px;
        letter-spacing: 0px;
        color: #333333;
        text-align: center;
      }
      .qrCode {
        width: 128px;
        height: 130px;
        margin: 80px auto 30px;
        display: block;
      }
      .save-code {
        text-align: center;
        font-size: 14px;
        font-weight: normal;
        font-stretch: normal;
        line-height: 16px;
        letter-spacing: 0px;
        color: #999999;
      }
      .van-button {
        width: 160px;
        height: 36px;
        background-color: #88c678;
        border-radius: 4px;
        font-size: 18px;
        color: #ffffff;
        margin: 85px auto 0;
        display: block;
      }
    }
  }
}
</style>
