<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick" type="border-card">
      <el-tab-pane
        :key="item.name"
        v-for="item in processOption"
        :label="item.name"
        :name="item.id"
        :closable="item.close"
      >
        <el-table
          :data="subproductionplanList.results"
          border
          stripe
          style="width: 100%"
          height="250"
          highlight-current-row
          @current-change="handleCurrentChange"
        >
          <el-table-column type="index" width="50" />

          <el-table-column label="子计划编号" width="100">
            <template slot-scope="scope">{{ scope.row.number }}</template>
          </el-table-column>
          <el-table-column label="产品名称">
            <template slot-scope="scope">{{
              scope.row.plan_product_.name
            }}</template>
          </el-table-column>
          <el-table-column label="产品型号">
            <template slot-scope="scope">{{
              scope.row.product_.specification
            }}</template>
          </el-table-column>
          <el-table-column label="生产主产品" width="140">
            <template slot-scope="scope">{{
              scope.row.product_.name
            }}</template>
          </el-table-column>
          <el-table-column label="名称">
            <template slot-scope="scope">{{
              scope.row.subproduction_.name
            }}</template>
          </el-table-column>

          <el-table-column label="生产车间">
            <template slot-scope="scope">{{
              scope.row.workshop_.name
            }}</template>
          </el-table-column>

          <el-table-column label="子工序" width="160">
            <template slot-scope="scope" v-if="scope.row.steps">
              <el-tag
                v-for="item in scope.row.steps"
                :key="item.number"
                :label="item.name"
                :value="item.number"
                >{{ item.name }}</el-tag
              >
            </template>
          </el-table-column>
          <el-table-column label="开工时间">
            <template slot-scope="scope">{{ scope.row.start_date }}</template>
          </el-table-column>
          <el-table-column label="完工时间">
            <template slot-scope="scope">{{ scope.row.end_date }}</template>
          </el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
              {{ state_[scope.row.state] }}</template
            >
          </el-table-column>
          <el-table-column label="领料状态" width="100">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.is_picked == false">未领料</el-tag>
              <el-tag v-else>已领料</el-tag>
            </template>
          </el-table-column>

          <el-table-column label="计划/生产/合格">
            <template slot-scope="scope"
              >{{ scope.row.count }}/{{ scope.row.count_real }}/{{
                scope.row.count_ok
              }}</template
            >
          </el-table-column>

          <el-table-column align="center" label="操作" width="130px">
            <template slot-scope="scope">
              <el-link
                type="success"
                v-if="scope.row.is_picked == false"
                @click="handleNeed(scope)"
                >领料</el-link
              >
              <el-link
                type="success"
                v-if="scope.row.is_picked"
                @click="handleNeed(scope)"
                >继续领料</el-link
              >
              <el-link type="primary" @click="handlepick(scope)"
                >领半成品</el-link
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="subproductionplanList.count > 0"
          :total="subproductionplanList.count"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.page_size"
          @pagination="subproductionplanList"
        />
        <el-row :gutter="2">
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>半成品</span>
              </div>
              <el-button
                type="primary"
                style="margin-left: 2px"
                v-for="item in steps"
                :key="item.number"
                :label="item.name"
                :value="item.number"
                @click="handlework(item)"
                >{{ item.name }}</el-button
              >
               <el-button
                type="primary"
                @click="handleScrapbcp()"
                id="scrap"
                style="float: right; display: none"
                >报废</el-button
              >
              <el-badge :value="count" class="item"  style="float:right">
  <el-button
                type="primary"
                @click="handleAll()"
               
                >显示全部</el-button
              >
</el-badge>
             
             

              <el-table
                :data="wproductData"
                @selection-change="handleSelectionChange"
                border
                fit
                stripe
                style="width: 100%"
                max-height="300"
              >
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column type="index" width="50" />
                <el-table-column label="子计划编号"  width="100">
                  <template slot-scope="scope">{{
                    scope.row.subproduction_plan_.number
                  }}</template>
                </el-table-column>

                <el-table-column label="玻璃编号">
                  <template slot-scope="scope">{{ scope.row.number }}</template>
                </el-table-column>

                <el-table-column label="玻璃状态">
                  <template slot-scope="scope">{{
                    scope.row.material_.name
                  }}</template>
                </el-table-column>

                <el-table-column label="所在子工序">
                  <template slot-scope="scope">{{
                    scope.row.step_.name
                  }}</template>
                </el-table-column>
                <el-table-column label="进行状态">
                  <template slot-scope="scope">{{
                    actstate_[scope.row.act_state]
                  }}</template>
                </el-table-column>
 <el-table-column label="不合格标记">
              <template slot-scope="scope">
                {{ ng_sign_[scope.row.ng_sign] }}
              </template>
            </el-table-column>
                <el-table-column label="更新时间">
                  <template slot-scope="scope">{{
                    scope.row.update_time
                  }}</template>
                </el-table-column>
              </el-table>


              
            </el-card>
            
          </el-col>
          <el-col :span="12">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>车间物料</span>
              </div>
              <el-table
                :data="wmaterialList"
                border
                fit
                stripe
                style="width: 100%"
                max-height="300"
              >
                <el-table-column type="index" width="50" />
                <el-table-column label="子计划编号"  width="100">
                  <template slot-scope="scope">{{
                    scope.row.subproduction_plan_.number
                  }}</template>
                </el-table-column>
                <el-table-column label="物料名称">
                  <template slot-scope="scope">{{
                    scope.row.material_.name
                  }}</template>
                </el-table-column>
                <el-table-column label="物料单位">
                  <template slot-scope="scope">{{
                    scope.row.material_.unit
                  }}</template>
                </el-table-column>
                <el-table-column label="物料批次">
                  <template slot-scope="scope">{{ scope.row.batch }}</template>
                </el-table-column>
                <el-table-column label="物料数量">
                  <template slot-scope="scope">{{ scope.row.count }}</template>
                </el-table-column>
              </el-table>
            </el-card>
          </el-col>
        </el-row>
      </el-tab-pane>
    </el-tabs>
     <el-dialog
      title="半成品报废"
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisiblebcp"
    >
      <el-form :model="formbcp">
        <el-form-item label="甩片原因" >
          <el-select
            style="width: 80%"
            v-model="formbcp.scrap_reason"
            placeholder="请甩片原因"
          >
            <el-option
              v-for="item in scrapreason"
              :key="item.lable"
              :label="item.lable"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisiblebcp = false">取 消</el-button>
        <el-button type="primary" @click="scrapesubmit">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="领半成品"
      :close-on-click-modal="false"
      :visible.sync="dialogTableVisiblepick"
    >
      <el-table :data="bcplist" style="width: 100%">
        <el-table-column prop="material_.name" label="物料名称">
        </el-table-column>
        <el-table-column prop="material_.number" label="物料编号">
        </el-table-column>
        <el-table-column prop="material_.specification" label="物料规格">
        </el-table-column>
        <el-table-column prop="material_.unit" label="物料单位">
        </el-table-column>
        <el-table-column prop="count" label="所需物料数量"> </el-table-column>
        <el-table-column prop="count_pick" label="已领物料数量">
        </el-table-column>
        <el-table-column prop="count_real" label="实际产出/消耗">
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-link
              v-if="checkPermission(['material_update'])"
              @click="handleReceive(scope)"
              >领半成品</el-link
            >
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisiblepick = false">取 消</el-button>
        <el-button type="primary" @click="bcpllSubmit">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="半成品列表"
      :close-on-click-modal="false"
      :visible.sync="dialogTableVisiblepicks"
    >
      <el-table
        :data="wproductslist"
        border
        fit
        stripe
        highlight-current-row
        max-height="300"
        @selection-change="handleSelectionChangess"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column type="index" width="50" />

        <el-table-column label="玻璃编号">
          <template slot-scope="scope">{{ scope.row.number }}</template>
        </el-table-column>

        <el-table-column label="玻璃状态">
          <template slot-scope="scope">{{ scope.row.material_.name }}</template>
        </el-table-column>

        <el-table-column label="子计划编号">
              <template slot-scope="scope">{{ scope.row.subproduction_plan_.number }}</template>
            </el-table-column>
        <el-table-column label="备注">
          <template slot-scope="scope">{{ scope.row.remark }}</template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisiblepicks = false">取 消</el-button>
        <el-button type="primary" @click="wproductSubmit">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="dialogVisiblenw"
      :close-on-click-modal="false"
      width="80%"
      title="领料"
    >
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>生产所需领料表</span>
        </div>
        <template>
          <el-table
            :data="needwl"
            highlight-current-row
            height="300"
            style="width: 100%"
          >
            <el-table-column prop="material_.name" label="物料名称">
            </el-table-column>
            <el-table-column prop="material_.number" label="物料编号">
            </el-table-column>
            <el-table-column prop="material_.specification" label="物料规格">
            </el-table-column>
            <el-table-column prop="material_.unit" label="物料单位">
            </el-table-column>
            <el-table-column prop="count" label="所需物料数量">
            </el-table-column>
            <el-table-column prop="count_pick" label="已领物料数量">
            </el-table-column>
          </el-table>
        </template>
      </el-card>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>当前仓库物料表</span>
          <el-button
            style="float: right; padding: 3px 0"
            @click="handlePick"
            type="text"
            >确认领料</el-button
          >
        </div>
        <template>
          <el-table
            :data="havewl"
            highlight-current-row
            height="300"
            style="width: 100%"
          >
            <el-table-column prop="batch" label="物料批次"> </el-table-column>
            <el-table-column prop="material_.name" label="物料名称">
            </el-table-column>
            <el-table-column prop="warehouse_.name" label="物料所在仓库">
            </el-table-column>
            <el-table-column prop="count" label="物料总数量"> </el-table-column>
            <el-table-column label="输入领料数量" width="140px">
              <template slot-scope="scope">
                <el-form
                  :model="scope.row"
                  v-if="scope.row.material_.type != 2"
                  widht="100px"
                >
                  <el-form-item size="mini">
                    <el-input-number
                      v-model="scope.row.pick_count"
                      :min="0"
                      :controls="false"
                      :value="0"
                    ></el-input-number>
                  </el-form-item>
                </el-form>
              </template>
            </el-table-column>

            <el-table-column prop="count_pick" label="已领物料数量">
            </el-table-column>
            <el-table-column prop="material_.specification" label="物料规格">
            </el-table-column>
            <el-table-column prop="material_.unit" label="物料单位">
            </el-table-column>
            <el-table-column align="center" label="操作" width="220px">
              <template slot-scope="scope">
                <el-link
                  v-if="scope.row.material_.type == 2"
                  @click="handlewproduct(scope)"
                  >选择半成品</el-link
                >
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-card>
    </el-dialog>
    <el-dialog
      title="半成品列表"
      :close-on-click-modal="false"
      :visible.sync="dialogTableVisible"
    >
      <el-table
        :data="iproductData"
        border
        fit
        stripe
        highlight-current-row
        max-height="600"
        @selection-change="handleSelectionChanges"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column type="index" width="50" />
        <el-table-column label="玻璃编号">
          <template slot-scope="scope">{{ scope.row.number }}</template>
        </el-table-column>

        <el-table-column label="半成品批次">
          <template slot-scope="scope">{{ scope.row.batch }}</template>
        </el-table-column>
        <el-table-column label="玻璃状态">
          <template slot-scope="scope">{{ scope.row.material_.name }}</template>
        </el-table-column>
        
        <el-table-column label="所在仓库">
          <template slot-scope="scope">{{
            scope.row.warehouse_.name
          }}</template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisible = false">取 消</el-button>
        <el-button type="primary" @click="iproductsSubmit">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="dialogVisiblework"
      :close-on-click-modal="false"
      :fullscreen="true"
      title="填写记录"
    >
      <el-steps
        :active="values"
        spac="400px"
        align-center=""
        finish-status="success"
        style="padding-top: 20px"
      >
        <el-step
          :title="item.name"
          v-for="(item, index) in forms"
          :key="index"
          @click.native="stepclick(item.id)"
        >
        </el-step>
      </el-steps>
      <el-row :gutter="2">
        <el-col :span="14">
          <el-card class="box-card" v-if="showPrise1 && values === 0">
            <div slot="header" class="clearfix">
              <span>消耗物料表</span>

              <el-table :data="input" border style="width: 100%">
                <el-table-column
                  prop="subproduction_plan"
                  label="子计划编号"
                  width="180"
                >
                </el-table-column>
                <el-table-column
                  prop="material_.name"
                  label="物料名称"
                  width="180"
                >
                </el-table-column>
                <el-table-column prop="batch" label="物料批次" width="150">
                </el-table-column>
                <el-table-column prop="count" label="可用数量" width="80">
                </el-table-column>
                <el-table-column
                  prop="count_input"
                  label="使用数量"
                  width="180"
                >
                  <template slot-scope="scope">
                    <el-form :model="scope.row">
                      <el-form-item size="mini">
                        <el-input-number
                          v-model="scope.row.count_input"
                          :min="0"
                          :value="0"
                        ></el-input-number>
                      </el-form-item>
                    </el-form>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-card>
        </el-col>
        <el-col :span="10">
          <el-card class="box-card" v-if="values === 0 && showPrise">
            <div slot="header" class="clearfix">
              <span>产出物料表</span>

              <el-table :data="output" border style="width: 100%">
                <el-table-column
                  prop="subproduction_plan"
                  label="子计划编号"
                  width="180"
                >
                </el-table-column>
                <el-table-column
                  prop="material__name"
                  label="物料名称"
                  width="180"
                >
                </el-table-column>

                <el-table-column
                  prop="count_output"
                  label="产出数量"
                  width="180"
                >
                  <template slot-scope="scope">
                    <el-form :model="scope.row">
                      <el-form-item size="mini">
                        <el-input-number
                          v-model="scope.row.count_output"
                          :min="0"
                          :value="0"
                        ></el-input-number>
                      </el-form-item>
                    </el-form>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <el-card class="box-card" v-if="values === 0">
        <div slot="header" class="clearfix">
          <span>备注</span>
        </div>
        <el-form ref="form" label-width="80px">
          <el-form-item label="操作备注">
            <el-input v-model="remark" width="300"></el-input>
          </el-form-item>
        </el-form>
        <el-button style="margin-top: 12px" @click="next" v-if="values == 0"
          >下一步</el-button
        >
      </el-card>
      <el-card
        class="box-card"
        v-for="(itemf, $index) in otherforms"
        :key="$index"
      >
        <el-form
          label-width="80px"
          label-position="right"
          v-if="values === $index + 1"
        >
          <el-row v-for="(item, $index) in itemf.form_fields" :key="$index">
            <el-form-item
              v-if="item.field_type === 'string'"
              :label="item.field_name"
            >
              <el-input placeholder="请输入" v-model="item.sort" />
            </el-form-item>
            <el-form-item
              v-else-if="item.field_type === 'int'"
              :label="item.field_name"
            >
              <el-input
                type="number"
                placeholder="请输入"
                v-model="item.sort"
              />
            </el-form-item>
            <el-form-item
              v-else-if="item.field_type === 'float'"
              :label="item.field_name"
            >
              <el-input
                type="number"
                placeholder="请输入"
                v-model="item.sort"
              />
            </el-form-item>
            <el-form-item
              v-else-if="item.field_type === 'date'"
              :label="item.field_name"
            >
              <el-date-picker
                v-model="item.create_time"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item
              v-else-if="item.field_type === 'datetime'"
              :label="item.field_name"
            >
              <el-date-picker
                v-model="item.create_time"
                type="datetime"
                placeholder="选择日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item
              v-else-if="item.field_type === 'select'"
              :label="item.field_name"
            >
              <el-select
                style="width: 100%"
                v-model="item.sort"
                placeholder="请选择"
              >
                <el-option
                  v-for="item1 in item.field_choice"
                  :key="item1"
                  :label="item1"
                  :value="item1"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item
              v-else-if="item.field_type === 'selects'"
              :label="item.field_name"
            >
              <el-select
                style="width: 100%"
                v-model="optio"
                multiple
                placeholder="请选择"
              >
                <el-option
                  v-for="item1 in item.field_choice"
                  :key="item1"
                  :label="item1"
                  :value="item1"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-row>
        </el-form>
        <el-button
          style="margin-top: 12px"
          @click="next"
          v-if="values == $index + 2"
          >下一步</el-button
        >
        <el-button
          style="margin-top: 12px"
          @click="prev"
          v-if="values == $index + 1"
          >上一步</el-button
        >
      </el-card>

      <div style="text-align: right; position: sticky">
        <el-button type="danger" @click="dialogVisiblework = false"
          >取消</el-button
        >
        <el-button type="primary" @click="submint()">确认</el-button>
      </div>
    </el-dialog>
   
  </div>
</template>
<style>
.item {
 
  margin-right: 20px;
}
</style>
  <script>
import { getsubproductionplanList, createPick_need } from "@/api/pm";
import checkPermission from "@/utils/permission";
import { getProcessList, getStepLists } from "@/api/mtm";
import {
  createPick,
  getwmaterialList,
  submitWork,
  getwproductList,
  getsubplanList,
  getpickhalfList,
  createpickhalf,
  createOperation,
  scrap
} from "@/api/wpm";
import { getiproductList } from "@/api/inm";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
const defaulteneed = {};
export default {
  components: { Pagination },

  data() {
    return {
      need: defaulteneed,
      subproductionplanList: {
        count: 0,
      },
      wmaterialList: [],
      listQuery: {
        page: 1,
        page_size: 20,
      },
      iproductData: [],
      remark: "",
      values: 0,
      active: 0,
      activeName: "1",
      havewl: "",
      needwl: "",
      showPrise: false,
      showPrise1: false,
      actstate_: {
        6: "待复检",
        10: "操作进行中",
        20: "待检验",
        30: "已合格",
        40: "库存中",
        50: "不合格",
        60: "待成品检验",
        8: "操作准备中",
        26: "待夹层检验",
        70: "报废",
      },
      ng_sign_: {
         10: "返工",
        20: "返修",
        30: "报废",
        40: "让步接受",
        50: "偏离许可",
        60: "降级使用",
        70: "退回供方",
        80: "召回",
       
      },
      state_: {
        0: "制定中",
        1: "已下达",
        2: "已接受",
        3: "生产中",
        4: "已完成",
      },
      listLoading: true,
      listLoading: true,
      id: "",
      dialogTableVisible: false,
      dialogVisible: false,
      dialogTableVisiblepick: false,
      dialogTableVisiblepicks: false,
      dialogType: "new",
      dialogVisiblework: false,
      dialogVisiblenw: false,
      dialogTypenw: "new",
      picks: [],
      pickData: {},
      steps: [],
      step: null,
      processOption: [],
      subproduction_plan: "",
      form1: [],
      form2: [],
      form3: [],
      input: [],
      output: [],
      forms: [],
      inputData: [],
      outputData: [],
      field1: [],
      field2: [],
      fromData: [],
      wproductData: [],
      wpID: [],
      multipleSelection: [],
      wproducts: [],
      otherforms: [],
      from: [],
      Operation: {},
      wproductdata: {},
      workData: {},
      bcplist: [],
      wproductslist: [],
      formbcp: {},
      dialogFormVisiblebcp: false,
      scrapreason: [
        { lable: "气泡", value: 10 },
        { lable: "破点", value: 20 },
        { lable: "划伤", value: 30 },
        { lable: "其他", value: 40 },
      ],
      count:null,
    };
  },
  process: "",
  computed: {},
  watch: {},
  created() {
    this.getProcessList();
  },
  methods: {
    checkPermission,

    //选项卡切换
    handleClick(tab) {
      this.process = tab.name;
      this.listQuery.process = tab.name;
      if (tab.name == 1) {
        document.getElementById("scrap").style.display = "block";
      }
      this.steps = [];
      getsubplanList(this.listQuery).then((response) => {
        if (response.data) {
          this.subproductionplanList = response.data;
        }
      });

      //子工序列表

      getStepLists(tab.name).then((response) => {
        if (response.data) {
          this.steps = response.data;
        }
      });
      //车间物料表
      this.getwmaterialLists();
      // 半成品表
      this.getwproductLists();
    },

    //车间物料
    getwmaterialLists() {
      getwmaterialList({
        subproduction_plan__process: this.process,
        page: 0,
      }).then((response) => {
        if (response.data) {
          this.wmaterialList = response.data;
        }
      });
    },

    //待检半成品报废
    handleScrapbcp() {
      this.dialogFormVisiblebcp = true;
    },
 

    //确定报废半成品
    scrapesubmit() {
      console.log(this.formbcp);
      scrap(this.wpID, this.formbcp).then((response) => {
        if (response.code==200) {
        this.$message.success("该半成品已报废！");
          this.dialogFormVisiblebcp = false;
            // 半成品表
      this.getwproductLists();
        }
      });
    },

    //工序对应的子计划，弹出对应的车间物料
    handleCurrentChange(row) {
      // this.steps = row.steps; //调出子工序

      this.subproduction_plan = row.id; //子计划Id
      this.getwproductLists();
      getwmaterialList({
        subproduction_plan__process: this.process,
        subproduction_plan: row.id,
        page: 0,
      }).then((response) => {
        if (response.data) {
          this.wmaterialList = response.data;
        }
      });
    },
    //大工序工序渲染
    getProcessList() {
      getProcessList({ page: 0 }).then((response) => {
        if (response.data) {
          this.processOption = response.data;
        }
      });
    },

    //显示全部子计划
    handleAll() {
      this.listQuery.process = this.process;
      this.subproduction_plan = "";
      //子计划
      getsubproductionplanList(this.listQuery).then((response) => {
        if (response.data) {
          this.subproductionplanList = response.data;
        }
      });
      //车间物料表
      this.getwmaterialLists();
      // 半成品表
      this.getwproductLists();
    },

    //大工序下子工序产出的半成品
    getwproductLists() {
      this.wproductdata.page = 0;
     this.wproductdata.tag = "no_scrap";
      this.wproductdata.step__process = this.process;
      if (this.subproduction_plan != "") {
        this.wproductdata.subproduction_plan = this.subproduction_plan;
      }
      getwproductList(this.wproductdata).then((response) => {
        if (response.data) {
          this.wproductData = response.data;
          //console.log( this.wproductData)
        }
      });
    },
    //调出该批次，该仓库的所有半成品
    handlewproduct(scope) {
      this.dialogTableVisible = true;
      this.pcId = scope.row.id;
      getiproductList({
        page: 0,
        material: scope.row.material,
        warehouse: scope.row.warehouse,
        batch: scope.row.batch,
      }).then((response) => {
        if (response.data) {
          this.iproductData = response.data;
        }
      });
    },
    //勾选半成品
    handleSelectionChanges(val) {
      this.iproducts = [];
      val.forEach((item) => {
        this.iproducts.push(item.id);
      });
    },
    //提交半成品
    iproductsSubmit() {
      this.dialogTableVisible = false;
      this.havewl.forEach((item) => {
        if (item.id == this.pcId) {
          item.iproducts = this.iproducts;
        }
      });
    },

    //领料
    handleNeed(scope) {
      this.need = Object.assign({}, defaulteneed);
      this.dialogVisiblenw = true;
      this.id = scope.row.id;
      createPick_need(this.id, this.need).then((res) => {
        if (res.code >= 200) {
          this.havewl = res.data.have;
          this.needwl = res.data.need;
        }
      });
    },

    //确认领料
    handlePick() {
      this.pickData.subproduction_plan = this.id;

      this.pickData.picks = this.havewl;

      createPick(this.pickData).then((res) => {
        if (res.code >= 200) {
          this.dialogVisiblenw = false;

          this.$message.success("领料成功！");
          //车间物料表
          this.getwmaterialLists();
          // 半成品表
          this.getwproductLists();
        }
      });
      //半成品
      getwproductList({ page: 0, step__process: this.process }).then(
        (response) => {
          if (response.data) {
            this.wproductData = response.data;
            console.log(this.wproductData);
          }
        }
      );
    },

    //领半成品
    handlepick(scope) {
      this.dialogTableVisiblepick = true;
      this.spid = scope.row.id;
      getpickhalfList(this.spid).then((res) => {
        if (res.code >= 200) {
          this.bcplist = res.data;
        }
      });
    },
    //根据半成品ID+检测状态调取未入库半成品
    handleReceive(scope) {
      this.dialogTableVisiblepicks = true;
      this.bcpxlID = scope.row.id;
      getwproductList({
        material: scope.row.material,
        act_state: 30,
        page: 0,
      }).then((res) => {
        if (res.code >= 200) {
          this.wproductslist = res.data;
        }
      });
    },
    handleSelectionChangess(val) {
      this.bcpproducts = [];
      val.forEach((item) => {
        this.bcpproducts.push(item.id);
      });
    },
    wproductSubmit() {
      this.dialogTableVisiblepicks = false;

      this.bcplist.forEach((item) => {
        if (item.id == this.bcpxlID) {
          item.iproducts = this.bcpproducts;
        }
      });
    },

    //提交领的半成品
    bcpllSubmit() {
      this.bcplists = []; //新的半成品表
      this.bcplist.forEach((item) => {
        this.bcplists.push({
          id: item.id,
          wproducts: item.iproducts,
        });
      });
      console.log(this.bcplists);
      createpickhalf(this.spid, this.bcplists).then((res) => {
        if (res.code >= 200) {
          this.$message.success("半成品领料成功！");
          this.dialogTableVisiblepick = false;
          //车间物料表
          this.getwproductLists();
          // 半成品表
          this.getwproductLists();
        }
      });
    },

    prev() {
      --this.values;
      if (this.values < 0) this.values = 0;
    },
    next() {
      if (this.values++ > this.forms.length) this.values = 0;
    },
    handleSelectionChange(val) {
      this.count=val.length;
      console.log(this.count);
      let _this = this;

      _this.wpID = [];
      val.forEach((item) => {
        _this.wpID.push(item.id);
      });
    },
    //车间操作
    handlework(item) {
      this.step = item.id;
      // console.log(this.wpID);
      this.values = 0;
      this.Operation.step = item.id;
      this.Operation.wproducts = this.wpID;

      createOperation(this.Operation).then((res) => {
        if (res.code >= 200) {
          this.$message.success("操作记录创建成功！");
          this.$router.push({ name: "operation", params: { id: item.id } });
        }
      });
    },

    //提交
    submint() {
      this.form = [];
      this.otherforms.forEach((item) => {
        let _this = this;
        _this.field1 = [];
        item.form_fields.forEach((items) => {
          _this.field1.push({
            form_field: items.id,
            field_value: items.sort,
          });
        });

        this.form.push({
          form: item.id,
          record_data: _this.field1,
        });
      });

      this.workData.step = this.step;
      this.workData.wproducts = this.wproducts;
      this.workData.input = this.input;
      this.workData.output = this.output;
      this.workData.forms = this.from;
      this.workData.remark = this.remark;
      if (this.subproduction_plan != "") {
        this.wproductdata.subproduction_plan = this.subproduction_plan;
      }
      console.log(this.remark);

      submitWork(this.workData).then((res) => {
        if (res.code >= 200) {
          this.dialogVisiblework = false;
          this.$message.success("成功！");
          this.getwproductLists();
        }
      });
    },
  },
};
</script>