<template>
  <div class="secureselftest">
    <div class="list">
      <!-- <div v-if="todoList.length == 0"> -->
      <div class="list-row" v-for="(item, index) in todoList"
        @click="junmpMyMechantsDetails(item.routeParam, item.handleType)" :key="index">
        <div class="cell_1">
          <div class="width100 height44rpx mb16rpx">
            <div class="first_title">
              {{ item.title }}
            </div>
          </div>
          <div class="width100 height40rpx">
            <div class="second_title" style="width: 100%">
              {{ item.createdAt }}
            </div>
          </div>
        </div>
      </div>
      <!-- </div> -->
      <!-- <div v-else> -->
      <van-empty v-if="todoList.length == 0" class="disblock marginauto" style="background: white" description="暂无数据" />
      <!-- </div> -->
    </div>
  </div>
</template>

<script>
import { handleList, getByCodes, getUserLocalStorageInfo } from "@/js_sdk/http";
import vanEmpty from "../../../wxcomponents/weapp/dist/empty/index";

export default {
  components: {
    vanEmpty,
  },
  data() {
    return {
      dic_key: ["safety_inspection_type"],
      dic_SelectList: {},
      active: 0,
      todoList: [],
      search: {
        pageSize: 10,
        pageNum: 1,
        types: "8,9,10,11",
        userId: "",
      },
      statusList: [
        { label: "全部", value: null },
        { label: "电梯自检", value: "1" },
        { label: "消防自检", value: "2" },
        { label: "电柜检查", value: "3" },
        { label: "电器线路", value: "4" },
      ],
    };
  },
  onShow() {
    // this.getByCodes();
    this.search.userId = getUserLocalStorageInfo().user.id;
    this.gettodoList();
  },
  methods: {
    getDicType(value) {
      if (!value) return "未知类型";

      let safety_inspection_type = this.dic_SelectList.safety_inspection_type;
      let index = safety_inspection_type.findIndex((e) => e.value == value);
      return safety_inspection_type[index].label;
    },

    junmpMyMechantsDetails(routeParam, type) {
      console.log(routeParam, type);
      if (type == 8) {
        uni.navigateTo({
          url: "/pages/subPackages/repairprocessing-app/detail?id=" + routeParam,
        });
        return
      }
      if (type == 9) {
        let param = routeParam.split(",");
        console.log(param);
        if (param[0] == "报事报修待派单") {
          console.log("报事报修待派单");
          uni.navigateTo({
            url: "/pages/subPackages/repairDispatch-app/detail?id=" + param[0],
          });
        }
        // if (param[0] == "报事报修待处理") {
        console.log("报事报修待处理");
        uni.navigateTo({
          url:
            "/pages/subPackages/repairprocessing-app/detail?" + param,
        });
      }
      // }
      if (type == 11) {
        uni.navigateTo({
          url:
            "/pages/subPackages/venueRoom/audit?" +
            routeParam +
            "&readOnlyType=" +
            1,
        });
      }
      if (type == 10) {
        uni.navigateTo({
          url: "/pages/subPackages/meetingroom/audit?" + routeParam,
        });
      }
    },
    jumpReport() {
      uni.navigateTo({
        url: "/pages/subPackages/secureselftest/report?id=" + null,
      });
    },
    async getMoreListData() {
      let that = this;

      that.search.pageNum = that.search.pageNum + 1;
      let list = await handleList(that.search);

      if (list.rows == 0) {
        that.$showToast("没有更多数据了");
      } else {
        list.rows.forEach((e) => {
          that.todoList.push(e);
        });
      }
    },
    onReachBottom() {
      this.getMoreListData();
    }, //下拉执行的时候触发 （下拉刷新）
    onChange(e) {
      this.search.type = e.detail.name == null ? "" : e.detail.name;
      this.gettodoList();
    },
    endDate() {
      return this.getDate("end");
    },
    startDate() {
      return this.getDate("start");
    },

    async getByCodes() {
      let data = await getByCodes(JSON.stringify(this.dic_key));
      this.dic_SelectList = this.$common.handleDicList(data);
      this.gettodoList();
    },
    getDate(type) {
      const date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();

      if (type === "start") {
        year = year - 60;
      } else if (type === "end") {
        year = year + 2;
      }
      month = month > 9 ? month : "0" + month;
      day = day > 9 ? day : "0" + day;
      return `${year}-${month}-${day}`;
    },
    async gettodoList() {
      this.search.pageSize = 10;
      this.search.pageNum = 1;
      let list = await handleList(this.search);
      //   /wx/SafetyController/handleList

      this.todoList = list.rows;
    },
    jumpAddCompanyPage() {
      uni.navigateTo({
        url: "/pages/subPackages/addCompany/addCompany",
      });
    },

    jumpPage(e) {
      uni.navigateTo({
        url: "/pages/subPackages/companyDetails/companyDetails?id=" + e,
      });
    },
  },
};
</script>


<style lang="scss">
.chooseyears {
  width: 326rpx;
  height: 56rpx;
  background: rgba(29, 24, 188, 0.05);
  border-radius: 8rpx 8rpx 8rpx 8rpx;
  text-align: center;
  line-height: 56rpx;
  display: flex;
  color: #1d18bc;
}

.searchbox {
  display: block;
  background: white;
}

.chaochuyincang {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.secureselftest {
  .custom-class {
    background: white;
  }
}
</style>