<template>
  <div class="inbound-items-container">
    <!-- 保留查询表单，但可以通过props控制显示 -->
    <el-form 
      v-if="showSearchForm" 
      :model="queryParams" 
      ref="queryForm" 
      size="small" 
      :inline="true" 
      label-width="100px"
      class="mb8"
    >
      <el-form-item label="货物ID" prop="materialId">
        <el-input
          v-model="queryParams.materialId"
          placeholder="请输入货物ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="批次ID" prop="batchId">
        <el-input
          v-model="queryParams.batchId"
          placeholder="请输入批次ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="仓库ID" prop="warehouseId">
        <el-input
          v-model="queryParams.warehouseId"
          placeholder="请输入仓库ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库位ID" prop="locationId">
        <el-input
          v-model="queryParams.locationId"
          placeholder="请输入库位ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <!-- 添加关联查询按钮 -->
        <el-button v-if="embedded" type="info" icon="el-icon-connection" size="mini" @click="handleLoadRelated">加载关联</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作按钮区域 -->
    <div v-if="showToolbar" class="toolbar-container mb8">
      <el-row :gutter="10">
        <el-col :span="1.5">
          <el-button
            v-if="showAddButton"
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAddItem"
          >新增明细</el-button>
        </el-col>
        <!-- <el-col :span="1.5">
          <el-button
            v-if="showEditButton"
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleEditItem"
          >修改</el-button>
        </el-col> -->
        <el-col :span="1.5">
          <el-button
            v-if="showDeleteButton"
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleBatchDelete"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5" v-if="showExportButton">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleImport"
            v-hasPermi="['inventory:inbound_items:import']"
          >导入</el-button>
        </el-col>
        <el-col :span="1.5" v-if="showExportButton">
          <el-button
            type="warning"
            plain
            icon="el-icon-upload"
            size="mini"
            @click="handleExport"
          >导出</el-button>
        </el-col>
      </el-row>
    </div>

    <!-- 表格区域 -->
    <div class="table-container">
      <el-table 
        v-loading="loading" 
        :data="displayData" 
        @selection-change="handleSelectionChange"
        :row-key="getRowKey"
        ref="dataTable"
        border
        stripe
        size="medium"
        v-bind="$attrs"
        v-on="$listeners"
      >
        <!-- 选择列 -->
        <el-table-column 
          v-if="showSelection" 
          type="selection" 
          width="55" 
          align="center"
          :reserve-selection="true"
        />
        
        <!-- 序号列 -->
        <el-table-column label="序号" align="center" width="60" type="index" />
        
        <!-- 数据列 -->
        <el-table-column 
          v-for="column in columns"
          :key="column.prop"
          :label="column.label" 
          :prop="column.prop" 
          :align="column.align || 'center'"
          :width="column.width"
          :min-width="column.minWidth"
          :fixed="column.fixed"
        >
          <template slot-scope="scope">
            <!-- 可编辑模式 -->
            <template v-if="scope.row.editable && column.editable !== false">
              <template v-if="column.type === 'select'">
                <el-select 
                  v-model="scope.row[column.prop]" 
                  size="small" 
                  style="width: 100%"
                  @change="handleColumnChange(scope.row, column.prop)"
                >
                  <el-option
                    v-for="option in column.options"
                    :key="option.value"
                    :label="option.label"
                    :value="option.value"
                  />
                </el-select>
              </template>
              <template v-else-if="column.type === 'number'">
                <el-input-number
                  v-model="scope.row[column.prop]"
                  :min="column.min || 0"
                  :max="column.max"
                  :step="column.step || 1"
                  size="small"
                  style="width: 100%"
                  controls-position="right"
                  @change="handleNumberChange(scope.row, column.prop)"
                />
              </template>
              <template v-else>
                <el-input
                  v-model="scope.row[column.prop]"
                  size="small"
                  :placeholder="column.placeholder || '请输入'"
                  @blur="handleInputBlur(scope.row, column.prop)"
                  @change="handleInputChange(scope.row, column.prop)"
                />
              </template>
            </template>
            
            <!-- 只读模式 -->
            <template v-else>
              <!-- 状态显示 -->
              <template v-if="column.prop === 'itemStatus'">
                <el-tag 
                  :type="getStatusType(scope.row[column.prop])"
                  size="small"
                >
                  {{ getStatusText(scope.row[column.prop]) }}
                </el-tag>
              </template>
              
              <!-- 数字格式化 -->
              <template v-else-if="column.type === 'number'">
                {{ formatNumber(scope.row[column.prop]) }}
              </template>
              
              <!-- 默认显示 -->
              <template v-else>
                {{ scope.row[column.prop] }}
              </template>
            </template>
          </template>
        </el-table-column>
        
        <!-- 操作列 -->
        <el-table-column 
          v-if="showActionColumn"
          label="操作" 
          align="center" 
          width="150"
          fixed="right"
        >
          <template slot-scope="scope">
            <template v-if="embedded">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleRowEdit(scope.row)"
                v-if="!scope.row.editable"
              >编辑</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-check"
                @click="handleRowSave(scope.row)"
                v-else
              >保存</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleRowDelete(scope.row, scope.$index)"
              >删除</el-button>
            </template>
            <template v-else>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="() => { this.$refs.dataTable.toggleRowSelection(scope.row); handleEditItem(); }"
              >编辑</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleRowDelete(scope.row)"
              >删除</el-button>
            </template>
          </template>
        </el-table-column>
      </el-table>
      
      <!-- 分页 -->
      <pagination
        v-if="showPagination && !embedded"
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <import-excel
          ref="import"
          title="导入"
          import-url="/inventory/inbound_items/import"
          template-url="/inventory/inbound_items/exportTemplate"
          template-name="入库明细模板"
          @success="getList"
        />
    </div>

    <!-- 非嵌入式模式下的添加/编辑对话框 -->
    <el-dialog 
      v-if="!embedded"
      :title="dialogTitle" 
      :visible.sync="dialogVisible" 
      width="800px" 
      append-to-body
      @closed="handleDialogClosed"
    >
      <el-form 
        ref="dialogForm" 
        :model="form" 
        :rules="rules" 
        label-width="120px"
        size="small"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="货物ID" prop="materialId">
              <el-input v-model="form.materialId" placeholder="请输入货物ID" />
            </el-form-item>
            <el-form-item label="批次ID" prop="batchId">
              <el-input v-model="form.batchId" placeholder="请输入批次ID" />
            </el-form-item>
            <el-form-item label="仓库ID" prop="warehouseId">
              <el-input v-model="form.warehouseId" placeholder="请输入仓库ID" />
            </el-form-item>
            <el-form-item label="库位ID" prop="locationId">
              <el-input v-model="form.locationId" placeholder="请输入库位ID" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划数量" prop="plannedQuantity">
              <el-input-number 
                v-model="form.plannedQuantity" 
                :min="0" 
                :step="1"
                style="width: 100%"
              />
            </el-form-item>
            <el-form-item label="实际数量" prop="actualQuantity">
              <el-input-number 
                v-model="form.actualQuantity" 
                :min="0" 
                :step="1"
                style="width: 100%"
              />
            </el-form-item>
            <el-form-item label="单价" prop="unitPrice">
              <el-input-number 
                v-model="form.unitPrice" 
                :min="0" 
                :precision="2"
                style="width: 100%"
              />
            </el-form-item>
            <el-form-item label="状态" prop="itemStatus">
              <el-select v-model="form.itemStatus" placeholder="请选择状态" style="width: 100%">
                <el-option label="待入库" value="1" />
                <el-option label="已入库" value="2" />
                <el-option label="已取消" value="3" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" :rows="2" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitDialogForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInbound_items, getInbound_items, delInbound_items, addInbound_items, updateInbound_items } from "@/api/inventory/inbound_items"
import ImportExcel from "@/components/ImportExcel/index"
export default {
  name: "InboundItems",
  inheritAttrs: false,
  components: {
    ImportExcel
  },
  props: {
    // 数据源（用于嵌入式模式）
    value: {
      type: Array,
      default: () => []
    },
    // 是否为嵌入式模式（在表单中）
    embedded: {
      type: Boolean,
      default: false
    },
    // 主表ID（入库单号）
    orderId: {
      type: [String, Number],
      default: null
    },
    // 是否显示查询表单
    showSearchForm: {
      type: Boolean,
      default: true
    },
    // 是否显示工具栏
    showToolbar: {
      type: Boolean,
      default: true
    },
    // 是否显示操作列
    showActionColumn: {
      type: Boolean,
      default: true
    },
    // 是否显示选择框
    showSelection: {
      type: Boolean,
      default: false
    },
    // 是否显示分页
    showPagination: {
      type: Boolean,
      default: true
    },
    // 是否显示新增按钮
    showAddButton: {
      type: Boolean,
      default: true
    },
    // 是否显示编辑按钮
    showEditButton: {
      type: Boolean,
      default: true
    },
    // 是否显示删除按钮
    showDeleteButton: {
      type: Boolean,
      default: true
    },
    // 是否显示导出按钮
    showExportButton: {
      type: Boolean,
      default: true
    },
    // 权限控制
    permissions: {
      type: Array,
      default: () => []
    },
    // 初始查询参数
    initQuery: {
      type: Object,
      default: () => ({})
    },
    // 表格列配置
    columns: {
      type: Array,
      default: () => [
        { prop: 'materialId', label: '货物ID', width: '120', editable: true },
        { prop: 'batchId', label: '批次ID', width: '120', editable: true },
        { prop: 'warehouseId', label: '仓库ID', width: '120', editable: true },
        { prop: 'locationId', label: '库位ID', width: '120', editable: true },
        { prop: 'plannedQuantity', label: '计划数量', width: '100', type: 'number', editable: true },
        { prop: 'actualQuantity', label: '实际数量', width: '100', type: 'number', editable: true },
        { prop: 'plannedPackages', label: '计划件数', width: '100', type: 'number', editable: true },
        { prop: 'actualPackages', label: '实际件数', width: '100', type: 'number', editable: true },
        { prop: 'unitPrice', label: '单价', width: '100', type: 'number', editable: true },
        { prop: 'itemStatus', label: '状态', width: '100', editable: true, type: 'select' },
        { prop: 'remark', label: '备注', minWidth: '150', editable: true },
      ]
    }
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      selectedRows: [],
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 显示数据
      displayData: [],
      // 对话框相关
      dialogVisible: false,
      dialogTitle: "",
      dialogMode: 'add', // 'add' or 'edit'
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: this.orderId,
        materialId: null,
        batchId: null,
        warehouseId: null,
        locationId: null,
        labelColor: null,
        ...this.initQuery
      },
      // 表单参数
      form: this.getDefaultForm(),
      // 表单校验
      rules: {
        materialId: [
          { required: true, message: "货物ID不能为空", trigger: "blur" }
        ],
        plannedQuantity: [
          { required: true, message: "计划数量不能为空", trigger: "blur" },
          { type: 'number', min: 0, message: "计划数量不能小于0", trigger: "blur" }
        ],
        actualQuantity: [
          { type: 'number', min: 0, message: "实际数量不能小于0", trigger: "blur" }
        ]
      },
      // 缓存原始数据（用于嵌入式模式）
      cachedData: []
    }
  },
  watch: {
    // 监听value变化（嵌入式模式）
    value: {
      immediate: true,
      handler(newVal) {
        if (this.embedded) {
          // 只有当数据真正变化时才更新
          const stringifiedNewVal = JSON.stringify(newVal || [])
          const stringifiedDisplayData = JSON.stringify(this.displayData.map(item => {
            const { editable, tempId, ...rest } = item
            return rest
          }))
          
          if (stringifiedNewVal !== stringifiedDisplayData) {
            this.cachedData = JSON.parse(JSON.stringify(newVal || []))
            this.displayData = (newVal || []).map(item => ({
              ...item,
              editable: false,
              tempId: item.id || Date.now() + Math.random()
            }))
            this.calculateTotals()
          }
        }
      }
    },
    // 监听嵌入式数据变化，通知父组件
    displayData: {
      deep: true,
      handler(newVal) {
        if (this.embedded) {
          const dataToEmit = newVal.map(item => {
            const { editable, tempId, ...rest } = item
            // 确保新添加的行有orderId
            if (this.orderId && !rest.orderId) {
              rest.orderId = this.orderId
            }
            return rest
          })
          
          // 避免不必要的更新循环
          const shouldEmit = JSON.stringify(dataToEmit) !== JSON.stringify(this.value || [])
          if (shouldEmit) {
            this.$emit('input', dataToEmit)
            this.$emit('data-change', dataToEmit)
          }
          this.calculateTotals()
        }
      }
    },
    // 监听orderId变化
    orderId: {
      immediate: true,
      handler(newVal) {
        if (newVal) {
          if (!this.embedded) {
            this.queryParams.orderId = newVal
            this.getList()
          } else {
            // 在嵌入式模式下，更新所有没有orderId的项
            this.displayData = this.displayData.map(item => ({
              ...item,
              orderId: item.orderId || newVal
            }))
          }
        }
      }
    }
  },
  computed: {
    // 计算总数量和金额
    totals() {
      if (!this.displayData.length) return { plannedQuantity: 0, actualQuantity: 0, totalAmount: 0 }
      
      return this.displayData.reduce((acc, item) => {
        acc.plannedQuantity += parseFloat(item.plannedQuantity) || 0
        acc.actualQuantity += parseFloat(item.actualQuantity) || 0
        acc.totalAmount += (parseFloat(item.plannedQuantity) || 0) * (parseFloat(item.unitPrice) || 0)
        return acc
      }, { plannedQuantity: 0, actualQuantity: 0, totalAmount: 0 })
    }
  },
  created() {
    if (!this.embedded) {
      this.getList()
    }
  },
  methods: {
    /** 获取默认表单数据 */
    getDefaultForm() {
      return {
        id: null,
        orderId: this.orderId,
        materialId: null,
        batchId: null,
        warehouseId: null,
        locationId: null,
        plannedQuantity: 0,
        actualQuantity: 0,
        plannedPackages: 0,
        actualPackages: 0,
        unitPrice: 0,
        itemStatus: '1',
        remark: null
      }
    },
    
    /** 查询数据列表 */
    getList() {
      this.loading = true
      listInbound_items(this.queryParams).then(response => {
        this.displayData = response.rows
        this.total = response.total
        this.loading = false
        this.$emit('load-success', response)
      }).catch(() => {
        this.loading = false
      })
    },
    
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        orderId: this.orderId,
        ...this.initQuery
      }
      this.handleQuery()
    },
    
    /** 加载关联数据 */
    handleLoadRelated() {
      if (!this.orderId) {
        this.$message.warning('请先保存主表信息')
        return
      }
      this.queryParams.orderId = this.orderId
      this.getList()
    },
    
    /** 处理选择变化 */
    handleSelectionChange(selection) {
      this.selectedRows = selection
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
      this.$emit('selection-change', selection)
    },
    
    /** 获取行key */
    getRowKey(row) {
      return row.id || row.tempId
    },
    
    /** 新增明细项 */
    handleAddItem() {
      if (this.embedded) {
        // 嵌入式模式：直接添加行
        const newItem = {
          ...this.getDefaultForm(),
          editable: true,
          tempId: Date.now() + Math.random()
        }
        this.displayData.push(newItem)
        this.$emit('item-added', newItem)
      } else {
        // 独立模式：打开对话框
        this.dialogMode = 'add'
        this.dialogTitle = "添加入库明细"
        this.form = this.getDefaultForm()
        this.dialogVisible = true
      }
    },
    
    /** 编辑明细项 */
    handleEditItem() {
      if (this.single) return
      const row = this.selectedRows[0]
      if (this.embedded) {
        // 嵌入式模式：直接设置为可编辑
        const index = this.displayData.findIndex(item => (item.id || item.tempId) === (row.id || row.tempId))
        if (index > -1) {
          this.$set(this.displayData[index], 'editable', true)
        }
      } else {
        // 独立模式：打开对话框
        this.dialogMode = 'edit'
        this.dialogTitle = "修改入库明细"
        this.form = JSON.parse(JSON.stringify(row))
        this.dialogVisible = true
      }
    },
    
    /** 行编辑 */
    handleRowEdit(row) {
      const index = this.displayData.findIndex(item => (item.id || item.tempId) === (row.id || row.tempId))
      if (index > -1) {
        this.$set(this.displayData[index], 'editable', true)
      }
    },
    
    /** 行保存 */
    handleRowSave(row) {
      const index = this.displayData.findIndex(item => (item.id || item.tempId) === (row.id || row.tempId))
      if (index > -1) {
        this.$set(this.displayData[index], 'editable', false)
        this.$emit('row-saved', row)
      }
    },
    
    /** 批量删除 */
    handleBatchDelete() {
      if (this.selectedRows.length === 0) {
        this.$message.warning('请先选择要删除的项')
        return
      }
      
      this.$confirm('确定要删除选中的明细项吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.embedded) {
          // 嵌入式模式：从displayData中删除
          const idsToDelete = this.selectedRows.map(row => row.id || row.tempId)
          this.displayData = this.displayData.filter(item => 
            !idsToDelete.includes(item.id || item.tempId)
          )
          this.selectedRows = []
          this.$emit('batch-delete', idsToDelete)
        } else {
          // 独立模式：调用API删除
          const ids = this.selectedRows.map(row => row.id).join(',')
          delInbound_items(ids).then(() => {
            this.$modal.msgSuccess("删除成功")
            this.getList()
            this.selectedRows = []
          })
        }
      })
    },
    
    /** 行删除 */
    handleRowDelete(row, index) {
      this.$confirm('确定要删除该明细项吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.embedded) {
          this.displayData.splice(index, 1)
          this.$emit('row-deleted', row)
        } else {
          delInbound_items(row.id).then(() => {
            this.$modal.msgSuccess("删除成功")
            this.getList()
          })
        }
      })
    },
    
    /** 导出 */
    handleExport() {
      this.download('inventory/inbound_items/export', {
        ...this.queryParams
      }, `inbound_items_${new Date().getTime()}.xlsx`)
    },
    
    /** 处理输入框变化 */
    handleInputChange(row, prop) {
      this.$emit('cell-change', { row, prop, value: row[prop] })
    },
    
    /** 处理数字变化 */
    handleNumberChange(row, prop) {
      row[prop] = parseFloat(row[prop]) || 0
      this.$emit('cell-change', { row, prop, value: row[prop] })
    },
    
    /** 处理列变化 */
    handleColumnChange(row, prop) {
      this.$emit('cell-change', { row, prop, value: row[prop] })
    },
    
    /** 处理输入框失去焦点 */
    handleInputBlur(row, prop) {
      // 可以在这里添加验证逻辑
      this.$emit('cell-blur', { row, prop, value: row[prop] })
    },
    
    /** 提交对话框表单 */
    submitDialogForm() {
      this.$refs["dialogForm"].validate(valid => {
        if (valid) {
          if (this.dialogMode === 'add') {
            addInbound_items(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.dialogVisible = false
              this.getList()
            })
          } else {
            updateInbound_items(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.dialogVisible = false
              this.getList()
            })
          }
        }
      })
    },
    
    /** 对话框关闭 */
    handleDialogClosed() {
      this.$refs["dialogForm"].resetFields()
    },
    
    /** 获取状态类型 */
    getStatusType(status) {
      const map = { '1': 'info', '2': 'success', '3': 'danger' }
      return map[status] || 'info'
    },
    
    /** 获取状态文本 */
    getStatusText(status) {
      const map = { '1': '待入库', '2': '已入库', '3': '已取消' }
      return map[status] || status
    },
    
    /** 格式化数字 */
    formatNumber(num) {
      if (num == null) return ''
      return parseFloat(num).toLocaleString()
    },
    
    /** 计算总数并通知父组件 */
    calculateTotals() {
      if (this.embedded) {
        const totals = this.totals
        this.$emit('totals-change', totals)
      }
    },
    
    /** 验证数据 */
    validate() {
      const errors = []
      this.displayData.forEach((item, index) => {
        if (!item.materialId) {
          errors.push(`第${index + 1}行：货物ID不能为空`)
        }
        if (parseFloat(item.plannedQuantity) <= 0) {
          errors.push(`第${index + 1}行：计划数量必须大于0`)
        }
      })
      return errors
    },
    
    /** 获取所有数据 */
    getItems() {
      return this.displayData.map(item => {
        const { editable, tempId, ...rest } = item
        return rest
      })
    },
    
    /** 重置数据（嵌入式模式） */
    resetEmbeddedData() {
      this.displayData = JSON.parse(JSON.stringify(this.cachedData)).map(item => ({
        ...item,
        editable: false,
        tempId: item.id || Date.now() + Math.random()
      }))
    },
     /** 导入按钮操作 */
    handleImport() {
      this.$refs.import.show()
    },
    /** 新增明细项（供父组件调用） */
    addItem(options = {}) {
      const newItem = {
        ...this.getDefaultForm(),
        ...options,
        orderId: this.orderId || options.orderId,
        editable: true,
        tempId: Date.now() + Math.random()
      }
      this.displayData.push(newItem)
      return newItem
    },
    
    /** 新增空行（嵌入式模式） */
    addEmptyRow() {
      return this.addItem()
    },
    
    /** 删除选中项（供父组件调用） */
    deleteSelected() {
      if (this.selectedRows.length > 0) {
        const idsToDelete = this.selectedRows.map(row => row.id || row.tempId)
        this.displayData = this.displayData.filter(item => 
          !idsToDelete.includes(item.id || item.tempId)
        )
        this.selectedRows = []
        this.$emit('batch-delete', idsToDelete)
        return true
      }
      return false
    }
  }
}
</script>

<style scoped>
.inbound-items-container {
  width: 100%;
}

.toolbar-container {
  background: #f8f9fa;
  padding: 10px;
  border-radius: 4px;
  border: 1px solid #ebeef5;
}

.table-container {
  margin-top: 10px;
}

/* 行内编辑样式 */
.el-table .cell .el-input,
.el-table .cell .el-input-number,
.el-table .cell .el-select {
  width: 100%;
}

.el-table .cell .el-input-number {
  line-height: 32px;
}

/* 调整表格内边距 */
.el-table--medium td {
  padding: 6px 0;
}
</style>