<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">
          <div class="businessTitle">
            <van-icon name="link-o" />
            {{ item.orderId }}
          </div>
          <div class="productionNo" v-if="item.statementNo || item.reportNo">
            <van-icon name="coupon-o" />
            {{ item.statementNo }}
            <!-- 产品号都不为空才显示中间的分割空格, 以保持页面间距统一 -->
            <span v-if="item.statementNo && item.reportNo">&nbsp;&nbsp;</span>
            {{ item.reportNo }}
          </div>
          <div class="projectName">
            <div>
              <van-icon name="location-o" />
              {{ item.name }}
            </div>
          </div>
          <div>
            <van-tag type="primary" size="medium" class="van-tag">{{ item.nodeName }}</van-tag>
            <van-tag type="success" size="medium" class="van-tag">{{ item.handler }}</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/major';

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;
      });
    },
  },
};
</script>

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

.productionNo {
  width: 100%;
  font-size: 14px;
}

.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%;
}
</style>