<template>
  <view class="my-doorplate" :class="{'my-doorplate--elder':$uiStyle==='elder'}">
    <view
      class="list"
      style="item.doorplateCode===curDoorId ? background:# : ''"
      v-for="item in doorList"
      :key="item.doorplateCode"
      @click="changeDoorPlate(item)"
    >
      <!--旧代码-->
      <!--<view class="left">-->
      <!--  <image class="icon" mode="aspectFit" src="/static/images/my/doorplate.png" />-->
      <!--  <view class="text">{{item.bzdz}}</view>-->
      <!--</view>-->
      <!--<view class="right" v-if="item.doorplateCode===curDoorId">当前地址</view>-->
      <custom-door-list style="width: 100%;margin-top: 10px" :infoData="item"></custom-door-list>
    </view>
    <view v-if="total===0" class="no-doorplate">暂无绑定的门牌</view>
  </view>
</template>

<script>
import { getMyDoorplateAll, changeMyDoorplate } from '@/api/user'
import { DOOR_TYPE } from "@/utils/const";
import  customDoorList from "@/components/custom-door-list/index.vue";
const app = getApp();

export default {
  name: "changeDoor",
  components: {
    customDoorList
  },
  data() {
    return {
      userInfo: {},
      curDoorId: '',
      doorplateType: '',
      doorList: [],
      total: 0,
    }
  },
  onLoad(option) {
    this.doorplateType = Number(option.doorplateType);
    if (this.doorplateType == DOOR_TYPE.HOUSE.VALUE) {
      uni.setNavigationBarTitle({title: '我的家庭门牌'})
    } else if (this.doorplateType == DOOR_TYPE.ENTERPRISE.VALUE) {
      uni.setNavigationBarTitle({title: '我的企业门牌'})
    }
    this.userInfo = uni.getStorageSync('userInfo');
    const globalData = app.globalData;
    if (globalData.doorplateInfo.code) {
      this.curDoorId = globalData.doorplateInfo.code;
    } else {
		  this.curDoorId = globalData.doorInfo.baseInfo.doorplateCode;
    }
    this.getMyDoorplateAll();
  },
  methods: {
    getMyDoorplateAll () {
//      旧接口
//      const data = {
//        userInfoId: this.userInfo.uuid,
//        doorplateType: this.doorplateType
//      }
//      getMyDoorplateAll(data).then(res => {
//        this.doorList = res.data;
//        this.total = res.total;
//      })


      if (this.doorplateType == DOOR_TYPE.HOUSE.VALUE) {
        //我的家庭门牌
        getPersonalHouseNumber({
          idCard: this.userInfo.idCard,
        }).then(res => {
          this.doorList = res.data;
          this.total = res.data.length;
        })
      } else if (this.doorplateType == DOOR_TYPE.ENTERPRISE.VALUE) {
        //我的企业门牌
        getPersonalCompany({
          idCard: this.userInfo.idCard,
        }).then(res => {
          this.doorList = res.data;
          this.total = res.data.length;
        })
      }
    },
    changeDoorPlate (val) {
      // const data = {
      //   userInfoId: this.userInfo.uuid,
      //   doorplateCode: val.doorplateCode
      // }
      // changeMyDoorplate(data).then(res => {
      //   if (res.code === 0) {
      //     this.curDoorId = val.doorplateCode;
      //     app.globalData.doorplateInfo = {
      //       code: val.doorplateCode,
      //       bzdz: val.bzdz
      //     };
      //     const pages = getCurrentPages();
      //     const beforePage = pages[pages.length - 2];
      //     beforePage.$vm.doorName = val.bzdz;
      //     uni.navigateBack({
      //       delta: 1
      //     })
      //   }
      // })
      this.curDoorId = val.doorplateCode;
      app.globalData.doorplateInfo = {
        code: val.doorplateCode,
        bzdz: val.bzdz,
        bzdz1: val.bzdz1,
        x: val.x,
        y: val.y,
        type: val.type
      };
      const pages = getCurrentPages();
      const beforePage = pages[pages.length - 2];
      beforePage.$vm.doorName = val.bzdz;
      uni.navigateBack({
        delta: 1
      })
    }
  },
} 
</script>

<style lang="scss" scoped>
.my-doorplate {
  //height: 100%;
  //background-color: #fff;
  //.list {
  //  padding: 10px 0;
  //  margin: 0 15px;
  //  border-bottom: 0.5px solid #eee9e9;
  //  display: flex;
  //  justify-content: space-between;
  //  align-items: center;
  //  .left {
  //    width: calc(100% - 70px);
  //    display: flex;
  //    align-items: center;
  //    .icon {
  //      width: 25px;
  //      height: 25px;
  //      margin-right: 7px;
  //    }
  //    .text {
  //      width: calc(100% - 30px);
  //      font-size: 15px;
  //    }
  //  }
  //  .right {
  //    width: 70px;
  //    font-size: 14px;
  //    color: #1676fe;
  //  }
  //
  //}
  height: 100%;
  background-color: #fff;
  .list {
    margin: 0 15px;
    border-bottom: 0.5px solid #eee9e9;
    .right {
      width: 70px;
      font-size: 14px;
      color: #1676fe;
    }
  .no-doorplate {
    padding: 15px;
  }
}

.my-doorplate--elder {
  .list {
    .left {
      .icon {
        width: calc(25px * $zlb-elder-font-scale);
        height: calc(25px * $zlb-elder-font-scale);
        margin-right: 7px;
      }
      .text {
        font-size: calc(14px * $zlb-elder-font-scale);
      }
    }
    .right {
      width: 70px;
      font-size: calc(12px * $zlb-elder-font-scale);
    }
  }
  .no-doorplate {
    font-size: calc(13px * $zlb-elder-font-scale);
  }
}
}
</style>