<template>
  <view>
    <view class="searcher">
      <view>
        <u-search
          v-model="searchForm.keyword"
          placeholder="请输入关键字"
          shape="round"
          bg-color="#f7f7f8"
          action-text="搜索"
          @search="fnResetPaging"
          @custom="fnResetPaging"
        />
      </view>
    </view>

    <view class="info_mainer">
      <view v-if="list.length > 0">
        <u-list @scrolltolower="scrolltolower">
          <u-list-item
            v-for="item in list"
            :key="item.CORPINFO_ID"
            class="wrap"
          >
            <view class="tit">
              <view class="u-line-2">{{ item.CORP_NAME }}</view>
            </view>
            <view class="text">
              <text>安全监管类型:</text>
              {{ item.INDUSTRY_SPSIC }}
            </view>
            <view class="text">
              <text>管理单位:</text>
              {{ item.ALL_REGULATORY_DEPARTMENT_NAME }}
            </view>
            <view class="text">
              <text>属地:</text>
              {{ item.COMPANY_AREA.replace(/\,/g, "/") }}
            </view>
            <view class="text">
              <text>检查次数:</text>
              {{ item.INSPECTNUM }}
            </view>
            <view class="bottem">
              <u-button
                text="查看"
                color="linear-gradient(to right, #27a0ff, #2a56f7)"
                custom-style="width:150upx; height:60upx; margin-left: 20upx;margin-right: 0;"
                @click="
                  $u.route({
                    url: '/pages/special_rectification/inspect_record_list',
                    params: {
                      SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID:
                        SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID,
                      CORPINFO_ID: item.CORPINFO_ID,
                      ISREPORT: ISREPORT,
                    },
                  })
                "
              />
              <u-button
                v-if="ISREPORT === 'true'"
                text="专项检查"
                color="linear-gradient(to right, #27a0ff, #2a56f7)"
                custom-style="width:150upx; height:60upx; margin-left: 20upx;margin-right: 0;"
                @click="
                  $u.route({
                    url: '/pages/special_rectification/add_inspect',
                    params: {
                      SPECIAL_RECTIFICATION_ACTIVITY_ID:
                        SPECIAL_RECTIFICATION_ACTIVITY_ID,
                      SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID:
                        SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID,
                      CORPINFO_ID: item.CORPINFO_ID,
                      CORP_NAME: item.CORP_NAME,
                      ADDRESS_BUSINESS: item.ADDRESS_BUSINESS,
                      LR_NAME: item.LR_NAME || '',
                      LR_PHONE: item.LR_PHONE || '',
                    },
                  })
                "
              />
            </view>
          </u-list-item>
        </u-list>
      </view>
      <empty v-else />
    </view>
  </view>
</template>

<script>
import { getSpecialRectificationInspectionEnterpriseList } from "@/api";

export default {
  data() {
    return {
      SPECIAL_RECTIFICATION_ACTIVITY_ID: "",
      SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID: "",
      list: [],
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      searchForm: {
        keyword: "",
      },
      ISREPORT: "true",
    };
  },
  onLoad(query) {
    this.SPECIAL_RECTIFICATION_ACTIVITY_ID =
      query.SPECIAL_RECTIFICATION_ACTIVITY_ID;
    this.SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID =
      query.SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID;
    this.ISREPORT = query.ISREPORT;
  },
  // created() {
  //   this.fnGetData();
  // },
  onShow() {
    this.list = [];
    this.pageSize = 10;
    this.currentPage = 1;
    this.totalPage = 0;
    this.fnGetData();
  },
  methods: {
    async fnGetData() {
      const resData = await getSpecialRectificationInspectionEnterpriseList({
        showCount: this.pageSize,
        currentPage: this.currentPage,
        SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID:
          this.SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID,
        KEYWORDS: this.searchForm.keyword,
      });
      this.list = [...this.list, ...resData.varList];
      this.totalPage = resData.page.totalPage;
    },
    scrolltolower() {
      this.currentPage++;
      if (this.totalPage >= this.currentPage) this.fnGetData();
    },
    fnResetPaging() {
      this.list = [];
      this.currentPage = 1;
      this.fnGetData();
    },
  },
};
</script>

<style scoped lang="scss">
.searcher {
  width: 100%;
  background: #ffffff;
  padding: 20upx;
  box-sizing: border-box;
  margin-top: 20upx;
  border-bottom: 1px solid #eeeeee;

  .mainer {
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-top: 20upx;
    align-items: center;
    font-size: 28upx;
  }
}

.info_mainer {
  width: 100%;
  margin-top: 20upx;

  .wrap {
    width: 100%;
    background: #ffffff;
    margin-bottom: 20upx;
    padding: 20upx;
    line-height: 2;
    box-sizing: border-box;

    .tit {
      font-weight: bold;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .text text {
      color: #999999;
      margin-right: 10upx;
    }

    .bottem {
      width: 100%;
      border-top: 1px solid #eeeeee;
      margin-top: 20upx;
      display: flex;
      justify-content: flex-end;
      padding: 20upx 0 0;
    }
  }
}
</style>
