<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>
    </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
              @click="
                $u.route({
                  url: '/pages/information/user_list',
                  params: { CORPINFO_ID: item.CORPINFO_ID },
                })
              "
            >
              <view class="tit">
                <view class="u-line-2">{{ item.CORP_NAME }}</view>
                <view>
                  <u-icon name="arrow-right" color="#999999"></u-icon>
                </view>
              </view>
              <view class="info_main">
                <view>
                  <view class="list">
                    <view class="lable">安全监管类型:</view>
                    <view>{{ item.INDUSTRY_SPSIC }}</view>
                  </view>
                  <view class="list">
                    <view class="lable">管理单位:</view>
                    <view>{{ item.ALL_REGULATORY_DEPARTMENT_NAME }}</view>
                  </view>
                </view>
                <view class="list">
                  <view class="lable">主要负责人:</view>
                  <view>{{ item.TZ_NUM }}人</view>
                </view>
                <view class="list">
                  <view class="lable">安全生产管理人员:</view>
                  <view>{{ item.QY_NUM }}人</view>
                </view>
                <view class="list">
                  <view class="lable">特种作业人员:</view>
                  <view>{{ item.AQ_NUM }}人</view>
                </view>
                <view class="list">
                  <view class="lable">特种设备操作人员:</view>
                  <view>{{ item.ZZ_NUM }}人</view>
                </view>
              </view>
            </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 { getCertifiedPersonnelList } 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,
      searchForm: {
        keyword: "",
        departmentName: "",
        departmentId: "",
      },
    };
  },
  created() {
    this.fnGetData();
  },
  methods: {
    async fnGetData() {
      const resData = await getCertifiedPersonnelList({
        showCount: this.pageSize,
        currentPage: this.currentPage,
        KEYWORDS: this.searchForm.keyword,
        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">
.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: 100%;
      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 {
        flex-basis: 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>
