<template>
  <view class="content">
    <view class="search card">
      <u--input
          prefixIcon="search"
          placeholder="请输入关键字"
          border="surround"
          v-model="CORP_NAME"
          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.CORP_NAME }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>
              属地:
              <template v-if="item.prvinceName">{{ item.prvinceName }}</template>
              <template v-if="item.cityName"> -- {{ item.cityName }}</template>
              <template v-if="item.countryName"> --{{ item.countryName }}</template>
              <template v-if="item.villageName"> -- {{ item.villageName }}</template>
            </text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>所属行业:{{ item.INDUSTRY_NAME }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>法定代表人:{{ item.LR_NAME }}</text>
            <text>电话:{{ item.CONTACTS_PHONE }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>地址:{{ item.ADDRESS_BUSINESS }}</text>
          </view>
          <view class="flex-end mt-10 btn">
            <u-button type="primary" text="查看" size="mini" @click="fnNavigatorDetail(item.CORPINFO_ID)"></u-button>
          </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
  </view>
</template>

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

export default {
  data() {
    return {
      CORP_NAME: '',
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      list: [],
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },
  onLoad() {
    this.resetList()
  },
  methods: {
    async getData() {
      let resData = await getCorpInfoList({
        USER_ID: this.userInfo.USER_ID,
        CORP_NAME: this.CORP_NAME,
        showCount: this.pageSize,
        currentPage: this.currentPage,
      });
      this.list = [...this.list, ...resData.varList];
      this.totalPage = resData.page.totalPage;
    },
    resetList() {
      this.pageSize = 10
      this.currentPage = 1
      this.list = []
      this.getData()
    },
    fnNavigatorDetail(CORPINFO_ID) {
      uni.$u.route({
        url: '/pages/branch-information-management/branch-information/detail',
        params: {
          CORPINFO_ID,
        }
      })
    },
    scrolltolower() {
      this.currentPage++;
      if (this.totalPage >= this.currentPage) this.getData();
    },
  }
}
</script>

<style scoped lang="scss">
.search {
  display: flex;

  .ml-10 {
    margin-left: 10rpx;
  }

  .bth-mini {
    width: 100rpx;
  }

}

.btn {
  width: 100rpx;
  float: right;
}

</style>