<template>
  <view
    ><page-view
      @loadList="
        (v) => {
          getList(v);
        }
      "
      :noMoreData="pageList.noMoreData"
      :list="pageList.list"
      :height="204"
      :isLoading="pageList.isLoading"
    >
      <view class="box">
        <scroll-view scroll-x class="scroll-view">
          <uni-table stripe emptyText="">
            <!-- 表头行 -->
            <uni-tr>
              <uni-th v-for="(item, index) in tableTitleList" :key="index"
                >{{ item.name }}
              </uni-th>
            </uni-tr>
            <!-- 表格数据行 -->
            <uni-tr v-for="(item, index) in pageList.list" :key="index">
              <uni-td v-for="(tItem, index) in tableTitleList" :key="index">{{
                item[tItem.key]
              }}</uni-td>
              <uni-td>
                <u-button type="primary" shape="circle" @click="goRegis(item.id)"
                  >去登记</u-button
                >
              </uni-td>
            </uni-tr>
          </uni-table>
        </scroll-view>
      </view>
    </page-view>

    <view class="btn-box-fix-btn">
      <view
        ><u-button type="primary" shape="circle" @click="goInquiry()"
          >去询价</u-button
        >
        <view @click="goRecovery" class="regis">不需询价, 直接登记回收</view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import PageView from "@/components/PageView/index.vue";
import { VehicleApi } from "@/services";
import pinia from "@/store";
import { useMemberStore } from "@/store/index";
const pageList: PageResult<any> = reactive({
  total: 0,
  list: [],
  pageNum: 1,
  pageSize: 100,
});
const resetPageList = () => {
  pageList.noMoreData = false;
  pageList.total = 0;
  pageList.list = [];
  pageList.pageNum = 1;
  pageList.pageSize = 100;
};
const tableTitleList = reactive([
  {
    name: "时间",
    key: "createdTime",
  },
  {
    name: "品牌型号",
    key: "brandModel",
  },
  {
    name: "总重量",
    key: "totalWeight",
  },
  {
    name: "预估价格",
    key: "totalPrice",
  }
]);
// VehicleApi.queryRegis({
//   startTime: "2024-09-01 00:00:00",
//   endTime: "2024-09-30 23:59:59",
// }).then((res:any) => {
//   if(res.code === 200) {
//     res.data.list
//   }
// });
const goRegis = (id:number) => {
  uni.navigateTo({
    url: "/pagesVehicle/registration?id=" + id, // 要跳转到的页面路径
  });
};

const goInquiry = () => {
  uni.navigateTo({
    url: "/pagesVehicle/inquiry", // 要跳转到的页面路径
  });
};

const goRecovery = () => {
  uni.navigateTo({
    url: "/pagesVehicle/recovery", // 要跳转到的页面路径
  });
};

const getList = (v?: boolean) => {
  if (v) {
    if (Math.ceil(pageList.total / pageList.pageSize) > pageList.pageNum) {
      pageList.pageNum++;
    } else {
      pageList.noMoreData = true;
      return;
    }
  }
  let params: any = {
    pageSize: pageList.pageSize,
    pageNum: pageList.pageNum,
    status: 1, // 待登记
  };
  pageList.isLoading = true;
  VehicleApi.getRegisList(params).then((res: any) => {
    if (res.code === 200) {
      pageList.isLoading = false;
      pageList.list = pageList.list = pageList.list.concat(res.data.list);
      pageList.total = res.data.total;
    }
  });
};

getList();
</script>
<style lang="scss" scoped>
.box {
  padding: 28rpx 20rpx;
  .scroll-view {
    white-space: nowrap;
    width: 100%;
    overflow: auto;
  }
  ::v-deep.uni-table{
    min-width: 700px !important;
  }
}
.btn-box-fix-btn {
  justify-content: center;
  view {
    width: 70%;
  }
}
.regis {
  font-size: 12px;
  text-align: center;
  padding-top: 15px;
  width: 100% !important;
  color: $u-primary;
  font-weight: bold;
}
</style>
