<template>
  <div class="ele-body">
    <el-card shadow="never" v-loading="loading">
      <order-search @search="reload" ref="searchRef"> </order-search>
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        :cache-key="cacheKeyUrl"
        @columns-change="handleColumnChange"
      >
        <template v-slot:Weight="{ row }">
          <span>{{ row.weight | weightFilter }}</span>
        </template>
        <template v-slot:SlottingType="{ row }">
          {{ getDictValue('开槽类型', row.slottingType + '') }}
        </template>
        <!-- <template v-slot:Status="{ row }">
          {{ hangingStatus(row.status) }}
        </template> -->
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-truck"
            @click="confirm(row)"
            v-if="row.status == 0"
          >
            任务下发
          </el-link>
        </template>
      </ele-pro-table>
    </el-card>
  </div>
</template>

<script>
// import { getList, releaseWorkOrder } from '@/api/workOrder/index.js';
import OrderSearch from './components/order-search.vue';
import dictMixins from '@/mixins/dictMixins';
import { hangingStatus } from '@/utils/util';

import {
  getPutMeshWorkOrderByPage,
  issuedPutMeshWorkOrder
} from '@/api/mergePutMesh/mergePutMesh';
import tabMixins from '@/mixins/tableColumnsMixin';

export default {
  components: {
    OrderSearch
  },
  mixins: [dictMixins, tabMixins],
  data() {
    return {
      visible: false,
      loading: false,
      releasParams: {
        teamId: '',
        id: ''
      },

      current: null,
      cacheKeyUrl: '79025f25-aps-hangingWorkOrder',
      columnsVersion:1
    };
  },
  computed: {
    // 表格列配置
    columns() {
      const num = this.columnsVersion;
      return [
        {
          columnKey: 'index',
          label: '序号',
          type: 'index',
          width: 55,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left'
        },
        {
          prop: 'weight',
          label: '等级',
          align: 'center',
          slot: 'Weight'
        },
        {
          prop: 'height',
          label: '高度',
          align: 'center'
        },
        {
          prop: 'length',
          label: '长1+长2+长3',
          align: 'center'
        },
        {
          prop: 'productName',
          label: '产品名称',
          align: 'center'
        },
        {
          prop: 'allowance',
          label: '余量',
          align: 'center'
        },
        {
          prop: 'moCount',
          label: '模数',
          align: 'center'
        },
        {
          prop: 'blockCount',
          label: '片1+片2+片3',
          align: 'center'
        },
        {
          prop: 'slottingType',
          label: '开槽类型',
          align: 'center',
          slot: 'SlottingType'
        },
        {
          prop: 'taskTime',
          label: '任务日期',
          align: 'center'
        },

        {
          prop: 'issuedTime',
          label: '下发日期',
          align: 'center'
        },

        {
          prop: 'teamName',
          label: '班组',
          align: 'center'
        },
        {
          prop: 'status',
          label: '状态',
          align: 'center',
          formatter: (row, column, cellValue) => {
            return hangingStatus(cellValue);
          }
        },
        {
          prop: 'remark',
          label: '完结原因',
          align: 'center'
        },
        {
            prop: 'customerName',
            label: '客户名称',
            align: 'center',
            showOverflowTooltip: true
        },
        {
          prop: 'serialNo',
          label: '客户代号',
          align: 'center',
          showOverflowTooltip: true
        },

        {
          prop: 'simpleName',
          label: '客户简称',
          align: 'center',
          showOverflowTooltip: true
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 120,
          align: 'center',
          resizable: false,
          fixed: 'right',
          slot: 'action',
          showOverflowTooltip: true
        }
      ];
    }
  },
  created() {
    this.requestDict('开槽类型');
  },
  filters: {
    weightFilter(value) {
      let weight = '';
      switch (value) {
        case 1:
          weight = 'A';
          break;
        case 2:
          weight = 'B';
          break;
        case 3:
          weight = 'C';
          break;
      }
      return weight;
    }
  },
  methods: {
    /* 表格数据源 */
    datasource({ page, limit, where }) {
      return getPutMeshWorkOrderByPage({
        pageNum: page,
        size: limit,
        ...where
      });
    },

    // 下达
    toRelease(row) {
      this.current = row;
      this.visible = true;
    },
    // 下达
    confirm(row) {
      this.$confirm('确认下发选中的任务吗？', '提示', {
        confirmButtonText: '确定',
        cancleButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const res = await issuedPutMeshWorkOrder({
            id: [row.id],
            status: 1
          });
          this.$message.success('任务下发成功！');
          this.reload();
        })
        .catch(() => {});
    },
    /* 刷新表格 */
    reload(where) {
      console.log(where,'where')
      this.$nextTick(() => {
        this.$refs.table.reload({ page: 1, where });
      });
    }
  }
};
</script>

<style lang="scss" scoped></style>
