<template>
    <div class="home_wrapper">
        <div class="head_main">
            <div class="location">
              <div class="address" @click="villageVisbile = true"><i class="icon"></i>{{deptName}}</div>
              <van-popup v-model="villageVisbile" round position="bottom">
                <van-cascader v-model="villageValue" title="请选择所在村" :options="hcAreaInfoOption" @close="hcAreaInfoClose" @finish="hcAreaInfoFinish" active-color="#1989fa" :field-names="hcAreaInfoFieldName"/>
              </van-popup>

              <div class="address" @click="bookVisbile = true">{{bookName}}</div>
              <van-popup v-model="bookVisbile" round position="bottom">
                <van-picker title="请选择账套" show-toolbar :columns="bookList" @confirm="onConfirmBook" @cancel="onCancelBook" value-key="bookName"/>
              </van-popup>

            </div>
            <van-popover v-model="showPopover" trigger="click" placement="bottom-end" @select="selectChange">
              <div style="width: 4rem;">
                  <van-cell :title="item.text" @click="selectChange(item)" :border="false" :icon="item.icon" v-for="(item,index) in actions" :key="index" />
              </div>
              <template #reference>
                <div class="exit_btn">
                  <i class="icon"></i>
                </div>
              </template>
            </van-popover>
<!--          @click="logout"-->
        </div>
        <img src="../../../static/images/sunVillage_info/sunVillage_info_index_header.png" style="display:block;width:94%;margin:2vh auto 0;" alt="">
        <div class="index_info">
            <div class="nav_list" v-for="(item,idx) in menusList" :key="idx">
              <div class="nav_list_box">
                <van-cell :border="false" style="border-radius: 6px;">
                  <template #title>
                    <p style="font-weight: bold;font-size: 18px;display: inline-block">{{item.modleName}}</p>
                  </template>
                </van-cell>
                <router-link
                  v-for="(childrenItem,childrenIdx) in item.menus"
                  :key="childrenItem.id"
                  :to="{name:childrenItem.menuUrl,query:{typeX:childrenItem.urlPara}}"
                  class="nav_item n_13"
                  v-if="childrenItem.menuIcon!=null"
                  :style="`background:url(${require('@/assets/images/sunVillage_info/' + childrenItem.menuIcon)}) no-repeat center top;background-size: 50%;`"
                >
                  {{childrenItem.menuName}}
                </router-link>
              </div>
            </div>

        </div>
        <div class="footer">
          {{configValue == ""?'技术支持：公司':configValue}}
        </div>

    </div>
</template>
<script>
  import { changeBook , listByDeptId , treeselectByUser , menus } from "@/api/sunVillage_info/fixedAssets";
  import { getInfo } from "@/api/login/index";
  import {changeDept} from "../../api/onlineHome/done";
  import Cookies from "js-cookie";
  import {logout} from "../../api/login";
  import { sysConfig } from "@/api/homesteadSurvey/index";
  import {removeToken} from "@/utils/auth";
  import { getConfigKey } from "@/api/system/config";
  export default {
    name: "certificateList",
    data() {
      return {
        showPopover: false,
        actions: [
          { text: '个人信息', icon: 'manager-o' , index: 0 },
          { text: '修改密码', icon: 'edit' , index: 1 },
          { text: '事项审批', icon: 'todo-list-o' , index: 2 },
          { text: '宅基地调查', icon: 'newspaper-o' , index: 3 },
          { text: '确权延包调查', icon: 'orders-o' , index: 4 },
          { text: '农业行政执法', icon: 'label-o' , index: 5 },
          { text: '生产托管', icon: 'notes-o' , index: 6 },
          { text: '产权交易', icon: 'home-o' , index: 7 },
          { text: '退出登录', icon: 'revoke' , index: 8 },
        ],
        deptIdOptions:[],
        villageVisbile:false,
        showBookList:false,
        deptName:'',
        //选中的值
        villageValue: "",
        //省市区区级list
        hcAreaInfoOption: [],
        hcAreaInfoFieldName: {
          text: "label",
          value: "value",
          children: "children",
        },
        bookName:'',
        queryParams: {
          pageNum: 1,
          pageSize: 100,
        },
        //账套列表
        bookVisbile:false,
        bookList:[],
        bookName:"",
        bookId:"",
        book:"",
        ygcwList:[],
        zcsqList:[],
        cwxxList:[],
        menusList:[],

        configValue:''
      };
    },
    created() {
      getConfigKey("system.app.yinnongExclusive").then(response => {
        if(response.msg == "Y"){
          this.actions=[
            { text: '个人信息', icon: 'manager-o' , index: 0 },
            { text: '修改密码', icon: 'edit' , index: 1 },
            { text: '事项审批', icon: 'todo-list-o' , index: 2 },
            { text: '退出登录', icon: 'revoke' , index: 8 },
          ];
        }
      });
      getInfo().then(response => {
        this.bookName = response.user.bookName
        this.deptName = response.user.deptName
        Cookies.set("bookName", response.user.bookName, {
          expires: 30,
        });
        Cookies.set("deptName", response.user.deptName, {
          expires: 30,
        });
        Cookies.set("bookId", response.user.loginBookId, {
          expires: 30,
        });
        Cookies.set("deptId", response.user.loginDeptId, {
          expires: 30,
        });
        this.getBookList(response.user.loginDeptId);
      });
      treeselectByUser().then((res) => {
        if (res.code == 200) {
          this.hcAreaInfoOption = res.data;
        }
      });

      let query = {
        identityType:3
      }
      menus(query).then((res) => {
        if (res.code == 200) {
          this.menusList = res.data;
          // this.ygcwList = res.data[0].menus;
          // this.zcsqList = res.data[1].menus;
          // this.cwxxList = res.data[2].menus;
        }
      });
      this.$set(this.queryParams, "systemType", '4');
      let params={
        configKey: "system.company.name"}
      sysConfig(params).then((res) => {
        if (res.code == 200) {
          this.configValue = res.rows[0].configValue;
        }
      });
    },
    methods: {
      getPath(url){
        // '@/assets/images/sunVillage_info/index_block_13.png'
        return require( '@/assets/images/sunVillage_info/' + url );
      },
      //关闭选择地址弹窗
      hcAreaInfoClose() {
        this.villageVisbile = false;
      },
      hcAreaInfoFinish({ value, selectedOptions, tabIndex }) {
        // 切换部门
        let Depquery={"loginDeptID":value}
        changeDept(Depquery).then((response) => {
          if (response.code === 200) {
            this.$store.dispatch("GetInfo").then(() => {
              // this.$router.go(0);
              window.location.href = "/sunVillage_info/index";
            });
          }
        });
        this.villageVisbile = false;
      },
      getBookList(e){
        let params = {
          loginDeptID:e
        }
        listByDeptId(params).then((response) => {
          if (response.code == 200) {
            this.bookList = response.rows;
          }
        })
      },
      onConfirmBook(e){
        this.bookVisbile = false
        this.bookName = e.bookName
        let param={"loginBookId":e.id}
        changeBook(param).then((response) => {
          if (response.code === 200) {
            this.$store.dispatch("GetInfo").then(() => {
              // this.$router.go(0);
              window.location.href = "/sunVillage_info/index";
            });
          }
        });
      },
      onCancelBook(e){
        this.bookVisbile = false
      },
      logout(){
        logout().then(res => {
          removeToken();
          this.$router.push({path:"/sunVillage_info/index_code",query:{bookId:Cookies.get('bookId'),deptId:Cookies.get('deptId')}})
        })
      },
      selectChange(val){
        val.icon === 'manager-o' ? this.$router.push({path:"/sunVillage_info/user"}) :
          val.icon === 'edit' ? this.$router.push({path:"/sunVillage_info/passWord"}) :
            val.icon === 'todo-list-o' ? this.$router.push({path:"../yinnong/my"}) :
              val.icon === 'newspaper-o' ? this.$router.push({path:"../homesteadSurvey/index"}) :
                val.icon === 'orders-o' ? this.$router.push({path:"../contracted/index"}) :
                  val.icon === 'label-o' ? this.$router.push({path:"../lawEnforcement/index_new"}) :
                    val.icon === 'notes-o' ? this.$router.push({path:"../agriculturalTrusteeship/index"}) :
                      val.icon === 'home-o' ? this.$router.push({path:"../index"}) :
                        val.icon === 'revoke' ? this.logout() : '';
      }
    },
  }
</script>
<style scoped lang="scss">
.home_wrapper{
    width: 100vw;
    min-height: 100vh;
    background: #F5F6F9 url('../../../static/images/sunVillage_info/page_bg.png') no-repeat top center;
    background-size: 100% auto;
    .head_main{
        position: relative;
        display: flex;
        align-items: self-start;
        justify-content: space-between;
        width: 94%;
        margin: 0 auto;
        padding: 2vh 0 0;
        .location{
            /*height: 42px;*/
            line-height: 42px;
            display: flex;
            flex-direction: column;
            align-items: self-start;
            .address{
                padding:0 18PX;
                background:rgba(255,255,255,0.75);
                border-radius: 42px;
                font-size: 28px;
                color: #3f3d56;
                margin-right: 12px;
                display: flex;
                align-items:center;
                margin-bottom: 10PX;
                .icon{
                    display: block;
                    width: 20px;
                    height: 26px;
                    background: url('../../../static/images/sunVillage_info/index_icon_1.png') no-repeat;
                    background-size: 100% 100%;
                    margin-right: 10PX;
                }
            }
        }
        /deep/ .van-popover__wrapper{

        }
        /deep/ .van-popover__action{
          width: 4rem;
        }
        .exit_btn{
            width: 61px;
            height: 61px;
            /*background: #3f3d56;*/
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            /*position: absolute;*/
            /*top: 64px;*/
            /*right: 36px;*/
            .icon{
                width: 100%;
                height: 100%;
                background: url('../../../static/images/sunVillage_info/login_head_h.png') no-repeat;
                background-size: 100% 100%;
            }
        }
    }
    .index_info{
        /*padding-top: 4.1vh;*/
        .title{
            width: 521px;
            height: 52px;
            background: url('../../assets/images/sunVillage_info/index_title.png') no-repeat;
            background-size: 100% 100%;
            margin:0 auto;
        }
        .nav_list{
          width: 94%;
          margin: 3vh auto 0;
          /*&:nth-child(2){*/
          /*  margin-top: 6vh;*/
          /*}*/
          .van-cell{
            background: transparent;
          }
          .nav_list_box{
            display: flex;
            flex-flow: wrap;
            box-shadow: 0px 0px 18px rgba(63,68,75,0.2);
            /*padding: 0 0 20PX;*/
            border-radius: 15PX;
            overflow: hidden;
            background: #ffffff;
          }
          .nav_box{
            box-shadow: 0px 0px 18px rgba(63,68,75,0.2);
            margin-bottom: 40PX;
            border-radius: 15PX;
            overflow: hidden;
            /deep/ .van-grid-item__content{
              background: transparent;
              padding-top: 0;
            }
          }
          .nav_item{
                width: 25%;
                /*height: 180px;*/
                border-radius: 30px;
                font-size: 24px;
                color: #3f3d56;
                text-align: center;
                display: flex;
                align-items: center;
                justify-content: center;
                padding-top: 100px;
                &.n_1{
                    background: url('../../assets/images/sunVillage_info/index_block_01.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                 &.n_2{
                    background: url('../../assets/images/sunVillage_info/index_block_02.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                &.n_3 {
                    background: url('../../assets/images/sunVillage_info/index_block_03.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                &.n_4 {
                    background: url('../../assets/images/sunVillage_info/index_block_04.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                &.n_5 {
                    background: url('../../assets/images/sunVillage_info/index_block_05.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                &.n_6 {
                    background: url('../../assets/images/sunVillage_info/index_block_06.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                &.n_7 {
                    background: url('../../assets/images/sunVillage_info/index_block_07.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                &.n_8 {
                    background: url('../../assets/images/sunVillage_info/index_block_08.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                &.n_9 {
                    background: url('../../assets/images/sunVillage_info/index_block_09.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;

                }
                &.n_10 {
                    background: url('../../assets/images/sunVillage_info/index_block_10.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                &.n_11 {
                    background: url('../../assets/images/sunVillage_info/index_block_11.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                &.n_12 {
                    background: url('../../assets/images/sunVillage_info/index_block_12.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                &.n_13 {
                    background-size: 50%;
                    margin-bottom: 20PX;
                }
                &.n_14 {
                    background: url('../../assets/images/sunVillage_info/index_block_14.png') no-repeat center top;
                    background-size: 50%;
                    margin-bottom: 20PX;
                }


                &.n_01 {
                  background: url('../../assets/images/sunVillage_info/index_icon_01.png') no-repeat center top;
                  background-size: 50%;
                  margin-bottom: 20PX;
                }
                &.n_02 {
                  background: url('../../assets/images/sunVillage_info/index_icon_02.png') no-repeat center top;
                  background-size: 50%;
                  margin-bottom: 20PX;
                }
                &.n_03 {
                  background: url('../../assets/images/sunVillage_info/index_icon_03.png') no-repeat center top;
                  background-size: 50%;
                  margin-bottom: 20PX;
                }
                &.n_04 {
                  background: url('../../assets/images/sunVillage_info/index_icon_04.png') no-repeat center top;
                  background-size: 50%;
                  margin-bottom: 20PX;
                }
                &.n_05 {
                  background: url('../../assets/images/sunVillage_info/index_icon_05.png') no-repeat center top;
                  background-size: 50%;
                  margin-bottom: 20PX;
                }
                &.n_06 {
                  background: url('../../assets/images/sunVillage_info/index_icon_06.png') no-repeat center top;
                  background-size: 50%;
                  margin-bottom: 20PX;
                }
                &.n_07 {
                  background: url('../../assets/images/sunVillage_info/index_icon_07.png') no-repeat center top;
                  background-size: 50%;
                  margin-bottom: 20PX;
                }
            }
          .icon{
            padding: 15px;
            border-radius: 10px;
            box-sizing: border-box;
            width: 80px;
            height: 80px;
            text-align:center;
          }
          .icon img{
            width:50px;
          }
        }
    }
    .footer{
      width: 100%;
      font-size: 22px;
      color: #3f3d56;
      text-align: center;
      padding-top: 20px;
      padding-bottom: 25PX;
    }
}
</style>
