<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="300"
          highlight-current-row
          @current-change="handleCurrentChange"
        >
          <el-table-column type="index" width="50" />

          <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="领料状态">
            <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.main_product_.name
            }}</template>
          </el-table-column>
          <el-table-column label="生产进度">
            <template slot-scope="scope"
              >{{ scope.row.main_count_real }}/{{
                scope.row.main_count
              }}</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: 50px"
                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="handleAll()"
                style="float: right"
                >显示全部</el-button
              >
            </el-card>
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>半成品</span>
              </div>
              <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="半成品编号">
                  <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">
                    <el-tag v-if="scope.row.is_executed">已执行</el-tag>
                    <el-tag v-else>待执行</el-tag>
                  </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="400"
              >
                <el-table-column type="index" width="50" />

                <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="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_real" label="已领物料数量">
            </el-table-column>
             <el-table-column prop="count_pick" 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="600"
        @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 }}</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" 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_real" 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" 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" 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_real" 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="checkPermission(['warehouse_update'])"
              @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>
  <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
} from "@/api/wpm";
import { getiproductList } from "@/api/inm";
import { createWork } from "@/api/wpm";
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,
      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: [],
      workdata: {},
      wproductdata: {},
      workData:{},
      bcplist:"",
      wproductslist:"",
    };
  },
  process: "",
  computed: {},
  watch: {},
  created() {
    this.getProcessList();
  },
  methods: {
    checkPermission,

    //选项卡切换
    handleClick(tab) {
      this.process = tab.name;
      this.listQuery.process = tab.name;
      this.steps = [];
      getsubplanList(this.listQuery).then((response) => {
        if (response.data) {
          this.subproductionplanList = response.data;
        }
        this.listLoading = false;
      });
      getwmaterialList({
        subproduction_plan__process: this.process,
        page: 0,
      }).then((response) => {
        if (response.data) {
          this.wmaterialList = response.data;
        }
        this.listLoading = false;
      });
      //子工序列表

      getStepLists(tab.name).then((response) => {
        if (response.data) {
          this.steps = response.data;
        }
        this.listLoading = 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;
        }
        this.listLoading = false;
      });
     
    },
    //工序渲染
    getProcessList() {
      getProcessList({ page: 0 }).then((response) => {
        if (response.data) {
          this.processOption = response.data;
        }
        this.listLoading = false;
      });
    },

    //显示全部子计划
    handleAll() {
      this.listQuery.process = this.process;
      this.subproduction_plan = "";
      //子计划
      getsubproductionplanList(this.listQuery).then((response) => {
        if (response.data) {
          this.subproductionplanList = response.data;
        }
        this.listLoading = false;
      });
      //车间物料表
      getwmaterialList({
        subproduction_plan__process: this.process,
        page: 0,
      }).then((response) => {
        if (response.data) {
          this.wmaterialList = response.data;
        }
        this.listLoading = false;
      });
      //半成品
    getwproductList({page:0,step__process:this.process}).then((response) => {
        if (response.data) {
          this.wproductData = response.data;
          //console.log( this.wproductData)
        }
      });
    },
  

     //大工序下子工序产出的半成品
    getwproductLists() {
      this.wproductdata.page = 0;
      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;
        }
        this.listLoading = false;
      });
     
    
    },
    //勾选半成品
    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("领料成功！");
        }
     });
    },

//领半成品
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:3,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;
        }
      });


      
    },


 
    prev() {
      --this.values;
      if (this.values < 0) this.values = 0;
    },
    next() {
      if (this.values++ > this.forms.length) this.values = 0;
    },
    handleSelectionChange(val) {
      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.workdata.step = item.id;
      this.workdata.wproducts = this.wpID;
      if (this.subproduction_plan != "") {
        this.workdata.subproduction_plan = this.subproduction_plan;
      }

      createWork(this.workdata).then((res) => {
        if (res.code >= 200) {
          this.dialogVisiblework = true;
          this.forms = res.data.forms;
          this.otherforms = res.data.forms.slice(0); //渲染生产表
          this.otherforms.shift();
          //console.log(this.otherforms)

          if (
            res.data.forms[0].input !== undefined &&
            res.data.forms[0].input.length > 0
          ) {
            this.input = res.data.forms[0].input; //消耗
            this.showPrise1 = true;
          } else {
            this.showPrise1 = false;
          }
          if (
            res.data.forms[0].output !== undefined &&
            res.data.forms[0].output.length > 0
          ) {
            this.output = res.data.forms[0].output; //产出
            this.showPrise = true;
          } else {
            this.showPrise = false;
          }

          this.wproducts = res.data.forms[0].wproducts;
        }
      });
    },

    //提交
    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>