<template>
  <div>
    <!-- 主内容 -->
    <div>
      <div class="app-container">
        <el-input
          v-model="getProductionWorkOrder.parammaps.orderCode"
          placeholder="生产单号"
          clearable
          style="width: 150px"
          class="filter-item"
        />

        <el-input
          v-model="getProductionWorkOrder.parammaps.goodsName"
          placeholder="货品名称"
          clearable
          style="width: 150px"
          class="filter-item"
        />

        <el-input
          v-model="getProductionWorkOrder.parammaps.goodsCode"
          placeholder="货品编码"
          clearable
          style="width: 150px"
          class="filter-item"
        />

        <el-select
          v-model="getProductionWorkOrder.parammaps.orderStatus"
          clearable
          placeholder="处理状态"
          class="filter-item"
          style="width: 150px"
        >
          <el-option
            v-for="item in statuesList"
            :key="item.name"
            :label="item.name"
            :value="item.name"
          />
        </el-select>

        <el-select
          v-model="getProductionWorkOrder.parammaps.priority"
          clearable
          placeholder="优先级"
          class="filter-item"
          style="width: 150px"
        >
          <el-option
            v-for="item in priorityList"
            :key="item.name"
            :label="item.name"
            :value="item.name"
          />
        </el-select>

        <el-date-picker
          ref="inputDatetime2"
          v-model="getProductionWorkOrder.parammaps.inputDatetime2"
          class="inputDatetime"
          type="daterange"
          style="width: 250px; top: 0px"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />

        <el-button
          v-waves
          class="search-button"
          type="primary"
          icon="el-icon-search"
          @click="get_production_work_order"
          >搜索</el-button
        >
      </div>

      <div class="search-button-container">
        <el-button
          v-if="isProductionWorkOrderAdd"
          class="search-button"
          type="primary"
          icon="el-icon-edit"
          @click="form_add"
          >新增生产计划</el-button
        >

        <el-button
          v-if="isProductionWorkOrderExcel"
          class="search-button"
          type="primary"
          icon="el-icon-upload2"
          @click="derive_data_excel"
          >导出</el-button
        >

        <el-radio-group
          v-model="radioAll"
          style="margin-top: -5px"
          @change="changeAll()"
        >
          <el-radio-button label="全部" />
          <el-badge :value="pending.total" class="item">
            <el-radio-button label="待处理" />
          </el-badge>
          <el-radio-button label="已处理" />
        </el-radio-group>
      </div>

      <div>
        <el-table
          :key="tableKey"
          v-loading="listLoading"
          element-loading-text="给我一点时间"
          :data="list"
          border
          fit
          highlight-current-row
          style="width: 100%; margin-left: 20px"
          :row-style="rowStyle"
          :cell-style="cellStyle"
          class="elTable table-fixed"
          :max-height="myHeight"
        >
          <el-table-column
            label="序号"
            align="center"
            type="index"
            width="50px"
          >
            <template slot-scope="scope">
              <span>{{ scope.$index + (pageNum - 1) * pageSize + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="生产单号" align="center" prop="orderCode" />
          <el-table-column label="货品" align="center" prop="goodsName" />
          <el-table-column label="优先级" align="center" prop="priority" />
          <el-table-column label="总数量" align="center" prop="totalQuantity" />
          <el-table-column
            label="已生产数量"
            align="center"
            prop="producedQuantity"
          />
          <el-table-column label="剩余量" align="center" prop="remaining" />
          <!-- <el-table-column label="生产进度" align="center" prop="schedule" /> -->
          <el-table-column
            label="生产进度"
            header-align="center"
            align="center"
          >
            <template slot-scope="scope">
              <el-progress
                :text-inside="true"
                :stroke-width="26"
                :percentage="scope.row.schedule"
              ></el-progress>
            </template>
          </el-table-column>

          <el-table-column label="下单人" align="center" prop="orderername" />
          <el-table-column label="下单时间" align="center" prop="orderTime" />
          <el-table-column label="反馈时间" align="center" prop="acceptTime" />
          <el-table-column
            label="预估完成时间"
            align="center"
            prop="estimatedCompletionTime"
          />
          <!-- <el-table-column label="距预估时间还剩/天" align="center" prop="days_diff"  sortable /> -->

          <el-table-column
            prop="days_diff"
            label="距预估完成时间还剩"
            align="center"
            width="160"
          >
          <template slot-scope="scope">
  <template
    v-if="
      scope.row.days_diff !== null &&
      scope.row.days_diff !== undefined &&
      scope.row.days_diff !== ''
    "
  >
    <span
      :class="{
        'normal-time': scope.row.days_diff > 3 || (scope.row.days_diff < 0),
        'warning-time': scope.row.days_diff >= 0 && scope.row.days_diff <= 3,
        'overdue-time': scope.row.days_diff < 0,
      }"
    >
      <template v-if="scope.row.days_diff < 0">
        已逾期 {{ Math.abs(scope.row.days_diff) }} 天 <!-- 负数全部显示为已逾期 -->
      </template>
      <template v-else>
        <!-- 如果 orderStatus 是 '生产完成' 且 days_diff > 0，显示 '提前 X 天' -->
        <template v-if="scope.row.orderStatus === '生产完成' && scope.row.days_diff > 0">
          提前 {{ scope.row.days_diff }} 天
        </template>
        <template v-else>
          {{ scope.row.days_diff }} 天 <!-- 其他情况直接显示天数 -->
        </template>
      </template>
    </span>
  </template>
  <template v-else>
    <!-- 如果 days_diff 是空字符串、null 或 undefined，显示空 -->
  </template>
</template>
          </el-table-column>

          <el-table-column
            label="实际完成时间"
            align="center"
            prop="actualCompletionTime"
          />
          <el-table-column label="处理状态" align="center" prop="orderStatus" />
          <!-- <el-table-column label="接单人" align="center" prop="acceptername" /> -->
          <el-table-column label="备注" align="center" prop="remarks" />

          <el-table-column
            label="操作"
            min-width="250px"
            header-align="center"
            align="center"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                class="add-button"
                type="primary"
                size="mini"
                @click="handleGet(scope.row)"
                >查看</el-button
              >

              <el-button
                class="add-button"
                v-if="
                  scope.row.orderStatus === '未生产' &&
                  isProductionWorkOrderFeedback
                "
                :style="{ backgroundColor: '#28d251' }"
                size="mini"
                @click="handleOrderTaking(scope.row)"
                >反馈</el-button
              >
              <el-button
                class="add-button"
                v-if="
                  scope.row.orderStatus === '未生产' &&
                  isProductionWorkOrderClose
                "
                :style="{ backgroundColor: '#ff3737' }"
                size="mini"
                @click="handleTurnDown(scope.row)"
                >关单</el-button
              >

              <el-button
                class="add-button"
                v-if="
                  scope.row.orderStatus === '已关单' &&
                  isProductionWorkOrderEdit
                "
                :style="{ backgroundColor: '#5adc79' }"
                size="mini"
                @click="handleEdit(scope.row)"
                >编辑</el-button
              >
              <el-button
                class="add-button"
                v-if="
                  scope.row.orderStatus === '已关单' && isProductionWorkOrderDel
                "
                :style="{ backgroundColor: '#ff3737' }"
                size="mini"
                @click="handleWorkOrderDel(scope.row)"
                >删除</el-button
              >

              <el-button
                class="add-button"
                v-if="
                  scope.row.orderStatus === '待生产' &&
                  isProductionWorkOrderStart
                "
                :style="{ backgroundColor: '#eeb47f' }"
                size="mini"
                @click="startProduction(scope.row)"
                >开始生产</el-button
              >

              <el-button
                class="add-button"
                v-if="
                  scope.row.orderStatus === '生产中' &&
                  isProductionWorkOrderFillout
                "
                :style="{ backgroundColor: '#eeb47f' }"
                size="mini"
                @click="handleFillInDaily(scope.row)"
                >每日填写</el-button
              >
              <el-button
                class="add-button"
                v-if="
                  scope.row.orderStatus === '生产中' &&
                  isProductionWorkOrderComplete
                "
                :style="{ backgroundColor: '#28d251' }"
                size="mini"
                @click="completeProduction(scope.row)"
                >完成</el-button
              >

              <!-- <el-button class="add-button" v-if="scope.row.orderStatus === '已撤销'" :style="{ backgroundColor: '#28d251' }" size="mini" @click="handleOrderTaking(scope.row)">编辑</el-button> -->
              <el-button
                class="add-button"
                v-if="
                  scope.row.orderStatus === '生产完成' &&
                  isProductionWorkOrderDel
                "
                :style="{ backgroundColor: '#ff3737' }"
                size="mini"
                @click="handleWorkOrderDel(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <Pagination
      v-show="total >= 0"
      :total="total"
      :page.sync="getProductionWorkOrder.offset"
      :limit.sync="getProductionWorkOrder.pagecount"
      @Pagination="get_production_work_order"
    />

    <el-dialog
      :title="dialogTitle"
      :visible.sync="isEdit"
      :close-on-click-modal="false"
      @close="handleCancel"
      :style="{ maxHeight: '100vh', overflowY: 'auto' }"
    >
      <div class="app-add">
        <el-form
          ref="form"
          :rules="rules"
          :inline="true"
          :model="formLabelAlign"
          label-position="left"
          label-width="auto"
          style="width: 90%; margin: 0 auto 30px"
        >
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="生产单号:" prop="orderCode">
                <el-input
                  v-model="formLabelAlign.orderCode"
                  placeholder="请输入生产单号"
                />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="录入人:" prop="createrId">
                <el-select
                  v-model="formLabelAlign.createrId"
                  placeholder="请选择"
                  :disabled="isView"
                  clearable
                  style="width: 200px"
                >
                  <el-option
                    v-for="item in empList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="下单时间:">
                <el-date-picker
                  style="width: 200px"
                  v-model="formLabelAlign.date"
                  type="datetime"
                  :disabled="isView"
                  align="right"
                  placeholder="下单时间"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="优先级:" prop="priority">
                <el-select
                  v-model="formLabelAlign.priority"
                  placeholder="请选择"
                  :disabled="isView"
                  clearable
                  style="width: 187px"
                >
                  <el-option
                    v-for="item in priorityList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="备注:" prop="remarks">
                <el-input
                  v-model="formLabelAlign.remarks"
                  style="width: 200px"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="18">
              <el-form-item label="货品：">
                <el-autocomplete
                  ref="autocomplete"
                  v-model="getGoodsListByCodeParm.parammaps.goodsCode"
                  value-key="id"
                  :fetch-suggestions="fetchGoods"
                  placeholder="请输入备件编号或备件名称或备件规格"
                  style="width: 600px"
                  @select="handleEditInputGoods"
                >
                  <template slot-scope="{ item }">
                    <b>备件编号：</b>
                    <div class="name" style="display: inline">
                      {{ item.goodsCode }}
                    </div>
                    &nbsp; | &nbsp;<b>备件名称：</b
                    ><span class="addr">{{ item.goodsName }}</span
                    >&nbsp; | &nbsp;<b>备件规格：</b
                    ><span class="addr">{{ item.goodsSpecification }}</span>
                  </template>
                </el-autocomplete>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-table
              :key="tableKey"
              v-loading="listLoading"
              element-loading-text="给我一点时间"
              :data="productionOrderGoodsList"
              border
              fit
              highlight-current-row
              style="width: 100%; margin-left: 20px"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
              :max-height="myHeight"
            >
              <el-table-column label="序号" align="center" type="index" />
              <el-table-column
                label="货品编号"
                align="center"
                prop="goodsCode"
              />
              <el-table-column
                label="货品名称"
                align="center"
                prop="goodsName"
              />
              <el-table-column
                label="货品规格"
                align="center"
                prop="goodsSpecification"
              />
              <el-table-column label="货品图片" align="center">
                <template slot-scope="scope">
                  <el-popover placement="right" title="" trigger="hover">
                    <!-- 判断 imagePath 是否存在 -->
                    <template v-if="scope.row.goodsImagePath">
                      <img
                        slot="reference"
                        :src="scope.row.goodsImagePath"
                        style="height: 100px; width: 100px"
                      />
                      <!-- 悬停时显示的内容 -->
                      <img
                        :src="scope.row.goodsImagePath"
                        style="height: 200px; width: 200px"
                      />
                    </template>
                    <template v-else></template>
                  </el-popover>
                </template>
              </el-table-column>

              <el-table-column label="计量单位" align="center" prop="label" />

              <el-table-column label="现有库存" align="center" />
              <el-table-column label="计划生产总量" align="center">
                <template slot-scope="{ row }">
                  <el-input
                    v-model="row.totalQuantity"
                    placeholder="计划生产总量"
                    clearable
                    type="number"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    style="padding-right: 0px"
                  />
                </template>
              </el-table-column>
              <!--
              <el-table-column label="优先级" align="center">
                <template slot-scope="scope">
                  <el-select
                    v-model="scope.row.priority"
                    clearable
                    placeholder="请选择优先级"
                    class="filter-item"
                    style="padding-right:0px;"
                  >
                    <el-option
                      v-for="item in priorityList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </template>
              </el-table-column> -->

              <el-table-column>
                <template slot-scope="scope">
                  <el-button
                    type="primary"
                    size="mini"
                    @click="handleEditDel(scope.row)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-row>

          <el-row :gutter="24" style="margin-top: 10px">
            <span
              style="
                font-size: 22px;
                margin-top: 15px;
                font-weight: bold;
                margin-bottom: 15px;
              "
              >工序</span
            >
            <el-button
              type="primary"
              style="margin-left: 10px; padding: 10px"
              size="mini"
              @click="handleEditProcess"
              >选择工序</el-button
            >
          </el-row>
          <el-row :gutter="24" style="margin-top: 10px">
            <el-table
              :key="tableKey"
              v-loading="listLoading"
              element-loading-text="给我一点时间"
              :data="processRecordsList"
              border
              fit
              highlight-current-row
              style="width: 100%; margin-left: 20px"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
              :max-height="myHeight"
            >
              <el-table-column label="序号" align="center" type="index" />
              <el-table-column label="工序" align="center" prop="process" />

              <el-table-column label="数量" align="center">
                <template slot-scope="{ row }">
                  <el-input
                    v-model="row.amount"
                    placeholder="数量"
                    clearable
                    type="number"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    style="padding-right: 0px"
                  />
                </template>
              </el-table-column>

              <el-table-column label="备注" align="center">
                <template slot-scope="{ row }">
                  <el-input
                    v-model="row.remark"
                    placeholder="备注"
                    clearable
                    style="padding-right: 0px"
                  />
                </template>
              </el-table-column>
              <!-- <el-table-column
                label="备注"
                align="center"
                prop="remark"
              /> -->

              <el-table-column>
                <template slot-scope="scope">
                  <el-button
                    type="primary"
                    size="mini"
                    @click="handleEditProcessRecordsDel(scope.row)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-row>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button class="add-button" @click="handleEditAndOff"
          >保存并关闭</el-button
        >
        <el-button
          class="add-button"
          style="background-color: #ffffff; color: black"
          @click="handleCancel"
          >取消并关闭</el-button
        >
      </div>
    </el-dialog>

    <!-- 弹窗 -->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogFormVisible"
      :close-on-click-modal="false"
      @close="handleCancel"
      :style="{ maxHeight: '100vh', overflowY: 'auto' }"
    >
      <div class="app-add">
        <el-form
          ref="form"
          :rules="rules"
          :inline="true"
          :model="formLabelAlign"
          label-position="left"
          label-width="auto"
          style="width: 90%; margin: 0 auto 30px"
        >
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="生产单号:" prop="orderCode">
                <el-input
                  :disabled="true"
                  v-model="formLabelAlign.orderCode"
                  placeholder="请输入生产单号"
                />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="录入人:" prop="createrId">
                <el-select
                  v-model="formLabelAlign.createrId"
                  placeholder="请选择"
                  :disabled="isView"
                  clearable
                  style="width: 200px"
                >
                  <el-option
                    v-for="item in empList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="下单时间:">
                <el-date-picker
                  style="width: 200px"
                  v-model="formLabelAlign.date"
                  type="datetime"
                  :disabled="isView"
                  align="right"
                  placeholder="下单时间"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="优先级:" prop="priority">
                <el-select
                  v-model="formLabelAlign.priority"
                  placeholder="请选择"
                  :disabled="isView"
                  clearable
                  style="width: 187px"
                >
                  <el-option
                    v-for="item in priorityList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="备注:" prop="remarks">
                <el-input
                  v-model="formLabelAlign.remarks"
                  style="width: 200px"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="18">
              <el-form-item label="货品：">
                <el-autocomplete
                  ref="autocomplete"
                  v-model="getGoodsListByCodeParm.parammaps.goodsCode"
                  value-key="id"
                  :fetch-suggestions="fetchGoods"
                  placeholder="请输入备件编号或备件名称或备件规格"
                  style="width: 600px"
                  @select="handleInputGoods"
                >
                  <template slot-scope="{ item }">
                    <b>备件编号：</b>
                    <div class="name" style="display: inline">
                      {{ item.goodsCode }}
                    </div>
                    &nbsp; | &nbsp;<b>备件名称：</b
                    ><span class="addr">{{ item.goodsName }}</span
                    >&nbsp; | &nbsp;<b>备件规格：</b
                    ><span class="addr">{{ item.goodsSpecification }}</span>
                  </template>
                </el-autocomplete>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-table
              :key="tableKey"
              v-loading="listLoading"
              element-loading-text="给我一点时间"
              :data="listAdd"
              border
              fit
              highlight-current-row
              style="width: 100%; margin-left: 20px"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
              :max-height="myHeight"
            >
              <el-table-column label="序号" align="center" type="index" />
              <el-table-column
                label="货品编号"
                align="center"
                prop="goodsCode"
              />
              <el-table-column
                label="货品名称"
                align="center"
                prop="goodsName"
              />
              <el-table-column
                label="货品规格"
                align="center"
                prop="goodsSpecification"
              />
              <el-table-column label="货品图片" align="center">
                <template slot-scope="scope">
                  <el-popover placement="right" title="" trigger="hover">
                    <!-- 判断 imagePath 是否存在 -->
                    <template v-if="scope.row.goodsImagePath">
                      <img
                        slot="reference"
                        :src="scope.row.goodsImagePath"
                        style="height: 100px; width: 100px"
                      />
                      <!-- 悬停时显示的内容 -->
                      <img
                        :src="scope.row.goodsImagePath"
                        style="height: 200px; width: 200px"
                      />
                    </template>
                    <template v-else></template>
                  </el-popover>
                </template>
              </el-table-column>

              <el-table-column label="计量单位" align="center" prop="label" />

              <el-table-column label="现有库存" align="center" />
              <el-table-column label="计划生产总量" align="center">
                <template slot-scope="{ row }">
                  <el-input
                    v-model="row.totalQuantity"
                    placeholder="计划生产总量"
                    clearable
                    type="number"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    style="padding-right: 0px"
                  />
                </template>
              </el-table-column>
              <!--
              <el-table-column label="优先级" align="center">
                <template slot-scope="scope">
                  <el-select
                    v-model="scope.row.priority"
                    clearable
                    placeholder="请选择优先级"
                    class="filter-item"
                    style="padding-right:0px;"
                  >
                    <el-option
                      v-for="item in priorityList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </template>
              </el-table-column> -->

              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button
                    type="primary"
                    size="mini"
                    @click="handleDel(scope.row)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-row>

          <el-row :gutter="24" style="margin-top: 10px">
            <span
              style="
                font-size: 22px;
                margin-top: 15px;
                font-weight: bold;
                margin-bottom: 15px;
              "
              >工序</span
            >
            <el-button
              type="primary"
              style="margin-left: 10px; padding: 10px"
              size="mini"
              @click="handleProcess"
              >选择工序</el-button
            >
          </el-row>
          <el-row :gutter="24" style="margin-top: 10px">
            <el-table
              :key="tableKey"
              v-loading="listLoading"
              element-loading-text="给我一点时间"
              :data="processRecordsListAdd"
              border
              fit
              highlight-current-row
              style="width: 100%; margin-left: 20px"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
              :max-height="myHeight"
            >
              <el-table-column label="序号" align="center" type="index" />
              <el-table-column label="工序" align="center" prop="process" />

              <el-table-column label="数量" align="center">
                <template slot-scope="{ row }">
                  <el-input
                    v-model="row.amount"
                    placeholder="数量"
                    clearable
                    type="number"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    style="padding-right: 0px"
                  />
                </template>
              </el-table-column>

              <!-- <el-table-column
                label="数量"
                align="center"
              >
                <template slot-scope="{ row }">
                  <el-input
                    v-model="row.amount"
                    placeholder="数量"
                    clearable
                      type="number"
                       oninput="value=value.replace(/[^\d]/g,'')"
                    style="padding-right:0px;"
                  />
                </template>
              </el-table-column> -->

              <el-table-column label="备注" align="center">
                <template slot-scope="{ row }">
                  <el-input
                    v-model="row.remark"
                    placeholder="备注"
                    clearable
                    style="padding-right: 0px"
                  />
                </template>
              </el-table-column>

              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button
                    type="primary"
                    size="mini"
                    @click="handleProcessRecordsDel(scope.row)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-row>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button class="add-button" @click="handleAddAndOff"
          >保存并关闭</el-button
        >
        <el-button
          class="add-button"
          style="background-color: #ffffff; color: black"
          @click="handleCancel"
          >取消并关闭</el-button
        >
      </div>
    </el-dialog>

    <!-- :title="dialogTitle" -->
    <el-dialog
      :visible.sync="dialogGetVisible"
      :close-on-click-modal="false"
      @close="handleCancel"
      :style="{ maxHeight: '100vh', overflowY: 'auto' }"
    >
      <template #title>
        <div style="display: flex; align-items: center">
          <el-menu
            mode="horizontal"
            :default-active="String(activeMenuItem)"
            @select="handleMenuSelect"
            style="border-bottom: none"
          >
            <el-menu-item index="1">查看</el-menu-item>
            <el-menu-item index="2">生产记录</el-menu-item>
          </el-menu>
        </div>
      </template>
      <div class="app-add" v-if="activeMenuItem == 2">
        <el-form
          ref="form"
          :inline="true"
          :model="formLabelAlign"
          label-position="left"
          label-width="auto"
          style="width: 90%; margin: 0 auto 30px"
        >
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="预计完成时间:">
                <el-input
                  v-model="formLabelAlign.estimatedCompletionTime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="距完成时间还剩:">
                <el-input v-model="formLabelAlign.days_diff" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="6">
              <el-date-picker
                ref="inputDatetime2"
                v-model="getProductionOrderProcessParm.parammaps.inputDatetime2"
                class="inputDatetime"
                type="daterange"
                style="width: 250px; top: 0px"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </el-col>
            <el-col :span="6">
              <el-input
                v-model="getProductionOrderProcessParm.parammaps.empname"
                :disabled="false"
                placeholder="人员"
              />
            </el-col>

            <el-col :span="6">
              <el-button
                class="records-button"
                type="primary"
                size="mini"
                @click="handleGetProductionOrderProcess"
                >搜索</el-button
              >
              <el-button
                class="records-button"
                type="primary"
                size="mini"
                @click="handleGetProductionOrderProcessExcel"
                >导出</el-button
              >
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-table
              :key="tableKey"
              v-loading="listLoading"
              element-loading-text="给我一点时间"
              :data="productionOrderProcessList"
              border
              fit
              highlight-current-row
              style="width: 100%; margin-left: 20px; margin-top: 15px"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
              :max-height="myHeight"
              :span-method="spanMethod"
            >
              <el-table-column label="日期" align="center" prop="workDate" />
              <el-table-column label="工序" align="center" prop="process" />
              <el-table-column
                label="计划数量"
                align="center"
                prop="planamount"
              />
              <el-table-column
                label="已完成"
                align="center"
                prop="completeamount"
              />

              <el-table-column label="剩余量" align="center" prop="remaining" />

              <el-table-column
                label="今日完成量"
                align="center"
                prop="amount"
              />

              <el-table-column label="生产人员" align="center" prop="empname" />

              <el-table-column label="备注" align="center" prop="remark" />
            </el-table>
          </el-row>
        </el-form>
      </div>

      <div class="app-add" v-if="activeMenuItem == 1">
        <el-form
          ref="form"
          :inline="true"
          :model="formLabelAlign"
          label-position="left"
          label-width="auto"
          style="width: 90%; margin: 0 auto 30px"
        >
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="生产单号:">
                <el-input v-model="formLabelAlign.orderCode" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="下单人:">
                <el-input
                  v-model="formLabelAlign.orderername"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="下单时间:">
                <el-input v-model="formLabelAlign.orderTime" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="优先级:">
                <el-input v-model="formLabelAlign.priority" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="生产进度:">
                <el-input v-model="formLabelAlign.schedule" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="预估完成时间:">
                <el-input
                  v-model="formLabelAlign.estimatedCompletionTime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="距预估时间还剩:">
                <el-input v-model="formLabelAlign.days_diff" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="实际完成时间:">
                <el-input
                  v-model="formLabelAlign.actualCompletionTime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="备注:">
                <el-input v-model="formLabelAlign.remarks" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="货品编号:">
                <el-input v-model="formLabelAlign.goodsCode" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="货品名称:">
                <el-input v-model="formLabelAlign.goodsName" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="货品规格:">
                <el-input
                  v-model="formLabelAlign.goodsSpecification"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="计量单位:">
                <el-input v-model="formLabelAlign.goodsUnit" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="现有库存:">
                <el-input :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="计划生产总量:">
                <el-input
                  v-model="formLabelAlign.totalQuantity"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="反馈人:">
                <el-input
                  v-model="formLabelAlign.acceptername"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="反馈时间:">
                <el-input
                  v-model="formLabelAlign.acceptTime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
            <el-col v-if="formLabelAlign.orderStatus === '已关单'" :span="8">
              <el-form-item label="驳回说明:">
                <el-input
                  v-model="formLabelAlign.rejectedReason"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-table
              :key="tableKey"
              v-loading="listLoading"
              element-loading-text="给我一点时间"
              :data="processRecordsList"
              border
              fit
              highlight-current-row
              style="width: 100%; margin-left: 20px"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
              :max-height="myHeight"
            >
              <el-table-column label="序号" align="center" type="index" />
              <el-table-column label="工序" align="center" prop="process" />
              <el-table-column label="数量" align="center" prop="amount" />
              <el-table-column
                label="已完成数量"
                align="center"
                prop="completedAmount"
              />

              <el-table-column label="剩余量" align="center">
                <template #default="scope">
                  {{ scope.row.amount - scope.row.completedAmount }}
                </template>
              </el-table-column>

              <el-table-column label="备注" align="center" prop="remark" />
            </el-table>
          </el-row>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          class="add-button"
          v-if="
            this.formLabelAlign.orderStatus === '未生产' &&
            isProductionWorkOrderFeedback
          "
          :style="{ backgroundColor: '#28d251' }"
          size="mini"
          @click="handleOrderTakingById(formLabelAlign)"
          >反馈</el-button
        >
        <el-button
          class="add-button"
          style="background-color: #ffffff; color: black"
          @click="handleCancel"
          >关闭</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      :title="dialogTitle"
      :visible.sync="isOrderTaking"
      :close-on-click-modal="false"
      @close="handleOrderTakingCancel"
      :width="600 + 'px'"
      :style="{ maxHeight: '100vh', overflowY: 'auto' }"
    >
      <div class="app-add">
        <el-form
          ref="form"
          :rules="rules1"
          :inline="true"
          :model="isOrderTakingData"
          label-position="center"
          label-width="auto"
          style="width: 90%; margin: 0 auto 30px"
        >
          <el-row :gutter="24" style="display: flex; justify-content: center">
            <el-form-item label="反馈人:" prop="accepterName">
              <el-input
                v-model="isOrderTakingData.accepterName"
                :disabled="true"
              />
            </el-form-item>
          </el-row>

          <el-row :gutter="24" style="display: flex; justify-content: center">
            <el-form-item label="反馈时间:" prop="acceptTime">
              <el-input
                v-model="isOrderTakingData.acceptTime"
                :disabled="true"
              />
            </el-form-item>
          </el-row>

          <el-row :gutter="24" style="display: flex; justify-content: center">
            <el-form-item label="预估完成时间:" prop="estimatedCompletionTime">
              <el-date-picker
                type="date"
                style="width: 187px"
                v-model="isOrderTakingData.estimatedCompletionTime"
                :disabled="false"
                @change="formatDate"
              />
            </el-form-item>
          </el-row>
        </el-form>
      </div>

      <div
        slot="footer"
        class="dialog-footer"
        style="display: flex; justify-content: center"
      >
        <el-button class="add-button" @click="productionOrderTaking"
          >确认反馈</el-button
        >
        <el-button
          class="add-button"
          style="background-color: #ffffff; color: black"
          @click="handleOrderTakingCancel"
          >关闭</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      :title="dialogTitle"
      :visible.sync="isFillOut"
      :close-on-click-modal="false"
      @close="handleFillInDailyCancel"
      :style="{ maxHeight: '100vh', overflowY: 'auto' }"
    >
      <div>
        <el-form
          ref="form"
          :inline="true"
          :model="isFillInDailyData"
          label-position="center"
          label-width="auto"
          style="width: 90%; margin: 0 auto 30px"
        >
          <el-row style="white-space: nowrap; overflow: hidden" :gutter="24">
            <el-col :span="6">
              <el-form-item label="记录人:" style="margin-left: -90px">
                <el-input
                  v-model="isFillInDailyData.orderername"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="预计完成时间:" style="margin-left: -80px">
                <el-input
                  v-model="isFillInDailyData.estimatedCompletionTime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="距完成时间还剩:" style="margin-left: -55px">
                <el-input
                  v-model="isFillInDailyData.days_diff"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="备注:" style="margin-left: -90px">
                <el-input
                  v-model="isFillInDailyData.remarks"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="日期（最多可选3天）:">
                <el-date-picker
                  v-model="selectedDates"
                  type="dates"
                  placeholder="选择日期（最多可选3天）"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  :style="{ width: '400px' }"
                  :picker-options="{
                    disabledDate(time) {
                      return time.getTime() > Date.now();
                    },
                  }"
                  @change="handleDateChange"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-table
              :key="tableKey"
              v-loading="listLoading"
              element-loading-text="给我一点时间"
              :data="productionOrderGoodsList"
              border
              fit
              highlight-current-row
              style="width: 100%; margin-left: 20px"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
              :max-height="myHeight"
            >
              <el-table-column label="日期" align="center" prop="date" />
              <el-table-column label="工序" align="center" prop="process" />
              <el-table-column
                label="计划生产量"
                align="center"
                prop="totalQuantity"
              />
              <el-table-column
                label="累计完成量"
                align="center"
                prop="producedQuantity"
              />

              <el-table-column label="今日完成量" align="center">
                <template slot-scope="{ row }">
                  <el-input
                    v-model="row.todayQuantity"
                    placeholder="今日完成量"
                    clearable
                    type="number"
                    oninput="value=value.replace(/[^\d]/g,'')"
                    style="padding-right: 0px"
                  />
                </template>
              </el-table-column>

              <el-table-column label="剩余量" align="center" prop="remaining" />

              <el-table-column label="备注" align="center">
                <template slot-scope="{ row }">
                  <el-input
                    v-model="row.remark"
                    placeholder="备注"
                    clearable
                    style="padding-right: 0px"
                  />
                </template>
              </el-table-column>
            </el-table>
          </el-row>
        </el-form>
      </div>
      <div
        slot="footer"
        class="dialog-footer"
        style="display: flex; justify-content: center"
      >
        <el-button class="add-button" @click="saveFillInDailyCancel"
          >保存</el-button
        >
        <el-button
          class="add-button"
          style="background-color: #ffffff; color: black"
          @click="handleFillInDailyCancel"
          >关闭</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      :title="dialogTitle"
      :visible.sync="isTurnDown"
      :close-on-click-modal="false"
      @close="handleFillInDailyCancel"
      :width="500 + 'px'"
      :style="{ maxHeight: '100vh', overflowY: 'auto' }"
    >
      <div>
        <el-form
          ref="form"
          :inline="true"
          :model="isFillInDailyData"
          label-position="center"
          label-width="auto"
          style="width: 90%; margin: 0 auto 30px"
        >
          <el-row :gutter="24">
            <el-form-item label="驳回说明:">
              <el-input
                v-model="isFillInDailyData.rejectedReason"
                :disabled="false"
                style="width: 320px"
              />
            </el-form-item>
          </el-row>
        </el-form>
      </div>
      <div
        slot="footer"
        class="dialog-footer"
        style="display: flex; justify-content: center"
      >
        <el-button class="add-button" @click="saveTurnDown">驳回</el-button>
        <el-button
          class="add-button"
          style="background-color: #ffffff; color: black"
          @click="handleTurnDownCancel"
          >关闭</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      :title="dialogTitle"
      :visible.sync="isProductionRecord"
      :close-on-click-modal="false"
      @close="handleFillInDailyCancel"
      :width="500 + 'px'"
      :style="{ maxHeight: '100vh', overflowY: 'auto' }"
    >
      <div>
        <el-form
          ref="form"
          :inline="true"
          :model="isFillInDailyData"
          label-position="center"
          label-width="auto"
          style="width: 90%; margin: 0 auto 30px"
        >
          <el-row :gutter="24">
            <el-form-item label="驳回说明:">
              <el-input
                v-model="isFillInDailyData.rejectedReason"
                :disabled="false"
                style="width: 320px"
              />
            </el-form-item>
          </el-row>
        </el-form>
      </div>
      <template>
        <div
          class="dialog-footer"
          style="display: flex; justify-content: center"
        >
          <el-button class="add-button" @click="saveTurnDown">驳回</el-button>
          <el-button
            class="add-button"
            style="background-color: #ffffff; color: black"
            @click="handleTurnDownCancel"
            >关闭</el-button
          >
        </div>
      </template>
    </el-dialog>

    <el-dialog
      :title="dialogTitle"
      :visible.sync="isProcess"
      :close-on-click-modal="false"
      @close="handleProcessCancel"
      :style="{ overflowY: 'auto' }"
    >
      <el-row :gutter="24">
        <!-- 左侧树形组件 -->
        <el-col :span="4">
          <el-card style="height: 65vh; overflow-y: auto">
            <div style="margin-top: 20px; margin-left: 10px">
              <el-tree
                :data="processList"
                v-model="getProcessRecordsParm.parammaps.processId"
                :props="defaultProps"
                @node-click="handleNodeClick"
                :disabled="false"
              ></el-tree>
            </div>
          </el-card>
        </el-col>

        <!-- 右侧表格 -->
        <el-col :span="20">
          <el-table
            :key="tableKey"
            v-loading="listLoading"
            element-loading-text="给我一点时间"
            :data="processRecordsList"
            border
            fit
            highlight-current-row
            style="width: 100%; margin-left: 20px"
            :row-style="rowStyle"
            :cell-style="cellStyle"
            class="elTable table-fixed"
            :max-height="myHeight"
          >
            <el-table-column
              label="序号"
              align="center"
              type="index"
              width="50px"
              prop="sort"
            />
            <el-table-column label="工序" align="center" prop="process" />
            <el-table-column label="备注" align="center" prop="remark" />
          </el-table>
        </el-col>
      </el-row>
      <div class="dialog-footer">
        <el-button class="process-button" @click="saveProcess">确定</el-button>
        <el-button class="process-button" @click="handleProcessCancel"
          >取消</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import "element-ui/lib/theme-chalk/index.css";
import Cookies from "js-cookie";
import {
  GetDataByName,
  postJson,
  GetDataByNames,
  checkButtons,
  PostDataByName,
  ExecDataByConfig,
  GetAccount,
  transData,
} from "@/api/common";
import Pagination from "@/components/Pagination1";
import { MessageBox } from "element-ui";
import waves from "@/directive/waves"; // waves directive
import TreeSelect from "@/components/TreeSelect";

export default {
  components: { Pagination, TreeSelect },
  directives: { waves },
  data() {
    return {
      getProductionWorkOrder: {
        name: "getProductionWorkOrder",
        page: 1,
        offset: 1,
        returntype: "Map",
        pagecount: 10,
        parammaps: {},
      },
      getProductionWorkOrderExcel: {
        name: "getProductionWorkOrderExcel",
        returntype: "Map",
        parammaps: {},
      },
      getOrderCodeParm: { name: "getOrderCode" },
      getProductionOrderGoodsParm: {
        name: "getProductionOrderGoods",
        parammaps: { id: "" },
      },
      getProductionOrderGoodsFillOutParm: {
        name: "getProductionOrderGoodsFillOut",
        parammaps: { id: "" },
      },
      defaultProps: {
        children: "children",
        label: "process",
      },
      pending: {},
      empList: [],
      productionOrderGoodsList: [],
      productionOrderProcessList: [], //工序
      getProcessRecordsParm: {
        name: "getProcessRecords",
        parammaps: { pid: "" },
      },
      activeList: [],
      spanArr: [],
      position: 0,
      queryCondition: "",
      processList: [], //工序列表
      tableKey: 0,
      active: 1,
      listLoading: true,
      isView: false,
      isEdit: false,
      isProcess: false,
      dialogFormVisible: false,
      dialogGetVisible: false,
      isOrderTaking: false, //接单
      isTurnDown: false, //接单驳回
      isFillOut: false,
      isProductionRecord: false,
      dialogTitle: "",
      list: [],
      activeMenuItem: "1",
      listAdd: [],
      workList: [],
      processRecordsList: [],
      processRecordsListAdd: [],
      priorityList: [
        { id: "紧急", name: "紧急" },
        { id: "高", name: "高" },
        { id: "一般", name: "一般" },
      ],
      rules: {
        orderCode: [
          { required: true, message: "货品编码不能为空", trigger: "blur" },
        ],
        createrId: [
          { required: true, message: "创建人不能为空", trigger: "blur" },
        ],
        priority: [
          { required: true, message: "优先级不能为空", trigger: "blur" },
        ],
      },
      rules1: {
        estimatedCompletionTime: [
          { required: true, message: "预估完成时间不能为空", trigger: "blur" },
        ],
        acceptTime: [
          { required: true, message: "接单时间不能为空", trigger: "blur" },
        ],
        accepterName: [
          { required: true, message: "接单人不能为空", trigger: "blur" },
        ],
      },
      goodsList: [],
      createProductionOrderParm: {},
      createProductionOrderWorkParm: {},
      editProductionOrderGoodsCountParn: {},
      getEmployeesSelectParm: { name: "getEmployeesSelect" },
      getProductionOrderProcessParm: {
        name: "getProductionOrderProcess",
        parammaps: {},
      },
      getProductionOrderProcessByPidParm: {
        name: "getProductionOrderProcessByPid",
        parammaps: {},
      },
      updateProductionOrderTaking: {
        name: "updateProductionOrderTaking",
        parammaps: {},
      },
      getProcessByIdParm: { name: "getProcessById", parammaps: {} },
      // productionOrderGoodsList: [],
      formLabelAlign: { orderCode: "", priority: [] },
      isOrderTakingData: { acceptTime: "" },
      isFillInDailyData: {},
      myHeight: document.documentElement.clientHeight - 85 - 250,
      rowStyle: { maxHeight: 50 + "px", height: 45 + "px" },
      cellStyle: { padding: 0 + "px" },
      radioAll: "全部",
      pageNum: 0,
      pageSize: 0,
      selectedDates: [new Date().toISOString().split("T")[0]],
      getGoodsListByCodeParm: {
        name: "getGoodsListByCode",
        parammaps: { goodsCode: "" },
      },
      delProductionWorkOrder: {
        name: "delProductionWorkOrder",
        parammaps: { id: "" },
      },
      completeProductionWorkOrder: {
        name: "completeProductionWorkOrder",
        parammaps: { id: "" },
      },
      editProductionStartProductionParm: {
        name: "editProductionStartProduction",
        parammaps: { id: "" },
      },
      getOrderCode: { name: "getOrderCode" },
      getContractPullParm: { name: "getContractPull" },
      editProductionOrderRejectedParm: {
        name: "editProductionOrderRejected",
        parammaps: { id: "" },
      },
      completeProductionParm: {
        name: "completeProduction",
        parammaps: { id: "" },
      },
      contractList: [],
      excelList: [],
      isProductionWorkOrderAdd: false,
      isProductionWorkOrderFillout: false,
      isProductionWorkOrderComplete: false,
      isProductionWorkOrderFeedback: false,
      isProductionWorkOrderEdit: false,
      isProductionWorkOrderDel: false,
      isProductionWorkOrderClose: false,
      isProductionWorkOrderStart: false,
      isProductionWorkOrderExcel: false,
      // productManagement:productionWorkOrder:excel

      statuesList: [
        { id: "0", name: "未生产" },
        { id: "1", name: "已关单" },
        { id: "2", name: "待生产" },
        { id: "3", name: "生产中" },
        { id: "4", name: "生产完成" },
      ],
    };
  },
  methods: {
    async handleDateChange(dates) {
      dates = [...new Set(dates)]; // 去重
      if (!dates) {
        this.selectedDates = [];
        this.productionOrderGoodsList = [];
        return;
      }

      // 限制最多选择3天
      if (dates.length > 3) {
        this.$message.warning("最多只能选择3天");
        this.selectedDates = dates.slice(0, 3);
        dates = this.selectedDates;
      }

      GetDataByName(this.getProductionOrderGoodsFillOutParm).then(
        (response) => {
          if (response.data.list == null) {
            this.productionOrderGoodsList = [];
          } else {
            for (let index = 0; index < response.data.list.length; index++) {
              response.data.list[index].remaining =
                response.data.list[index].totalQuantity -
                response.data.list[index].producedQuantity;
            }

            this.productionOrderGoodsList = []; // 清空数组

            for (let i = 0; i < dates.length; i++) {
              for (let index = 0; index < response.data.list.length; index++) {
                const n = { ...response.data.list[index] }; // 创建副本
                n.date = dates[i]; // 更新日期字段
                this.productionOrderGoodsList.push(n); // 添加到结果数组
              }
            }
          }
        }
      );
    },
    get_auto_buttons() {
      const ProductionWorkOrderExcel =
        "productManagement:productionWorkOrder:excel";
      const isProductionWorkOrderExcel = checkButtons(
        this.$store.state.user.buttons,
        ProductionWorkOrderExcel
      );
      this.isProductionWorkOrderExcel = isProductionWorkOrderExcel;

      const productionWorkOrderAdd =
        "productManagement:productionWorkOrder:add";
      const isProductionWorkOrderAdd = checkButtons(
        this.$store.state.user.buttons,
        productionWorkOrderAdd
      );
      this.isProductionWorkOrderAdd = isProductionWorkOrderAdd;

      const ProductionWorkOrderFillout =
        "productManagement:productionWorkOrder:fillout";
      const isProductionWorkOrderFillout = checkButtons(
        this.$store.state.user.buttons,
        ProductionWorkOrderFillout
      );
      this.isProductionWorkOrderFillout = isProductionWorkOrderFillout;
      console.log(this.isProductionWorkOrderFillout);

      const ProductionWorkOrderComplete =
        "productManagement:productionWorkOrder:complete";
      const isProductionWorkOrderComplete = checkButtons(
        this.$store.state.user.buttons,
        ProductionWorkOrderComplete
      );
      this.isProductionWorkOrderComplete = isProductionWorkOrderComplete;

      const ProductionWorkOrderFeedback =
        "productManagement:productionWorkOrder:feedback";
      const isProductionWorkOrderFeedback = checkButtons(
        this.$store.state.user.buttons,
        ProductionWorkOrderFeedback
      );
      this.isProductionWorkOrderFeedback = isProductionWorkOrderFeedback;

      const ProductionWorkOrderEdit =
        "productManagement:productionWorkOrder:edit";
      const isProductionWorkOrderEdit = checkButtons(
        this.$store.state.user.buttons,
        ProductionWorkOrderEdit
      );
      this.isProductionWorkOrderEdit = isProductionWorkOrderEdit;

      const ProductionWorkOrderDel =
        "productManagement:productionWorkOrder:del";
      const isProductionWorkOrderDel = checkButtons(
        this.$store.state.user.buttons,
        ProductionWorkOrderDel
      );
      this.isProductionWorkOrderDel = isProductionWorkOrderDel;

      const ProductionWorkOrderClose =
        "productManagement:productionWorkOrder:close";
      const isProductionWorkOrderClose = checkButtons(
        this.$store.state.user.buttons,
        ProductionWorkOrderClose
      );
      this.isProductionWorkOrderClose = isProductionWorkOrderClose;

      const ProductionWorkOrderStart =
        "productManagement:productionWorkOrder:start";
      const isProductionWorkOrderStart = checkButtons(
        this.$store.state.user.buttons,
        ProductionWorkOrderStart
      );
      this.isProductionWorkOrderStart = isProductionWorkOrderStart;
    },

    formatJson(filterVal, jsonData) {
      return jsonData.map((v) =>
        filterVal.map((j) => {
          if (j === "timestamp") {
            return parseTime(v[j]);
          } else {
            return v[j];
          }
        })
      );
    },
    handleGetProductionOrderProcessExcel() {
      console.log(this.getProductionOrderProcessParm);

      if (
        this.getProductionOrderProcessParm.parammaps.inputDatetime2 !==
          undefined &&
        this.getProductionOrderProcessParm.parammaps.inputDatetime2 !== null
      ) {
        this.getProductionOrderProcessParm.parammaps.startTime =
          this.getProductionOrderProcessParm.parammaps.inputDatetime2[0];
        this.getProductionOrderProcessParm.parammaps.endTime =
          this.getProductionOrderProcessParm.parammaps.inputDatetime2[1];
      } else {
        this.getProductionOrderProcessParm.parammaps.startTime = "";
        this.getProductionOrderProcessParm.parammaps.endTime = "";
      }

      GetDataByName(this.getProductionOrderProcessParm).then((response) => {
        if (response.data && response.data.list) {
          for (let index = 0; index < response.data.list.length; index++) {
            response.data.list[index].remaining =
              response.data.list[index].planamount -
              response.data.list[index].completeamount;
            response.data.list[index].estimatedCompletionTime =
              this.formLabelAlign.estimatedCompletionTime;
            response.data.list[index].orderCode = this.formLabelAlign.orderCode;
            response.data.list[index].goodsName = this.formLabelAlign.goodsName;
            response.data.list[index].days_diff = this.formLabelAlign.days_diff;
          }
          //           formLabelAlign.estimatedCompletionTime
          // formLabelAlign.orderCode
          // formLabelAlign.goodsName

          // 生产单号	货品	预计完成时间	距完成时间还剩/天	日期	工序	计划数量	已完成	剩余量	今日完成量	生产人员	备注

          import("@/vendor/Export2Excel").then((excel) => {
            const tHeader = [
              "生产单号",
              "货品",
              "预计完成时间",
              "距完成时间还剩/天",
              "日期",
              "工序",
              "计划数量",
              "已完成",
              "剩余量",
              "今日完成量",
              "生产人员",
              "备注",
            ];

            const filterVal = [
              "orderCode",
              "goodsName",
              "estimatedCompletionTime",
              "days_diff",
              "workDate",
              "process",
              "planamount",
              "completeamount",
              "remaining",
              "amount",
              "empname",
              "remark",
            ];
            const list1 = response.data.list;
            const data1 = this.formatJson(filterVal, list1);
            excel.export_json_to_excel({
              header: tHeader,
              data: data1,
              filename: "生产工单记录导出",
              autoWidth: true,
              bookType: "xlsx",
            });
          });
        } else {
          this.productionOrderProcessList = [];
          this.listLoading = false;
        }
      });
    },
    derive_data_excel() {
      // this.get_production_work_order_excel()

      this.getProductionWorkOrderExcel.parammaps =
        this.getProductionWorkOrder.parammaps;
      if (
        this.getProductionWorkOrderExcel.parammaps.inputDatetime2 !==
          undefined &&
        this.getProductionWorkOrderExcel.parammaps.inputDatetime2 !== null
      ) {
        this.getProductionWorkOrderExcel.parammaps.startDate =
          this.getProductionWorkOrderExcel.parammaps.inputDatetime2[0];
        this.getProductionWorkOrderExcel.parammaps.endDate =
          this.getProductionWorkOrderExcel.parammaps.inputDatetime2[1];
      } else {
        this.getProductionWorkOrderExcel.parammaps.startDate = "";
        this.getProductionWorkOrderExcel.parammaps.endDate = "";
      }

      GetDataByName(this.getProductionWorkOrderExcel).then((response) => {
        if (response.data && response.data.list) {
          import("@/vendor/Export2Excel").then((excel) => {
            const tHeader = [
              "生产单号",
              "货品",
              "优先级",
              "总数量",
              "已生产数量",
              "剩余量",
              "生产进度",
              "下单人",
              "下单时间",
              "开始时间",
              "预估完成时间",
              "距预估时间还剩/天",
              "实际完成时间",
              "处理状态",
              "备注",
            ];

            const filterVal = [
              "orderCode",
              "goodsName",
              "priority",
              "totalQuantity",
              "producedQuantity",
              "remaining",
              "schedule",
              "orderername",
              "orderTime",
              "acceptTime",
              "estimatedCompletionTime",
              "days_diff",
              "actualCompletionTime",
              "orderStatus",
              "remarks",
            ];

            const list1 = response.data.list;
            const data1 = this.formatJson(filterVal, list1);
            excel.export_json_to_excel({
              header: tHeader,
              data: data1,
              filename: "生产工单导出",
              autoWidth: true,
              bookType: "xlsx",
            });
          });
        } else {
          this.excelList = [];
        }
      });
    },
    completeProduction(row) {
      MessageBox.confirm("确认完成生产？", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.completeProductionParm.parammaps.id = row.id;
        PostDataByName(this.completeProductionParm).then((response) => {
          if (response.msg !== "fail") {
            this.get_production_work_order();
            this.$notify({
              title: "成功",
              message: "完成计划",
              type: "success",
              duration: 2000,
            });
          } else {
            failproccess(response, this.$notify);
          }
        });
      });
    },

    startProduction(row) {
      MessageBox.confirm("确认开始生产？", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.editProductionStartProductionParm.parammaps.id = row.id;
        PostDataByName(this.editProductionStartProductionParm).then(
          (response) => {
            if (response.msg !== "fail") {
              this.get_production_work_order();
              this.$notify({
                title: "成功",
                message: "开始生产",
                type: "success",
                duration: 2000,
              });
            } else {
              failproccess(response, this.$notify);
            }
          }
        );
      });
    },
    get_production_order_process_by_pid() {
      this.getProductionOrderProcessByPidParm.parammaps.pid = this.pid;
      GetDataByName(this.getProductionOrderProcessByPidParm).then(
        (response) => {
          if (response.data && response.data.list) {
            this.processRecordsList = response.data.list;
          } else {
            this.processRecordsList = [];
          }
        }
      );
    },

    handleProcessRecordsDel(row) {
      console.log(row);
      this.processRecordsListAdd = this.processRecordsListAdd.filter(
        (item) => item.id !== row.id
      );
    },

    handleEditProcessRecordsDel(row) {
      console.log(row);
      this.processRecordsList = this.processRecordsList.filter(
        (item) => item.id !== row.id
      );
    },
    saveProcess() {
      this.isProcess = false;
      if (this.isEdit === true) {
        this.processRecordsList = this.processRecordsList;
        this.processList = [];
      } else {
        this.processRecordsListAdd = this.processRecordsList;
        for (
          let index = 0;
          index < this.processRecordsListAdd.length;
          index++
        ) {
          this.processRecordsListAdd[index].remark = "";
          this.processRecordsListAdd[index].amount =
            this.listAdd[0].totalQuantity ?? 0;
        }
        this.processRecordsList = [];
      }
    },
    handleNodeClick(data, node) {
      if (node.isLeaf) {
        this.pid = data.id;
        this.get_process_records();
      }
    },
    get_process_records() {
      this.getProcessRecordsParm.parammaps.pid = this.pid;
      GetDataByName(this.getProcessRecordsParm).then((response) => {
        if (response.data && response.data.list) {
          this.processRecordsList = response.data.list;
        } else {
          this.processRecordsList = [];
        }
      });
    },
    handleProcessCancel() {
      this.isProcess = false;
      this.dialogTitle = "";
      this.processList = [];
    },
    handleProcess() {
      if (this.listAdd.length > 0) {
        this.isProcess = true;
        this.dialogTitle = "选择工序";
        this.getProcessByIdParm.parammaps.id = this.listAdd[0].categoryId;
        GetDataByName(this.getProcessByIdParm).then((response) => {
          if (response.data.list == null) {
            this.processList = [];
          } else {
            this.processList = transData(
              response.data.list,
              "id",
              "pid",
              "children"
            );
            // this.processList = response.data.list;
          }
        });
      }
    },
    handleEditProcess() {
      if (this.productionOrderGoodsList.length > 0) {
        this.isProcess = true;
        this.dialogTitle = "选择工序";
        this.getProcessByIdParm.parammaps.id =
          this.productionOrderGoodsList[0].categoryId;
        GetDataByName(this.getProcessByIdParm).then((response) => {
          if (response.data.list == null) {
            this.processList = [];
          } else {
            this.processList = transData(
              response.data.list,
              "id",
              "pid",
              "children"
            );
            // this.processList = response.data.list;
          }
        });
      }
    },
    spanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex < 5) {
        const _row = this.spanArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
    },
    calculateSpan() {
      this.spanArr = [];
      this.position = 0;
      for (let i = 0; i < this.productionOrderProcessList.length; i++) {
        if (i === 0) {
          this.spanArr.push(1);
          this.position = 0;
        } else {
          // 判断日期和工序是否和上一行一致
          if (
            this.productionOrderProcessList[i].workDate ===
              this.productionOrderProcessList[i - 1].workDate &&
            this.productionOrderProcessList[i].process ===
              this.productionOrderProcessList[i - 1].process
          ) {
            this.spanArr[this.position]++;
            this.spanArr.push(0);
          } else {
            this.spanArr.push(1);
            this.position = i;
          }
        }
      }
    },

    handleGetProductionOrderProcess() {
      if (
        this.getProductionOrderProcessParm.parammaps.inputDatetime2 !==
          undefined &&
        this.getProductionOrderProcessParm.parammaps.inputDatetime2 !== null
      ) {
        this.getProductionOrderProcessParm.parammaps.startTime =
          this.getProductionOrderProcessParm.parammaps.inputDatetime2[0];
        this.getProductionOrderProcessParm.parammaps.endTime =
          this.getProductionOrderProcessParm.parammaps.inputDatetime2[1];
      } else {
        this.getProductionOrderProcessParm.parammaps.startTime = "";
        this.getProductionOrderProcessParm.parammaps.endTime = "";
      }

      GetDataByName(this.getProductionOrderProcessParm).then((response) => {
        if (response.data && response.data.list) {
          this.productionOrderProcessList = response.data.list;
          for (
            let index = 0;
            index < this.productionOrderProcessList.length;
            index++
          ) {
            this.productionOrderProcessList[index].remaining =
              this.productionOrderProcessList[index].planamount -
              this.productionOrderProcessList[index].completeamount;
          }
          this.calculateSpan();
          this.listLoading = false;
        } else {
          this.productionOrderProcessList = [];
          this.listLoading = false;
        }
      });
    },
    handleMenuSelect(index) {
      this.activeMenuItem = index; // 更新选中的菜单项
      console.log(this.activeMenuItem);
    },
    form_search() {},
    changeAll() {
      console.log(this.radioAll);
      this.getProductionWorkOrder.parammaps.radioAll = this.radioAll;
      this.get_production_work_order();
    },
    derive_data() {},
    handleOrderTaking(row) {
      this.dialogTitle = "确认反馈";
      this.isOrderTaking = true;
      this.isOrderTakingData.acceptTime = this.getDefaultDate();
      this.isOrderTakingData.id = row.id;
      this.isOrderTakingData.accepterId = Cookies.get("employeid");
      this.isOrderTakingData.accepterName = Cookies.get("employename");
    },
    handleOrderTakingById(row) {
      console.log(row);
      this.dialogTitle = "确认反馈";
      this.isOrderTaking = true;
      this.isOrderTakingData.acceptTime = this.getDefaultDate();
      this.isOrderTakingData.id = this.formLabelAlign.id;
      this.isOrderTakingData.accepterId = Cookies.get("employeid");
      this.isOrderTakingData.accepterName = Cookies.get("employename");
    },

    productionOrderTaking(row) {
      this.updateProductionOrderTaking.parammaps.id = this.isOrderTakingData.id;
      this.updateProductionOrderTaking.parammaps.accepterId =
        this.isOrderTakingData.accepterId;
      this.updateProductionOrderTaking.parammaps.acceptTime =
        this.isOrderTakingData.acceptTime;
      this.updateProductionOrderTaking.parammaps.estimatedCompletionTime =
        this.isOrderTakingData.estimatedCompletionTime;
      this.updateProductionOrderTaking.parammaps.orderStatus = "待生产";
      // orderStatus,accepterId,acceptTime,estimatedCompletionTime,id
      PostDataByName(this.updateProductionOrderTaking).then((response) => {
        if (response.msg !== "fail") {
          this.get_production_work_order();
          this.updateProductionOrderTaking.parammaps = null;
          this.isOrderTakingData.id = 0;
          this.isOrderTakingData.acceptTime = "";
          this.isOrderTakingData.accepterId = "";
          this.isOrderTakingData.estimatedCompletionTime = "";
          this.isOrderTaking = false;
          this.formLabelAlign.orderStatus = "待生产";
          this.$notify({
            title: "成功",
            message: "反馈成功",
            type: "success",
            duration: 2000,
          });
        } else {
          failproccess(response, this.$notify);
        }
      });
    },
    handleFillInDaily(row) {
      this.dialogTitle = "每日填写";
      this.isFillOut = true;
      this.selectedDates = [new Date().toISOString().split("T")[0]];
      this.isFillInDailyData.orderername = Cookies.get("employename");
      this.isFillInDailyData.remarks = row.remarks;
      this.isFillInDailyData.days_diff = row.days_diff;
      this.isFillInDailyData.estimatedCompletionTime =
        row.estimatedCompletionTime;
      console.log(row);
      this.getProductionOrderGoodsFillOutParm.parammaps.id = row.id;
      this.getProductionOrderGoodsFillOutParm.parammaps.empId =
        Cookies.get("employeid");
      GetDataByName(this.getProductionOrderGoodsFillOutParm).then(
        (response) => {
          if (response.data.list == null) {
            this.productionOrderGoodsList = [];
          } else {
            for (let index = 0; index < response.data.list.length; index++) {
              response.data.list[index].remaining =
                response.data.list[index].totalQuantity -
                response.data.list[index].producedQuantity;
            }
            this.productionOrderGoodsList = response.data.list;
          }
        }
      );
    },
    handleFillInDailyCancel() {
      this.dialogTitle = "";
      this.isFillOut = false;
    },
    handleTurnDown(row) {
      this.isFillInDailyData.id = row.id;
      this.dialogTitle = "关单  ";
      this.isTurnDown = true;
    },

    saveTurnDown(row) {
      this.editProductionOrderRejectedParm.parammaps.id =
        this.isFillInDailyData.id;
      this.editProductionOrderRejectedParm.parammaps.rejectedReason =
        this.isFillInDailyData.rejectedReason;
      this.editProductionOrderRejectedParm.parammaps.accepterId =
        Cookies.get("employeid");
      console.log(this.isFillInDailyData);
      PostDataByName(this.editProductionOrderRejectedParm).then((response) => {
        if (response.msg !== "fail") {
          this.get_production_work_order();
          this.isTurnDown = false;

          this.$notify({
            title: "成功",
            message: "驳回成功",
            type: "success",
            duration: 2000,
          });
        } else {
          failproccess(response, this.$notify);
        }
      });
    },
    handleTurnDownCancel() {
      this.dialogTitle = "";
      this.isTurnDown = false;
    },
    saveFillInDailyCancel(row) {
      console.log(this.productionOrderGoodsList);
      if (
        this.productionOrderGoodsList &&
        this.productionOrderGoodsList.length > 0
      ) {
        this.createProductionOrderWorkParm = {
          data: [
            {
              name: "productionOrderGoods",
              resultmaps: {
                list: this.productionOrderGoodsList,
              },
              children: [
                {
                  name: "addProductionOrderWork",
                  type: "e",
                  parammaps: {
                    productionId: "@productionOrderGoods.productionId",
                    process: "@productionOrderGoods.process",
                    createId: Cookies.get("employeid"),
                    amount: "@productionOrderGoods.todayQuantity",
                    workDate: "@productionOrderGoods.date",
                    remark: "@productionOrderGoods.remark",
                  },
                },
              ],
            },
          ],
        };
      }
      ExecDataByConfig(this.createProductionOrderWorkParm).then((response) => {
        if (response.msg !== "fail") {
          this.editProductionOrderGoodsCountParn = {
            name: "editProductionOrderGoodsCount",
            type: "e",
            parammaps: {
              id: this.productionOrderGoodsList[0].productionOrderId,
            },
          };
          PostDataByName(this.editProductionOrderGoodsCountParn);
          this.get_production_work_order();
          this.isFillOut = false;
          this.$notify({
            title: "成功",
            message: "操作成功",
            type: "success",
            duration: 2000,
          });
        } else {
          this.$notify({
            title: "失败",
            message: response.data,
            type: "error",
            duration: 2000,
          });
        }
      });
    },
    formatDate() {
      if (this.isOrderTakingData.estimatedCompletionTime) {
        const date = new Date(this.isOrderTakingData.estimatedCompletionTime);
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, "0");
        const day = String(date.getDate()).padStart(2, "0");
        this.isOrderTakingData.estimatedCompletionTime = `${year}-${month}-${day}`;
      }
    },

    handleWorkOrderComplete(row) {
      MessageBox.confirm("名称：" + row.orderCode, "确认完成？", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.delProductionWorkOrder.parammaps.id = row.id;
        PostDataByName(this.delProductionWorkOrder).then((response) => {
          if (response.msg !== "fail") {
            this.get_production_work_order();
            this.$notify({
              title: "成功",
              message: "删除成功",
              type: "success",
              duration: 2000,
            });
          } else {
            failproccess(response, this.$notify);
          }
        });
      });
    },

    handleWorkOrderDel(row) {
      MessageBox.confirm("名称：" + row.orderCode, "确认删除？", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.delProductionWorkOrder.parammaps.id = row.id;
        PostDataByName(this.delProductionWorkOrder).then((response) => {
          if (response.msg !== "fail") {
            this.get_production_work_order();
            this.$notify({
              title: "成功",
              message: "删除成功",
              type: "success",
              duration: 2000,
            });
          } else {
            failproccess(response, this.$notify);
          }
        });
      });
    },
    handleOrderTakingCancel() {
      this.dialogTitle = "";
      this.isOrderTaking = false;
    },
    handleDel(row) {
      console.log(this.listAdd);
      MessageBox.confirm("设备名称：" + row.goodsName, "确认删除？", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        for (var i = 0; i < this.listAdd.length; i++) {
          console.log(this.listAdd[i]);
          if (this.listAdd[i].id === row.id) {
            var listAddIndex = this.listAdd.indexOf(this.listAdd[i]);
          }
          if (listAddIndex > -1) {
            this.listAdd.splice(listAddIndex, 1);
            return;
          }
        }
      });
    },
    handleEditDel(row) {
      console.log(this.productionOrderGoodsList);
      MessageBox.confirm("设备名称：" + row.goodsName, "确认删除？", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        for (var i = 0; i < this.productionOrderGoodsList.length; i++) {
          console.log(this.productionOrderGoodsList[i]);
          if (this.productionOrderGoodsList[i].id === row.id) {
            var listAddIndex = this.productionOrderGoodsList.indexOf(
              this.productionOrderGoodsList[i]
            );
          }
          if (listAddIndex > -1) {
            this.productionOrderGoodsList.splice(listAddIndex, 1);
            return;
          }
        }
      });
    },
    fetchGoods(queryString, cb) {
      this.getGoodsListByCodeParm.parammaps.goodsCode = queryString;
      GetDataByName(this.getGoodsListByCodeParm).then((response) => {
        if (response.data.list == null) {
          cb([]);
        } else {
          cb(response.data.list);
        }
      });
    },
    handleEdit(row) {
      this.pid = row.id; // 使用 row.id 而不是 id
      // this.get_process_records();
      // this.getProductionOrderGoods(row.id);
      // this.get_production_order_process_by_pid();

      this.productionOrderGoodsList = [];
      this.getProductionOrderGoodsParm.parammaps.id = row.id; // 这里也要使用 row.id
      GetDataByName(this.getProductionOrderGoodsParm).then((response) => {
        if (response.data && response.data.list) {
          for (let i = 0; i < response.data.list.length; i++) {
            // response.data.list[index].goodsImagePath = process.env.VUE_APP_BASE_API + response.data.list[index].goodsImagePath;

            if (response.data.list[i].goodsImagePath !== "") {
              response.data.list[i].goodsImagePath =
                process.env.VUE_APP_BASE_API +
                response.data.list[i].goodsImagePath;
            } else {
              response.data.list[i].goodsImagePath = "";
            }
          }
          this.productionOrderGoodsList = response.data.list;

          // this.getProcessRecordsParm.parammaps.pid = this.pid;
          this.getProductionOrderProcessByPidParm.parammaps.pid = this.pid;
          GetDataByName(this.getProductionOrderProcessByPidParm).then(
            (response) => {
              if (response.data && response.data.list) {
                this.processRecordsList = response.data.list;

                console.log("processRecordsList:", this.processRecordsList);
                console.log(
                  "productionOrderGoodsList:",
                  this.productionOrderGoodsList
                );
                this.dialogTitle = "编辑";

                this.formLabelAlign.id = row.id;
                this.formLabelAlign.orderCode = row.orderCode;
                this.formLabelAlign.priority = row.priority;
                this.formLabelAlign.goodsName = row.goodsName;
                this.formLabelAlign.orderStatus = row.orderStatus;
                this.formLabelAlign.orderTime = row.orderTime;
                this.formLabelAlign.orderername = row.orderername;
                this.formLabelAlign.producedQuantity = row.producedQuantity;
                this.formLabelAlign.remaining = row.remaining;
                this.formLabelAlign.remarks = row.remarks;
                this.formLabelAlign.schedule = row.schedule;
                this.formLabelAlign.totalQuantity = row.totalQuantity;
                this.formLabelAlign.days_diff = row.days_diff;
                this.formLabelAlign.estimatedCompletionTime =
                  row.estimatedCompletionTime;
                this.formLabelAlign.createTime = row.createTime;
                this.formLabelAlign.goodsCode = row.goodsCode;
                this.formLabelAlign.goodsName = row.goodsName;
                this.formLabelAlign.goodsSpecification = row.goodsSpecification;
                this.formLabelAlign.goodsUnit = row.goodsUnit;
                this.formLabelAlign.totalQuantity = row.totalQuantity;
                this.formLabelAlign.date = row.createTime;
                this.formLabelAlign.createrId = row.ordererId;

                this.getProductionOrderProcessParm.parammaps.id = row.id;
                this.activeList = [
                  {
                    title: "生产下单",
                    status: "success",
                    name: row.orderername,
                    date: row.orderTime,
                  },
                  { title: "生产接单" },
                  { title: "开始生产" },
                  { title: "生产完成" },
                  { title: "生产入库" },
                  { title: "生产接单" },
                ];
                this.isEdit = true;
                this.handleGetProductionOrderProcess();
              } else {
                this.processRecordsList = [];
              }
            }
          );
        } else {
          this.productionOrderGoodsList = [];
        }
      });
    },
    handleGet(row) {
      this.getProductionOrderGoods(row.id);
      this.pid = row.id;
      this.get_production_order_process_by_pid();
      this.dialogTitle = "查看";
      this.dialogGetVisible = true;
      this.formLabelAlign.id = row.id;
      this.formLabelAlign.orderCode = row.orderCode;
      this.formLabelAlign.priority = row.priority;
      this.formLabelAlign.goodsName = row.goodsName;
      this.formLabelAlign.orderStatus = row.orderStatus;
      this.formLabelAlign.orderTime = row.orderTime;
      this.formLabelAlign.orderername = row.orderername;
      this.formLabelAlign.producedQuantity = row.producedQuantity;
      this.formLabelAlign.remaining = row.remaining;
      this.formLabelAlign.remarks = row.remarks;
      this.formLabelAlign.schedule = row.schedule + "%";
      this.formLabelAlign.totalQuantity = row.totalQuantity;
      this.formLabelAlign.days_diff = row.days_diff;
      this.formLabelAlign.estimatedCompletionTime = row.estimatedCompletionTime;
      this.formLabelAlign.actualCompletionTime = row.actualCompletionTime;
      // this.formLabelAlign.remaining =  this.formLabelAlign.amount - this.formLabelAlign.completedAmount
      this.formLabelAlign.acceptTime = row.acceptTime;
      this.formLabelAlign.acceptername = row.acceptername;

      this.formLabelAlign.goodsCode = row.goodsCode;
      this.formLabelAlign.goodsName = row.goodsName;
      this.formLabelAlign.goodsSpecification = row.goodsSpecification;
      this.formLabelAlign.goodsUnit = row.goodsUnit;
      this.formLabelAlign.totalQuantity = row.totalQuantity;
      // this.formLabelAlign.producedQuantity = this.productionOrderGoodsList[0].producedQuantity
      this.formLabelAlign.rejectedReason = row.rejectedReason;
      this.getProductionOrderProcessParm.parammaps.id = row.id;
      this.activeList = [
        {
          title: "生产下单",
          status: "success",
          name: row.orderername,
          date: row.orderTime,
        },
        { title: "生产接单" },
        { title: "开始生产" },
        { title: "生产完成" },
        { title: "生产入库" },
        { title: "生产接单" },
      ];
      this.handleGetProductionOrderProcess();
    },
    handleInputGoods(item) {
      this.getGoodsListByCodeParm.parammaps.goodsCode = item.goodsCode;
      // item.goodsImagePath = process.env.VUE_APP_BASE_API + item.goodsImagePath;
      if (item.goodsImagePath !== "") {
        item.goodsImagePath =
          process.env.VUE_APP_BASE_API + item.goodsImagePath;
      } else {
        item.goodsImagePath = "";
      }
      this.listAdd = [];
      this.listAdd.push(item);
    },
    handleEditInputGoods(item) {
      this.getGoodsListByCodeParm.parammaps.goodsCode = item.goodsCode;
      // item.goodsImagePath = process.env.VUE_APP_BASE_API + item.goodsImagePath;

      if (item.goodsImagePath !== "") {
        item.goodsImagePath =
          process.env.VUE_APP_BASE_API + item.goodsImagePath;
      } else {
        item.goodsImagePath = "";
      }
      this.productionOrderGoodsList = [];
      this.productionOrderGoodsList.push(item);
    },
    form_add() {
      this.dialogTitle = "新增工单";
      this.get_order_code();
      this.formLabelAlign.createrId = Cookies.get("employeid");
      this.dialogFormVisible = true;
      this.formLabelAlign.date = this.getDefaultDate();
    },
    getDefaultDate() {
      const date = new Date();
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, "0");
      const day = String(date.getDate()).padStart(2, "0");
      const hours = String(date.getHours()).padStart(2, "0");
      const minutes = String(date.getMinutes()).padStart(2, "0");
      const seconds = String(date.getSeconds()).padStart(2, "0");
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    resetForm() {
      this.dialogFormVisible = false;
      this.formLabelAlign.orderCode = "";
      this.getGoodsListByCodeParm.parammaps.goodsCode = "";
      this.listAdd = [];
      this.formLabelAlign.priority = "";

      this.formLabelAlign.contractIds = "";
      this.dialogGetVisible = false;
      this.formLabelAlign = { orderCode: "", priority: [] };
    },

    handleEditAndOff() {
      console.log(this.productionOrderGoodsList.length);
      console.log(this.productionOrderGoodsList);
      if (this.productionOrderGoodsList.length === 0) {
        this.$notify({
          title: "失败",
          message: "货品不能为空！",
          type: "error",
          duration: 2000,
        });
        return;
      }

      if (this.formLabelAlign.priority === "") {
        this.$notify({
          title: "失败",
          message: "优先级不能为空！",
          type: "error",
          duration: 2000,
        });
        return;
      }
      this.createProductionOrderParm = {
        data: [
          {
            name: "editProductionOrder",
            type: "e",
            parammaps: {
              priority: this.formLabelAlign.priority,
              ordererId: this.formLabelAlign.createrId,
              remarks: this.formLabelAlign.remarks,
              id: this.formLabelAlign.id,
            },
          },
          {
            name: "delProductionOrderGoods",
            type: "e",
            parammaps: {
              id: this.formLabelAlign.id,
            },
          },
          {
            name: "delProductionOrderProcess",
            type: "e",
            parammaps: {
              id: this.formLabelAlign.id,
            },
          },
          {
            name: "insertProductionOrderGoods",
            resultmaps: {
              list: this.productionOrderGoodsList,
            },
            children: [
              {
                name: "insertProductionOrderGoods",
                type: "e",
                parammaps: {
                  productionOrderId: this.formLabelAlign.id,
                  goodsId: "@insertProductionOrderGoods.id",
                  priority: "@insertProductionOrderGoods.priority",
                  totalQuantity: "@insertProductionOrderGoods.totalQuantity",
                },
              },
            ],
          },
          {
            name: "insertProductionOrderWork",
            resultmaps: {
              list: this.processRecordsList,
            },
            children: [
              {
                name: "addProductionOrderProcess",
                type: "e",
                parammaps: {
                  productionId: this.formLabelAlign.id,
                  process: "@insertProductionOrderWork.process",
                  amount: "@insertProductionOrderWork.amount",
                  remark: "@insertProductionOrderWork.remark",
                },
              },
            ],
          },
        ],
      };
      ExecDataByConfig(this.createProductionOrderParm).then((response) => {
        if (response.msg !== "fail") {
          this.resetForm();
          this.isEdit = false;
          this.productionOrderGoodsList = [];
          this.processRecordsList = [];
          this.get_production_work_order();
          this.$notify({
            title: "成功",
            message: "操作成功",
            type: "success",
            duration: 2000,
          });
        } else {
          this.$notify({
            title: "失败",
            message: response.data,
            type: "error",
            duration: 2000,
          });
        }
      });
    },
    handleAddAndOff() {
      if (this.listAdd.length === 0) {
        this.$notify({
          title: "失败",
          message: "货品不能为空！",
          type: "error",
          duration: 2000,
        });
        return;
      }

      if (this.formLabelAlign.priority === "") {
        this.$notify({
          title: "失败",
          message: "优先级不能为空！",
          type: "error",
          duration: 2000,
        });
        return;
      }

      if (this.processRecordsListAdd.length === 0) {
        this.$notify({
          title: "失败",
          message: "请选择工序！",
          type: "error",
          duration: 2000,
        });
        return;
      }

      this.createProductionOrderParm = {
        data: [
          {
            name: "createProductionOrder",
            type: "e",
            parammaps: {
              orderCode: this.formLabelAlign.orderCode,
              priority: this.formLabelAlign.priority,
              contractIds: (this.formLabelAlign.contractIds || []).join(","),
              ordererId: this.formLabelAlign.createrId,
              orderTime: this.formLabelAlign.date,
              remarks: this.formLabelAlign.remarks,
            },
          },
          {
            name: "insertProductionOrderGoods",
            resultmaps: {
              list: this.listAdd,
            },
            children: [
              {
                name: "insertProductionOrderGoods",
                type: "e",
                parammaps: {
                  productionOrderId: "@createProductionOrder.LastInsertId",
                  goodsId: "@insertProductionOrderGoods.id",
                  priority: "@insertProductionOrderGoods.priority",
                  totalQuantity: "@insertProductionOrderGoods.totalQuantity",
                },
              },
            ],
          },
          {
            name: "insertProductionOrderWork",
            resultmaps: {
              list: this.processRecordsListAdd,
            },
            children: [
              {
                name: "addProductionOrderProcess",
                type: "e",
                parammaps: {
                  productionId: "@createProductionOrder.LastInsertId",
                  process: "@insertProductionOrderWork.process",
                  amount: "@insertProductionOrderWork.amount",
                  remark: "@insertProductionOrderWork.remark",
                },
              },
            ],
          },
        ],
      };
      ExecDataByConfig(this.createProductionOrderParm).then((response) => {
        if (response.msg !== "fail") {
          this.get_production_work_order();
          this.resetForm();
          this.get_production_work_order();
          this.$notify({
            title: "成功",
            message: "操作成功",
            type: "success",
            duration: 2000,
          });
        } else {
          this.$notify({
            title: "失败",
            message: "数据填写不完整，保存失败！",
            type: "error",
            duration: 2000,
          });
          return;
        }
      });
    },
    handleCancel() {
      this.activeMenuItem = 1;
      this.pid = "";
      this.processRecordsList = [];
      this.isEdit = false;
      this.processRecordsListAdd = [];
      this.resetForm();
    },
    get_emp_data() {
      GetDataByName(this.getEmployeesSelectParm).then((response) => {
        if (response.data && response.data.list) {
          this.empList = response.data.list;
        } else {
          this.empList = [];
        }
      });
    },
    getProductionOrderGoods(id) {
      this.productionOrderGoodsList = [];
      this.getProductionOrderGoodsParm.parammaps.id = id;
      GetDataByName(this.getProductionOrderGoodsParm).then((response) => {
        if (response.data && response.data.list) {
          for (let i = 0; i < response.data.list.length; i++) {
            // response.data.list[index].goodsImagePath =  process.env.VUE_APP_BASE_API +response.data.list[index].goodsImagePath;
            if (response.data.list[i].goodsImagePath !== "") {
              response.data.list[i].goodsImagePath =
                process.env.VUE_APP_BASE_API +
                response.data.list[i].goodsImagePath;
            } else {
              response.data.list[i].goodsImagePath = "";
            }
          }
          this.productionOrderGoodsList = response.data.list;
        } else {
          // this.list = [];
          this.productionOrderGoodsList = [];
          this.listLoading = false;
        }
      });
    },
    get_production_work_order() {
      if (
        this.getProductionWorkOrder.parammaps.inputDatetime2 !== undefined &&
        this.getProductionWorkOrder.parammaps.inputDatetime2 !== null
      ) {
        this.getProductionWorkOrder.parammaps.startDate =
          this.getProductionWorkOrder.parammaps.inputDatetime2[0];
        this.getProductionWorkOrder.parammaps.endDate =
          this.getProductionWorkOrder.parammaps.inputDatetime2[1];
      } else {
        this.getProductionWorkOrder.parammaps.startDate = "";
        this.getProductionWorkOrder.parammaps.endDate = "";
      }

      GetDataByName(this.getProductionWorkOrder).then((response) => {
        if (response.data && response.data.list) {
          this.list = response.data.list;
          this.listLoading = false;
          this.pageNum = response.data.pageNum;
          this.pageSize = response.data.pageSize;
          this.total = response.data.total;
          this.get_auto_buttons();
        } else {
          this.list = [];
          this.total = 0;
          this.get_auto_buttons();
          this.listLoading = false;
        }
      });
    },
    get_production_work_order_excel() {
      this.getProductionWorkOrderExcel.parammaps =
        this.getProductionWorkOrder.parammaps;
      if (
        this.getProductionWorkOrderExcel.parammaps.inputDatetime2 !==
          undefined &&
        this.getProductionWorkOrderExcel.parammaps.inputDatetime2 !== null
      ) {
        this.getProductionWorkOrderExcel.parammaps.startDate =
          this.getProductionWorkOrderExcel.parammaps.inputDatetime2[0];
        this.getProductionWorkOrderExcel.parammaps.endDate =
          this.getProductionWorkOrderExcel.parammaps.inputDatetime2[1];
      } else {
        this.getProductionWorkOrderExcel.parammaps.startDate = "";
        this.getProductionWorkOrderExcel.parammaps.endDate = "";
      }

      GetDataByName(this.getProductionWorkOrderExcel).then((response) => {
        if (response.data && response.data.list) {
          this.excelList = response.data.list;
        } else {
          this.excelList = [];
        }
      });
    },
    get_order_code() {
      GetDataByName(this.getOrderCodeParm).then((response) => {
        if (response.data && response.data.list) {
          console.log(response.data.list[0].generated_code);
          this.formLabelAlign.orderCode = response.data.list[0].generated_code;
          console.log(this.formLabelAlign.orderCode);
        }
      });
    },
    get_contract_pull() {
      GetDataByName(this.getContractPullParm).then((response) => {
        if (response.data && response.data.list) {
          console.log(response.data.list[0].generated_code);
          this.contractList = response.data.list;
        }
      });
    },

    get_goods_list() {
      GetDataByName(this.getGoodsListByCodeParm).then((response) => {
        if (response.data && response.data.list) {
          for (let i = 0; i < response.data.list.length; i++) {
            // response.data.list[index].goodsImagePath =  process.env.VUE_APP_BASE_API +response.data.list[index].goodsImagePath;
            if (response.data.list[i].goodsImagePath !== "") {
              response.data.list[i].goodsImagePath =
                process.env.VUE_APP_BASE_API +
                response.data.list[i].goodsImagePath;
            } else {
              response.data.list[i].goodsImagePath = "";
            }
          }
          this.goodsList = response.data.list;
        }
      });
    },
  },
  created() {
    this.get_contract_pull();
    this.get_emp_data();

    this.get_production_work_order();
  },
};
</script>

<style>
.app-container {
  padding: 10px;
  margin-left: 10px;
}

.search-button-container {
  padding: 10px;
  padding-left: 20px;
}

.search-button {
  padding: 10px 20px;
  border: 0.01px solid #ccc; /* 黑色边框，宽度为 2px */
  margin-left: 10px;
}

.add-button {
  background-color: #2196f3; /* 绿色背景 */
  color: white; /* 白色文字 */
  padding: 10px 20px; /* 内边距 */
  border-radius: 5px; /* 圆角 */
  cursor: pointer; /* 鼠标悬停时显示手型 */
  font-size: 16px; /* 字体大小 */
  transition: background-color 0.3s ease; /* 背景颜色过渡效果 */
  padding: 7px 12px;
  margin: 15px 3px;
  border: 0.01px solid #ccc; /* 黑色边框，宽度为 2px */
}

.records-button {
  background-color: #2196f3; /* 绿色背景 */
  color: white; /* 白色文字 */
  padding: 10px 20px; /* 内边距 */
  border-radius: 5px; /* 圆角 */
  cursor: pointer; /* 鼠标悬停时显示手型 */
  font-size: 16px; /* 字体大小 */
  transition: background-color 0.3s ease; /* 背景颜色过渡效果 */
  margin: 15px 3px;
  border: 0.01px solid #ccc; /* 黑色边框，宽度为 2px */
  margin-top: 2px;
}

.dialog-footer {
  right: 10px;
  position: absolute;
  bottom: 10px;
}

.el-step__head.is-success {
  color: #409eff;
  border-color: #409eff;
}
.el-step__title.is-success {
  color: #409eff;
}
.el-step__head.is-process {
  color: #409eff;
  border-color: #409eff;
  .el-step__icon.is-text {
    background: #409eff;
    color: #fff;
  }
}

.process-button {
  background-color: #2196f3;
  color: white;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s ease;
  padding: 7px 12px;
  margin: 15px 3px;
  border: 0.01px solid #ccc;
  /* position: absolute;
  right: 10px;
  bottom: 10px; */
}

.overdue-time {
  color: #f56c6c;
  font-size: 15px;
  font-weight: bold;
}

.app-add {
  white-space: nowrap; /* 防止换行 */
  overflow: hidden; /* 隐藏溢出内容 */
  text-overflow: ellipsis; /* 使用省略号表示溢出内容 */
}
</style>
<<<<<<< HEAD



=======
>>>>>>> f1f1d66c68304db39e340601f5791d2da4a32a97
