<template>
  <el-dialog
    :title="title"
    :visible.sync="selectDriverDialogFlag"
    :before-close="handleClose"
    :close-on-click-modal="false"
    top="5vh"
    :close-on-press-escape="false"
    append-to-body
    width="70%"
  >
    <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 {driverBookPageListAPI} from "@/api/transportManager/driverBook";

export default {
  components: {
    DepartmentTree
  },
  props: {
    selectDriverDialogFlag: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      currentIndex: 0,
      title: '选择司机',
      visible: false,
      statusList: [
        {
          label: '空闲',
          value: 1,
        },
        {
          label: '派单中',
          value: 2,
        }
      ],
      columns: [
        {
          action: 'action',
          slot: 'action',
          align: 'center',
          label: '选择'
        },
        {
          columnKey: 'index',
          label: '序号',
          type: 'index',
          width: 55,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'driverName',
          label: '姓名',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 120,
          slot: 'driverName'
        },
        {
          prop: 'sex',
          label: '性别',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100,
          formatter: (_row, _column, cellValue) => {
            return cellValue == 1 ? '男' : cellValue == 2 ? '女' : '';
          }
        },
        {
          prop: 'age',
          label: '年龄',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 100
        },
        {
          prop: 'phone',
          label: '手机号',
          align: 'center',
          slot: 'phone',
          showOverflowTooltip: true,
          minWidth: 120,
        },
        {
          prop: 'personId',
          label: '身份证号',
          align: 'center',
          slot: 'personId',
          showOverflowTooltip: true,
          minWidth: 120,
        },
        {
          prop: 'driverAge',
          label: '驾龄',
          align: 'center',
          slot: 'driverAge',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'drivingLicenseType',
          label: '驾驶证类型',
          align: 'center',
          slot: 'drivingLicenseType',
          showOverflowTooltip: true,
          minWidth: 100,
        },
        {
          prop: 'status',
          label: '状态',
          align: 'center',
          slot: 'status',
          showOverflowTooltip: true,
          minWidth: 100,
          formatter: (_row, _column, cellValue) => {
            return this.statusList.find(i => i.value == cellValue)?.label;
          },
        }
      ],

      radio: null
    };
  },

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

    /* 表格数据源 */
    datasource({page, limit, where, order}) {
      return driverBookPageListAPI({
        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:selectDriverDialogFlag', 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>
