<template>
  <div class="app-container">
    <el-card>
      <div slot="header" class="clearfix">
        <span>基本信息</span>
        <el-button
          style="float: right; padding: 3px 0"
          @click="getWordText()"
          type="text"
        >查看作业指导书
        </el-button>
      </div>
      <el-descriptions :column="3" border style="margin-bottom: 20px">
        <el-descriptions-item label="任务编号" v-if="operationData.number">{{operationData.number}}</el-descriptions-item>
        <el-descriptions-item label="产品名称" v-if="operationData.name">{{operationData.name}}</el-descriptions-item>
        <el-descriptions-item label="规格型号" v-if="operationData.specification">{{operationData.specification}}</el-descriptions-item>
        <el-descriptions-item label="子工序">{{operationData.step_.name}}</el-descriptions-item>
        <el-descriptions-item label="创建时间">{{operationData.create_time}}</el-descriptions-item>
        <el-descriptions-item label="操作人">{{operationData.user}}</el-descriptions-item>
      </el-descriptions>
      <el-button
        v-if="operationData.is_submited == false"
        type="primary"
        style="float: right"
        @click="handlesubmit()"
      >
        提交本次操作
      </el-button>
     <!-- <el-form
        ref="form"
        inline="true"
        :model="operationData"
        label-width="80px"
      >
        <el-form-item label="子工序">
          <el-input
            v-model="operationData.step_.name"
            disabled="disabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="任务编号" v-show="operationData.number">
          <el-input
            v-model="operationData.number"
            disabled="disabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="产品名称" v-show="operationData.name">
          <el-input
            v-model="operationData.name"
            disabled="disabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="规格型号" v-show="operationData.specification">
          <el-input
            v-model="operationData.specification"
            disabled="disabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="操作人">
          <el-input
            v-model="operationData.user"
            disabled="disabled"
          ></el-input>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-input
            v-model="operationData.create_time"
            disabled="disabled"
          ></el-input>
        </el-form-item>
        <el-form-item>

        </el-form-item>
        &lt;!&ndash;
          <el-form-item label="边角料">
            <el-radio-group v-model="operationData.use_scrap">
              <el-radio border
                :label="item.value"
                :key="item.value"
                v-for="item in scrap"
                >{{ item.lable }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
          <el-form-item label="备注" v-if="operationData.use_scrap">
            <el-input type="textarea" v-model="operationData.remark"></el-input>
          </el-form-item>
!&ndash;&gt;
        <el-form-item v-if="operationData.use_scrap">
          <el-button
            type="primary"
            @click="scrapSubmit()"
          >
            创建
          </el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>-->
      <el-drawer
        title="作业指导书查看!"
        :visible.sync="drawer"
        direction="rtl"
        size="70%"
      >
        <el-tabs @tab-click="handleClick">
          <el-tab-pane
            :key="item.file_.id"
            v-for="item in techdocList"
            :label="item.file_.name"
            :name="item.file_.path"
            :closable="item.close"
          ></el-tab-pane>
        </el-tabs>
        <div class="word-wrap" id="file"></div>
      </el-drawer>
    </el-card>
    <el-row gutter="2">
      <el-col span="8">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>半成品</span>
          </div>

          <template>
            <el-table
              :data="operationwpData"
              border
              fit
              stripe
              highlight-current-row
              height="230"
              style="width: 100%"
            >
              <el-table-column type="index" width="50"/>
              <el-table-column
                prop="subproduction_plan_.number"
                label="子计划编号"
                width="100"
              >
              </el-table-column>
              <el-table-column prop="number" label="玻璃编号" width="100">
              </el-table-column>
              <el-table-column
                prop="material_.name"
                label="玻璃状态"
                width="170"
              >
              </el-table-column>
              <el-table-column prop="place" label="摆放位置"></el-table-column>
              <el-table-column align="center" label="操作" width="100px" fixed="right">
                <template slot-scope="scope">
                  <el-link type="primary" @click="handleupdatewproduct(scope)"
                  >编辑
                  </el-link>
                  <el-link
                    v-if="checkPermission(['warehouse_update'])"
                    type="danger"
                    @click="handleDeletewproduct(scope)"
                  >删除
                  </el-link>
                </template>
              </el-table-column>
            </el-table>
            <el-dialog
              :visible.sync="dialogwproductplace"
              :close-on-click-modal="false"
              width="60%"
              title="半成品摆放位置"
            >
              <el-form
                ref="Form"
                :model="wproductplace"
                label-width="100px"
                label-position="right"
              >
                <el-form-item label="位置" prop="place">
                  <el-input v-model="wproductplace.place" placeholder="位置"/>
                </el-form-item>
              </el-form>
              <div style="text-align: right">
                <el-button type="danger" @click="dialogwproductplace = false"
                >取消
                </el-button>
                <el-button type="primary" @click="submitwproductplace"
                >确认
                </el-button>
              </div>
            </el-dialog>
          </template>
        </el-card>
      </el-col>
      <el-col span="8">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>设备</span>
          </div>
          <template>
            <el-table
              :data="equData"
              border
              fit
              stripe
              highlight-current-row
              height="230"
              style="width: 100%"
            >
              <el-table-column prop="equip_.number" label="设备编号">
              </el-table-column>
              <el-table-column prop="equip_.name" label="设备名称">
              </el-table-column>
              <el-table-column label="设备状态">
                <template slot-scope="scope">
                  <div v-if="scope.row.equip_.type === 2">
                    <el-tag v-if="scope.row.equip_.state === 40" type="danger">
                      禁用
                    </el-tag>
                    <el-tag v-else type="success"> 合格</el-tag>
                  </div>
                  <div v-else>
                    <el-tag v-if="scope.row.equip_.state === 10" type="success">
                      {{ state_[scope.row.equip_.state] }}
                    </el-tag>
                    <el-tag v-else-if="scope.row.equip_.state === 20">
                      {{ state_[scope.row.equip_.state] }}
                    </el-tag>
                    <el-tag
                      v-else-if="scope.row.equip_.state === 30"
                      type="warning"
                    >
                      {{ state_[scope.row.equip_.state] }}
                    </el-tag>
                    <el-tag v-else type="danger">
                      {{ state_[scope.row.equip_.state] }}
                    </el-tag>
                  </div>
                </template>
              </el-table-column>

              <el-table-column align="center" label="操作" width="100px">
                <template slot-scope="scope">
                  <el-link
                    v-if="checkPermission(['warehouse_update'])"
                    type="danger"
                    @click="handleDeletequip(scope)"
                  >删除
                  </el-link>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-card>
      </el-col>
      <el-col span="8">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>生产记录表</span>
          </div>
          <template>
            <el-table
              :data="recordData"
              border
              fit
              stripe
              highlight-current-row
              height="230"
              style="width: 100%"
            >
              <el-table-column prop="form_.name" label="名称">
              </el-table-column>
              <el-table-column label="是否填写">
                <template slot-scope="scope">
                  <el-tag v-if="scope.row.is_filled == false">未填写</el-tag>
                  <el-tag v-else>已填写</el-tag>
                </template>
              </el-table-column>
              <el-table-column align="center" label="操作" width="100px">
                <template slot-scope="scope">
                  <el-link
                    type="primary"
                    @click="handlerecord(scope)"
                  >填写表单
                  </el-link>
                  <el-link
                    v-if="scope.row.is_filled"
                    type="primary"
                    @click="handlerecordExport(scope)"
                  >导出
                  </el-link>
                </template>
              </el-table-column>
            </el-table>
            <el-dialog
              :model="tableForm"
              :visible.sync="dialogVisibleForm"
              :close-on-click-modal="false"
              :title="fieldList.name"
            >
              <el-form label-width="80px" label-position="right">
                <el-row
                  v-for="(item, $index) in fieldList.record_data"
                  :key="$index"
                >
                  <el-form-item
                    v-if="item.field_type === 'string'"
                    :label="item.field_name"
                  >
                    <el-input v-model="item.field_value" placeholder="请输入"/>
                  </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.field_value"
                    />
                  </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.field_value"
                    />
                  </el-form-item>
                  <el-form-item
                    v-else-if="item.field_type === 'date'"
                    :label="item.field_name"
                  >
                    <el-date-picker
                      v-model="item.field_value"
                      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.field_value"
                      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.field_value"
                      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="item.field_value"
                      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>
              <span slot="footer">
                <el-button type="danger" @click="dialogVisibleForm = false"
                >取消</el-button>
                <el-button type="primary" @click="recordconfirm()"
                >提交</el-button>
              </span>
            </el-dialog>
          </template>
        </el-card>
      </el-col>
    </el-row>
    <el-row gutter="2">
      <el-col span="8">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>消耗物料</span>
            <el-button
              style="float: right; padding: 3px 0"
              type="text"
              @click="cjllclick()"
            >从车间领料
            </el-button>
          </div>
          <template>
            <el-table
              :data="inputData"
              border
              fit
              stripe
              highlight-current-row
              height="230"
              style="width: 100%"
            >
              <el-table-column
                prop="subproduction_plan_.number"
                label="子计划编号"
              >
              </el-table-column>
              <el-table-column prop="batch" label="物料批次"></el-table-column>
              <el-table-column prop="material_.name" 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 align="center" label="操作" width="100px">
                <template slot-scope="scope">
                  <el-link
                    v-if="checkPermission(['warehouse_update'])"
                    type="danger"
                    @click="handleDeleteinput(scope)"
                  >删除
                  </el-link>
                </template>
              </el-table-column>
            </el-table>
            <el-dialog
              title="车间物料"
              :close-on-click-modal="false"
              :visible.sync="dialogTablepick"
            >
              <el-table
                :data="wmaterialData"
                border
                fit
                stripe
                style="width: 100%"
                max-height="400"
                ref="multipleTable"
              >
                <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.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-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 align="center" label="操作" width="100px">
                    <template slot-scope="scope">
                      <el-link
                        v-if="checkPermission(['warehouse_update'])"
                        @click="handlepick(scope)"
                        >提交</el-link
                      >
                    </template>
                  </el-table-column>!-->
              </el-table>
              <div style="text-align: right">
                <el-button type="danger" @click="dialogTablepick = false"
                >取消
                </el-button>
                <el-button type="primary" @click="handlepicks()"
                >提交
                </el-button>
              </div>
            </el-dialog>
          </template>
        </el-card>
      </el-col>
      <el-col span="8">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>产出物料</span>
            <el-button
              style="float: right; padding: 3px 0"
              type="text"
              @click="dialogTableoutput = true"
            >选择产出
            </el-button>
          </div>
          <el-table
            :data="outputData"
            border
            fit
            stripe
            highlight-current-row
            height="230"
            style="width: 100%"
          >
            <el-table-column
              prop="subproduction_plan_.number"
              label="子计划编号"
            >
            </el-table-column>

            <el-table-column prop="material_.name" 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>
          <el-dialog
            title="产出物料"
            :close-on-click-modal="false"
            :visible.sync="dialogTableoutput"
          >
            <el-table
              :data="tprogressData"
              border
              fit
              stripe
              style="width: 100%"
              max-height="400"
              ref="multipleTables"
            >
              <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.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.count }}/{{ scope.row.count_real }}/{{
                  scope.row.count_ok
                  }}
                </template>
              </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.output_count"
                        :min="0"
                        :controls="false"
                        :value="0"
                      ></el-input-number>
                    </el-form-item>
                  </el-form>
                </template>
              </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-switch v-model="scope.row.use_scrap"></el-switch>
                    </el-form-item>
                  </el-form>
                </template>
              </el-table-column>
              <!-- <el-table-column align="center" label="操作" width="100px">
                  <template slot-scope="scope">
                    <el-link
                      v-if="checkPermission(['warehouse_update'])"
                      @click="handleoutput(scope)"
                      >提交</el-link
                    >
                  </template>
                </el-table-column>!-->
            </el-table>
            <div style="text-align: right">
              <el-button type="danger" @click="dialogTableoutput = false"
              >取消
              </el-button>
              <el-button type="primary" @click="handleoutputs()"
              >提交
              </el-button>
            </div>
          </el-dialog>
        </el-card>
      </el-col>
      <el-col span="8">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>工具工装</span>
          </div>
          <el-table
            :data="tool"
            border
            fit
            stripe
            highlight-current-row
            height="230"
            style="width: 100%"
          >
            <el-table-column prop="material_.name" label="物料名称">
            </el-table-column>
            <el-table-column prop="material_.unit" label="物料单位">
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="limitedPhoto" @close="closeCamera" id="loginFaceWrap">
      <div style="font-size: 28px;color: #333333;text-align: center;font-weight: bold;">操作人员确认</div>
      <div class="testTracking">
        <faceLogin
          v-if="limitedPhoto"
          ref="faceTracking"
          name="faceLogin"
          @func="getMsgFormSon"
        ></faceLogin>
      </div>
    </el-dialog>
  </div>
</template>
<style scoped>
  .word-wrap {
    padding: 25px;
  }
  .box-card {
    height: 300px;
  }
</style>
<script>
  import {
    getoperation,
    createoperation,
    getoperationwproductList,
    getequList,
    getrecordList,
    getinputList,
    getwmaterialList,
    createInput,
    getoutputList,
    createOutput,
    createRecord,
    submitOperation,
    deleteOperationequip,
    deleteOperationwproduct,
    gettoolList,
    createInputs,
    recordInit,
    createOutputs,
    deleteOperationeinput,
    wproductPlace,
  } from "@/api/wpm";
  import { gettechdocList} from "@/api/mtm";
  import checkPermission from "@/utils/permission";
  import {getprogressList} from "@/api/pm";
  import {getTestRecordExport} from "@/api/qm";
  import faceLogin from '@/components/faceLogin/review.vue';

  export default {
    components: {faceLogin},
    inject: ["reload"],
    data() {
      return {
        techdocList: "",
        operationList: {
          count: 0,
        },
        drawer: false,
        listQuery: {
          page: 1,
          page_size: 20,
        },
        state_: {
          10: "完好",
          20: "限用",
          30: "在修",
          40: "禁用",
        },
        scrap: [
          {lable: "使用", value: true},
          {lable: "不使用", value: false},
        ],
        listQueryfield: {
          page: 1,
          page_size: 20,
        },
        wproductplace: {},
        operationData: {
          user: "",
        },
        scrapData: {},
        dialogVisibleForm: false,
        tableForm: {
          name: "",
        },
        dialogwproductplace: false,
        listQueryrecordform: {
          page: 1,
          page_size: 20,
        },
        recordformList: {
          count: 0,
        },
        fieldList: {
          count: 0,
          name: "",
        },
        highoptions: [
          {value: 1, label: "<"},
          {value: 2, label: "<="},
        ],
        lowoptions: [
          {value: 1, label: ">"},
          {value: 2, label: ">="},
        ],
        highoptionss_: {
          1: "<",
          2: "<=",
        },
        lowoptionss_: {
          1: ">",
          2: ">=",
        },
        options_: {
          string: "文本",
          int: "整数",
          float: "小数",
          date: "日期",
          datetime: "日期时间",
          select: "单选",
          selects: "多选",
        },
        fieldtypeoptions: [
          {
            value: "string",
            label: "文本",
          },
          {
            value: "int",
            label: "整数",
          },
          {
            value: "float",
            label: "小数",
          },
          {
            value: "date",
            label: "日期",
          },
          {
            value: "time",
            label: "时间",
          },
          {
            value: "datetime",
            label: "日期时间",
          },
          {
            value: "select",
            label: "单选",
          },
          {
            value: "selects",
            label: "多选",
          },
        ],
        formID: "",
        limitedPhoto: false,
        dialogTablepick: false,
        dialogTableoutput: false,
        picks: {},
        output: {},
        record_data: [],
        record: {},
        inputData: [],
        operationwpData: [],
        equData: [],
        recordData: [],
        wmaterialData: [],
        outputData: [],
        tprogressData: [],
        tool: "",
        wordText: "",
        pdf: "",
      };
    },

    mounted() {
      this.id = this.$route.params.id; //操作ID
      this.readbook();
      this.getList(); //边角料
      this.getpwpList(); //半成品
      this.getequList(); //设备
      this.getrecordLists(); //自定义表
      this.getinputLists(); //物料消耗
      this.getoutputLists(); //产出物料
      this.getwmaterialList();
      this.getprogressList(); //产出物料调出
      this.gettoolList(); //工序工装
    },

    methods: {
      checkPermission,

      //作业指导书
      //选项卡切换
      handleClick(tab) {
        console.log(tab.name);
        var str = tab.label.substr(tab.label.length - 1, 1);
        //  if (str == "x") {
        //   const xhr = new XMLHttpRequest();

        //  xhr.open("get", tab.name, true);

        //   xhr.responseType = "arraybuffer";

        //    xhr.onload = () => {
        //   if (xhr.status == 200) {
        //     mammoth
        //      .convertToHtml({ arrayBuffer: new Uint8Array(xhr.response) })
        //     .then((resultObject) => {
        //         this.$nextTick(() => {
        //            this.wordText = resultObject.value;
        //          });
        //         });
        //     };
        //       xhr.send();
        //     var filediv = document.getElementById("file");
        //   filediv.innerHTML =
        //    ' <div id="wordView" v-html=' + this.wordText + " />";
        //    }
        if (str == "f") {
          this.pdf = tab.name;
          var filediv = document.getElementById("file");
          filediv.innerHTML =
            " <iframe width=1000 height=900 frameborder=0 scrolling=auto src=" +
            tab.name +
            "></iframe>";
        } else if (str == "g") {
          var filediv = document.getElementById("file");
          filediv.innerHTML =
            " <img width=1000 height=900 frameborder=0 scrolling=auto src=" +
            tab.name +
            "></img>";
        }
      },
      getWordText() {
        this.drawer = true;
      },
      readbook() {
        gettechdocList({operation: this.id, page: 0, enabled: true}).then(
          (response) => {
            if (response.data) {
              this.techdocList = response.data;
              console.log(this.techdocList);
            }
          }
        );
      },

      //是否使用边角料
      getList() {
        getoperation(this.id).then((response) => {
          if (response.data) {
            this.operationData = response.data;
            let names = '';
            let numbers = '';
            let specification = '';
            response.data.out_detail.forEach(item=>{
              names +=item.product.name;
              numbers +=item.plan.number;
              specification +=item.product.specification;
            });
            this.operationData.number = numbers;
            this.operationData.name =  names;
            this.operationData.specification = specification;

            if (response.data.is_submited) {
              this.operationData.user = response.data.create_by_.name;
            } else {
              this.operationData.user = '';
            }
          }
        });
      },
      //如果使用边角料提交
      scrapSubmit() {
        // this.scrapData.use_scrap = this.operationData.use_scrap;
        // this.scrapData.remark = this.operationData.remark;
        createoperation(this.id, this.scrapData).then((res) => {
          if (res.code >= 200) {
            this.$message.success("成功！");
            this.getList(); //
          }
        });
      },
      //操作使用的半成品
      getpwpList() {
        getoperationwproductList({operation: this.id, page: 0}).then(
          (response) => {
            if (response.data) {
              this.operationwpData = response.data;
            }
          }
        );
      },
      //半成品摆放的位置
      handleupdatewproduct(scope) {
        this.dialogwproductplace = true;
        this.wproductplaceID = scope.row.id;
      },
      submitwproductplace() {
        wproductPlace(this.wproductplaceID, this.wproductplace).then((res) => {
          if (res.code >= 200) {
            this.getpwpList();
            this.dialogwproductplace = false;
            this.$message.success("成功");
          }
        });
      },
      //操作半成品删除
      handleDeletewproduct(scope) {
        this.$confirm("确认删除该半成品?", "警告", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "error",
        })
          .then(async () => {
            await deleteOperationwproduct(scope.row.id);
            this.getpwpList();
            this.$message.success("成功");
          })
          .catch((err) => {
            console.error(err);
          });
      },
      //操作设备
      getequList() {
        getequList({operation: this.id, page: 0}).then((response) => {
          if (response.data) {
            this.equData = response.data;
          }
        });
      },
      //操作删除设备
      handleDeletequip(scope) {
        alert(scope.row.equip_.id);

        this.$confirm("确认删除该设备?", "警告", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "error",
        })
          .then(async () => {
            await deleteOperationequip(scope.row.id);
            this.getequList();
            this.$message.success("成功");
          })
          .catch((err) => {
            console.error(err);
          });
      },
      //操作自定义表
      getrecordLists() {
        getrecordList({operation: this.id, page: 0, enabled: true}).then(
          (response) => {
            if (response.data) {
              this.recordData = response.data;
            }
          }
        );
      },
      //调出表单内容
      handlerecord(scope) {
        this.tableForm = Object.assign({}, scope.row); // copy obj
        this.formID = scope.row.id;
        recordInit(this.formID).then((response) => {
          if (response.data) {
            this.fieldList = response.data;
            this.fieldList.name = response.data.form_.name;
          }
        });
        this.dialogVisibleForm = true;
      },
      handlerecordExport(scope){
        let exportFormId = scope.row.id;
        getTestRecordExport(exportFormId).then(res=>{
          if(res.code===200){
            let link = document.createElement('a');
            link.href = res.data.path;
            document.body.appendChild(link);
            link.click();
          }
        })
      },

      //工序工装列表
      gettoolList() {
        gettoolList({operation: this.id, page: 0}).then((response) => {
          if (response.data) {
            this.tool = response.data;
          }
        });
      },

      //提交表单内容
      recordconfirm() {
        let _this = this;
        _this.record_data = []; //检查项目
        this.fieldList.record_data.forEach((item) => {
          if (item.field_type === "int") {
            item.field_value = parseInt(item.field_value);
          } else if (item.field_type === "float") {
            item.field_value = parseFloat(item.field_value);
          }
          _this.record_data.push({
            id: item.id,
            field_value: item.field_value,
          });
        });
        this.record.record_data = _this.record_data;
        createRecord(this.formID, this.record).then((res) => {
          if (res.code >= 200) {
            this.getrecordLists();
            this.$message.success("提交成功！");

            this.dialogVisibleForm = false;
          }
        });
      },

      //操作消耗物料列表
      getinputLists() {
        getinputList({operation: this.id, page: 0}).then((response) => {
          if (response.data) {
            this.inputData = response.data;
          }
        });
      },
      cjllclick() {
        this.dialogTablepick = true;
      },

      //从车间领料
      getwmaterialList() {
        getwmaterialList({operation: this.id, page: 0}).then((response) => {
          if (response.data) {
            this.wmaterialData = response.data;
          }
        });
      },
      //车间物料消耗提交
      handlepick(scope) {
        this.picks.operation = this.id;
        this.picks.wmaterial = scope.row.id;
        this.picks.count = scope.row.pick_count;
        let _this = this;
        createInput(this.picks).then((res) => {
          if (res.code >= 200) {
            this.$message.success("创建成功！");
            _this.getinputLists();
            this.dialogTablepick = false;
          }
        });
      },
      //消耗物料删除
      handleDeleteinput(scope) {
        this.$confirm("确认删除该消耗物料操作?", "警告", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "error",
        })
          .then(async () => {
            await deleteOperationeinput(scope.row.id);
            this.getinputLists();
            this.$message.success("成功");
          })
          .catch((err) => {
            console.error(err);
          });
      },
      //车间领料批量提交
      handlepicks() {
        let _this = this;

        (this.pickDatas = []),
          this.$refs.multipleTable.selection.forEach((item) => {
            if (item.pick_count > 0) {
              this.pickDatas.push({
                operation: this.id,
                wmaterial: item.id,
                count: item.pick_count,
              });
            }
          });

        createInputs(this.pickDatas).then((res) => {
          if (res.code >= 200) {
            this.dialogTablepick = false;
            this.$message.success("提交成功！");
            _this.getinputLists();
          }
        });
      },

      //操作产出物料列表
      getoutputLists() {
        getoutputList({operation: this.id, page: 0}).then((response) => {
          if (response.data) {
            this.outputData = response.data;
          }
        });
      },
      //产出物料选择
      getprogressList() {
        getprogressList({operation: this.id, page: 0, type: 2}).then(
          (response) => {
            if (response.data) {
              this.tprogressData = response.data;
            }
          }
        );
      },
      //车间产出物料提交
      handleoutput(scope) {
        this.output.operation = this.id;
        this.output.subproduction_progress = scope.row.id;
        this.output.count = scope.row.output_count;
        this.output.use_scrap = scope.row.use_scrap;
        createOutput(this.output).then((res) => {
          if (res.code >= 200) {
            this.getoutputLists();
            this.$message.success("创建成功！");

            this.dialogTableoutput = false;
          }
        });
      },
      //车间产出物料批量提交
      handleoutputs() {
        (this.outputDatas = []),
          this.$refs.multipleTables.selection.forEach((item) => {
            if (item.output_count > 0) {
              this.outputDatas.push({
                operation: this.id,
                subproduction_progress: item.id,
                count: item.output_count,
                use_scrap: item.use_scrap,
              });
            }
          });

        createOutputs(this.outputDatas).then((res) => {
          if (res.code >= 200) {
            this.dialogTableoutput = false;

            this.$message.success("提交成功！");
            this.getoutputLists();
          }
        });
      },

      //提交本次操作
      handlesubmit() {
        this.limitedPhoto = true;
        /* if (this.inputData == "") {
           this.$confirm("没有消耗物料确定提交吗?", "提示", {
             confirmButtonText: "确认",
             cancelButtonText: "取消",
             type: "error",
           })
             .then(async () => {
               await submitOperation(this.id);
               this.$router.push({name: "operation"});
               this.$message.success("操作提交成功！");
             })
             .catch((err) => {
               console.error(err);
             });
         } else {
           submitOperation(this.id).then((res) => {
             if (res.code >= 200) {
               this.$router.push({name: "operation"});
               this.$message.success("操作提交成功！");
             }
           });
         }*/

      },
      /*关闭相机*/
      closeCamera() {
        this.$refs.faceTracking.closeCamera();
        let video = document.getElementById('video');
        let stream = video.srcObject;
        // console.log(stream);
        let tracks = stream.getTracks();
        tracks.forEach(track => {
          track.stop()
        });
        video.srcObject = null;
      },
      //获取人脸数据
      getMsgFormSon(data) {
        let that = this;
        that.operationData.user = data.name;
        let text = '确定以操作员'+data.name+'身份提交？';
        if (data.token !== '' && data.token !== null && data.token !== undefined) {
          if (that.inputData == "") {
            that.$confirm("没有消耗物料，"+text, "提示", {
              confirmButtonText: "确认",
              cancelButtonText: "取消",
              type: "error",
            })
              .then( () => {
                that.limitedPhoto = false;
                submitOperation(that.id,{token:data.token}).then(res=>{
                  if(res.code===200){
                    that.$router.push({name: "operation"});
                    that.$message.success("操作提交成功！");
                  }else{
                    that.$message.error(res.msg)
                  }
                });
              }).catch(() => {
              that.limitedPhoto = false;
              });
          } else {
            this.$confirm(text, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              that.limitedPhoto = false;
              submitOperation(that.id,{token:data.token}).then((res) => {
                if (res.code === 200) {
                  that.$router.push({name: "operation"});
                  that.$message.success("操作提交成功！");
                }else{
                  that.$message.error(res.msg)
                }
              }).catch((err) => {
                that.$message.error(err);
              });
            }).catch(() => {
              that.limitedPhoto = false;
            });

          }
        }
      },
    },
  };
</script>
