<template>
  <el-dialog
    :title="title"
    :visible.sync="selectCarDialogFlag"
    :before-close="handleClose"
    :close-on-click-modal="false"
    top="5vh"
    :close-on-press-escape="false"
    append-to-body
    width="90%"
  >
    <el-card shadow="never">
      <!-- 表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        row-key="id"
        height="calc(100vh - 400px)"
        class="dict-table"
        @cell-click="cellClick"
      >
        <!-- 表头工具栏 -->
        <template v-slot:action="{ row }">
          <el-radio class="radio" v-model="radio" :label="row.id"
          ><i></i
          ></el-radio>
        </template>
      </ele-pro-table>
    </el-card>

    <div class="btns">
      <el-button type="primary" size="small" @click="selected">选择</el-button>
      <el-button size="small" @click="handleClose">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import DepartmentTree from '@/components/DepartmentTree/index.vue';
import {carBookPageListAPI} from "@/api/transportManager/carBook";

export default {
  components: {
    DepartmentTree
  },
  props: {
    selectCarDialogFlag: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      currentIndex: 0,
      title: '选择车辆',
      visible: false,
      columns: [
        {
          action: 'action',
          slot: 'action',
          align: 'center',
          label: '选择'
        },
        {
          columnKey: 'index',
          label: '序号',
          type: 'index',
          width: 55,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'trakNumber',
          label: '车牌号',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 120,
          slot: 'trakNumber'
        },
        {
          prop: 'status',
          label: '状态',
          align: 'center',
          showOverflowTooltip: true,
          slot: 'status',
          minWidth: 80
        },
        {
          prop: 'type',
          label: '车型',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100
        },
        {
          prop: 'maxVolume',
          label: '最大体积',
          align: 'center',
          slot: 'maxVolume',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'loadWeight',
          label: '载重',
          align: 'center',
          slot: 'loadWeight',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'freeWeight',
          label: '空车重量',
          align: 'center',
          slot: 'freeWeight',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'drivingLicenseFile',
          label: '行驶证',
          align: 'center',
          slot: 'drivingLicenseFile',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'transportLicenseFile',
          label: '运输证',
          align: 'center',
          slot: 'transportLicenseFile',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'defaultDriver',
          label: '默认司机',
          align: 'center',
          slot: 'defaultDriver',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'phone',
          label: '联系电话',
          align: 'center',
          slot: 'phone',
          showOverflowTooltip: true,
          minWidth: 120,
        },
        {
          prop: 'YSZYXQ',
          label: '运输证有效期',
          align: 'center',
          slot: 'YSZYXQ',
          showOverflowTooltip: true,
          minWidth: 120,
          formatter: (row, column) => {
            return row.trafficInsuranceValidityStart ? row.trafficInsuranceValidityStart.split(' ')[0] + '-' + row.trafficInsuranceValidityEnd.split(' ')[0] : ''
          }
        },
        {
          prop: 'maintenanceStandards',
          label: '保养标准',
          align: 'center',
          slot: 'maintenanceStandards',
          showOverflowTooltip: true,
          minWidth: 120,
        },
        {
          prop: 'addressName',
          label: '区域',
          align: 'center',
          slot: 'addressName',
          showOverflowTooltip: true,
          minWidth: 120,
        }
      ],

      radio: null
    };
  },

  watch: {},
  methods: {
    open(item, index = 0) {},

    /* 表格数据源 */
    datasource({page, limit, where, order}) {
      return carBookPageListAPI({
        pageNum: page,
        size: limit,
        ...where
      });
    },

    /* 刷新表格 */
    reload(where) {
      this.$refs.table.reload({pageNum: 1, where: where});
    },

    handleNodeClick(data, node) {
      this.curNodeData = data;
      this.reload({groupId: data.id});
    },

    // 单击获取id
    cellClick(row) {
      this.current = row;
      this.radio = row.id;
    },
    handleClose() {
      this.$emit('update:selectCarDialogFlag', false);
    },

    selected() {
      if (!this.current) {
        return this.$message.warning('请选择');
      }
      this.$emit('changeParent', this.current, this.currentIndex);
      this.handleClose();
    }
  }
};
</script>

<style lang="scss" scoped>
.tree_col {
  border: 1px solid #eee;
  padding: 10px 0;
  box-sizing: border-box;
  height: 500px;
  overflow: auto;
}

.table_col {
  padding-left: 10px;

  ::v-deep .el-table th.el-table__cell {
    background: #f2f2f2;
  }
}

.pagination {
  text-align: right;
  padding: 10px 0;
}

.btns {
  text-align: center;
  padding: 10px 0;
}

.topsearch {
  margin-bottom: 15px;
}
</style>
