<template>
  <div class="AddMerchan">
    <AiTopFixed>
      <u-search placeholder="请输入店名、店主、电话" :show-action="false" v-model="keyword" @search="current=1,getList()"/>
    </AiTopFixed>
    <div class="userList" v-if="list.length">
      <ul v-for="(item,index) in list" :key="index">
        <li class="main">
          <div class="user">
            <div>
              <img src="./components/img/xz.png" alt="" class="checkbox" v-if="!item.checked" @click="userClick(index)">
              <img src="./components/img/xzh.png" alt="" class="checkbox" v-else @click="userClick(index)">
            </div>
            <div class="userInfo">
              <!-- <div>
               <img :src="item.photo" alt="" class="userImg"  v-if="item.photo">
               <img src="./components/img/user-img.png" alt="" class="userImg" v-else>
              </div>
              <div class="info">
                 <div class="name">
                  <span class="user-name">{{item.name}}</span>
                  <span class="user-tel">{{item.phone}}</span>
                 </div>
                <div class="idCard">{{item.idNumber && item.idNumber.replace(/^(\d{6})\d{8}(.{4}$)/g, `$1${Array(9).join('*')}$2`)}}</div>
                <div class="address">{{item.currentAreaName || '' }}{{ item.currentAddress || '' }}</div>
              </div> -->
              <div class="item-title">
                <img src="./components/img/xz.png" alt="">
                <p>采苓岩茶烟酒专营店</p>
              </div>
              <div class="info">
                <img src="./components/img/xz.png" alt="">
                <div>林轶峰 18600882921</div>
              </div>
              <div class="info">
                <img src="./components/img/xz.png" alt="">
                <div>陕西省西安市新城区中山门街道168号陕西省西安市新城区中山门街道168号</div>
              </div>
            </div>
          </div>
        </li>
      </ul>
    </div>
    <AiEmpty description="暂无数据" class="emptyWrap" v-if="!list.length"></AiEmpty>
    <div style="height:70px;"></div>
    <!-- <div class="btn">
      <div class="handleCheck" @click="confirm">确定选择</div>
    </div> -->
    <div class="footer" @click="confirm">确定选择</div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      list: [],
      current: 1,
      value: '',
      checked: true,
      userList: {},
      userId: '',
      areaId: '',
      areaName:'',
      girdId: ''
    }
  },
  computed: { ...mapState(['user']) },
  methods: {
    getList(){
      this.$http.post(`/app/appresident/list?areaId=${this.areaId}&householdName=1&current=${this.current}&con=${this.value}`).then((res) => {
        if (res.code == 0) {
          res.data.records.map((item) => {
            item.checked = false
            item.girdMemberId = this.userId
            item.residentId = item.id
          })
          this.list = this.current > 1 ? [...this.list, ...res.data.records] : res.data.records
        }
      })
    },
    getListInit(){
      this.list = []
      this.current = 1
      this.getList()
    },
    userClick(index) {
      this.list[index].checked = !this.list[index].checked
    },
    confirm() {
      var checkUserList = []
      this.list.map((item) => {
        if(item.checked) {
          var info = {
            girdMemberId: this.userId,
            residentId: item.id,
            name: item.name,
            girdId: this.girdId
          }
          checkUserList.push(info)
        }
      })
      if(!checkUserList.length) {
        return this.$u.toast('请选择户主')
      }
      this.$http.post(`/app/appgirdmemberresident/add`, {residentList:checkUserList}).then((res) => {
        if (res.code == 0) {
          this.$u.toast('提交成功')
          uni.$emit('updateList')
          setTimeout(() => {
            uni.navigateBack()
          }, 600)
        }
      }).catch((err) => {
         this.$u.toast(err)
      })
    },
    areaSelect(e) {
      this.areaId =e
      this.getListInit()
    },
  },
  onLoad(option) {
    this.userId = option.id
    this.areaId = this.user.areaId
    this.areaName = this.user.areaName
    this.girdId = option.girdId
  },
  onShow() {
    document.title = '责任商户'
    this.getList()
  },
  onReachBottom() {
    this.current = this.current + 1
    this.getList()
  },
}
</script>

<style lang="scss" scoped>
.AddMerchan {
  .userList {
    width: 100%;
    margin-top: 24px;
      ul {
        padding: 0 32px 0 0;
        li {
          list-style-type: none;
        .user {
          display: flex;
          justify-content: flex-start;
          padding-top: 24px;
          padding-left: 32px;
          height: 100%;
          .checkbox{
            margin-top: 20px;
            margin-right: 32px;
            width: 48px;
            height: 48px;
          }
          .userInfo {
            width: 100%;
            background: #FFF;
            border-radius: 16px;
            padding: 32px 24px 32px 32px;
            box-sizing: border-box;
            margin-bottom: 30px;
            .item-title{
              margin-bottom: 32px;
              img{
                width: 72px;
                height: 72px;
                margin-right: 16px;
                vertical-align: middle;
              }
              p{
                display: inline-block;
                width: 400px;
                font-size: 32px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #000;
                line-height: 32px;
              }
              span{
                display: inline-block;
                width: calc(100% - 488px);
                text-align: right;
                font-size: 24px;
                font-family: PingFangSC-Regular, PingFang SC;
                color: #999;
                line-height: 24px;
              }
            }
            .info{
              img{
                width: 28px;
                height: 28px;
                margin-right: 16px;
              }
              div{
                display: inline-block;
                width: calc(100% - 44px);
                word-break: break-all;
                font-size: 28px;
                font-family: PingFangSC-Regular, PingFang SC;
                color: #333;
                line-height: 40px;
                vertical-align: text-top;
              }
            }
          }
        }
      }
    }
  }
  .footer {
    position: fixed;
    left: 0px;
    bottom: 0px;
    width: 100%;
    height: 112px;
    background-color: #1365DD;
    line-height: 112px;
    text-align: center;
    font-size: 36px;
    color: #FFFFFF;
  }
}
</style>




