<template>
  <el-dialog
    title="选择工单"
    custom-class="ele-dialog-form long-dialog-form"
    :visible.sync="associationVisible"
    :before-close="handleClose"
    :close-on-click-modal="false"
    top="5vh"
    :close-on-press-escape="false"
    append-to-body
    width="70%"
  >
    <el-card shadow="never">
      <page-search-table @search="reload"></page-search-table>
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        row-key="id"
        height="calc(100vh - 500px)"
        class="dict-table"
        :selection.sync="selection"
      >
      </ele-pro-table>
    </el-card>

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

<script>
  import { logistictraklistnotePageListAPI } from '@/api/transportManager/shipManage/taskWork';
  import pageSearchTable from '@/views/transportManager/shipManage/taskWorkManage/pageSearchTable';

  export default {
    components: {
      pageSearchTable
    },
    //客户管理数据
    props: {
      contactData: {
        type: Object,
        default: () => {
          return {};
        }
      },
      saleOrderData: {
        type: Object,
        default: () => {
          return {};
        }
      },
      associationVisible: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        // visible: false,
        statusList: [
          { value: 0, label: '待接收' },
          { value: 1, label: '执行中' },
          { value: 2, label: '已完成' }
        ],
        columns: [
          {
            width: 45,
            type: 'selection',
            columnKey: 'selection',
            align: 'center'
          },
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'code',
            label: '工单单号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150,
            slot: 'code'
          },
          {
            prop: 'status',
            label: '状态',
            align: 'center',
            slot: 'status',
            showOverflowTooltip: true,
            formatter: (_row, _column, cellValue) => {
              return this.statusList[_row.status]?.label;
            },
            minWidth: 120
          },
          {
            prop: 'planCode',
            label: '计划编号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 150,
            slot: 'planCode'
          },
          {
            prop: 'planName',
            label: '计划名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 120,
            slot: 'planName'
          },
          {
            prop: 'planTimeStart',
            label: '预计开始时间',
            align: 'center',
            slot: 'planTimeStart',
            showOverflowTooltip: true,
            minWidth: 160
          },
          {
            prop: 'planTimeEnd',
            label: '预计结束时间',
            align: 'center',
            slot: 'planTimeEnd',
            showOverflowTooltip: true,
            minWidth: 160
          },
          {
            prop: 'realStartTime',
            label: '开始时间',
            align: 'center',
            slot: 'realStartTime',
            showOverflowTooltip: true,
            minWidth: 160
          },
          {
            prop: 'realEndTime',
            label: '完成时间',
            align: 'center',
            slot: 'realEntTime',
            showOverflowTooltip: true,
            minWidth: 160
          },
          {
            prop: 'responsibleDeptName',
            label: '负责部门',
            align: 'center',
            slot: 'responsibleDeptName',
            showOverflowTooltip: true,
            minWidth: 120
          },
          {
            prop: 'responsiblePersonName',
            label: '负责人',
            align: 'center',
            slot: 'responsiblePersonName',
            showOverflowTooltip: true,
            minWidth: 120
          },
          {
            prop: 'trakNumber',
            label: '车牌号',
            align: 'center',
            slot: 'trakNumber',
            showOverflowTooltip: true,
            minWidth: 120
          },
          {
            prop: 'driverName',
            label: '司机',
            align: 'center',
            slot: 'driverName',
            showOverflowTooltip: true,
            minWidth: 120
          },
          {
            prop: 'phone',
            label: '司机电话',
            align: 'center',
            slot: 'phone',
            showOverflowTooltip: true,
            minWidth: 120
          },
          {
            prop: 'createTime',
            label: '创建时间',
            align: 'center',
            slot: 'createTime',
            showOverflowTooltip: true,
            minWidth: 120
          }
        ],
        selection: []
      };
    },

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

      /* 刷新表格 */
      reload(where) {
        this.$nextTick(() => {
          this.$refs.table.reload({ page: 1, where });
        });
      },
      handleNodeClick(data, node) {
        this.reload({ categoryId: data.id });
      },
      handleClose() {
        this.$emit('update:associationVisible', false);
        this.selection = [];
      },

      selected() {
        if (this.selection.length == 0) {
          return this.$message.warning('请至少选择一条数据');
        }
        this.$emit('associationSelect', this.selection);
        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>
