<template>
  <div>
    <page-search-table @search="reload"></page-search-table>
    <!-- 数据表格 -->
    <ele-pro-table
      ref="table"
      :columns="columns"
      :datasource="datasource"
      height="calc(100vh - 430px)"
      full-height="calc(100vh - 116px)"
      tool-class="ele-toolbar-form"
      :selection.sync="selection"
      cache-key="eomContactPageTable"
    >
      <!-- 表头工具栏 -->
      <template v-slot:toolbar>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-plus"
          class="ele-btn-icon"
          @click="handleAddOrEdit('','add')"
        >
          新建
        </el-button>
      </template>
      <!-- 操作 -->
      <template v-slot:action="{row}">
        <el-link
          type="primary"
          :underline="false"
          icon="el-icon-edit"
          v-if="[0].includes(row.status)"
          @click="handleReportingWork(row,1)"
        >
          开始
        </el-link>
        <el-link
          type="primary"
          :underline="false"
          icon="el-icon-edit"
          v-if="[0].includes(row.status)"
          @click="handleTransfer(row)"
        >
          转派
        </el-link>
        <el-link
          type="primary"
          :underline="false"
          icon="el-icon-edit"
          v-if="[1].includes(row.status)"
          @click="handleFee(row,'update')"
        >
          报工
        </el-link>
      </template>
      <template v-slot:planName="{row}">
        <el-link
          type="primary"
          :underline="false"
          @click="handleDetail(row,'view')"
        >
          {{ row.planName }}
        </el-link>
      </template>
      <template v-slot:code="{row}">
        <el-link
          :disabled="![2].includes(row.status)"
          type="primary"
          :underline="false"
          @click="handleFee(row,'view')"
        >
          {{ row.code }}
        </el-link>
      </template>
    </ele-pro-table>
    <!-- 计划详情   -->
    <plan-detail-dialog :detail-dialog-flag.sync="planDetailDialogFlag" v-if="planDetailDialogFlag"
                        ref="planDetailDialogRef"></plan-detail-dialog>
    <!-- 费用申请   -->
    <fee-info-dialog ref="feeInfoDialogRef" :fee-info-dialog-flag.sync="feeInfoDialogFlag"
                     v-if="feeInfoDialogFlag" @reload="reload"></fee-info-dialog>
    <!-- 转派   -->
    <transfer-dialog ref="transferDialogRef" :transfer-dialog-flag.sync="transferDialogFlag" v-if="transferDialogFlag"
                     @reload="reload"></transfer-dialog>
    <!-- 新增外派工单 -->
    <add-or-edit-dialog ref="addOrEditDialogRef" :add-or-edit-dialog-flag.sync="addOrEditDialogFlag"
                        v-if="addOrEditDialogFlag" @reload="reload"></add-or-edit-dialog>
  </div>

</template>

<script>
import popModal from '@/components/pop-modal';
import dictMixins from "@/mixins/dictMixins";
import pageSearchTable from "./pageSearchTable.vue";
import feeInfoDialog from "./components/feeInfoDialog.vue";
import addOrEditDialog from './components/addOrEditDialog.vue'
import planDetailDialog from '@/views/transportManager/shipManage/dispatchManage/components/detailDialog.vue'
import transferDialog from './components/transferDialog.vue'
import {
  logistictraklistnotePageListAPI, logistictraklistnoteUpdateAPI,
} from "@/api/transportManager/shipManage/taskWork";

export default {
  mixins: [dictMixins],
  components: {
    addOrEditDialog,
    pageSearchTable,
    feeInfoDialog,
    popModal,
    transferDialog,
    planDetailDialog
  },
  data() {
    return {
      selection: [],
      statusList: [
        {value: 0, label: '待接收'},
        {value: 1, label: '执行中'},
        {value: 2, label: '已完成'}
      ],
      delVisible: false,
      // 加载状态
      loading: false,
      planDetailDialogFlag: false,
      feeInfoDialogFlag: false,
      transferDialogFlag: false,
      addOrEditDialogFlag: false,
    };
  },
  computed: {
    columns() {
      return [
        {
          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,
        },

        {
          columnKey: 'action',
          label: '操作',
          width: 180,
          align: 'center',
          resizable: false,
          slot: 'action',
          showOverflowTooltip: true,
          fixed: 'right'
        }
      ]
    }
  },
  created() {
  },
  methods: {
    //报工、完成
    async handleReportingWork(row = {}, status) {
      row.status = status
      await logistictraklistnoteUpdateAPI(row)
      this.$message.success('操作成功！');
      this.reload()
    },
    //计划详情
    handleDetail(row = {}, type) {
      this.planDetailDialogFlag = true
      this.$nextTick(() => {
        let params = {id: row.planId}
        this.$refs.planDetailDialogRef.init(params, type)
      })
    },
    //新建工单
    handleAddOrEdit(row = {}, type) {
      this.addOrEditDialogFlag = true
      this.$nextTick(() => {
        this.$refs.addOrEditDialogRef.init(row, type)
      })
    },
    //转派
    handleTransfer(row) {
      this.transferDialogFlag = true
      this.$nextTick(() => {
        this.$refs.transferDialogRef.init(row)
      })
    },
    //费用申请
    handleFee(row, type) {
      this.feeInfoDialogFlag = true
      this.$nextTick(() => {
        this.$refs.feeInfoDialogRef.init(row, type)
      })
    },
    /* 表格数据源 */
    datasource({page, limit, where, order}) {
      return logistictraklistnotePageListAPI({
        pageNum: page,
        size: limit,
        ...where
      });
    },

    /* 刷新表格 */
    reload(where) {
      this.$nextTick(() => {
        this.$refs.table.reload({page: 1, where});
      })
    },
  }
};
</script>

<style lang="scss" scoped>
:deep(.el-link--inner) {
  margin-left: 0px !important;
}

.sys-organization-list {
  height: calc(100vh - 264px);
  box-sizing: border-box;
  border-width: 1px;
  border-style: solid;
  overflow: auto;
}

.sys-organization-list :deep(.el-tree-node__content) {
  height: 40px;

  & > .el-tree-node__expand-icon {
    margin-left: 10px;
  }
}
</style>
