<template>
  <div style="background-color: #EFEFEF;width: 100%;">
    <div style="padding: 0rem 9rem;color: #A1A1A1;font-size: 0.75rem;height: 2.125rem;line-height: 2.125rem;">
      <n-flex justify="space-between">
        <div>您好，欢迎来到洛阳百姓问政！</div>
        <div v-if="userPhone==''" style="cursor: pointer" @click="tn('/login')">
          请<span style="color:#7B83FF">「登录」</span>或<span style="color:#7B83FF">「注册」</span>
        </div>
        <div v-if="userPhone!=''" style="cursor: pointer" @click="tn('/login')">
          <span @click="tn('/user');">{{ userPhone }}</span><span @click="quit" style="color:#7B83FF;margin-left: 20px">退出</span>
        </div>
      </n-flex>
    </div>
  </div>
  <div class="b1-back">
    <div style="padding:0 0 0 9rem;font-weight: 600;">
      <div>
        <div style="font-size: 2.5rem;color: #FFFFFF;;">洛阳百姓问政</div>
        <div style="font-size: 1.19rem;color: #FFFFFF;letter-spacing: 0.52rem;margin-top: -0.9rem;">
          wz.lytv.com.cn
        </div>
      </div>
      <div style="position: absolute;text-align: center;top: 25px;left: 405px">
        <img src="/src/assets/img/logo.png" style="width: 45px">
        <div style="color: #FFFFFF;font-size: 12px">洛阳广播电视台</div>
      </div>
    </div>
    <div style="font-weight: 600;padding:0px 9rem;">
      <n-input-group>
        <n-input v-model:value="searchName" placeholder="请输入想找的问题" style="width: 17rem;"/>
        <n-flex :size="[1,0]">
          <div>
            <n-button @click="tn('/search?name='+searchName)" :round="false" :bordered="false" color="#0051B1">
              搜索
            </n-button>
          </div>
          <div>
            <n-button :theme-overrides="buttonThemeOverrides" :round="false" color="#0051B1"  @click="tn('/question')">
              <img src="../assets/img/brush.png" style="width: 1.5625rem;height: 1.5625rem;">
              <span style="margin-left: 0.625rem;">我要投诉</span>
            </n-button>
          </div>
        </n-flex>
      </n-input-group>
    </div>
  </div>
  <div style="padding: 5px 0px;">
    <n-flex justify="center" align="center" :size="[141,10]">
      <div class="left-line"></div>
      <n-button @click="tn('/')" text :color="x=='/'?'#0051B1':'#000000'">
        <template #default>
          <span :style="`${x=='/'?'font-weight: 600':''};font-size: 1.25rem;`">首页</span>
        </template>
      </n-button>
      <div class="left-line"></div>
      <n-button text @click="tn('/department')" :color="x=='/department'?'#0051B1':'#000000'">
        <template #default>
          <span :style="`${x=='/department'?'font-weight: 600':''};font-size: 1.25rem;`">部门</span>
        </template>
      </n-button>
      <div class="left-line"></div>
      <n-button text @click="tn('/question')" :color="x=='/question'?'#0051B1':'#000000'">
        <template #default>
          <span style="font-size: 1.25rem;">提问</span>
        </template>
      </n-button>
      <div class="left-line"></div>
      <n-button text @click="tn('/live')" :color="x=='/live'?'#0051B1':'#000000'">
        <template #default>
          <span :style="`${x=='/live'?'font-weight: 600':''};font-size: 1.25rem;`">直播</span>
        </template>
      </n-button>
      <div class="left-line"></div>
      <n-button @click="tn('/user')" text :color="x=='/user'?'#0051B1':'#000000'">
        <template #default>
          <span :style="`${x=='/user'?'font-weight: 600':''};font-size: 1.25rem;`">我的</span>
        </template>
      </n-button>
      <div class="left-line"></div>
    </n-flex>
  </div>
  <div style="width: 100%;background-color: #7261D9;height: 0.05rem;opacity: 0.35;"></div>
  <div
      style="background: #D9D9D9;width: 120px;height: 180px;text-align: center;padding: 5px 0px 10px 0px;position: fixed;top: 40%;left: 10px">
    <div style="text-align: right;padding-right: 5px">
      <svg style="width: 20px;height: 20px;color: #999797" xmlns="http://www.w3.org/2000/svg"
           xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 512 512">
        <path
            d="M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208s208-93.31 208-208S370.69 48 256 48zm86.63 272L320 342.63l-64-64l-64 64L169.37 320l64-64l-64-64L192 169.37l64 64l64-64L342.63 192l-64 64z"
            fill="currentColor"></path>
      </svg>
    </div>
    <div style="color: #0051B1;font-size: 12px">洛阳百姓问政</div>
    <div style="color: #0051B1;font-size: 12px">公众号</div>
    <div>
      <img src="@/assets/img/qrcode1.png" style="width: 100px;height: 100px;margin-top: 10px">
    </div>
  </div>
  <div
      style="background: #D9D9D9;width: 120px;height: 180px;text-align: center;padding: 5px 0px 10px 0px;position: fixed;top: 40%;right: 10px">
    <div style="text-align: right;padding-right: 5px">
      <svg style="width: 20px;height: 20px;color: #999797" xmlns="http://www.w3.org/2000/svg"
           xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 512 512">
        <path
            d="M256 48C141.31 48 48 141.31 48 256s93.31 208 208 208s208-93.31 208-208S370.69 48 256 48zm86.63 272L320 342.63l-64-64l-64 64L169.37 320l64-64l-64-64L192 169.37l64 64l64-64L342.63 192l-64 64z"
            fill="currentColor"></path>
      </svg>
    </div>
    <div style="color: #0051B1;font-size: 12px">洛阳百姓问政</div>
    <div style="color: #0051B1;font-size: 12px">公众号</div>
    <div>
      <img src="@/assets/img/qrcode1.png" style="width: 100px;height: 100px;margin-top: 10px">
    </div>
  </div>
</template>

<script setup lang="ts">
import {useRouter} from "vue-router";
import {ref, reactive, onMounted} from 'vue'
import {ButtonProps, useMessage} from 'naive-ui'

type ButtonThemeOverrides = NonNullable<ButtonProps['themeOverrides']>
const buttonThemeOverrides: ButtonThemeOverrides = {
  borderRadius: '0px'
}
const message = useMessage()
const router = useRouter()
const userPhone = ref();
const x = ref();
const searchName=ref();
onMounted(() => {
  var item = sessionStorage.getItem('user');
  if (item != null) {
    const jsonArray = JSON.parse(item);
    const hiddenPhoneNumber = jsonArray.mobile.substring(0, 3) + "****" + jsonArray.mobile.substring(7);
    userPhone.value = hiddenPhoneNumber;
  } else {
    userPhone.value = '';
  }
  x.value = router.options.history.location;
})
const quit = () => {
  sessionStorage.removeItem('user');
  userPhone.value = '';
}
const tn = (url) => {
  if (url == '/user' && userPhone.value == '') {
    message.error('请登录！')
    return;
  }
  if (url == '/question' && userPhone.value == '') {
    message.error('请登录！')
    return;
  }
  x.value = url;
  console.log(url);
  router.push(url)
}
</script>

<style scoped>
.left-line {
  height: 1.2rem;
  background-color: #000000;
  width: 0.05rem;
  opacity: 0.15;
}

.n-button {
  border-radius: 0px;
  height: 2.25rem;
}

.b1-back {
  display: flex;
  justify-content: space-between;
  align-items: center;
  align-self: center;
  position: relative;
  width: 100%;
  height: 6.25rem;
  background: url('../assets/img/b1.png') no-repeat;
}
</style>
