<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="mt-10">
        <u-radio-group
          v-model="searchForm.state"
          style="width: 100%; display: flex; justify-content: space-between"
          @change="fnResetPaging"
        >
          <u-radio
            v-for="(item, index) in stateList"
            :key="index"
            :name="item.ID"
            :label="item.NAME"
          />
        </u-radio-group>
      </view>
      <view class="mt-10">
        <u-checkbox-group
          v-model="searchForm.isMine"
          placement="column"
          @change="checkMine"
        >
          <u-checkbox
            v-for="(item, index) in isMineList"
            :key="index"
            :custom-style="{ marginBottom: '8px' }"
            :name="item.ID"
            :label="item.NAME"
          >
          </u-checkbox>
        </u-checkbox-group>
      </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.SPECIAL_RECTIFICATION_INSPECT_HIDDEN_ID"
            class="wrap"
          >
            <view class="tit">
              <view class="u-line-2">{{ item.CORP_NAME }}</view>
            </view>
            <view class="text">
              <text>专项行动:</text>
              {{ item.ACTIVITY_TASK_NAME }}
            </view>
            <view class="text">
              <view style="display: flex">
                <text>检查人:</text>
                <view style="width: 70%; display: flex; flex-direction: column">
                  <view
                    v-for="(val, index) in item.inspectUserList"
                    :key="index"
                  >
                    {{ val }}
                  </view>
                </view>
              </view>
            </view>
            <view class="text">
              <text>发现时间:</text>
              {{ item.DISCOVER_TIME }}
            </view>
            <view class="text">
              <text>整改截止时间:</text>
              {{ item.RECTIFY_DEADLINE }}
            </view>
            <view class="text">
              <text>整改意见:</text>
              {{ item.DISPOSE }}
            </view>
            <view class="text">
              <text>隐患状态:</text>
              <template v-if="item.STATE === '1'"
                >{{ item.QUALIFIED === "0" ? "打回" : "" }}待整改</template
              >
              <template v-if="item.STATE === '2'">待复查</template>
              <template v-if="item.STATE === '3'">已复查</template>
            </view>
            <view class="bottem">
              <u-button
                v-if="item.STATE === '2'"
                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/hidden_review',
                    params: {
                      SPECIAL_RECTIFICATION_INSPECT_HIDDEN_ID:
                        item.SPECIAL_RECTIFICATION_INSPECT_HIDDEN_ID,
                    },
                  })
                "
              />
              <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/hidden_view',
                    params: {
                      SPECIAL_RECTIFICATION_INSPECT_HIDDEN_ID:
                        item.SPECIAL_RECTIFICATION_INSPECT_HIDDEN_ID,
                    },
                  })
                "
              />
              <u-button
                text="删除"
                type="error"
                custom-style="width:150upx; height:60upx; margin-left: 20upx;margin-right: 0;"
                @click="fnDelete(item.SPECIAL_RECTIFICATION_INSPECT_HIDDEN_ID)"
              />
            </view>
          </u-list-item>
        </u-list>
      </view>
      <empty v-else />
    </view>
  </view>
</template>

<script>
import {
  getSpecialRectificationInspectionEnterpriseHiddenList,
  setSpecialRectificationInspectionEnterpriseHiddenDelete,
} from "@/api";

export default {
  data() {
    return {
      list: [],
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      searchForm: {
        keyword: "",
        state: "",
        isMine: [],
      },
      stateList: [
        { ID: "", NAME: "全部" },
        { ID: "1", NAME: "待整改" },
        { ID: "2", NAME: "待复查" },
        { ID: "3", NAME: "已复查" },
      ],
      isMineList: [{ ID: "1", NAME: "只看自己" }],
    };
  },
  created() {
    this.searchForm.isMine.push("1");
    this.fnGetData();
  },
  methods: {
    async fnGetData() {
      const resData =
        await getSpecialRectificationInspectionEnterpriseHiddenList({
          showCount: this.pageSize,
          currentPage: this.currentPage,
          KEYWORDS: this.searchForm.keyword,
          STATE: this.searchForm.state,
          ISMINE:
            this.searchForm.isMine.length > 0 ? this.searchForm.isMine[0] : "",
        });
      resData.varList.forEach((item) => {
        const inspectUserList = [];
        item.INSPECT_USER_NAME.split("_").forEach((user) => {
          inspectUserList.push(user ? user.replace(/,/g, "/") : "");
        });
        item.inspectUserList = inspectUserList;
      });
      this.list = [...this.list, ...resData.varList];
      this.totalPage = resData.page.totalPage;
    },
    scrolltolower() {
      this.currentPage++;
      if (this.totalPage >= this.currentPage) this.fnGetData();
    },
    checkMine(n) {
      this.searchForm.isMine = n;
      this.list = [];
      this.currentPage = 1;
      this.fnGetData();
    },
    fnResetPaging() {
      this.list = [];
      this.currentPage = 1;
      this.fnGetData();
    },
    fnDelete(SPECIAL_RECTIFICATION_INSPECT_HIDDEN_ID) {
      uni.showModal({
        title: "提示",
        content: "确认要删除吗？",
        success: async (res) => {
          if (res.confirm) {
            await setSpecialRectificationInspectionEnterpriseHiddenDelete({
              SPECIAL_RECTIFICATION_INSPECT_HIDDEN_ID,
            });
            setTimeout(() => {
              uni.$u.toast("删除成功");
            });
            this.fnResetPaging();
          }
        },
      });
    },
  },
};
</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>
