<template>
  <div class="mod-carManage app-container">
    <!--    卡片 视图区域-->
    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-input
          v-model="dataForm.fleetCompanyId"
          placeholder="车队id"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <!--        车辆管理添加驾驶员-->
        <!--车队可以加车辆-->
        <!--        个人照片改成身份证-->
        <el-button @click="getDataList()">查询</el-button>
        <el-button type="primary" @click="addOrUpdateHandle()"
          >添加车辆</el-button
        >
        <!--        <el-button v-if="isAuth('fleet:carManage:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%"
    >
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
      >
      </el-table-column>
      <el-table-column
        prop="fleetCompanyName"
        header-align="center"
        align="center"
        width="120"
        :show-overflow-tooltip="true"
        label="车队名称"
      >
      </el-table-column>
      <el-table-column
        prop="driverName"
        header-align="center"
        align="center"
        width="120"
        :show-overflow-tooltip="true"
        label="司机名称"
      >
      </el-table-column>

      <el-table-column
        prop="carNum"
        header-align="center"
        align="center"
        width="130"
        label="车牌号"
      >
      </el-table-column>
      <el-table-column
        prop="hangNum"
        header-align="center"
        align="center"
        label="挂号"
      >
      </el-table-column>
      <el-table-column
        prop="fuelType"
        header-align="center"
        align="center"
        width="130"
        label="燃油类型"
      >
      </el-table-column>
      <el-table-column
        prop="carType"
        header-align="center"
        align="center"
        width="130"
        label="车辆类型"
      >
      </el-table-column>
      <el-table-column
        prop="carName"
        header-align="center"
        align="center"
        width="130"
        label="车辆名称"
      >
      </el-table-column>
      <el-table-column
        prop="carBrand"
        header-align="center"
        align="center"
        width="130"
        label="车辆品牌"
      >
      </el-table-column>
      <!--<el-table-column
        prop="manufactureUnit"
        header-align="center"
        align="center"
        width="130"
        label="制造单位">
      </el-table-column>
      <el-table-column
        prop="officeOfCertificate"
        header-align="center"
        align="center"
        width="130"
        label="发证机关">
      </el-table-column>
      <el-table-column
      prop="buyCarDate"
      header-align="center"
      align="center"
      width="130"
      label="购车日期">
    </el-table-column>
    <el-table-column
        prop="drivingLicenseSrc"
        header-align="center"
        align="center"
        width="150"
        label="行驶证头图片">
      </el-table-column>
      <el-table-column
        prop="drivingPendantSrc"
        header-align="center"
        align="center"
        width="150"
        label="行驶证挂件图片">
      </el-table-column>
      <el-table-column
        prop="operationLicenseSrc"
        header-align="center"
        align="center"
        width="150"
        label="运营证头图片">
      </el-table-column>
      <el-table-column
        prop="technologySrc"
        header-align="center"
        align="center"
        width="150"
        label="技术评定证书图片">
      </el-table-column>
      <el-table-column
        prop="drivingLoadSrc"
        header-align="center"
        align="center"
        width="150"
        label="营运挂载图片">
      </el-table-column>
      <el-table-column
        prop="secondLvMaintainSrc"
        header-align="center"
        align="center"
        width="150"
        label="二级维护图片">
      </el-table-column>
      <el-table-column
        prop="tafficConstranintInsuranceSrc"
        header-align="center"
        align="center"
        width="150"
        label="交强险图片">
      </el-table-column>
      <el-table-column
        prop="businessInsuranceSrc"
        header-align="center"
        align="center"
        width="150"
        label="商业保险图片">
      </el-table-column>
      <el-table-column
        prop="accpetCarrageInsuranceSrc"
        header-align="center"
        align="center"
        width="150"
        label="承运人保险图片">
      </el-table-column>
      <el-table-column
        prop="pullCarType"
        header-align="center"
        align="center"
        width="150"
        label="牵引车辆型号">
      </el-table-column>
      <el-table-column
        prop="pullCarShelfNum"
        header-align="center"
        align="center"
        width="150"
        label="牵引车车架号">
      </el-table-column>-->
      <el-table-column
        prop="mountCarType"
        header-align="center"
        align="center"
        width="130"
        label="挂车型号"
      >
      </el-table-column>
      <el-table-column
        prop="mountCarNum"
        header-align="center"
        align="center"
        width="130"
        label="挂车车架号"
      >
      </el-table-column>
      <el-table-column
        prop="engine"
        header-align="center"
        align="center"
        width="130"
        label="发动机型号"
      >
      </el-table-column>
      <el-table-column
        prop="carLoadPersion"
        header-align="center"
        align="center"
        width="130"
        label="核载人数"
      >
      </el-table-column>

      <el-table-column
        prop="outerSize"
        header-align="center"
        align="center"
        width="130"
        label="外阔尺寸mm"
      >
      </el-table-column>
      <el-table-column
        prop="sumWeight"
        header-align="center"
        align="center"
        label="总重量kg"
      >
      </el-table-column>
      <el-table-column
        prop="vouchWeight"
        header-align="center"
        align="center"
        width="150"
        label="核定重量kg"
      >
      </el-table-column>
      <el-table-column
        prop="equipWeight"
        header-align="center"
        align="center"
        width="150"
        label="装备质量kg"
      >
      </el-table-column>

      <el-table-column
        prop="regiestDate"
        header-align="center"
        align="center"
        width="130"
        label="注册日期"
      >
        <template slot-scope="scope">
          <span v-if="!scope.row.regiestDate"></span>
          <span v-else>{{ scope.row.regiestDate.slice(0, 10) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="abandonDate"
        header-align="center"
        align="center"
        width="130"
        label="报废日期"
      >
        <template slot-scope="scope">
          <span v-if="!scope.row.abandonDate"></span>
          <span v-else>{{ scope.row.abandonDate.slice(0, 10) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="creatTime"
        header-align="center"
        align="center"
        width="130"
        label="添加时间"
      >
        <template slot-scope="scope">
          <span v-if="!scope.row.creatTime"></span>
          <span v-else>{{ scope.row.creatTime.slice(0, 10) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="130"
        label="操作"
      >
        <!--        <template slot-scope="scope">-->
        <!--          <el-tooltip class="item" effect="dark" content="修改" :enterable="false" placement="top">-->
        <!--            <el-button-->
        <!--              v-hasPermi="['fleet:carManage:edit']"-->
        <!--              type="primary"-->
        <!--              icon="el-icon-edit"-->
        <!--              content="修改"-->
        <!--              size="mini"-->
        <!--              circle @click="addOrUpdateHandle(scope.row)"-->
        <!--            ></el-button>-->
        <!--          </el-tooltip>-->
        <!--          <el-tooltip class="item" effect="dark" content="删除" :enterable="false" placement="top">-->
        <!--            <el-button v-hasPermi="['fleet:carManage:delete']"-->
        <!--                       icon="el-icon-delete"-->
        <!--                       type="danger"-->
        <!--                       circle-->
        <!--                       size="mini" @click="deleteHandle(scope.row.Id)"-->
        <!--            ></el-button>-->
        <!--          </el-tooltip>-->
        <!--        </template>-->
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="addOrUpdateHandle(scope.row)"
            >查看
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row.Id)"
            >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="dataForm.pageNum"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="dataForm.pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="getDataList"
      :dataForm="editModel"
    ></add-or-update>
  </div>
</template>

<script>
import { listFtmsorderbills, deleted } from "@/api/fleet/carManage";
import AddOrUpdate from "./carManage-add-or-update";
import { addSet, select, resetModule } from "@/api/system/set";
import Cookies from "js-cookie";
import draggable from "vuedraggable";

export default {
  data() {
    return {
      dataForm: {
        pageNum: 1,
        pageSize: 10,
      },
      editModel: {},
      dataList: [],
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
    };
  },
  components: {
    AddOrUpdate,
  },
  activated() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = false;
      listFtmsorderbills(this.dataForm).then((data) => {
        console.log(data);
        if (data && data.code === 200) {
          this.dataList = data.rows;
          this.totalPage = data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.dataForm.pageSize = val;
      console.log(val);
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      console.log(val);
      this.dataForm.pageNum = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    addOrUpdateHandle(row) {
      this.addOrUpdateVisible = true;
      if (row) {
        this.editModel = row;
      } else {
        this.editModel = {
          id: null,
          fleetCompanyId: null,
          carNum: null,
          hangNum: null,
          fuelType: null,
          carType: null,
          carName: null,
          carBrand: null,
          manufactureUnit: null,
          officeOfCertificate: null,
          pullCarType: null,
          pullCarShelfNum: null,
          mountCarType: null,
          mountCarNum: null,
          engine: null,
          carLoadPersion: null,
          buyCarDate: null,
          regiestDate: null,
          abandonDate: null,
          outerSize: null,
          sumWeight: null,
          vouchWeight: null,
          equipWeight: null,
          drivingLicenseSrc: null,
          drivingPendantSrc: null,
          operationLicenseSrc: null,
          technologySrc: null,
          drivingLoadSrc: null,
          secondLvMaintainSrc: null,
          tafficConstranintInsuranceSrc: null,
          businessInsuranceSrc: null,
          accpetCarrageInsuranceSrc: null,
          creatTime: null,
          modificationTime: null,
        };
      }
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init();
      });
    },
    // 删除
    deleteHandle(id) {
      let carManageIds = [
        id
          ? [id]
          : this.dataListSelections.map((item) => {
              return item.userId;
            }),
      ];
      this.$confirm(
        `确定对[id=${carManageIds.join(",")}]进行[${
          id ? "删除" : "批量删除"
        }]操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          deleted(carManageIds).then((data) => {
            if (data && data.code === 200) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.getDataList();
                },
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="scss" scoped>
.tabSetting {
  display: flex;
  justify-content: flex-end;
}
.listStyle {
  display: flex;
  border-top: 1px solid #dcdfe6;
  border-left: 1px solid #dcdfe6;
  border-right: 1px solid #dcdfe6;
}
.listStyle:last-child {
  border-bottom: 1px solid #dcdfe6;
}
.progress {
  display: flex;
  align-items: center;
  padding: 2px;
  background-color: rgba(0, 0, 0, 0.05);
  height: 100%;
}
</style>