<template>
  <div class="app-container">
    <el-card>
      <div class="page-header">生产记录单</div>
      <el-form ref="queryForm" :model="queryForm" label-width="120px" class="query-form">
        <el-row :gutter="16">
          <el-col :span="6">
            <el-form-item label="生产记录单日期" prop="recordDateStart">
              <el-date-picker
                v-model="queryForm.recordDateStart"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="开始日期"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="至" prop="recordDateEnd">
              <el-date-picker
                v-model="queryForm.recordDateEnd"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="结束日期"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="生猪批次" prop="pigBatch">
              <el-input v-model="queryForm.pigBatch" placeholder="生猪批次"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="16">
          <el-col :span="6">
            <el-form-item label="生产类型" prop="productionType">
              <el-select v-model="queryForm.productionType" placeholder="请选择生产类型" clearable filterable style="width: 100%">
                <el-option
                  v-for="item in dict.type.inventory_production_type"
                  :key="item.value"
                  :value="item.value"
                  :label="item.label"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
             <el-form-item label="品种" prop="variety">
              <el-select v-model="queryForm.variety" placeholder="请选择品种" clearable filterable style="width: 100%">
                <el-option
                  v-for="item in varietyList"
                  :key="item.varietyNo"
                  :value="item.varietyNo"
                  :label="item.varietyName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="动物标识" prop="animalIdentification">
              <el-input v-model="queryForm.animalIdentification" placeholder="动物标识"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="16">
          <el-col :span="6">
            <el-form-item label="级别" prop="levelStart">
              <el-select v-model="queryForm.levelStart" placeholder="请选择级别" clearable filterable style="width: 100%">
                <el-option
                  v-for="item in levelList"
                  :key="item.levelNo"
                  :value="item.levelNo"
                  :label="item.levelName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="至" prop="levelEnd">
              <el-select v-model="queryForm.levelEnd" placeholder="请选择级别" clearable filterable style="width: 100%">
                <el-option
                  v-for="item in levelList"
                  :key="item.levelNo"
                  :value="item.levelNo"
                  :label="item.levelName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="质检结果" prop="inspectResult">
              <el-select v-model="queryForm.inspectResult" placeholder="质检结果" style="width: 100%">
                <el-option :value="1" label="合格"></el-option>
                <el-option :value="0" label="不合格"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="16">
           <el-col :span="6">
            <el-form-item label="白条编号" prop="whiteNoStart">
              <el-input v-model="queryForm.whiteNoStart" placeholder="白条编号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="至" prop="whiteNoEnd">
              <el-input v-model="queryForm.whiteNoEnd" placeholder="白条编号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="批次" prop="batch">
              <el-input v-model="queryForm.batch" placeholder="批次"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="16">
           <el-col :span="6">
            <el-form-item label="加工类型" prop="processType">
              <el-select v-model="queryForm.processType" placeholder="加工类型" style="width: 100%">
                <el-option :value="null" label="全部"></el-option>
                <el-option :value="1" label="常规"></el-option>
                <el-option :value="2" label="精修"></el-option>
                <el-option :value="3" label="预冷"></el-option>
                <el-option :value="4" label="分割"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :offset="6" :span="6" class="query-buttons">
            <el-form-item>
              <el-button type="primary" @click="handleQuery">查询</el-button>
              <el-button @click="handleClose">关闭</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-table
        size="mini"
        :data="list"
        style="width: 100%;"
        border
        stripe
        height="520"
      >
        <el-table-column label="生产日期" align="center" width="120" prop="produceDate" min-width="120"></el-table-column>
        <el-table-column label="白条编号" align="center" width="120" prop="whiteStripNumber" min-width="120"></el-table-column>
        <el-table-column label="品种品类" align="center" width="120" prop="variety" min-width="120"></el-table-column>
        <el-table-column label="品类级别" align="center" width="120" prop="grade" min-width="120"></el-table-column>
        <el-table-column label="二次计重重量" align="center" width="120" prop="secondaryWeight" min-width="120"></el-table-column>
        <el-table-column label="三重" align="center" width="100" prop="tertiaryWeight" min-width="100"></el-table-column>
        <el-table-column label="钩重/皮重" align="center" width="120" prop="hookWeight" min-width="120"></el-table-column>
        <el-table-column label="数量" align="center" width="100" prop="quantity" min-width="100"></el-table-column>
        <el-table-column label="生产扣分合计" align="center" width="130" prop="productionDeductionTotal" min-width="130"></el-table-column>
        <el-table-column label="采购扣分合计" align="center" width="130" prop="procurementDeductionTotal" min-width="130"></el-table-column>
        <el-table-column label="生猪批次" align="center" width="120" prop="pigBatch" min-width="120"></el-table-column>
        <el-table-column label="毛色" align="center" width="100" prop="coatColor" min-width="100"></el-table-column>
        <el-table-column label="物料名称" align="center" width="120" prop="materialName" min-width="120"></el-table-column>
        <el-table-column label="动物标识" align="center" width="120" prop="animalIdentification" min-width="120"></el-table-column>
        <el-table-column label="称重状态" align="center" width="120" prop="weighingStatus" min-width="120"></el-table-column>

        <el-table-column label="初次计重时间" align="center" width="140" prop="initialWeighingTime" min-width="140"></el-table-column>
        <el-table-column label="物料编码" align="center" width="120" prop="materialCode" min-width="120"></el-table-column>
        <el-table-column label="计量单位" align="center" width="120" prop="measurementUnit" min-width="120"></el-table-column>
        <el-table-column label="辅助计量单位" align="center" width="120" prop="auxiliaryMeasurementUnit" min-width="120"></el-table-column>
        <el-table-column label="辅数量" align="center" width="100" prop="auxiliaryQuantity" min-width="100"></el-table-column>
        <el-table-column label="三重时间" align="center" width="140" prop="tripleWeighingTime" min-width="140"></el-table-column>
        <el-table-column label="来源类型" align="center" width="120" prop="sourceType" min-width="120"></el-table-column>
        <el-table-column label="预冷重量" align="center" width="120" prop="preCoolingWeight" min-width="120"></el-table-column>
        <el-table-column label="预冷时间" align="center" width="140" prop="preCoolingTime" min-width="140"></el-table-column>
        <el-table-column label="猪蹄重量" align="center" width="120" prop="pigTrotterWeight" min-width="120"></el-table-column>
        <el-table-column label="猪头重量" align="center" width="120" prop="pigHeadWeight" min-width="120"></el-table-column>
        <el-table-column label="二次计重时间" align="center" width="140" prop="secondaryWeighingTime" min-width="140"></el-table-column>
        <el-table-column label="生产计划单号" align="center" width="140" prop="productionPlanNumber" min-width="140"></el-table-column>
        <el-table-column label="库存组织" align="center" width="120" prop="inventoryOrganization" min-width="120"></el-table-column>
        <el-table-column label="生产类型" align="center" width="120" prop="productionType" min-width="120"></el-table-column>
        <el-table-column label="生产车间" align="center" width="120" prop="productionWorkshop" min-width="120"></el-table-column>
        <el-table-column label="加工类型" align="center" width="120" prop="processTypeName" min-width="120"></el-table-column>
        <el-table-column label="加工工艺" align="center" width="120" prop="processingTechnology" min-width="120"></el-table-column>
        <el-table-column label="完工状态" align="center" width="120" prop="completionStatus" min-width="120"></el-table-column>
        <el-table-column label="采购员" align="center" width="120" prop="purchaser" min-width="120"></el-table-column>
        <el-table-column label="采购部门" align="center" width="120" prop="purchasingDepartment" min-width="120"></el-table-column>
        <el-table-column label="采购入库单号" align="center" width="140" prop="purchasingReceiptNumber" min-width="140"></el-table-column>
        <el-table-column label="投料生产记录单的ID" align="center" width="170" prop="feedingProductionRecordId" min-width="170"></el-table-column>
        <el-table-column label="结算方式" align="center" width="120" prop="settlementMethod" min-width="120"></el-table-column>
        <el-table-column label="结算状态" align="center" width="120" prop="settlementStatus" min-width="120"></el-table-column>
        <el-table-column label="生产入库单号" align="center" width="140" prop="productionWarehousingNumber" min-width="140"></el-table-column>
        <el-table-column label="检验结果" align="center" width="120" prop="inspectionResult" min-width="120"></el-table-column>
        <el-table-column label="待发货状态" align="center" width="120" prop="deliveryStatus" min-width="120"></el-table-column>
        <el-table-column label="销售出库单单号" align="center" width="150" prop="salesOutboundNumber" min-width="150"></el-table-column>
        <el-table-column label="销售订单号" align="center" width="140" prop="salesOrderNumber" min-width="140"></el-table-column>
        <el-table-column label="发货日期" align="center" width="120" prop="deliveryDate" min-width="120"></el-table-column>
        <el-table-column label="编号" align="center" width="120" prop="code" min-width="120"></el-table-column>
        <el-table-column label="客户" align="center" width="120" prop="customer" min-width="120"></el-table-column>
        <el-table-column label="锁定物流线" align="center" width="140" prop="lockedLogisticsLine" min-width="140"></el-table-column>
        <el-table-column label="采购物料名称" align="center" width="140" prop="procurementMaterialName" min-width="140"></el-table-column>
        <el-table-column label="采购品种" align="center" width="120" prop="procurementVariety" min-width="120"></el-table-column>
        <el-table-column label="采购级别" align="center" width="120" prop="procurementGrade" min-width="120"></el-table-column>
        <el-table-column label="扣重前重量" align="center" width="120" prop="preDeductionWeight" min-width="120"></el-table-column>
        <el-table-column label="扣重比例%" align="center" width="120" prop="deductionRatio" min-width="120"></el-table-column>
      </el-table>

      <div class="bottom-actions bottom-actions-left">
        <el-button @click="handleExport">导出</el-button>
        <el-button @click="handleEdit">修改</el-button>
        <el-button @click="handleBatchSwap">批次互换</el-button>
        <el-button type="danger" @click="handleDelete">删除</el-button>
      </div>
    </el-card>
  </div>
</template>
<script>
  import { getProductionRecordList } from '../../../api/production/productionRecord'
  import { getVarietyList } from '../../../api/baseInfo/variety'
  import { getLevelList } from '../../../api/baseInfo/level'
  export default {
    name: 'ProductionRecord',
    dicts: ['inventory_production_type'],
    data() {
      return {
        queryForm: {
          recordDateStart: this.getTomorrowDate(),
          recordDateEnd: this.getTomorrowDate(),
          pigBatch: null,
          productionType: null,
          levelStart: null,
          levelEnd: null,
          inspectResult: null,
          variety: null,
          animalIdentification: null,
          whiteNoStart: null,
          whiteNoEnd: null,
          processType: null,
          batch: null
        },
        varietyList: [],
        levelList: [],
        list: []
      }
    },
    created() {
      this.getVariety()
      this.getLevel()
      this.resetQuery();
    },
    methods: {
      /** 获取品种下拉数据 */
      getVariety() {
        getVarietyList({}).then(res => {
          this.varietyList = res.data || []
        })
      },
      /** 获取级别下拉数据 */
      getLevel() {
        getLevelList({}).then(res => {
          this.levelList = res.data || []
        })
      },
      /** 获取明天日期（yyyy-MM-dd）作为默认查询日期 */
      getTomorrowDate() {
        const date = new Date()
        date.setDate(date.getDate() + 1)
        const year = date.getFullYear()
        const month = String(date.getMonth() + 1).padStart(2, '0')
        const day = String(date.getDate()).padStart(2, '0')
        return `${year}-${month}-${day}`
      },
      getList() {
        getProductionRecordList(this.queryForm).then(res => {
          this.list = res.data;
        })
      },
      handleQuery() {
        this.getList()
      },
      handleClose() {
        this.$router.go(-1);
      },
      handleExport() {
        // TODO: 导出
        this.$message.info('导出');
      },
      handleEdit() {
        // TODO: 修改
        this.$message.info('修改');
      },
      handleBatchSwap() {
        // TODO: 批次互换
        this.$message.info('批次互换');
      },
      handleDelete() {
        // TODO: 删除
        this.$message.warning('删除');
      },
      resetQuery() {
        this.queryForm = {
          recordDateStart: this.getTomorrowDate(),
          recordDateEnd: this.getTomorrowDate(),
          pigBatch: null,
          productionType: null,
          levelStart: null,
          levelEnd: null,
          inspectResult: null,
          variety: null,
          animalIdentification: null,
          whiteNoStart: null,
          whiteNoEnd: null,
          processType: null,
          batch: null
        };
      }
    },
    mounted() {}
  }
</script>

<style scoped lang="scss">
  .page-header {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 20px;
    text-align: center;
  }
  .query-form {
    margin-bottom: 20px;
  }
  .query-form .el-form-item {
    margin-bottom: 18px;
  }
  .query-buttons {
    text-align: right;
    padding-right: 20px;
  }
  .bottom-actions {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #ebeef5;
    text-align: right;
  }
  .bottom-actions-left {
    text-align: left;
  }
</style>
