<template>
  <div>
    <Breadcrumb :list="breadcrumbList" />
    <div class="top-nav">
      <div class="top-nav-list">
        <div v-for="(item, index) in navList" :key="item.key" :class="[item.ifActive ? 'top-nav-itemAC' : 'top-nav-item']" @click="chooseNav(item)">
          {{ item.name }}
        </div>
      </div>
    </div>
    <div class="table">
      <el-table :data="list" v-loading="loading" element-loading-text="加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 21, 64, 0.3)">
        <el-table-column label="序号" type="index" width="80" />
        <!-- 上报事件 -->
        <el-table-column v-if="otherTabel === 'sbsj'" prop="categoryName" label="事件类型" />
        <el-table-column v-if="otherTabel === 'sbsj'" prop="eventContent" label="事件描述" />
        <el-table-column v-if="otherTabel === 'sbsj'" prop="status" label="办理情况">
          <template slot-scope="scope">
            {{ getStatusMap(scope.row.status) }}
          </template>
        </el-table-column>
        <el-table-column v-if="otherTabel === 'sbsj'" prop="happenTime" label="上报时间" />
        <!-- 居民需求 -->
        <el-table-column v-if="otherTabel === 'jmxq'" prop="categoryName" label="需求类型" />
        <el-table-column v-if="otherTabel === 'jmxq'" prop="content" label="需求描述" />
        <el-table-column v-if="otherTabel === 'jmxq'" prop="status" label="办理情况">
          <template slot-scope="scope">
            {{ getStatusMapsb(scope.row.status) }}
          </template>
        </el-table-column>
        <el-table-column v-if="otherTabel === 'jmxq'" prop="reportTime" label="上报时间" />
        <!-- 统治人群 -->
        <el-table-column v-if="otherTabel === 'tzrq'" prop="organizationName" label="所属组织" />
        <el-table-column v-if="otherTabel === 'tzrq'" prop="gridName" label="所属网格" />
        <el-table-column v-if="otherTabel === 'tzrq'" prop="familyName" label="所属家庭" />
        <el-table-column v-if="otherTabel === 'tzrq'" prop="name" label="姓名" />
        <el-table-column v-if="otherTabel === 'tzrq'" prop="mobile" label="联系电话">
          <template slot-scope="scope">
            {{ $sensitive(scope.row.mobile, 3, 7) }}
          </template>
        </el-table-column>
        <el-table-column v-if="otherTabel === 'tzrq'" prop="gender" label="性别" />
        <el-table-column v-if="otherTabel === 'tzrq'" prop="idNum" label="证件号">
          <template slot-scope="scope">
            {{ $sensitive(scope.row.idNum, 6, 16) }}
          </template>
        </el-table-column>
        <el-table-column v-if="otherTabel === 'tzrq'" prop="categoryType" label="人员类别" />
        <el-table-column v-if="otherTabel === 'tzrq'" prop="remark" label="备注" />
        <!-- 安全隐患 -->
        <el-table-column v-if="otherTabel === 'aqyh'" prop="placeOrgName" label="场所名称" />
        <el-table-column v-if="otherTabel === 'aqyh'" prop="patrolTime" label="巡查时间" />
        <el-table-column v-if="otherTabel === 'aqyh'" prop="staffName" label="巡查人员" />
        <el-table-column v-if="otherTabel === 'aqyh'" prop="mobile" label="联系电话" />
        <el-table-column v-if="otherTabel === 'aqyh'" prop="detailed" label="隐患明细" />
        <el-table-column v-if="otherTabel === 'aqyh'" prop="attachmentUrl" label="图片" />
        <el-table-column v-if="otherTabel === 'aqyh'" prop="reviewTime" label="拟复查时间" />
        <el-table-column label="操作" width="90" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="handleView(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div v-if="showDialog">
      <same-dialog :resiId="this.rowId" @close="close" />
    </div>
    <div v-if="showDialogEvent">
      <report-an-event :id="rowId" @close="closeEvent" />
    </div>
    <div v-if="showDialogSaft">
      <Safetyhazard @close="closeSaft" />
    </div>
    <Pagination v-show="total > 0" :total="total" :page.sync="pageNum" :limit.sync="pageSize" @pagination="getList" />
  </div>
</template>

<script>
import Breadcrumb from "@/views/dataBoard/satisfactionEval/components/Breadcrumb";
import Pagination from "@/views/dataBoard/satisfactionEval/components/Pagination";
import SameDialog from "./components/popDetails.vue";
import ReportAnEvent from "./components/reportAnEvent.vue";
import Safetyhazard from "./components/safetyhazard.vue";
import { get } from "sortablejs";
export default {
  name: "Microgrid",
  components: { Breadcrumb, Pagination, SameDialog, ReportAnEvent, Safetyhazard },
  data() {
    return {
      loading: false,
      total: 0,
      pageNum: 1,
      pageSize: 10,
      navList: [
        {
          name: "上报事件",
          ifActive: true,
          key: 1,
        },
        {
          name: "居民需求",
          ifActive: false,
          key: 2,
        },
        {
          name: "统治人群",
          ifActive: false,
          key: 3,
        },
        // {
        //   name: "安全隐患",
        //   ifActive: false,
        //   key: 4,
        // },
      ],
      breadcrumbList: [
        {
          path: "/organizational/gridTree",
          name: "网格架构",
        },
        {
          path: "",
          name: "微网格",
        },
      ],
      rowId: null,
      itemNav: 1,
      showDialog: false,
      showDialogEvent: false,
      showDialogSaft: false,
      otherTabel: "sbsj",
      monthOptions: new Array(12).fill(0).map((_, index) => {
        return { label: index - 0 + 1 + "月", value: index - 0 + 1 };
      }),
      paramsData: {},
      list: [],
    };
  },
  watch: {
    otherTabel(n) {
      if (n) {
        this.getList();
      }
    },
  },
  created() {
    this.paramsData = this.$route.params;
  },
  mounted() {
    this.getList();
    this.breadcrumbList[1].name = this.paramsData.name + "（" + "微网格" + "）";
  },
  methods: {
    getList() {
      this.loading = true;
      const getUrl = new Map([
        ["sbsj", `/gov/org/organizational/neighborhood/getBuildingUnitLevelEvent?unitId=${this.paramsData.id}`],
        ["jmxq", `/gov/org/organizational/neighborhood/getBuildingUnitLevelUserDemand?unitId=${this.paramsData.id}`],
        ["tzrq", `/gov/org/organizational/neighborhood/getBuildingUnitLevelCtp?unitId=${this.paramsData.id}`],
        ["aqyh", `/gov/org/organizational/neighborhood/getEnterprisePatrolRecord?unitId=${this.paramsData.id}`],
      ]);
      const url = getUrl.get(this.otherTabel);
      // unitId=${this.paramsData.id}
      this.$http.get(`${url}&pageNo=${this.pageNum}&pageSize=${this.pageSize}`).then((res) => {
        const {
          code,
          data: { total, list },
        } = res.data;
        if (code === 0) {
          this.total = total;
          this.list = list;
          this.loading = false;
        }
      });
    },

    chooseNav(item) {
      this.list = [];
      this.itemNav = item.key;
      this.otherTabel = item.key === 1 ? "sbsj" : item.key === 2 ? "jmxq" : item.key === 3 ? "tzrq" : "aqyh";
      this.navList.forEach((d) => {
        if (item.key === d.key) {
          d.ifActive = true;
        } else {
          d.ifActive = false;
        }
      });
    },
    close(flag) {
      this.showDialog = flag;
      this.rowId = null;
    },
    closeEvent(flag) {
      this.showDialogEvent = flag;
      this.rowId = null;
    },
    closeSaft(flag) {
      this.showDialogSaft = flag;
      this.rowId = null;
    },
    handleView(row) {
      console.log("this.itemNav::", this.itemNav);
      this.rowId = row.id;
      if (this.itemNav === 1 || this.itemNav === 2) {
        this.showDialogEvent = true;
      }
      if (this.itemNav === 3) {
        this.showDialog = true;
      }
      if (this.itemNav === 4) {
        this.showDialogSaft = true;
      }
    },

    getStatusMap(s) {
      const statusMap = new Map([
        ["processing", "处理中"],
        ["closed_case", "已结办"],
        // ["assigned", "已派单"],
        // ["have_order", "已接单"],
        // ["finished", "已完成"],
      ]);
      return statusMap.get(s);
    },
    getStatusMapsb(s) {
      const statusMap = new Map([
        ["pending", "带办理"],
        ["canceled", "已取消"],
        ["assigned", "已派单"],
        ["have_order", "已接单"],
        ["finished", "已完成"],
      ]);
      return statusMap.get(s);
    },
  },
};
</script>

<style scoped lang="scss">
@import "@/assets/scss/dataBoard/table.scss";
@mixin navListCommon {
  width: 120px;
  height: 36px;
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 500;
  margin-right: 4px;
  text-align: center;
  line-height: 36px;
  cursor: pointer;
}
.screen {
  margin: 25px 0 40px;

  .el-select,
  .el-input {
    width: 150px;
    margin-right: 4px;
    border: 1px solid #126ac5;
    border-radius: 2px;

    /deep/ .el-input__inner {
      background: none;
      border: none;
      color: #fff;
    }
  }

  .btn {
    margin-left: 46px;
    height: 32px;
  }
}
.main-title {
  margin: 25px 0 32px;
}

.top-nav {
  margin: 32px 0;
  .top-nav-list {
    display: flex;
    margin-left: 28px;
    .top-nav-item {
      @include navListCommon;
      background-image: url("~@/assets/images/home/noChooseMain.png");
      color: #96b1ce;
    }
    .top-nav-itemAC {
      @include navListCommon;
      background-image: url("~@/assets/images/home/chooseMain.png");
      color: #fff;
    }
  }
}
</style>
