<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 class="mainer">
        <view class="area" @click="fnDepartmentShow">
          <view class="name u-line-1">
            {{ searchForm.departmentName || "请选择部门" }}
          </view>
          <view class="more">
            <u-icon name="arrow-down"></u-icon>
          </view>
        </view>
        <view class="radio_main">
          <u-radio-group
            v-model="searchForm.reportingStatus"
            style="width: 100%; display: flex; justify-content: space-between"
            @change="fnResetPaging"
          >
            <u-radio
              v-for="(item, index) in radioList"
              :key="index"
              :name="item.value"
              :label="item.name"
            />
          </u-radio-group>
        </view>
      </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 v-if="Number(item.STATUS_REPORTING) >= 0 && item.CORP_EXAMINE === '2'" class="fcr">
                已打回
              </view>
              <view v-if="Number(item.STATUS_REPORTING) >= 0 && item.CORP_EXAMINE === '1'" class="fcg">
                已通过
              </view>-->
              <view v-if="item.STATUS_REPORTING === '-1'" class="fct"
                >未填报</view
              >
              <view v-if="item.CORP_EXAMINE === '0'" class="fct">待审核</view>
              <view
                v-if="
                  Number(item.STATUS_REPORTING) >= 0 &&
                  item.CORP_EXAMINE === '1'
                "
                class="fcg"
                >已通过</view
              >
              <view
                v-if="
                  Number(item.STATUS_REPORTING) >= 0 &&
                  item.CORP_EXAMINE === '2'
                "
                class="fcr"
                >已打回</view
              >
            </view>
            <view class="text">
              <text>安全监管类型:</text>
              {{ item.INDUSTRY_SPSIC }}
            </view>
            <view class="text">
              <text>管理单位:</text>
              {{ item.ALL_REGULATORY_DEPARTMENT_NAME }}
            </view>
          </u-list-item>
        </u-list>
      </view>
      <empty v-else />
    </view>
    <tki-tree
      ref="departmentTreeRef"
      :range="department"
      id-key="id"
      range-key="name"
      children-name="nodes"
      select-parent
      @confirm="fnDepartmentTreeConfirm"
    />
  </view>
</template>

<script>
import { getInformationReviewList } from "@/api";
import TkiTree from "@/components/tki-tree/tki-tree.vue";

export default {
  components: {
    TkiTree,
  },
  props: {
    department: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      list: [],
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      radioList: [
        { name: "全部", value: "" },
        { name: "已通过", value: "3" },
        { name: "已打回", value: "2" },
      ],
      searchForm: {
        keyword: "",
        reportingStatus: "",
        departmentName: "",
        departmentId: "",
      },
    };
  },
  created() {
    this.fnGetData();
  },
  methods: {
    async fnGetData() {
      const resData = await getInformationReviewList({
        showCount: this.pageSize,
        currentPage: this.currentPage,
        KEYWORDS: this.searchForm.keyword,
        STATUS_REPORTING: this.searchForm.reportingStatus,
        REGULATORY_DEPARTMENT_ID: this.searchForm.departmentId,
      });
      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();
    },
    fnDepartmentShow() {
      this.$refs.departmentTreeRef._show();
    },
    fnDepartmentTreeConfirm(event) {
      this.searchForm.departmentName = event[0].name;
      this.searchForm.departmentId = event[0].id;
      this.fnResetPaging();
    },
  },
};
</script>

<style scoped lang="scss">
.fcg {
  color: #489b27;
  font-weight: normal;
}

.fct {
  color: #000000;
  font-weight: normal;
}

.fcr {
  color: #ff0000;
  font-weight: normal;
}

.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;

    .area {
      width: 40%;
      background: #f7f7f8;
      border-radius: 4upx;
      height: 72upx;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 10upx;

      .name {
        width: 90%;
      }
    }

    .radio_main {
      width: 60%;
      padding-left: 10upx;
    }
  }
}

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

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

    .info_main {
      width: 100%;
      display: flex;
      flex-wrap: wrap;

      .list {
        width: 50%;
        display: flex;

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

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

    .text text {
      color: #999999;
      margin-right: 10upx;
    }
  }
}
</style>
