<template>
  <div class="carmange">
    <div class="top">
      <div class="add">
        <div class="text" @click="jumpPage('/pages/subPackages/carmange/add')">
          新增
        </div>
        <van-icon name="add" />
      </div>
    </div>
    <div class="list">
      <div class="list-row" v-for="item in carList">
        <div class="left">
          <div class="info">车牌号：{{ item.carNo }}</div>
          <div class="info1">司机姓名：{{ item.driverName }}</div>
          <div class="info1">手机号：{{ item.driverUsername }}</div>
        </div>
        <div class="right">
          <van-icon
            @click="deteleRow(item)"
            size="48rpx"
            color="rgba(138, 5, 84, 1)"
            name="delete"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { bizCarListPage, deleteCar } from "@/js_sdk/chooseCarApi.js";
import { getUserLocalStorageInfo } from "@/js_sdk/localUserInfo.js";
import { dateCompare } from "../../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/util";

export default {
  data() {
    return {
      searchData: {
        pageNum: 1,
        pageSize: 10,
      },
      carList: [],
    };
  },
  onShow() {
    this.carList = [];
    this.searchData.bizId = getUserLocalStorageInfo().biz.id;
    this.bizCarListPage();
  },
  methods: {
    async deteleRow(item) {
      let that = this;
      that.$showToast("删除成功");
      wx.showModal({
        title: "提示",
        content: "是否确认删除该车辆记录",
        async success(res) {
          if (res.confirm) {
            let data = await deleteCar({ id: item.id });
            console.log(data);
            if (data.errmsg == "成功") {
              that.searchData.pageNum = 1;
              that.carList = [];
              that.bizCarListPage();
            }
            console.log(data);
          } else if (res.cancel) {
            console.log("用户点击取消");
          }
        },
      });
    },
    async bizCarListPage() {
      let { data } = await bizCarListPage(this.searchData);
      console.log(data);
      this.carList.push(...data.list);
    },
    jumpPage(path) {
      console.log(path);
      uni.navigateTo({
        url: path,
        fail: (fail) => {},
      });
    },
  },
};
</script>

<style lang="scss">
.carmange {
  .top {
    width: 750rpx;
    color: #8a0554;
    height: 80rpx;
    background: white;
    display: flex;
    align-items: center;
    padding: 0 36rpx;
    box-sizing: border-box;
    .add {
      display: flex;
      margin-left: auto;
      .text {
        margin-right: 12rpx;
      }
    }
  }
  .list {
    width: 100%;
    box-sizing: border-box;
    .list-row {
      box-sizing: border-box;
      padding: 24rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .left {
        .info {
          font-weight: 400;
          font-size: 32rpx;
          color: #222222;
          margin-bottom: 16rpx;
        }
        .info1 {
          font-weight: 400;
          font-size: 28rpx;
          color: #888888;
        }
      }
    }
  }
}
</style>