<template>
  <view class="content">
    <view class="search card">
      <u--input
          prefixIcon="search"
          placeholder="请输入关键字"
          border="surround"
          v-model="KEYWORDS"
          clearable
          shape="circle"
      ></u--input>
      <view class="bth-mini ml-10">
        <u-button type="success" text="确定" @click="resetList"></u-button>
      </view>

    </view>
    <u-list @scrolltolower="scrolltolower" v-if="list.length > 0">
      <u-list-item v-for="(item, index) in list" :key="index">
        <view>
          <view class="flex-between main-title">
            <text>{{ item.OUTSOURCED_NAME }}</text>
          </view>
          <view v-show="item.IS_CORP_TYPE== '1'" class="flex-between mt-10 subtitle">
            <text>
              主管部门：{{ item.Q_COMPETENT_DEPT_NAME }}
            </text>
          </view>
          <view v-show="item.IS_CORP_TYPE== '1'" class="flex-between mt-10 subtitle">
            <text>
              监督部门：{{ item.DEPARTMENT_NAME }}
            </text>
          </view>
          <view v-show="item.IS_CORP_TYPE== '0'" class="flex-between mt-10 subtitle">
            <text>
              主管部门：{{ item.MANAGER_DEPARTMENT_NAME }}
            </text>
          </view>
          <view v-show="item.IS_CORP_TYPE== '0'" class="flex-between mt-10 subtitle">
            <text>
              监管部门：{{ item.DEPARTMENT_NAME }}
            </text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>相关方单位负责人：{{ item.UNITS_PIC_NAME }}</text>
            <text>电话：{{ item.UNITS_PHONE }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>安全环保检查次数：{{ item.CHECK_COUNT }}</text>

            <view>
              <u-button type="primary" text="进入" size="mini"
                        @click="fnNavigatorDetail(item.OUTSOURCED_ID)"></u-button>
            </view>
          </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
  </view>
</template>

<script>
import {getKeyProjectsListOutsourced} from "../../../api";

export default {
  data() {
    return {
      KEYWORDS: '',
      CORPINFO_ID: '',
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      list: [],
    }
  },
  onLoad(e) {
    this.CORPINFO_ID = e.CORPINFO_ID
  },
  onShow() {
    this.resetList()
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },
  methods: {
    async getData() {
      let resData = await getKeyProjectsListOutsourced({
        KEYWORDS: this.KEYWORDS,
        showCount: this.pageSize,
        currentPage: this.currentPage,
        CORPINFO_ID: this.CORPINFO_ID,
        UserId: this.userInfo.USER_ID,
        STATE: '1'
      });
      this.list = [...this.list, ...resData.varList];
      this.totalPage = resData.page.totalPage;
    },
    resetList() {
      this.pageSize = 10
      this.currentPage = 1
      this.list = []
      this.getData()
    },
    fnNavigatorDetail(OUTSOURCED_ID) {
      uni.$u.route({
        url: '/pages/key-project-management/safety-environmental-inspection/detail-list',
        params: {
          OUTSOURCED_ID,
          CORPINFO_ID: this.CORPINFO_ID
        }
      })
    },
    scrolltolower() {
      this.currentPage++;
      if (this.totalPage >= this.currentPage) this.getData();
    },
  }
}
</script>

<style scoped lang="scss">
.see_btn {
  width: 200rpx;
  float: right;
}

</style>
