<template>
  <div class="main_box">
    <navbar title="支行详情"></navbar>
    <div class="wrapper">
      <div class="task_name">{{campaignName}}</div>
      <div class="container-list">
        <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
          <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            :immediate-check="false"
            @load="onLoad"
          >
            <div class="grid_item" v-for="(item, index) in list" :key="index">
              <div class="top-box">
                <div class="grid_item_top">
                  <div class="icon_box">
                    <van-icon
                      name="wap-home"
                      class="grid_item_top_icon"
                    ></van-icon>
                  </div>
                  <div class="grid_item_top_title">
                    {{ item.deptName }}
                  </div>
                </div>
                <div class="right-label">
                  <span class="label" v-if="item.orgDistributeStatus">{{item.orgDistributeStatus}}</span>
                </div>
              </div>
              <div class="item_content_box">
                <div class="item_content">
                  <span class="item_left">推送成功客户数：</span>
                  <span class="item_right">{{item.pushSuccessNum}}</span>
                </div>
                <div class="item_content">
                  <span class="item_left">已下发客户数：</span>
                  <span class="item_right">{{item.dispatchNum}}</span>
                </div>
                <div class="item_content" >
                  <span class="item_left">客户认领率：</span>
                  <span class="item_right">{{item.issuedNum}}</span>
                </div>
                <div class="item_content" >
                  <span class="item_left">有效待走访客户数：</span>
                  <span class="item_right">{{item.validVisitNum}}</span>
                </div>
                <div class="item_content" >
                  <span class="item_left">走访率：</span>
                  <span class="item_right">{{item.visitRate}}</span>
                </div>
                <div class="item_content" >
                  <span class="item_left">贷款合同签约率：</span>
                  <span class="item_right">{{item.loanSignRate}}</span>
                </div>
                <div class="item_content" >
                  <span class="item_left">活期存款金额提升：</span>
                  <span class="item_right">{{item.increaseDepositAmount}}</span>
                </div>
              </div>
              <div class="item_footer">
                <van-button type="primary" round class="btn" @click="goToOutlet(item)">查看网点</van-button>
                <van-button type="primary" round class="btn" @click="goToCustom(item)">查看个人</van-button>
              </div>
            </div>
          </van-list>
        </van-pull-refresh>
      </div>
      
    </div>
  </div>
</template>
<script>
import moment from "moment";
import navbar from "../../components/navbar/navbar.vue";
import { branchList } from "@/service/api/listStatistics.js";
import {
  Tab,
  Tabs,
  Icon,
  Button,
  Search,
  RadioGroup,
  Radio,
  List,
  PullRefresh,
  Dialog,
  Toast,
  Picker,
  DatetimePicker,
} from "vant";
export default {
  data() {
    return {
      custType: "",
      pageNum: 1,
      pageSize: 5,
      refreshing: false,
      loading: false,
      finished: false,
      currentPage: 1,
      list: [],
      isHeadAdmin: false,
      isPublic: false,
      isPrivate: false,
      isHeadOps: false,
      isBranchAdmin: false,
      isOutletAdmin: false,
      isCommonManager: false,
      campaignName:'',
      campaignId:'',
    };
  },
  components: {
    navbar: navbar,
    VanTab: Tab,
    VanTabs: Tabs,
    VanIcon: Icon,
    VanButton: Button,
    VanSearch: Search,
    VanRadioGroup: RadioGroup,
    VanRadio: Radio,
    VanList: List,
    VanPullRefresh: PullRefresh,
    VanToast: Toast,
    [Dialog.Component.name]: Dialog.Component,
    VanPicker: Picker,
    VanDatetimePicker: DatetimePicker,
  },

  created() {
    const str = sessionStorage.getItem("userInfo") || "{}";
    const userInfo = JSON.parse(str);
    if (userInfo?.roles?.includes("headAdmin")) {
      this.isHeadAdmin = true;
    } else if (userInfo?.roles?.includes("headPublic")) {
      this.isPublic = true;
    } else if (userInfo?.roles?.includes("headPrivate")) {
      this.isPrivate = true;
    } else if (userInfo?.roles?.includes("headOps")) {
      this.isHeadOps = true;
    } else if (userInfo?.roles?.includes("branchAdmin")) {
      this.isBranchAdmin = true;
    } else if (userInfo?.roles?.includes("outletAdmin")) {
      this.isOutletAdmin = true;
    } else if (userInfo?.roles?.includes("commonManager")) {
      this.isCommonManager = true;
    }
    const branchItem = JSON.parse(sessionStorage['branchItem'] || '{}');
    if(branchItem.campaignId){
      this.campaignId = branchItem.campaignId;
      this.campaignName = branchItem.campaignName;
      this.queryList();
    }
  },
  methods: {
    scrollToTop() {
      window.scrollTo({
        top: 0,
        behavior: "smooth",
      });
    },
     // 查看网点
    goToOutlet(item) {
      this.$router.push("/listStatisOutletDetail");
      sessionStorage.setItem('campaignId',item.campaignId);
      sessionStorage.setItem('campaignName',item.campaignName);
      sessionStorage.setItem('deptId',item.deptId);
      let outletItem = {
        campaignId:item.campaignId,
        campaignName:item.campaignName,
        deptId:item.deptId,
      }
      sessionStorage.setItem("outletItem", JSON.stringify(outletItem));
    },
    // 查看个人
    goToCustom(item) {
      this.$router.push("/listStatisCustomDetail");
      let customItem = {
        campaignId:item.campaignId,
        campaignName:item.campaignName,
        deptName:item.deptName,
        outlets:item.outlets || '',
        deptId:item.deptId || '',
        personType:'branch',
      }
       sessionStorage.setItem("customItem", JSON.stringify(customItem));
    },
   
    onSearch() {
      this.onRefresh();
    },
    onCancel() {
      this.onRefresh();
    },
    onClear() {
      this.onRefresh();
    },
    //下拉刷新
    onRefresh() {
      this.list = [];
      this.finished = false; //解除上拉加载之后数据不能再次上拉
      this.currentPage = 1;
      this.pageNum = this.currentPage;
      this.queryList();
    },
    //上拉加载
    onLoad() {
      console.log("上拉加载");
      this.pageNum = this.currentPage;
      this.queryList();
    },
    // 查询列表
    async queryList() {
      if (this.currentPage === 1) {
        this.list = [];
      }
      this.loading = true;
      const params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        campaignId:this.campaignId,
      };
      const res = await branchList(params);
      // console.log(res, "res");
      if (res.code == 200) {
        if (this.refreshing) {
          this.refreshing = false;
        }
        this.loading = false;
        if (res.rows) {
          this.list =
            params.pageNum == "1" ? res.rows : [...this.list, ...res.rows];
          if (res.rows.length < params.pageSize) {
            this.finished = true;
          }
          if (this.list.length == res.total) {
            this.finished = true;
          }
          this.currentPage++;
        } else {
          this.finished = true;
        }
      }
    },
  },
};
</script>
<style lang="less" scoped>
.main_box {
  position: relative;
  .backTop {
    position: fixed;
    bottom: 150px;
    right: 15px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #4682ff;
    box-shadow: 0px -2px 6px 0px rgba(70, 130, 255, 1);
    color: #fff;
    transform: rotate(180deg);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    .heng {
      display: block;
      width: 15px;
      border: 1px solid #fff;
    }
  }
}
.wrapper {
  padding-top: 46px;
  min-height: 100vh;
  font-size: 16px;
  padding-bottom: 60px;
  // position: relative;
  .banner-box {
    // position: fixed;
  }
  .task_name{
    height: 38px;
    line-height: 38px;
    padding-left: 12px;
    font-size: 14px;
    color: #262626;
    font-weight: 600;
  }
}
.task-box {
  margin: 12px;
  background: #1990ff;
  border-radius: 4px;
  padding-bottom: 9px;
  .task-title {
    font-size: 16px;
    color: #fff;
    text-align: center;
    line-height: 43px;
    font-weight: 600;
  }
  .grid_item_middle {
    margin: 0 8px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 4px;
  }
}

.wrapper_top {
  background-color: #fff;
  padding: 15px 20px;
}

.search-input {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 15px;
  background: #fff;
  .special-search {
    ::v-deep .van-field__control {
      font-size: 12px;
    }
  }
}

.special-input-box {
  margin-top: 0;
}

.search_btn {
  background-color: rgb(24, 144, 255);
  border-radius: 4px;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 40px;
  height: 40px;
  color: #fff;
  font-size: 20px;
  .icon {
    display: inline-block;
    width: 40px;
    text-align: center;
  }
}
.reset {
  background: #f7f8fa;
  color: rgba(0, 0, 0, 0.45);
  margin-left: 3px;
  margin-right: 8px;
}

/deep/ .van-search {
  width: 100%;
  padding: 5px 8px;
}

.radio_box {
  display: flex;
  align-items: center;
  margin: 15px 0 15px 15px;
}

.btn_box {
  padding: 8px 16px;
  background-color: #fff;
}

.isChecked {
  background-color: rgb(35, 114, 235);
  color: #fff;
  border-radius: 4px;
}
.grid_item {
  margin-bottom: 8px;
  padding: 10px 15px;
  background-color: #fff;
  .item_content_box{
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .item_content{
      margin-top: 8px;
      flex: 0 0 50%;
      font-size: 12px;
      .item_left{
        color: #8c8c8c;
      }
      .item_right{
        color: #262626;
        font-weight: 600;
        word-break: break-all;
      }
    }
  }
  .item_footer{
    text-align: right;
    margin-top: 10px;
    .btn{
      height: 30px;
      margin-left: 8px;
    }
  }
}
.top-box{
  display: flex;
  justify-content: space-between;
  .right-label{
    .label{
      display: inline-block;
      background: rgba(238,132,21,0.1);
      color: rgba(238,132,21,1);
      font-size: 14px;
      border-radius: 4px;
      margin-left: 5px;
      line-height: 20px;
      padding: 0 5px;
    }
  }
}
.grid_item_top {
  display: flex;
  align-items: center;
}
.icon_box {
  background-color: rgb(35, 114, 235);
  border-radius: 4px;
  width: 25px;
  height: 25px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.grid_item_top_icon {
  font-size: 16px;
  color: #fff;
}
.grid_item_top_title {
  font-size: 16px;
  font-weight: 600;
  margin-left: 10px;
}
.grid_item_middle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgb(249, 249, 250);
  padding: 10px 15px;
  margin-top: 10px;
}
.grid_item_middle_item {
  text-align: center;
  width: 30%;
}
.middle_num {
  margin-top: 10px;
  font-weight: 600;
  font-size: 14px;
  color: #262626;
}
.middle_title {
  font-size: 12px;
  color: #595959;
}
.line {
  width: 1px;
  height: 30px;
  background-color: rgb(255, 255, 255);
  border: 1px solid rgb(218, 220, 224);
}
.grid_item_bottom {
  margin-top: 8px;
  font-size: 12px;
}
.grid_item_bottom_item {
  margin-top: 5px;
  .branch-detail {
    color: #4886f8;
    margin-left: 5px;
  }
}
.bottom_item_left {
  color: rgb(140, 140, 140);
}
.myDialog {
  .content {
    padding: 5px 15px;
    .my-title {
      font-size: 14px;
      color: rgba(0, 0, 0, 0.45);
    }
    .item {
      margin: 8px 0;
      .index {
        display: inline-block;
        width: 16px;
        height: 16px;
        background: rgba(22, 132, 252, 1);
        color: #fff;
        border-radius: 4px;
        font-size: 14px;
        text-align: center;
        line-height: 16px;
      }
      .branch-name {
        font-size: 14px;
        color: rgba(0, 0, 0, 0.85);
        margin-left: 5px;
      }
    }
    .grid-box {
      max-height: 150px;
      overflow-y: auto;
    }
  }
  ::v-deep .van-button__content {
    color: #666;
  }
}
</style>