<template>
  <basic-container>
    <!-- 成本统计 -->
    <el-form :inline="true" :model="searchForm">
      <el-form-item label="月份">
        <el-date-picker v-model="searchForm.monthDate" type="month" placeholder="选择月" required>
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary">查询</el-button>
        <!-- <el-button type="primary">分派</el-button>
        <el-button type="primary">保存</el-button> -->
      </el-form-item>
    </el-form>
    <el-row>
      <el-col :span="20">
        <avue-crud :option="option" :table-loading="loading" :data="data" v-model="form" v-model:page="page" ref="crud"
          @row-update="rowUpdate" @row-save="rowSave" @search-change="searchChange" @search-reset="searchReset"
          @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
          @refresh-change="refreshChange" @on-load="onLoad">
          <template #menu-left>
            <el-button type="primary" @click="openCostCalcDialog">成本计算</el-button>
            <!-- <el-button type="primary" @click="isLockClick">锁定/解锁</el-button> -->
            <el-button type="danger" @click="handleDelete">删除</el-button>
            <el-button type="success">导出</el-button>
          </template>

          <!-- <template #wcCode="{ row }">{{ row.saCostConfig.bsWorkCenter.wcCode }}</template>
          <template #wcName="{ row }">{{ row.saCostConfig.bsWorkCenter.wcName }}</template> -->
        </avue-crud>
      </el-col>
      <el-col :span="4">
        <avue-crud :option="detailsOption" :table-loading="loading" :data="data" v-model="form" v-model:page="page"
          ref="crud" @row-update="rowUpdate" @row-save="rowSave" @search-change="searchChange"
          @search-reset="searchReset" @selection-change="selectionChange" @current-change="currentChange"
          @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad"
          style="margin-top: 46px; margin-left: 12px"></avue-crud>
      </el-col>
    </el-row>
    <el-dialog 
      :modelValue="openShow" 
      title="提示" 
      width="400px" 
      :close-on-click-modal="false"
      class="cost-confirm-dialog"
    >
      <div class="dialog-content">
        <i class="el-icon-warning"></i>
        <p><span class="month-highlight">{{ selectMonth }}</span>月已计算成本，是否重新计算？</p>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="handleRecalculate">重新计算</el-button>
          <el-button @click="CloseDialog">取消</el-button>
        </div>
      </template>
    </el-dialog>

  </basic-container>

</template>

<script>
import ClosedDialog from '../productionManagement/components/closedDialog.vue';

export default {
  data() {
    return {
      selectMonth: '',
      openShow: false,
      searchForm: {},
      loading: false,
      data: [],
      form: {},
      selectionList: [],
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        height: "auto",
        calcHeight: 32,
        tip: false,
        size: "medium",
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: true,
        viewBtn: false,
        delBtn: false,
        addBtn: false,
        editBtn: false,
        editBtnText: "修改",
        viewBtnText: "详情",
        labelWidth: 120,
        searchLabelWidth: 120,
        menu: true,
        menuWidth: 220,
        dialogWidth: 1200,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: false,
        filterBtn: true,
        searchShowBtn: false,
        columnSort: true,
        excelBtn: true,
        columnSort: true,
        index: false,
        showOverflowTooltip: true,
        searchLabelPosition: "left",
        searchLabelPosition: "left",
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: "left",
        gridBtn: false,
        searchMenuPosition: "right",
        addBtnIcon: " ",
        viewBtnIcon: " ",
        delBtnIcon: " ",
        editBtnIcon: " ",
        align: "center",

        column: [
          {
            label: "作业中心",
            prop: "wcName",
            search: false,
            sortable: true,
            overHidden: true,
          },
          {
            label: "月份",
            prop: "month",
            search: false,
            sortable: true,
            overHidden: true,
          },
          {
            label: "制造费用(元)",
            prop: "drainCosts",
            search: false,
            sortable: true,
            overHidden: true,
            width: 130,
          },
          {
            label: "作业中心材料费用(元)",
            prop: "materialCosts",
            search: false,
            sortable: true,
            overHidden: true,
            width: 200,
          },
          {
            label: "辅助人员材料费用(元)",
            prop: "materialCosts1",
            search: false,
            width: 200,
            sortable: true,
            overHidden: true,
          },
          {
            label: "单位成本(元)",
            prop: "unitCost",
            search: false,
            sortable: true,
            overHidden: true,
            width: 130,
          },
          {
            label: "月度产出(dm²)",
            prop: "monthlyOutput",
            search: false,
            width: 150,
            sortable: true,
            overHidden: true,
          },
          {
            label: "月度产出(v)",
            prop: "volumeOutput2",
            search: false,
            sortable: true,
            overHidden: true,
          },
        ],
      },
      detailsOption: {
        height: "auto",
        calcHeight: 32,
        tip: false,
        size: "medium",
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: true,
        selection: false,
        viewBtn: false,
        delBtn: false,
        addBtn: false,
        editBtn: false,
        editBtnText: "修改",
        viewBtnText: "详情",
        labelWidth: 120,
        searchLabelWidth: 120,
        menu: true,
        menuWidth: 220,
        dialogWidth: 1200,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: false,
        filterBtn: true,
        searchShowBtn: false,
        columnSort: true,
        excelBtn: true,
        columnSort: true,
        index: false,
        showOverflowTooltip: true,
        searchLabelPosition: "left",
        searchLabelPosition: "left",
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: "left",
        gridBtn: false,
        searchMenuPosition: "right",
        addBtnIcon: " ",
        viewBtnIcon: " ",
        delBtnIcon: " ",
        editBtnIcon: " ",
        align: "center",
        menu: true,
        header: false,

        column: [
          {
            label: "类型",
            prop: "wcCode",
            search: false,
            sortable: true,
            overHidden: true,
          },
          {
            label: "金额",
            prop: "wcCode1",
            search: false,
            sortable: true,
            overHidden: true,
          },
        ],
      },
    };
  },
  mounted() { },
  methods: {
    selectionChange(val) {
      this.selectionList = val;
    },
    isLockClick() {
      if (this.selectionList.length == 0) {
        this.$message.error("请先选择数据");
        return;
      }
    },
    handleDelete() {
      if (this.selectionList.length == 0) {
        this.$message.error("请先选择数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => { });
    },
    onLoad() {
      this.data = [
        {
          id: 1,
          wcName: "作业中心1",
          month: "2025-3",
          materialCosts: 99,
          materialCosts1: 0,
          unitCost: "89",
          monthlyOutput: 0,
          volumeOutput: "9",
          drainCosts: "99",
          volumeOutput2: "90",
          wcCode: "类型1",
          wcCode1: "4",
          selectMonth: '1',
        },
      ];
    },
    openCostCalcDialog() {
      this.openShow = true
    },
    CloseDialog() {
      this.openShow = false
    }
  },
};
</script>

<style scoped>
    /* 确保操作列不换行 */
    .avue-crud .el-table .cell {
      white-space: nowrap;
    }
    .cost-confirm-dialog .dialog-content {
      display: flex;
      align-items: center;
      padding: 10px 0;
      font-size: 16px;
      line-height: 24px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    
    .cost-confirm-dialog .el-icon-warning {
      color: #E6A23C;
      font-size: 24px;
      margin-right: 15px;
    }
    
    .cost-confirm-dialog .month-highlight {
      color: #409EFF;
      font-weight: bold;
      margin: 0 4px;
    }
    
    .cost-confirm-dialog .dialog-footer {
      text-align: right;
      margin-top: 20px;
    }
</style>
