<template>
  <div class="app-container">
    <div class="header_main">
      执行人员
      <div class="return_btn" @click="onClickLeft"></div>
    </div>
    <div style="height: 58px;"></div>

    <div class="search_box">
      <van-popover
        v-model="showPopover"
        trigger="click"
        :actions="belongTeamOptions"
        @select="popChange"
        placement="bottom-start"
      >
        <template #reference>
          <div class="select_box">
            <p>{{popValue}}</p>
            <van-icon name="arrow-down" color="#1D6FE9" />
          </div>
        </template>
      </van-popover>
      <div class="search">
        <input type="text" placeholder="请输入执行人姓名/证号" v-model="queryParams.nameOrEnforceNum" />
        <img src="../../../../static/images/lawEnforcement/new/index_icon_19.png" @click="goSearch">
      </div>
    </div>

    <div class="main_box" style="margin-top: 10px;">
      <div class="peopleList">
        <van-row class="peoplett">
          <van-col :span="4">执行主体</van-col>
          <van-col :span="20">执行人员</van-col>
        </van-row>

        <van-checkbox-group v-model="result">
          <van-row v-for="(item,index) in enforcerList" :key="index" >
            <van-col :span="4">{{item.belongTeam}}</van-col>
            <van-col :span="6">{{item.name}}</van-col>
            <van-col :span="10">{{item.enforceNum}}</van-col>
            <van-col :span="4">
              <div class="icon_box">
                <van-checkbox :name="item" shape="square"></van-checkbox>
              </div>
            </van-col>
          </van-row>
        </van-checkbox-group>
      </div>
    </div>

    <p class="submitButton" @click="choiceEnforcer">确定</p>

  </div>
</template>

<script>
  import { listEnforcer } from "@/api/lawEnforcement/index";
  import Cookies from "js-cookie";
  export default {
    name: "programmeDetail",
    data() {
      return {
        showPopover: false,
        form:{},
        result:[],
        queryParams: {
          // 分页
          pageNum: 1,
          pageSize: 999,
          // 查询排序
          orderByColumn: "id",
          isAsc: "desc",
          nameOrEnforceNum: null,  // 搜索参数-执行人姓名或证件号
          belongTeam: '1', // 搜索参数-所在中队
        },

        enforcerList:[],

        searchInput:'',
        belongTeamOptions:[],
        belongTeamOptions2:[],

        popValue:'一中队'

      };
    },
    created() {
      this.getDicts("team_category").then(response => {
        for (var i = 0; i < response.data.length; i++) {
          this.belongTeamOptions.push({text: response.data[i].dictLabel, value: response.data[i].dictValue});
        }
        this.belongTeamOptions2 = response.data;
      });
      this.getDictionaries()
    },
    methods: {
      getDictionaries(){
        listEnforcer(this.queryParams).then((response) => {
          response.rows.map(res=>{
            res.belongTeam = res.belongTeam == '' ? '' : this.selectDictLabel(this.belongTeamOptions2, res.belongTeam);
            this.enforcerList.push(res);
          })
        });
      },
      goSearch(){
        this.enforcerList = [];
        this.getDictionaries()
      },
      popChange(action,index){
        this.popValue = action.text;
        this.queryParams.belongTeam = action.value;
        this.enforcerList = [];
        this.getDictionaries();
      },
      choiceEnforcer(){
        const list = [];
        this.result.map(res=>{
          let obj = {};
          obj.relationType = "2";
          obj.enforcerId = res.id;   // 执法人员ID  -- 执法人员选择页面带回值
          obj.enforcerName = res.name;  // 执法人员姓名 -- 执法人员选择页面带回值
          obj.enforcerNum = res.enforceNum;  // 执法证号  -- 执法人员选择页面带回值
          obj.enforcerLeader = "";   // 是否带队  --勾选赋值
          list.push(obj)
        })
        Cookies.set("enforcer", list);
        Cookies.set("enforcerOld", this.result);
        history.back(-1);
      }
    },
  }
</script>

<style scoped lang="scss">
  .app-container {
    padding: 2% 0;
  }
  /deep/ .van-collapse-item__content{
    padding: 0;
  }
  /deep/ .van-checkbox{
    justify-content: center;
  }
  .icon_box{
    display: flex;
    justify-content: space-around;
  }
  .search_box{
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 92%;
    margin: 0PX auto;
    .select_box{
      border: 1px solid #1D6FE9;
      border-radius: 8PX;
      padding: 0 12PX ;
      background: #ffffff;
      height: 30PX;
      line-height: 30PX;
      display: flex;
      justify-content: space-around;
      align-items: center;
    }
    .search{
      flex: 1;
      background: #ffffff;
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 70%;
      margin: 10PX 0 10PX 10PX;
      border: 1px solid #1D6FE9;
      padding: 1PX 1PX 1PX 12PX ;
      border-radius: 8PX;
      input{
        flex: 1;
        background: transparent;
      }
    }
  }
  .cf{
    padding: 0 3%;
    margin-top: 20PX;
    margin-bottom: 20PX;
    .van-row{
      background: #F0F3F5;
      .van-col{
        padding: 5PX 0;
        font-size: 12PX!important;
        text-align: center;
        p{
          color: #1D6FE9;
        }
      }
      &:first-child{
        background: transparent;
      }
    }
  }
  .header_main{
    height: 116px;
    background: url('../../../../static/images/lawEnforcement/new/list_head.png') no-repeat;
    background-size: 100% 100%;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    font-size: 36px;
    line-height: 116px;
    text-align: center;
    color: #fff;
    z-index: 999;
    .return_btn{
      width: 24px;
      height: 43.2px;
      background: url('../../../assets/images/sunVillage_info/list_icon_5.png') center center no-repeat;
      background-size: 20px 36px;
      position: absolute;
      left: 38px;
      top: 36px;
    }
    .add_btn{
      width: 56.4px;
      height: 40.8px;
      background: url('../../../assets/images/sunVillage_info/list_icon_9.png') center center no-repeat;
      background-size: 47px 34px;
      position: absolute;
      right: 38px;
      top: 36px;
    }
  }
  /deep/ .van-radio--horizontal{
    margin-left: 0.32rem;
    margin-right: 0;
  }
  .peopleList{
    padding: 3%;
    text-align: center;
    .van-row{
      margin-bottom: 10PX;
      background: rgba(196,218,249,0.3);
      border-radius: 5PX;
      .van-col{
        text-align: center;
        font-size: 14PX;
        color: #333333;
        padding: 5PX 0;
      }
    }
    .peoplett{
      background: none;
      .van-col{
        padding: 0;
        color: #1D6FE9;
      }
    }
  }
  .main_title{
    font-size: 0.4rem;
    color: #1D6FE9;
    margin: 0.2rem 6%;
    margin-top: 0;
    position: relative;
  }
  .main_box{
    width: 96%;
    margin: 0 auto;
    border-radius: 10PX;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    overflow: hidden;
    background-color: #FFF;
    .van-icon{
      vertical-align: middle;
    }
    .custom-title{
      font-size: 17PX;
      color: #333333;
      vertical-align: middle;
      line-height: 1;
      position: relative;
    }
    .tap{
      color: #1D6FE9;
    }
    .bgBlue{
      display: block;
      position: absolute;
      width: 17PX;
      height: 17PX;
      border-radius: 50%;
      background-color: rgba(29,111,233,0.26);
      top: -2PX;
      right: -8PX;
    }
  }
  .submitButton{
    width: 45%;
    margin: 0 auto;
    background-image: linear-gradient(to right, #2E79E9 , #77A6EF);
    text-align: center;
    color: #ffffff;
    height: 70px;
    line-height: 70px;
    border-radius: 8PX;
    margin-top: 25PX;
  }

  .addFamily{
    position: absolute;
    top: -2px;
    right: 0;
    border-radius: 50%;
  }
</style>
