<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"
        >
          <div class="radio-group-wrap">
            <div v-for="(item, index) in inspectTypeList" :key="index">
              <u-radio
                :name="item.BIANMA"
                :label="item.NAME"
                style="margin-left: 10upx"
              />
            </div>
          </div>
        </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.SUPERVISE_INSPECT_ID"
            class="wrap"
          >
            <view class="tit">
              <view class="u-line-2">{{ item.INSPECT_DEPARTMENT_NAME }}</view>
            </view>
            <view class="text">
              <text>帮扶时间:</text>
              {{ item.INSPECTTIME }}
            </view>
            <view class="text">
              <text>帮扶人员:</text>
              {{ item.INSPECT_USER_NAME }}
            </view>
            <view class="text">
              <text>隐患数:</text>
              {{ item.HIDDENNUM }}
            </view>
            <view class="bottem">
              <u-button
                v-if="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/supervision_inspection/edit_inspect',
                    params: {
                      SUPERVISE_INSPECT_ID: item.SUPERVISE_INSPECT_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/supervision_inspection/inspect_record_view',
                    params: {
                      SUPERVISE_INSPECT_ID: item.SUPERVISE_INSPECT_ID,
                    },
                  })
                "
              />
              <u-button
                text="删除"
                type="error"
                custom-style="width:150upx; height:60upx; margin-left: 20upx;margin-right: 0;"
                @click="fnDelete(item.SUPERVISE_INSPECT_ID)"
              />
            </view>
          </u-list-item>
        </u-list>
      </view>
      <empty v-else />
    </view>
  </view>
</template>

<script>
import {
  getInspectType,
  getSupervisionInspectionRecordList,
  setSupervisionInspectionRecordDelete,
} from "@/api";

export default {
  data() {
    return {
      list: [],
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      searchForm: {
        inspectType: "",
      },
      CORPINFO_ID: "",
      inspectTypeList: [],
    };
  },

  onLoad(query) {
    this.CORPINFO_ID = query.CORPINFO_ID;
    this.fnGetInspectType();
  },
  onShow() {
    this.list = [];
    this.pageSize = 10;
    this.currentPage = 1;
    this.totalPage = 0;
    this.fnGetData();
  },
  methods: {
    async fnGetInspectType() {
      const resData = await getInspectType();
      this.inspectTypeList = resData.list;
    },
    async fnGetData() {
      const resData = await getSupervisionInspectionRecordList({
        showCount: this.pageSize,
        currentPage: this.currentPage,
        INSPECTTYPE: this.searchForm.inspectType,
        CORPINFO_ID: this.CORPINFO_ID,
      });
      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(SUPERVISE_INSPECT_ID) {
      uni.showModal({
        title: "提示",
        content: "确认要删除吗？",
        success: async (res) => {
          if (res.confirm) {
            await setSupervisionInspectionRecordDelete({
              SUPERVISE_INSPECT_ID,
            });
            setTimeout(() => {
              uni.$u.toast("删除成功");
            });
            this.fnResetPaging();
          }
        },
      });
    },
  },
};
</script>

<style scoped lang="scss">
.container {
  width: 100%;
  min-height: 100vh;
  background: #fafafa;
}
.radio-group-wrap {
  display: flex;
  flex-wrap: wrap;
  > div {
    padding: 10upx;
  }
}

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

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