<!-- <template>
  <div class="ele-body">
    <el-card shadow="never" v-loading="loading">
      <seek-page :seekList="seekList" @search="search"></seek-page>

      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        cache-key="wanLongDailyList"
        :current.sync="current"
        highlight-current-row
        row-key="id"
        :pageSize="20"
        :height="tableHeight"
        :selection.sync="selection"
        @fullscreen-change="fullscreenChange"
      >
        <template slot="subCountAllFirst" slot-scope="{ row }">
          <span class="clickable" @click="onClickSubCountAllFirst(row)">
            {{ row.subCountAllFirst != null ? row.subCountAllFirst : 0 }}
          </span>
        </template>

        <template slot="subCountSendFirst" slot-scope="{ row }">
          <span class="clickable" @click="onClickSubCountSendFirst(row)">
            {{ row.subCountSendFirst != null ? row.subCountSendFirst : 0 }}
          </span>
        </template>
      </ele-pro-table>
    </el-card>
  </div>
</template>

<script>
  import { getDailyList } from '@/api/wanLong/index';

  export default {
    name: 'wanLongIndex',

    data() {
      return {
        loading: false,
        current: null,
        selection: [],
        tableHeight: 'calc(100vh - 320px)',
        dynamicColumns: [], // 保存 taskList 动态列
        taskNames: [] // taskName 列名数组
      };
    },

    computed: {
      seekList() {
        return [
          {
            label: '开始时间:',
            value: 'startTime',
            type: 'date',
            dateType: 'daterange',
            placeholder: ''
          }
        ];
      },

      columns() {
        const baseColumns = [
          {
            columnKey: 'selection',
            type: 'selection',
            width: 45,
            align: 'center'
          },
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '物品名称',
            prop: 'categoryName',
            width: 150,
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '物品编码',
            prop: 'categoryCode',
            width: 160,
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '图号',
            prop: 'imgCode',
            width: 160,
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '图纸版本',
            prop: 'version',
            width: 160,
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '重量',
            prop: 'productUnitWeight',
            width: 120,
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '型号',
            prop: 'modelType',
            width: 120,
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '规格',
            prop: 'specification',
            width: 120,
            showOverflowTooltip: true,
            align: 'center'
          },

          {
            label: '中间状态数量',
            prop: 'middleNum',
            width: 120,
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '库存数量',
            prop: 'availableCountBase',
            width: 120,
            showOverflowTooltip: true,
            align: 'center'
          },

          {
            label: '下料初始值',
            prop: 'subCountAllFirst',
            width: 120,
            slot: 'subCountAllFirst',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '下料总数量',
            prop: 'subCountAll',
            width: 120,
            showOverflowTooltip: true,
            align: 'center'
          },

          {
            label: '送货初始值',
            prop: 'subCountSendFirst',
            width: 120,
            slot: 'subCountSendFirst',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '送货数量',
            prop: 'subCountSend',
            width: 120,
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '备注',
            prop: 'remark',
            width: 120,
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            label: '日期',
            prop: 'date',
            width: 100,
            showOverflowTooltip: true,
            align: 'center'
          }
        ];

        return baseColumns.concat(this.dynamicColumns);
      }
    },

    methods: {
      datasource({ page, limit, where }) {
        return getDailyList({
          pageNum: page,
          size: limit,
          ...where
        }).then((res) => {
          const data = res.data || [];

          if (data.length) {
            const firstItem = data[0];
            if (firstItem.taskList && firstItem.taskList.length) {
              this.taskNames = firstItem.taskList.map((t) => t.taskName);
              this.dynamicColumns = firstItem.taskList.map((t) => ({
                label: t.taskName,
                prop: `task_${t.taskName}`,
                width: 100,
                align: 'center'
              }));
            }
          }

          const tableData = data.map((item) => {
            const taskFields = {};
            if (item.taskList && item.taskList.length) {
              item.taskList.forEach((t) => {
                taskFields[`task_${t.taskName}`] = t.quantity;
              });
            }
            return Object.assign({}, item, taskFields);
          });

          return tableData;
        });
      },

      search(e) {
        this.$refs.table.reload(e);
      },

      fullscreenChange(fullscreen) {
        this.tableHeight = fullscreen
          ? 'calc(100vh - 120px)'
          : 'calc(100vh - 320px)';
      },

      onClickSubCountAllFirst(row) {
        console.log('点击下料初始值', row);
        this.$message.info(`下料初始值: ${row.subCountAllFirst}`);
      },

      onClickSubCountSendFirst(row) {
        console.log('点击送货初始值', row);
        this.$message.info(`送货初始值: ${row.subCountSendFirst}`);
      }
    }
  };
</script>

<style scoped>
  .clickable {
    cursor: pointer;
    color: #409eff;
  }
</style>  -->

<template> </template>

<script>
  export default {};
</script>

<style></style>
