<template>
  <cs-page :selected="4" isTab title="个人中心">
    <scroll-view class="owner-container" scroll-y>
      <view
        class="section wd-flex wd-flex-row wd-justify-between wd-items-center"
        @tap="edit"
      >
        <view class="wd-flex wd-flex-col" style="gap: 4px">
          <view
            class="wd-flex wd-flex-row"
            style="gap: 8px; align-items: center"
          >
            <text class="wd-font-800 wd-text-20">{{ user.realName }}</text>
            <u-tag
              :text="user.dept.name"
              shape="circle"
              bgColor="#000"
              borderColor="#000"
              size="mini"
            ></u-tag>
          </view>
          <view class="moblie">{{ user.mobile }}</view>
        </view>
        <view class="wd-flex wd-flex-row" style="gap: 10px">
          <u-avatar :src="user.avatar"></u-avatar>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view>
      <view class="section wd-flex wd-flex-row wd-justify-between">
        <view class="wd-flex wd-flex-row" style="gap: 8px">
          <u--image
            src="/static/images/owner/message.png"
            width="20px"
            height="20px"
            mode="aspectFit"
          ></u--image>
          <text class="wd-font-800">消息通知</text>
        </view>
        <!-- <view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px">
          <u-count-to
            :startVal="30"
            :endVal="500"
            fontSize="14px"
            separator=","
          ></u-count-to>
          <u-icon name="arrow-right"></u-icon>
        </view> -->
        <view
          class="wd-flex wd-flex-row wd-items-center"
          style="gap: 16rpx"
          @click="openSubMessage"
        >
          <text>点击开启</text>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view>
      <!-- <view class="section wd-flex wd-flex-row wd-justify-between">
        <view class="wd-flex wd-flex-row" style="gap: 8px">
          <u--image
            src="/static/images/owner/edit.png"
            width="20px"
            height="20px"
            mode="aspectFit"
          ></u--image>
          <text class="wd-font-800">执法记录</text>
        </view>
        <view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px">
          <u-count-to
            :startVal="30"
            :endVal="500"
            fontSize="14px"
            separator=","
          ></u-count-to>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view> -->
      <view
        class="section wd-flex wd-flex-row wd-justify-between"
        @click="btnPolicy"
      >
        <view class="wd-flex wd-flex-row" style="gap: 16rpx">
          <u--image
            src="/static/images/owner/list.png"
            width="20px"
            height="20px"
            mode="aspectFit"
          ></u--image>
          <text class="wd-font-800">政策法规</text>
        </view>
        <view
          class="wd-flex wd-flex-row wd-items-center"
          style="gap: 16rpx"
        >
          <u-count-to
            :startVal="0"
            :endVal="policyTotal"
            fontSize="14px"
            separator=","
          ></u-count-to>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view>
      <button
        class="section wd-flex wd-flex-row wd-justify-between"
        open-type="share"
        @click="invite"
      >
        <view class="wd-flex wd-flex-row" style="gap: 16rpx">
          <u--image
            src="/static/images/owner/edit.png"
            width="20px"
            height="20px"
            mode="aspectFit"
          ></u--image>
          <text class="wd-font-800">企业入驻</text>
        </view>
        <view
          class="wd-flex wd-flex-row wd-items-center"
          style="gap: 16rpx"
        >
          <u-icon name="arrow-right"></u-icon>
        </view>
      </button>
      <view
        class="section wd-flex wd-flex-row wd-justify-between"
        @click="callPhone"
      >
        <view class="wd-flex wd-flex-row" style="gap: 16rpx">
          <u--image
            src="/static/images/owner/phone.png"
            width="20px"
            height="20px"
            mode="aspectFit"
          ></u--image>
          <text class="wd-font-800">内部专线</text>
        </view>
        <view
          class="wd-flex wd-flex-row wd-items-center"
          style="gap: 16rpx"
        >
          <text>点击呼叫</text>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view>
    </scroll-view>
  </cs-page>
</template>

<script>
import { mapGetters } from 'vuex'
import { getUserProfile } from '@/api/system/user.js'
import { PolicyApi, formatPolicyContext } from '@/api/policy/index.js'

export default {
  data() {
    return {
      user: {},
      policyTotal: 0,
      share: {}
    }
  },
  computed: {},
  onShow() {
    this.init()
  },
  onShareAppMessage() {
    return this.share
  },
  onShareTimeline() {
    return this.share
  },
  methods: {
    btnPolicy() {
      uni.navigateTo({
        url: '/sub/owner/policy'
      })
    },
    init() {
      getUserProfile().then(res => {
        this.user = res.data
      })
      PolicyApi.getPolicyPage({
        pageNum: 1,
        pageSize: 10
      }).then(res => {
        this.policyTotal = res.data.total
      })
    },
    openSubMessage() {
      uni.requestSubscribeMessage({
        //此处填写刚才申请模板的模板ID
        tmplIds: ['E8RK91cPLMios6ZHoKx6FJOV4H2kodx6yPWYp7jpLJY'],
        success(res) {
          console.log('requestSubscribeMessage', res)
        }
      })
    },
    edit() {
      uni.navigateTo({
        url: '/sub/owner/edit'
      })
    },
    invite() {
      this.share = {
        title: '邀请企业入驻', // 标题
        path: `/pages/login?inviteId=${this.$store.getters.userId}`,
        imageUrl:
          'http://82.156.141.150:9001/api/v1/download-shared-object/aHR0cDovL2xvY2FsaG9zdDo5MDAwL2h1YW5iYW8vbWluaWFwcC9pbnZhdGUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUQxODY1RVA2NEczMEdEUUhDVTglMkYyMDI1MDIxOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMThUMDcyMDI0WiZYLUFtei1FeHBpcmVzPTQzMTk5JlgtQW16LVNlY3VyaXR5LVRva2VuPWV5SmhiR2NpT2lKSVV6VXhNaUlzSW5SNWNDSTZJa3BYVkNKOS5leUpoWTJObGMzTkxaWGtpT2lKQlJERTROalZGVURZMFJ6TXdSMFJSU0VOVk9DSXNJbVY0Y0NJNk1UY3pPVGt3TmpJME55d2ljR0Z5Wlc1MElqb2lZV1J0YVc0aWZRLmp6djBhdEY5QVBYXzVjYWg4c18yeXhVV3oxek9BekFzSVdzemVrUmZwcXlHd0RPWkptazlUSGJRUnBDdVNmLVMyU0otWTI1cldUd2hpNUlrY0xBSThRJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZ2ZXJzaW9uSWQ9bnVsbCZYLUFtei1TaWduYXR1cmU9MjcxZTkzOTE1MDkwYzUzYmRjYTg0MjQ1MTJhYjk3ZWQxZWMyN2QzM2MwM2U3NGUwYmRhNTBmYjQyNWI0N2MyOQ'
      }
    },
    callPhone() {
      uni.makePhoneCall({
        phoneNumber: '04167230123'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.header {
  display: flex;
  flex-flow: row nowrap;
  gap: 20rpx;
  align-items: center;
  .title {
    font-size: 32rpx;
  }
}
.owner-container {
  padding: 20rpx;
  height: 100%;
  .section {
    border-radius: $cs-border-radius;
    background: #fff;
    margin-bottom: $cs-gap;
    padding: 48rpx;
    font-size: 28rpx;
  }
  .moblie {
    color: $uni-text-color-grey;
  }
}
</style>
