<template>
  <view class="container">
    <!--    <view class="searcher">
      <view class="radio_main">
        <u-radio-group
          v-model="searchForm.inspectType"
          style="width: 100%; display: flex; justify-content: space-between"
          @change="fnResetPaging"
        >
          <u-radio
            v-for="(item, index) in inspectTypeList"
            :key="index"
            :name="item.BIANMA"
            :label="item.NAME"
          />
        </u-radio-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_ID"
            class="wrap"
          >
            <view class="text">
              <text>检查时间:</text>
              {{ item.INSPECTTIME }}
            </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.HIDDENNUM }}
            </view>
            <view class="bottem">
              <u-button
                v-if="ISREPORT === true && item.ISDELETE === '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/edit_inspect',
                    params: {
                      SPECIAL_RECTIFICATION_INSPECT_ID:
                        item.SPECIAL_RECTIFICATION_INSPECT_ID,
                      SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID:
                        item.SPECIAL_RECTIFICATION_ACTIVITY_TASK_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/inspect_record_view',
                    params: {
                      SPECIAL_RECTIFICATION_INSPECT_ID:
                        item.SPECIAL_RECTIFICATION_INSPECT_ID,
                    },
                  })
                "
              />
              <u-button
                v-if="ISREPORT === true"
                text="删除"
                type="error"
                custom-style="width:150upx; height:60upx; margin-left: 20upx;margin-right: 0;"
                @click="fnDelete(item.SPECIAL_RECTIFICATION_INSPECT_ID)"
              />
            </view>
          </u-list-item>
        </u-list>
      </view>
      <empty v-else />
    </view>
  </view>
</template>

<script>
import {
  getInspectType,
  getSpecialRectificationInspectionRecordList,
  setSpecialRectificationInspectionRecordDelete,
} from "@/api";

export default {
  data() {
    return {
      list: [],
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      searchForm: {
        inspectType: "",
      },
      SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID: "",
      CORPINFO_ID: "",
      inspectTypeList: [],
      ISREPORT: true,
    };
  },
  onLoad(query) {
    this.SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID =
      query.SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID;
    this.CORPINFO_ID = query.CORPINFO_ID;
    this.ISREPORT = query.ISREPORT === "true";
    // this.fnGetData();
    this.fnGetInspectType();
  },
  onShow() {
    this.list = [];
    this.pageSize = 10;
    this.currentPage = 1;
    this.totalPage = 0;
    this.fnGetData();
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo;
    },
  },
  methods: {
    async fnGetInspectType() {
      const resData = await getInspectType();
      this.inspectTypeList = resData.list;
    },
    async fnGetData() {
      const resData = await getSpecialRectificationInspectionRecordList({
        showCount: this.pageSize,
        currentPage: this.currentPage,
        INSPECTTYPE: this.searchForm.inspectType,
        SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID:
          this.SPECIAL_RECTIFICATION_ACTIVITY_TASK_ID,
        CORPINFO_ID: this.CORPINFO_ID,
      });
      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();
    },
    fnResetPaging() {
      this.list = [];
      this.currentPage = 1;
      this.fnGetData();
    },
    fnDelete(SPECIAL_RECTIFICATION_INSPECT_ID) {
      uni.showModal({
        title: "提示",
        content: "确认要删除吗？",
        success: async (res) => {
          if (res.confirm) {
            await setSpecialRectificationInspectionRecordDelete({
              OPERATOR: this.userInfo.NAME,
              SPECIAL_RECTIFICATION_INSPECT_ID,
            });
            setTimeout(() => {
              uni.$u.toast("删除成功");
            });
            this.fnResetPaging();
          }
        },
      });
    },
  },
};
</script>

<style scoped lang="scss">
.container {
  width: 100%;
  min-height: 100vh;
  background: #fafafa;
}

.searcher {
  width: 100%;
  background: #ffffff;
  padding: 20upx;
  box-sizing: border-box;
  margin-top: 20upx;
  border-bottom: 1px solid #eeeeee;
}

.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;
    }
    .flex {
      display: flex;
    }

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