<template>
  <div>
    <BackBar title="正在进行-个贷" lefttext="返回" />
    <van-search v-model="listQuery.keyword" placeholder="请输入搜索关键词" @search="onSearch()" />
    <van-pull-refresh v-model="loading" @refresh="onRefresh()">
      <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="getPendingOrder()">
        <div class="card" v-for="item in listData" :key="item.id" @click="toDetail(item)">
          <div class="businessTitle">
            <van-icon name="link-o" />
            {{ item.orderId }}
          </div>
          <div class="projectName">
            <div>
              <van-icon name="location-o" />
              {{ item.location }}
            </div>
          </div>
          <div class="clientInfo">
            <div>
              <van-icon name="contact-o" />
              {{ item.clientName }}-{{ item.clientSubName}}
            </div>
          </div>
          <div>
            <van-tag type="primary" size="medium" class="van-tag">{{ item.currentNodeName }}</van-tag>
            <van-tag type="success" size="medium" class="van-tag">{{ item.clientManager }}</van-tag>
            <van-tag color="#969799" size="medium" class="van-tag">{{ item.created }}</van-tag>
          </div>
        </div>
      </van-list>
    </van-pull-refresh>
    <van-back-top right="10vw" bottom="10vh" />
  </div>
</template>

<script>
import { pendingOrder } from '@/api/personal';

export default {
  data() {
    return {
      loading: false,
      listData: [],
      finished: false,
      listQuery: {
        // 当前页数
        current: 1,
        // 查询关键字
        keyword: null,
      },
    };
  },
  created() {
    this.getPendingOrder();
  },
  methods: {
    // 列表刷新
    onRefresh() {
      this.listQuery.current = 1;
      this.finished = false;
      this.listData = [];
      this.getPendingOrder();
    },
    // 列表关键字搜索
    onSearch() {
      this.listQuery.current = 1;
      this.finished = false;
      this.listData = [];
      this.getPendingOrder();
    },
    // 获取我的订单
    getPendingOrder() {
      this.loading = true;
      pendingOrder(this.listQuery).then((res) => {
        if (res.code == 200) {
          if (res.data.records) {
            this.listData = this.listData.concat(res.data.records);
          }
          // 判断是否还有下一页
          if (res.data.pages > this.listQuery.current) {
            // 服务端返回的总页数大于当前页数, 将当前页数+1
            this.listQuery.current++;
          } else {
            // 反之停止加载
            this.finished = true;
          }
        }
        this.loading = false;
      });
    },
    toDetail(item) {
      const detailInfo = {
        orderId: item.orderId,
        location: item.location,
        acreage: item.acreage,
        price: item.price,
        amount: item.amount / 10000,
        clientName: item.clientName,
        clientSubName: item.clientSubName,
        agent: item.agent,
        contactName: item.contactName,
        contactTel: item.contactTel,
        bailorA: item.bailorA,
        bailoraTel: item.bailoraTel,
        bailorbTel: item.bailorbTel,
        bailorB: item.bailorB,
        realAmount: item.realAmount,
        shouldAmount: item.shouldAmount,
        invoiceAmount: item.invoiceAmount,
        created: item.created,
      };
      this.$router.push({
        path: `/index/personal/detail`,
        query: {
          item: JSON.stringify(detailInfo),
        },
      });
    },
  },
};
</script>

<style scoped>
.card {
  background-color: white;
  border-radius: 5px;
  padding: 10px;
  margin: 10px;
}

.projectName {
  width: 100%;
  margin-bottom: 5px;
  display: flex;
}

.van-tag {
  margin: 2px;
}

.businessTitle {
  font-weight: bold;
  margin-bottom: 5px;
}

/deep/ .van-tabs__wrap {
  width: 100%;
}

.clientInfo {
  margin-bottom: 5px;
}
</style>