<template>
  <div class="box-center">
    <div class="head">
      <div>质控管家管理系统</div>
      <div class="callback" @click="goback" style="cursor: pointer">返回</div>
    </div>
    <div class="hid">
      选择后台|{{
        flag == 1 ? "选择代理商" : flag == 2 ? "选择公司" : "选择楼盘"
      }}
    </div>
    <div class="content" v-if="flag == 1">
      <div class="search">
        <el-input
          placeholder="请输入内容"
          style="width: 200px; margin-left: 40px; margin-right: 30px"
          v-model="agentName"
          clearable
        >
        </el-input>
        <el-button
          style="height: 32px; line-height: 13px"
          type="primary"
          size="medium"
          @click="getAgentList"
          >搜索</el-button
        >
      </div>
      <div class="con">
        <div
          v-for="item in list"
          :key="item.id"
          class="tab"
          @click="chose(item)"
        >
          <div class="text-1">{{ item.agentName }}</div>
          <div class="text-2">
            服务状态:
            <span
              style="font-size: 12px"
              :style="item.residueTime > 0 ? 'color:green;' : 'color:red;'"
              >{{ item.residueTime > 0 ? "服务中" : "已过期" }}</span
            >
          </div>
          <div class="text-3">{{ item.address }}</div>
        </div>
      </div>
    </div>
    <!-- <div class="content">
      <div class="search">
        <el-input
          placeholder="请输入内容"
          style="width: 200px; margin-left: 40px; margin-right: 30px"
          v-model="agentName"
          clearable
        >
        </el-input>
        <el-button
          style="height: 32px; line-height: 13px"
          type="primary"
          size="medium"
          @click="getAgentList"
          >搜索</el-button
        >
      </div>
      <el-row :gutter="20">
        <el-col class="tab" v-for="item in list" :key="item.id">
          <div>
            <div>{{ item.agentName }}</div>
            <div>服务状态{{ item.residueTime > 0 ? "未过期" : "已过期" }}</div>
            <div>{{ item.address }}</div>
          </div>
        </el-col>
      </el-row>
    </div> -->
    <div class="content" v-if="flag == 2">
      <div class="search">
        <el-input
          placeholder="请输入内容"
          style="width: 200px; margin-left: 40px; margin-right: 30px"
          v-model="companyName"
          clearable
        >
        </el-input>
        <el-button
          style="height: 32px; line-height: 13px"
          type="primary"
          size="medium"
          @click="getCompanyList"
          >搜索</el-button
        >
      </div>
      <div class="con">
        <div
          v-for="item in list"
          :key="item.id"
          class="tab"
          style="height: 78px"
          @click="chose(item)"
        >
          <div class="text-1">{{ item.name }}</div>
          <!-- <div class="text-2">
            服务状态:
            <span
              style="font-size: 12px"
              :style="item.residueTime > 0 ? 'color:green;' : 'color:red;'"
              >{{ item.residueTime > 0 ? "服务中" : "已过期" }}</span
            >
          </div> -->
          <div class="text-3">区域位置:{{ item.address || "暂无" }}</div>
        </div>
      </div>
    </div>
    <div class="content" v-if="flag == 3">
      <div class="search">
        <span style="line-height: 32px; margin-right: 20px">区域:</span>
        <el-cascader
          :props="props"
          v-if="info.selectHouseType == 1"
          @change="locationsChange"
          placeholder="省/市"
          size="small"
          separator="/"
          v-model="provice"
          clearable
        ></el-cascader>
        <el-select
          v-model="area"
          v-if="info.selectHouseType == 2"
          placeholder="请选择"
          class="div-inp"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-input
          v-if="info.selectHouseType == 1"
          placeholder="请输入楼盘名称"
          style="width: 200px; margin-left: 40px; margin-right: 30px"
          v-model="propertyName"
          clearable
        >
        </el-input>
        <el-button
          style="height: 32px; line-height: 13px"
          type="primary"
          size="medium"
          @click="zkhousePage"
          >搜索</el-button
        >
      </div>
      <div class="con">
        <div
          v-for="item in list"
          :key="item.id"
          class="tab"
          @click="chose(item)"
        >
          <div class="text-1">{{ item.propertyName }}</div>
          <div class="text-2">
            服务状态:
            <span
              style="font-size: 12px"
              :style="item.residueTime > 0 ? 'color:green;' : 'color:red;'"
              >{{ item.residueTime > 0 ? "服务中" : "已过期" }}</span
            >
          </div>
          <div class="text-3">{{ item.address }}</div>
        </div>
      </div>
    </div>
    <el-pagination
      style="margin: 20px auto"
      class="page"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-size="10"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { getAreaList } from "@/api/modules/api";
import { getStore, setStore } from "@/util/store";
export default {
  data() {
    return {
      props: {
        lazy: true,
        async lazyLoad(node, resolve) {
          const { level } = node;
          if (level == 0) {
            // console.log(23);
            const { data } = await getAreaList({ parentId: 0 }); //获取省接口
            var nodes = data.map((item) => {
              return {
                value: item.id,
                label: item.name,
                leaf: false,
              };
            });
            resolve(nodes);
          } else if (level == 1) {
            const { data } = await getAreaList({ parentId: node.data.value }); //获取市接口
            var nodes = data.map((item) => {
              return {
                value: item.id,
                label: item.name,
                leaf: true,
              };
            });
            resolve(nodes);
          }
        },
      },
      flag: 1,
      provice: [],
      area:'',
      provinceId: "", //省id
      cityId: "", //市id
      currentPage: 1,
      propertyName: "",
      agentName: "", //代理商名称
      companyName: "",
      total: 20,
      list: [],
      options: [],
      info: {},
    };
  },
  mounted() {
    // console.log(this.$route.query)
    // 给定一个标志做判断显隐
    this.flag = this.$route.query.flag;
    // 获取用户信息
    this.info = getStore({ name: "userInfo" });

    // 获取数据
    if (this.flag == 1) {
      // 获取代理商
      // return
      this.getAgentList();
    } else if (this.flag == 2) {
      // 获取公司
      this.getCompanyList();
    } else {
      // 获取楼盘
      this.zkhousePage();
      // 获取区域列表
      this.findArea()
    }
  },
  computed: {},
  methods: {
    // 获取代理商
    getAgentList() {
      this.$api.api
        .zkagentPage({
          current: this.currentPage,
          pageSize: 10,
          agentName: this.agentName,
        })
        .then((res) => {
          console.log(res);
          this.list = res.data.records;
          this.total = res.data.total;
        });
    },
    getCompanyList() {
      this.$api.api
        .zkorg({
          current: this.currentPage,
          size: 10,
          name: this.companyName,
          orgType: localStorage.getItem("orgType"),
        })
        .then((res) => {
          console.log(res);
          this.list = res.data.records;
          this.total = res.data.total;
        });
    },
    findArea(){
      this.$api.api.findArea()
      .then(res=>{
        console.log(res)
        this.options=res.data.records
      })
    },
    zkhousePage() {
      let obj = {
        current: this.currentPage,
        size: this.size,
        propertyName: this.propertyName,
      };
      if(this.info.selectHouseType == 1){
        this.$api.api.zkhousePage(obj).then((res) => {
        // console.log(res)
        this.list = res.data.records;
        this.total = res.data.total;
      });
      }
      if(this.info.selectHouseType == 2){
        this.$api.api.findHouseByArea({
          id:this.area
        }).then((res) => {
        // console.log(res)
        this.list = res.data.records;
        this.total = res.data.total;
      });
      }

    },
    chose(item) {
      console.log(item);
      if (this.flag == 1) {
        localStorage.setItem("agentId", item.id);
      }
      if (this.flag == 2) {
        localStorage.setItem("orgCode", item.orgCode);
      }
      if (this.flag == 3) {
        localStorage.setItem("orgCode", item.orgCode);
      }
      this.$router.push({ path: "/wel" });
    },
    goback() {
      this.$router.back();
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      if (this.flag == 1) {
        // 获取代理商
        this.getAgentList();
      } else if (this.flag == 2) {
        // 获取公司
        this.getCompanyList();
      } else {
        // 获取楼盘
      }
    },
    locationsChange(e) {
      console.log(e);
      if (!e) return;
      this.provinceId = e[0];
      this.cityId = e[1];
    },
  },
};
</script>

<style lang="scss" scoped >
.box-center {
  min-width: 1500px;
}
.head {
  height: 64px;
  background: #409eff;
  display: flex;
  padding: 0 20%;
  box-sizing: border-box;
  justify-content: space-between;
  line-height: 64px;
  color: #fff;
  font-size: 24px;
  .callback {
    font-size: 14px;
  }
}
.hid {
  margin-top: 25px;
  height: 50px;
  background: #f8f8f8;
  border-radius: 4px;
  text-align: center;
  line-height: 50px;
  font-size: 18px;
  color: #32363d;
}
.content {
  margin-top: 30px;
  padding: 0 20%;
  // height: 680px;
  min-height: 500px;
  .con {
    display: flex;
    flex-wrap: wrap;
  }
  .search {
    display: flex;
  }
  .tab {
    width: 200px;
    height: 98px;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
    box-sizing: border-box;
    padding-left: 20px;
    margin-left: 40px;
    margin-top: 20px;
    cursor: pointer;
    .text-1 {
      font-size: 16px;
      line-height: 30px;
      margin-top: 10px;
    }
    .text-2 {
      font-size: 14px;
      line-height: 30px;
    }
    .text-3 {
      font-size: 14px;
      line-height: 20px;
      margin-bottom: 10px;
    }
  }
}
.page {
  position: absolute;
  bottom: 0;
  left: 30%;
}
</style>
