<script>
import { area } from "@/api/area";
import punishmentMixin from "@/mixin/unit.js";
import { getglxsxz, getwbxsxz, getglztxz } from "@/api/management.js";
export default {
  name: "BasicInfoModalContent",
  mixins: [punishmentMixin],
  props: {
    flag: Number,
    qx: String,
  },
  watch: {
    flag: {
      handler(val) {
        this.showFlag = val;
      },
      immediate: true,
      deep: true,
    },
    qx: {
      handler(val) {
        this.value = val;
      },
      immediate: true,
      deep: true,
    },
  },
  data() {
    return {
      options: [],
      fxdjList: [],
      tableData: [],
      unitList: [],
      value: "全市",
      params: {
        pageSize: 10,
        pageNum: 1,
      },
      params1: {
        pageSize: 10,
        pageNum: 1,
      },
      params2: {
        pageSize: 10,
        pageNum: 1,
      },
      total: 0,
      total1: 0,
      total2: 0,
      showFlag: 1,
      wbxsList: [],
      glxsList: [],
    };
  },
  methods: {
    rowClickHandler(val) {
      this.$router.push(`/detail?id=${val.id}`);
    },
    // 管理主体
    funUnitList() {
      getglztxz({
        ...this.params,
        jzszqx: this.value === "重庆市" ? "" : this.value,
      }).then((res) => {
        this.tableData = res.data.rows;
        this.total = res.data.total;
      });
    },
    handleSizeChange(val) {
      this.params.pageSize = val;
      this.funUnitList();
    },
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.funUnitList();
    },
    // 管理形式
    handleSizeChange1(val) {
      this.params1.pageSize = val;
      this.getGlztList();
    },
    handleCurrentChange1(val) {
      this.params1.pageNum = val;
      this.getGlztList();
    },
    // 维保形式
    getWbztList() {
      getwbxsxz({
        ...this.params2,
        qx: this.value === "重庆市" ? "" : this.value,
      }).then((res) => {
        this.wbxsList = res.data.rows;
        this.total2 = res.data.total;
      });
    },
    // 维保形式
    handleSizeChange2(val) {
      this.params2.pageSize = val;
      this.getWbztList();
    },
    handleCurrentChange2(val) {
      this.params2.pageNum = val;
      this.getWbztList();
    },
    resetForm() {
      this.value = "";
      this.params.pageNum = 1;
      this.params1.pageNum = 1;
      this.params2.pageNum = 1;
      this.search()
    },
    // 搜索
    search() {
      if (this.showFlag == 1) {
        this.params1.pageNum = 1;
        this.getGlztList();
      }
      if (this.showFlag == 2) {
        this.params2.pageNum = 1;
        this.getWbztList();
      }
      if (this.showFlag == 3) {
        this.params.pageNum = 1;
        this.funUnitList();
      }
    },
    changeList(val) {
      this.showFlag = val;
      this.search();
    },
    addClass(i) {
      return this.showFlag === i ? "active" : "tab-item";
    },
    //请求管理形式
    getGlztList() {
      getglxsxz({
        ...this.params1,
        qx: this.value === "重庆市" ? "" : this.value,
      }).then((res) => {
        console.log(res.data.rows);
        this.glxsList = res.data.rows;
        this.total1 = res.data.total;
      });
    },
  },

  created() {
    this.funUnitList();
    this.getGlztList();
    this.getWbztList();
    area({
      pageNum: 1,
      pageSize: 100,
    }).then((res) => {
      this.options = res.data.rows;
    });
  },
};
</script>

<template>
  <div>
    <!-- 搜索 -->
    <div class="maintenance-supervision">
      <div class="tab">
        <span class="tab-item" @click="changeList(1)" :class="addClass(1)"
          >管理形式</span
        >
        <span class="tab-item" @click="changeList(2)" :class="addClass(2)"
          >维保形式</span
        >
        <span class="tab-item" @click="changeList(3)" :class="addClass(3)"
          >管理主体</span
        >
      </div>
      <div class="maintenance-supervision_header">
        <div class="select-item">
          <el-select v-model="value" placeholder="请选择">
            <el-option
              :value="item.areaTitle"
              :label="item.areaTitle"
              v-for="(item, index) in options"
              :key="index"
            >
            </el-option>
          </el-select>
        </div>
      </div>
      <div class="btn-item">
        <el-button @click="search">搜索</el-button>
        <el-button @click="resetForm">重置</el-button>
      </div>
    </div>

    <div v-if="showFlag === 3">
      <basic-table
        :data="tableData"
        @row-click="rowClickHandler"
        style="text-align: center"
      >
        <el-table-column type="index" label="序号" width="180">
        </el-table-column>
        <el-table-column
          prop="jzszqx"
          label="区县"
          width="180"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column prop="zddw" label="重点单位(家)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="ybdw"
          label="一般单位(家)"
          width="180"
          show-overflow-tooltip
        >
        </el-table-column>
      </basic-table>
    </div>
    <div v-if="showFlag === 1">
      <basic-table
        :data="glxsList"
        @row-click="rowClickHandler"
        style="text-align: center"
      >
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="qx" label="区县" show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="ygldwwy"
          label="有管理单位（物业）（栋）"
          width="240"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="ygldwfwy"
          label="有管理单位（非物业）（栋）"
          width="240"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="jmzggl"
          label="居民自主管理（栋）"
          width="220"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column prop="jdsqdg" label="街道社区代管" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="qtglxs" label="其他" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="wglzt" label="无管理主体" show-overflow-tooltip>
        </el-table-column>
      </basic-table>
    </div>
    <div v-if="showFlag === 2">
      <basic-table
        :data="wbxsList"
        @row-click="rowClickHandler"
        style="text-align: center"
      >
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="qx" label="区县" show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="zywb"
          label="专业维保（栋）"
          width="240"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="zzwb"
          label="自主维保（栋）"
          width="240"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="w"
          label="无维保（栋）"
          width="220"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column prop="jxhs" label="仅消火栓" show-overflow-tooltip>
        </el-table-column>
      </basic-table>
    </div>
    <br />
    <div v-if="showFlag == 3">
      <basic-pagination
        layout="->,prev, pager, next, sizes,jumper"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params.pageSize"
        :current-page="params.PageNum"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <div v-if="showFlag == 1">
      <basic-pagination
        layout="->,prev, pager, next, sizes,jumper"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params1.pageSize"
        :current-page="params1.PageNum"
        :total="total"
        @size-change="handleSizeChange1"
        @current-change="handleCurrentChange1"
      />
    </div>
    <div v-if="showFlag == 2">
      <basic-pagination
        layout="->,prev, pager, next, sizes,jumper"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params2.pageSize"
        :current-page="params2.PageNum"
        :total="total"
        @size-change="handleSizeChange2"
        @current-change="handleCurrentChange2"
      />
    </div>
  </div>
</template>

<style scoped lang="less">
.maintenance-supervision {
  display: flex;
  align-items: center;
  // padding: 10px 10px 0px 20px;
  ::v-deep(.el-input__inner) {
    border: none;
    background: linear-gradient(
      360deg,
      rgba(0, 148, 255, 0.5) 0%,
      rgba(0, 148, 255, 0.31) 100%
    );
    color: #fff;
  }
  ::v-deep(.el-button) {
    border: none;
    background: linear-gradient(360deg, #0094ff90 0%, #0094ff10 100%);
    color: #fff;
  }
  .maintenance-supervision_header {
    display: flex;
    // flex-wrap: wrap;
    justify-content: space-around;
    // border-bottom: 1px solid #154956;
    padding-bottom: 10px;
    font-size: 12px;
    color: rgb(79, 149, 186);
    // .select-item{
    //   margin-right: 20px;
    // }
  }
  .btn-item {
    margin-bottom: 10px;
  }

  .warp {
    height: 520px;
    margin: 0 auto;
    overflow: hidden;
    .item {
      list-style: none;
      padding: 0;
      margin: 0 auto;
      cursor: pointer;
    }
  }
  /deep/.el-input__inner {
    background-color: #184254;
    width: 150px;
    height: 30px;
    margin-bottom: 5px;
  }
  /deep/.el-button {
    width: 100px;
    height: 32px;
    font-size: 14px;
    line-height: 2px;
    // margin: 0 20px 0 30px;
    color: #fff;
    border-radius: 5px;
    border: none;
    margin-left: 20px;
  }
  /deep/.el-button:hover {
    color: rgb(80, 147, 224);
  }
  /deep/.select_btn {
    position: absolute;
    top: 225px;
    right: 320px;
    //下拉框
  }
  /deep/.el-input {
    width: 150px;
    // margin-left: 20px;
  }
  .header {
    color: #fff;
    height: 33px !important;
    line-height: 33px !important;
    background-color: rgba(0, 163, 255, 0.3) !important;
    color: #61dbff;
    margin-top: 15px;
    margin-bottom: 6px;
  }

  .row,
  li,
  a {
    display: block;
    height: 39px;
    line-height: 39px;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
    background-color: rgba(0, 0, 0, 0.2);
    .time,
    .num,
    .person,
    .result {
      flex: 0.33;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .num {
      flex: 0.15;
    }
  }
  .inp {
    margin-left: 20px;
  }
}
.unit-bulid {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  font-size: 18px;
}
.unit-num {
  width: 200px;
  height: 109px;
  border: 1px solid #0463a7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-items: center;
  line-height: 59px;
}
.tab {
  display: flex;
}
.active {
  background: #0463a7 !important;
}
.tab-item {
  display: inline-block;
  width: 120px;
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 16px;
  color: #fff;
  border: 1px solid #fff;
  border-radius: 5px;
  margin-right: 15px;
  margin-bottom: 15px;
}
</style>
