<template>
  <div>
    <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" @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" v-if="flag == 3">这是楼盘</div>
    <el-pagination
      style="margin: 20px auto"
      class="page"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      flag: 1,
      currentPage: 1,
      agentName: "", //代理商名称
      companyName:'',
      total:20,
      list: [],
    };
  },
  mounted() {
    // console.log(this.$route.query)
    // 给定一个标志做判断显隐
    this.flag = this.$route.query.flag;
    // 获取数据
    if (this.flag == 1) {
      // 获取代理商
      // return
      this.getAgentList();
    } else if (this.flag == 2) {
      // 获取公司
      this.getCompanyList()
    } else {
      // 获取楼盘
    }
  },
  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,
          pageSize: 10,
          name: this.companyName,
          orgType:localStorage.getItem('orgType')
        })
        .then((res) => {
          console.log(res);
          this.list = res.data.records;
          this.total=res.data.total
        });
    },
    chose(item) {
      console.log(item)
      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) {
        // 获取公司
      } else {
        // 获取楼盘
      }
    },
  },
};
</script>

<style lang="scss" scoped >
.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>
