<template>
  <div>
    <el-card>
      <div class="search-container">
        <span class="show-text">生产订单:</span>
        <el-input v-model="orderNo" placeholder="请输入生产订单" clearable style="width: 150px;margin-right: 10px" />
        <span class="show-text">销售订单:</span>
        <el-input v-model="contractNo" placeholder="请输入销售订单" clearable style="width: 150px;margin-right: 10px" />
        <span class="show-text">物料编码:</span>
        <el-input v-model="productCode" placeholder="请输入物料编码" clearable style="width: 150px;margin-right: 10px" />
        <span class="show-text">物料名称:</span>
        <el-input v-model="productName" placeholder="请输入物料名称" clearable style="width: 150px;margin-right: 10px" />
        
        
        <span class="show-text">计划号:</span>
        <el-input v-model="plannum" placeholder="请输入计划号" clearable style="width: 150px;margin-right: 10px" />
        <br>
        <br>
        <span class="show-text">任务状态:</span>
        <el-select v-model="taskstatus" placeholder="请选择">
          <el-option
            key='0'
            label="全部"
            value="0">
          </el-option>
          <el-option
            key='1'
            label="未下发"
            value="1">
          </el-option>
          <el-option
            key='2'
            label="已下发"
            value="2">
          </el-option>
        </el-select>
        <span class="show-text">属性:</span>
        <el-select v-model="orderstatus" placeholder="请选择">
          <el-option
            key='0'
            label="全部"
            value="0">
          </el-option>
          <el-option
            key='1'
            label="机加件"
            value="1">
          </el-option>
          <el-option
            key='2'
            label="装配件"
            value="2">
          </el-option>
        </el-select>
        <span class="show-text">下达日期:</span>
        <el-date-picker
          v-model="completionTime"
          :clearable="false"
          end-placeholder="结束时间"
          format="yyyy-MM-dd"
          popper-class="virtual-cell-time-picker"
          range-separator="-"
          start-placeholder="开始时间"
          style="width: 280px;vertical-align: top"
          type="datetimerange"
          value-format="yyyy-MM-dd" />
        <span class="show-text">工艺状态:</span>
        <el-select v-model="standardprocess" placeholder="请选择">
          <el-option
            key='0'
            label="全部"
            value="0">
          </el-option>
          <el-option
            key='1'
            label="标准工艺"
            value="1">
          </el-option>
          <el-option
            key='2'
            label="生产工艺"
            value="2">
          </el-option>
        </el-select>
        <el-button :disabled="loading" icon="el-icon-search" plain type="primary" @click="searchTable()">查询</el-button>
        <el-button type="warning" size="mini" style="width: 140px;"  @click="AllProductProcess">批量生成生产工艺</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        :height="'75vh'"
        border
        element-loading-background="rgba(0, 0, 0, 0.2)"
        element-loading-spinner="el-icon-loading"
        highlight-current-row
        size="mini"
        style="margin-top: 20px; width: 95%;"
        tooltip-effect="dark"
        ref="multipleTable"
        @row-click="handleRowClick"
        @selection-change="handleSelectionChange"
        >
        <el-table-column align="center" type="selection"  width="50" fixed />
        <el-table-column align="center" label="序号" type="index" width="50"  />
        <el-table-column align="center" prop="合同号" label="销售订单" width="100" />
        <el-table-column align="center" prop="计划号" label="计划号" width="80" />
        <el-table-column align="center" prop="订单编号" label="生产订单" width="80" />
        <el-table-column align="center" prop="物料编号" label="物料编码" width="220" />
        <el-table-column align="center" prop="物料描述" label="物料名称" width="190" />
        <el-table-column align="center" prop="自制件属性" label="属性" width="100" />
        <el-table-column align="center" prop="计划数量" label="计划数" width="80" />
        <el-table-column align="center" label="下达日期" width="170">
          <template slot-scope="scope">
            {{ scope.row.下达日期 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="计划开始" width="170">
          <template slot-scope="scope">
            {{ scope.row.计划开始 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="计划完成" width="170">
          <template slot-scope="scope">
            {{ scope.row.计划完成 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="加急状态" width="80">
          <template slot-scope="scope">
            <div class="status-light" :class="scope.row.加急状态 == 1 ? 'status-light-green' : 'status-light-gray'" />
          </template>
        </el-table-column>
        <el-table-column align="center" label="标准工艺" width="80">
          <template slot-scope="scope">
            <div class="status-light" :class="scope.row.标准工艺 == 1 ? 'status-light-green' : 'status-light-gray'" />
          </template>
        </el-table-column>
        <el-table-column align="center" label="生产工艺" width="80">
          <template slot-scope="scope">
            <div class="status-light" :class="scope.row.生产工艺 == 1 ? 'status-light-green' : 'status-light-gray'" />
          </template>
        </el-table-column>
        <el-table-column align="center" label="图纸" width="80">
          <template slot-scope="scope">
            <div class="status-light" :class="scope.row.worker != 0 ? 'status-light-green' : 'status-light-gray'" />
          </template>
        </el-table-column>
        <el-table-column align="center" prop="备注" label="备注" width="200" />
        <el-table-column align="center" label="操作" width="100" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="editProcess(scope.row)">编辑工艺</el-button>
          </template>
        </el-table-column>
        
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="pageCurrent"
          :page-sizes="[20, 50, 100]"
          :page-size="pageSize"
          :total="total1"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChanges"
          @current-change="handleCurrentChanges" />
      </div>
      <el-dialog :visible.sync="dialogcasual" title="编辑生产工艺" center style="min-height: 300px;" width="1400px">
        <el-card style="height: 750px">
        <el-row>
          <div style="height: 65px;overflow-y: scroll;">
            <div>物料编码：{{this.selectedRow.物料编号 }}</div>
            <div>物料名称：{{this.selectedRow.物料描述 }}</div>
            <div>原料:<span v-for="(item, index) in itemdata" :key="index">{{ item.子件编码 }}&nbsp;&nbsp;&nbsp;{{item.材质}} &nbsp;&nbsp;&nbsp;&nbsp;{{ item.子件名称 }}(计划数量:{{ item.计划数量 }}&nbsp;&nbsp;&nbsp;&nbsp;
              基本数量:{{ item.基本数量 }}&nbsp;&nbsp;&nbsp;&nbsp;存货量:{{ item.存货量 }})&nbsp;&nbsp;&nbsp;&nbsp;</span></div>
          </div>
          <div style="margin-top: 7px; margin-bottom: 7px">
            <!-- <el-button  icon="el-icon-document-copy" type="warning" plain size="small" style="margin-left: 10px;padding: 8px 15px;"  @click="copyData()">拷贝</el-button> -->
            <el-button  icon="el-icon-search" type="danger" plain size="small" style="margin-left: 10px;padding: 8px 15px; width: 100px;"  @click="getNum()" >零件图纸</el-button>
            <el-button  icon="el-icon-search" type="danger" plain size="small" style="margin-left: 10px;padding: 8px 15px; width: 100px;"  @click="getNum2()" >工艺图纸</el-button>
            <el-button  icon="el-icon-warning" type="success" plain size="small" style="margin-left: 10px;padding: 8px 15px; width: 140px;"  @click="processSave()">保存为标准工艺</el-button>
            <el-button  icon="el-icon-check" type="primary" plain size="small" style="margin-left: 10px;padding: 8px 15px; width: 100px;"  @click="workprocess()">下发任务</el-button>
            <el-button  icon="el-icon-document-copy" v-if="processStatus" type="success" plain size="small" style="margin-left: 10px;padding: 8px 15px;" >已保存</el-button>
          <el-button  icon="el-icon-document-copy" v-else type="success" plain size="small" style="margin-left: 10px;padding: 8px 15px;"  @click="saveProcess()">保存</el-button>
          </div>
          <div style="display: flex; ">
            <el-col style="margin-left: 7px;width:11%">
              <div style="margin-top: 10px">
                <el-input
                  v-model="processSearchName"
                  placeholder="请输入工序名称"
                  size="small"
                  clearable
                  style=" margin-bottom: 10px"
                  @input="filterProcess"
                />
                <el-table 
                :data="filteredTableData4" 
                :header-cell-style="{background: '#2283D4',color: 'white'}" 
                highlight-current-row 
                border 
                size="mini" 
                style="margin-top: 10px" height="550" 
                @row-click="editProcedure">
                  <el-table-column :width="setColumnWidth('日期时间')" label="工序" align="center" prop="" show-overflow-tooltip>
                    <template slot-scope="scope">
                      {{ scope.row.工艺名称 }}
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-col>
            <el-col style=" padding-right: 11%;">
              <div style="margin-top: 10px">
                <el-table v-loading="loading"  :data="tableData5" :header-cell-style="{background: '#19466E',color: 'white'}" style="margin-top: 10px;width: 100%;" height="600">
                  <el-table-column  width="50px" label="序号" align="center" prop="工艺顺序" show-overflow-tooltip fixed="left">
                    <template slot-scope="scope">
                      {{ scope.row.工艺顺序 }}
                    </template>
                  </el-table-column>
                  <el-table-column  width="130px" label="工序名称" align="center" prop="工艺名称" show-overflow-tooltip fixed="left">
                    <template slot-scope="scope">
                      {{ scope.row.工艺名称 }}
                    </template>
                  </el-table-column>
                  
                  <el-table-column label="准备工时" align="center" prop="准备工时" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.准备工时" size="mini" style="margin: 0;width: 100%" @input="updateProcess(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column  label="标准工时" align="center" prop="标准工时" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.标准工时" size="mini" style="margin: 0;width: 100%" @input="updateProcess(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column label="工时合计" align="center" prop="工时合计" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.工时合计" size="mini" style="margin: 0;width: 100%" @input="updateProcess(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column  label="工装量具" align="center" width="150px">
                    <template slot-scope="scope">
                      <el-select  v-model="scope.row.工卡量具" multiple placeholder="工装量具" size="small" filterable clearable @change="updateProcess(scope.row)">
                        <el-option
                          v-for="item in basedatagj"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column label="指定机床" align="center" width="150px" >
                    <template slot-scope="scope">
                      <el-select  v-model="scope.row.指定机床" multiple placeholder="指定机床" size="small" filterable clearable @change="updateProcess(scope.row)">
                        <el-option
                          v-for="item in basedatajc"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column label="车间" align="center" width="150px">
                    <template slot-scope="scope">
                      <el-select  v-model="scope.row.车间" placeholder="车间" size="small" filterable clearable @change="updateProcess(scope.row)">
                        <el-option
                          v-for="item in basedatacj"
                          :key="item.id"
                          :label="item.name"
                          :value="item.name">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column label="属性" align="center" width="150px">
                    <template slot-scope="scope">
                      <el-select  v-model="scope.row.属性" placeholder="属性" size="small" filterable clearable @change="updateProcess(scope.row)">
                        <el-option
                          v-for="item in basedatasx"
                          :key="item.id"
                          :label="item.name"
                          :value="item.name">
                        </el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column width="330px" label="工序说明" align="center" prop="" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.工艺要求" size="mini" style="margin: 0;width: 100%" @change="updateProcess(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column width="200px" label="备注" align="center" prop="" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.备注" size="mini" style="margin: 0;width: 100%" @change="updateProcess(scope.row)"/>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" align="center" width="250px" fixed="right" >
                    <template slot-scope="scope">
                      <el-tooltip :open-delay="700" effect="dark" content="下移工序" placement="top" style="width: 24px;">
                        <el-button type="text" icon="el-icon-bottom" size="mini" style="margin-right: 5px;margin-right: 0px;padding:0" @click="downOne(scope.row)"/>
                      </el-tooltip>
                      <el-tooltip :open-delay="700" effect="dark" content="上移工序" placement="top" style="width: 24px;">
                        <el-button type="text" icon="el-icon-top" size="mini" style="margin-right: 5px;margin-right: 0px;padding:0" @click="upOne(scope.row)"/>
                      </el-tooltip>
                      <el-tooltip :open-delay="700" effect="dark" content="插入工序" placement="top" style="width: 24px;">
                        <el-button type="text" icon="el-icon-plus" size="mini" style="margin-right: 5px;margin-right: 0px;padding:0" @click="insertOne(scope.row)"/>
                      </el-tooltip>
                      <el-tooltip :open-delay="700" effect="dark" content="删除工序" placement="top" style="width: 24px;">
                        <el-button type="text" icon="el-icon-minus" size="mini" style="margin-right: 5px;margin-right: 0px;padding:0" @click="deleteOne(scope.row)"/>
                      </el-tooltip>
                      <el-tooltip :open-delay="700" effect="dark" content="删除工序" placement="top" style="width: 50px;">
                        <el-button type="text" size="mini" style="margin-right: 5px;margin-right: 0px" @click="oneworkprocess(scope.row)">下发任务</el-button>
                      </el-tooltip>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-col>
          </div>
          
        </el-row>
      </el-card>
      </el-dialog>
      <el-dialog :visible.sync="dialogFormVisible" title="生产工艺拷贝" center style="min-height: 300px;" width="1100px">
            <el-row style="margin-bottom: 10px">
              <template>
                <el-checkbox v-model="processprodutc"  @change = 'copyData'>生产工艺</el-checkbox>
              </template>
              <el-select v-if ="processprodutc" v-model="partNameValue2" style="width:300px;margin-left: 10px" placeholder="生产工艺物料名称" size="small" filterable clearable @change="searchTable4" >
                <el-option
                    v-for="item in tableData3"
                    :key="item.AID"
                    :label="item.物料编号"
                    :value="item.物料编号">
                    
                  </el-option>
              </el-select>
              <el-select v-else v-model="partNameValue2" style="width:300px;margin-left: 10px" placeholder="物料名称" size="small" filterable clearable @change="searchTable2" >
                <el-option
                    v-for="item in tableData3"
                    :key="item.id"
                    :label="item.零件图号"
                    :value="item.零件图号">
                    
                  </el-option>
              </el-select>
            </el-row>
            <el-table :data="tableData6" :header-cell-style="{background: '#383E4B',color: 'white'}" size="mini" style="width: 100%;margin-top:15px" height="500px" border highlight-current-row>
              <el-table-column label="序号" align="center" prop="工艺顺序"  show-overflow-tooltip>

              </el-table-column>
              <el-table-column label="工序名称" align="center" prop="工艺名称" show-overflow-tooltip>

              </el-table-column>
              <el-table-column label="工序说明" align="center" prop="工艺要求" show-overflow-tooltip>

              </el-table-column>
              <el-table-column label="准备工时" align="center" prop="准备工时" show-overflow-tooltip>

              </el-table-column>
              <el-table-column  label="标准工时" align="center" prop="标准工时" show-overflow-tooltip>

              </el-table-column>
              <el-table-column label="工时合计" align="center" prop="工时合计" show-overflow-tooltip>

              </el-table-column>
              <el-table-column  label="工装量具" align="center" width="150px">
                  <template slot-scope="scope">
                    <el-select  v-model="scope.row.工卡量具" multiple placeholder="工装量具" size="small" disabled filterable clearable >
                      <el-option
                        v-for="item in basedatagj"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="指定机床" align="center" width="150px" >
                  <template slot-scope="scope">
                    <el-select  v-model="scope.row.指定机床" multiple placeholder="指定机床" size="small" disabled filterable clearable >
                      <el-option
                        v-for="item in basedatajc"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="车间" align="center" width="150px">
                  <template slot-scope="scope">
                    <el-select  v-model="scope.row.车间" placeholder="车间" size="small" disabled filterable clearable >
                      <el-option
                        v-for="item in basedatacj"
                        :key="item.id"
                        :label="item.name"
                        :value="item.name">
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
              <el-table-column label="备注" align="center" prop="备注" width="200px">

              </el-table-column>
            </el-table>
            <div slot="footer" class="dialog-footer">
              <el-button size="small" style="margin-left: 10px;padding: 8px 15px;" @click="dialogFormVisible=false">取消</el-button>
              <el-button type="primary" size="small" style="margin-left: 10px;padding: 8px 15px;" @click="submitCopy">确定</el-button>
            </div>
          </el-dialog>
          <el-dialog :visible.sync="seeVisible" title="图纸" center width="1200px" overflow="scroll" >
            <!-- <div id="pdf-container-placeholder" style="min-height: 500px;"></div> -->
            <div id="el-dialog__body" style="min-height: 500px;"></div>
            <div slot="footer" class="dialog-footer">
              <el-button @click="seeVisible = false">关闭</el-button>
            </div>
          </el-dialog>
    </el-card>
  </div>
</template>


<script>
import { mapGetters } from 'vuex'
import { MESDownFile } from '@/utils/request'
import { seepdf, initPDFKeyboardShortcuts, setZoom } from '@/utils/pdf';
export default {
  data() {
    return {
      seeVisible:false,
      processprodutc:false,
      partTool: '',
      state: 1,
      form:{
        物料编号:'',
      },
      productNameValue: '', // 产品部件名称
      productName: [], // 产品部件名称数组
      partNameValue: '', // 零件名称
      partNameLabel: '', // 零件名称
      partName: [], // 零件名称数组
      partNameValue1: '', // 零件名称
      productValue1: '',
      partName1: [], // 零件名称数组
      partName2: [], // 零件名称数组
      partNameValue2: '', // copy零件名称
      partNameLabel2: '',
      partNameValue3:'',// 零件名称
      partNameValue4:'',// 计划数
      dateRange: '', // 提交日期
      dialogVisible: false,
      dialogVisible1: false,
      dialogFormVisible: false,
      disabled: true,
      checked: false,
      hadFile: [],
      fileList: [],
      hadFile1: [],
      processValue: '',
      dialogName: true,
      showFileList: false,
      action: '',
      product1: [], // 产品名称数组
      loading: false, // 数据加载
      total: 0, // 分页总数
      tableData4: [], // 工艺列表
      tableData3: [], // 零件列表
      filteredTableData4: [], // 过滤后的工艺列表
      processSearchName: '', // 工序搜索框内容
      tableData5: [], // 工艺内容
      tableData6: [],
      pageCurrent: 1, // 分页当前页
      pageSize: 100, // 分页每页显示条数
      orderName: '', // 排序列名
      order: '', // 排序方式
      materialarr:[],
      basedata:[],
      basedatagj:[],
      basedatajc:[],
      basedatacj:[],
      basedatasx:[{'name':'外协','id':1},{'name':'自制','id':2}],
      basedatavalue1:'',
      basedatavalue2:'',
      basedatavalue3:'',
      dialogcasual:false,

      orderNo: '',
      contractNo: '',
      productCode: '',
      productName: '',
      processName: '',
      nature: '',
      productionStatus: '未完成',
      Doing:"",
      Doingoptions:[],
      completionTime: [],
      loading: false,
      tableData: [],
      multipleSelection: [],
      dialogVisible: false,
      submitLoading: false,
      currentRow: {},
      stationOptions: [],
      selectedRow: {},
      editnumber:0,
      submitstatus:0,
      remarkDialogVisible: false,
      remarkSubmitLoading: false,
      insertidx:0,
      processStatus:0,
      taskstatus:'1',
      orderstatus:'1',
      downPDF:MESDownFile,
      itemdata:[],
      standardprocess:"0",
      pageCurrent: 1,
      pageSize: 20,
      total1:0,
      plannum:''
    }
  },
  computed: {
    ...mapGetters([
      'id',
      'token'
    ])
  },
  watch: {
    partNameValue(val) {
      if (val) {
        this.disabled = false
      } else {
        this.disabled = true
      }
    }
  },
  created() {
    this.searchTable()
  },
  methods: {
    getitemdata(item){
      var param = []
      this.itemdata = []
      param.push(["订单编号",item])
      var Data = this.CreateData('11', '工艺管理_获取物料原料信息',param)
      this.ExecDatabase(Data).then(response => {
        response.data.forEach(element => {
          if(element.U_MoType  == '机加件'){
            this.itemdata.push({
              '子件编码':element.子件编码,
              '子件名称':element.子件名称,
              '计划数量':element.计划数量,
              '材质':element.材质,
              '基本数量':element.基本数量,
              '存货量':element.存货量,
              '待出数量':element.待出数量,
              '拣配数量':element.拣配数量,
            })
          }
        })
      })
    },
    editProcess(row){
      this.dialogcasual = true
      this.loading = true
      this.getitemdata(row.订单编号)
      this.editProcesssearch(row)
      
    },
    editProcesssearch(row){
      var param = []
      param[0] = ['物料编号',row.物料编号]
      param[1] = ['订单编号',row.订单编号]
      var Data = this.CreateData('11', '工艺管理_生产工艺_查询生产工艺', param)
      this.ExecDatabase(Data).then(response => {
        this.getProcess()
        this.getbasedata()
        this.loading = false
        this.tableData5 = response.data
        this.processStatus = 0
        this.fninsertidx()
      })
    },
    submitCopy() {
      if (this.partNameValue2 == '') {
        this.$message.warning('请先选择零件')
        return
      }
      var processtype = 0
      if(this.processprodutc){
        processtype = 1
      }
        var param1 = []
        param1[0] = ['物料编号', this.selectedRow.物料编号]
        param1[1] = ['零件图号', this.partNameValue2]
        param1[2] = ['订单编号', this.selectedRow.订单编号]
        param1[3] = ['计划数量', this.selectedRow.计划数量]
        param1[4] = ['工艺类型', processtype]
        // 参数数量与名称要与存储过程对应
        var Data1 = this.CreateData('12', '工艺管理_生产工艺_工艺拷贝', param1)
        this.ExecDatabase(Data1).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('拷贝成功')
            this.editProcesssearch(this.selectedRow)
            this.dialogFormVisible = false

          } else {
            this.$message.error('拷贝失败')
          }
        })
      
    },
    copyData() {
      this.dialogFormVisible = true
      this.loading = true
      if(this.processprodutc){
        var Data = this.CreateData('11', '工艺管理_生产工艺_生产工艺拷贝')
        this.ExecDatabase(Data).then(response => {
          this.tableData3 = response.data
          this.loading = false
        })
      }else{
        var Data = this.CreateData('11', '工艺管理_生产工艺_标准工艺拷贝')
        this.ExecDatabase(Data).then(response => {
          this.tableData3 = response.data
          this.loading = false
        })
      }
      
      
    },
    Doingform(value){
      console.log(value)
    },
    formatDate(date) {
      if (!date) return ''
      return date.split(' ').length > 1 ? date.split(' ')[0] : date
    },
    handleSizeChanges(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    
    handleCurrentChanges(val) {
      this.pageCurrent = val
      this.searchTable()
    },
    searchTable() {
      this.loading = true
      this.tableData = []
      var param = []
      param.push(['订单号', this.orderNo || 0])
      param.push(['合同号', this.contractNo])
      param.push(['产品编码', this.productCode])
      param.push(['产品名称', this.productName])
      param.push(['下达日期1', this.completionTime[0]])
      param.push(['下达日期2', this.completionTime[1]])
      param.push(['任务状态',this.taskstatus])
      param.push(['订单状态',this.orderstatus])
      param.push(['工艺状态',this.standardprocess])
      param.push(['计划号',this.plannum])
      param.push(['PageCurrent', this.pageCurrent]),
      param.push(['PageSize', this.pageSize]),
      param.push(['PageCount', '1111', 'int', '1']),
      param.push(['ItemCount', '1111', 'int', '1'])
      
      var Data = this.CreateData('11', '计划排产_生产订单_订单查询', param)
      this.ExecDatabase(Data).then(response => {
        if(response.data.result.length>0){
          this.loading = false
          this.tableData = response.data.result
          this.total1 = parseInt(response.data.output[0].ItemCount)

        }
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleRowClick(row){
      this.selectedRow = row
    },
    workprocess(){
      if(this.tableData5.length<1){
        return this.$message.info('下发失败')
      }
      var param = []
      param.push(['订单编号',this.selectedRow.订单编号])
      param.push(['物料编号',this.selectedRow.物料编号])
      param.push(['计划数量',this.selectedRow.计划数量])
      var Data = this.CreateData('11', '计划排产_生产订单_订单任务_生产工艺任务下发', param)
      this.ExecDatabase(Data).then(response => {
        if(response.data[0].result != 0){
          this.searchTable()
          this.dialogcasual = false
          this.$message.success('操作成功')
        }else{
          this.searchTable()
          this.dialogcasual = false
          this.$message.info('已下发任务')
        }
      }).catch(() => {
        this.searchTable()
        this.dialogcasual = false
        this.$message.success('操作成功')
      })
    },
    oneworkprocess(row){
      var param = []

      param.push(['订单编号',this.selectedRow.订单编号])
      param.push(['物料编号',this.selectedRow.物料编号])
      param.push(['计划数量',this.selectedRow.计划数量])
      param.push(['工艺顺序',row.工艺顺序])

      var Data = this.CreateData('12', '计划排产_生产订单_订单任务_单条生产工艺任务下发', param)
      this.ExecDatabase(Data).then(response => {
        this.searchTable()
        // this.dialogcasual = false
        this.$message.success('操作成功')
      }).catch(() => {
        this.$message.info('操作成功')
      })
    },
    AllProductProcess(){

      if(this.multipleSelection.length>=1){
        var multipleSelection = this.multipleSelection
        var orderids = []
        var ordernums = []
        var orderitems = []
        
        multipleSelection.forEach(item => {
          if(item.标准工艺 == 1 & item.生产工艺 !=1 ){
            orderids.push(item.订单编号)
            orderitems.push(item.物料编号)
            ordernums.push(item.计划数量)
          }
        });
        orderids =  orderids.join(",") 
        ordernums =  ordernums.join(",") 
        orderitems =  orderitems.join(",") 

        var param = []
        param.push(['订单编号',orderids])
        param.push(['零件图号',orderitems])
        param.push(['计划数量',ordernums])
        console.log(param)
        var Data = this.CreateData('12', '工艺管理_零件工序_生产工艺_批量生成生产工艺', param)
        this.ExecDatabase(Data).then(response => {
          this.searchTable()
          this.$message.success('操作成功')
        }).catch(() => {
          this.$message.info('操作成功')
        })
      }else{
        this.$message.error('请勾选数据')
      }
    },
    getbasedata(){
      var Data = this.CreateData('11', '设备管理_设备信息_查询')
      this.ExecDatabase(Data).then(response => {
        this.basedatagj = []
        this.basedatajc = []
        this.basedatacj = []
        response.data.forEach(element => {
          if(element.设备类型名称 == '量具'){
            this.basedatagj.push({
              name:element.设备名称,
              id:element.设备流水号
            })
          }
          if(element.设备类型名称 == '机床'){
            this.basedatajc.push({
              name:element.设备名称,
              id:element.设备流水号
            })
          }
          if(element.设备类型名称 == '车间'){
            this.basedatacj.push({
              name:element.设备名称,
              id:element.设备流水号
            })
          }
          
        });
        this.basedata = response.data
        this.loading = false
        console.log(this.basedatacj)
        console.log(this.basedatasx)
      })
    },
    searchTable2() {
      this.loading = true
      var param = []
      param[0] = ['物料编号',this.partNameValue2]
      var Data = this.CreateData('11', 'MES_ProcessManagement_ProcessBindGet', param)
      this.ExecDatabase(Data).then(response => {
        // if(response.data[0].length>0){
          // this.getPartProcess(response.data)
          this.loading = false
          this.tableData6 = response.data
          this.datadoing()
      })
    },
    searchTable4() {
      this.loading = true
      var param = []
      param[0] = ['物料编号',this.partNameValue2]
      var Data = this.CreateData('11', '工艺管理_制定标准工艺_拷贝生产工艺', param)
      this.ExecDatabase(Data).then(response => {
        // if(response.data[0].length>0){
          // this.getPartProcess(response.data)
          this.loading = false
          this.tableData6 = response.data
          this.datadoing()
          
      })
    },
    datadoing(){

      this.tableData6.forEach(item => {
        if(!item.工艺名称){
          this.insertidx = item.id
        }
        if(item.工卡量具){
          item.工卡量具 = item.工卡量具.split(",").map(Number)
        }
        if(item.指定机床){
          item.指定机床 = item.指定机床.split(",").map(Number)
        }
      });
    },
    getProcess() {
      var param = []
      param[0] = ['工艺编号','']
      var Data = this.CreateData('11', 'MES_ProcessManagement_ProcessGet', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData4 = response.data
        this.filteredTableData4 = response.data
      })
    },
    // 过滤工序
    filterProcess() {
      if (this.processSearchName) {
        this.filteredTableData4 = this.tableData4.filter(item => {
          return item.工艺名称.includes(this.processSearchName)
        })
      } else {
        this.filteredTableData4 = this.tableData4
      }
    },
    
    processSave(){
        var param1 = []
        param1[0] = ['物料编号', this.selectedRow.物料编号]
        param1[1] = ['订单编号', this.selectedRow.订单编号]
        // 参数数量与名称要与存储过程对应
        var Data1 = this.CreateData('12', '车间生产管理工艺_零件工序_保存为标准工艺', param1)
        this.ExecDatabase(Data1).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('保存成功')
            // this.searchTable1()
            this.dialogFormVisible = false
          } else {
            this.$message.error('保存失败')
          }
        })
    },

    getNum() {
      this.dialogVisible = true
      var row = this.selectedRow;
      if(row == ''){
        return this.$message.error('请先选择任务')
      }
      var param = []
      param[0] = ['物料编号',row.物料编号]
      var Data = this.CreateData('11', '工艺管理_图纸维护_查看图纸', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
           var pdfSrc =""+this.downPDF+""+ response.data[0].uid+".pdf"
            this.seeVisible = true
            this.$nextTick(() => {
                seepdf(pdfSrc,'see')
                    
            })
        }else{
          this.$message.error('未上传图纸')
        }
      })
    },
    getNum2() {
      this.dialogVisible = true
      var row = this.selectedRow;
      if(row == ''){
        return this.$message.error('请先选择任务')
      }
      var param = []
      param[0] = ['物料编号',row.物料编号]
      var Data = this.CreateData('11', '工艺管理_工艺维护_查看图纸', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length > 0) {
           var pdfSrc =""+this.downPDF+""+ response.data[0].uid+".pdf"
            this.seeVisible = true
            this.$nextTick(() => {
                seepdf(pdfSrc,'see')
                    
            })
        }else{
          this.$message.error('未上传图纸')
        }
      })
    },
    // async getFileList(value) {
    //   this.hadFile = []
    //   if (value) {
    //     await request({
    //       url: '',
    //       method: 'post',
    //       data: {
    //         type: '3',
    //         name: `select * from 机加工MES_零件图PDF表 where 是否启用 = 1 and name = '${value}'`
    //       }
    //     }).then(data => {
    //       this.suffix = data.data
    //       if (data.data.length > 0) {
    //         const server = `${MESDownloadFile}`.split('/')
    //         data.data.map(item => {
    //           this.hadFile.push({
    //             url: `http://${server[2]}/webpage/part/${item.uid}.${item.suffix}`,
    //             name: `${item.name}.${item.suffix}`,
    //             suffix: item.suffix,
    //             id: item.uid
    //           })
    //         })
    //       }
    //     })
    //   }
    // },
    
    editProcedure(row) {
      if(this.insertidx){
        var param1 = []
        param1[0] = ['工艺编号', row.工艺编号]
        param1[1] = ['idd', this.insertidx]
        param1[2] = ['计划数量', this.selectedRow.计划数量]
        param1[3] = ['订单编号', this.selectedRow.订单编号]
        this.updateProcess2(param1)
      }else{
        var param1 = []
        param1[0] = ['工艺编号', row.工艺编号]
        param1[1] = ['物料编号', this.selectedRow.物料编号]
        param1[2] = ['计划数量', this.selectedRow.计划数量]
        param1[3] = ['订单编号', this.selectedRow.订单编号]
        // 参数数量与名称要与存储过程对应
        var Data1 = this.CreateData('11', '工艺管理_零件工序_生产工艺_修改数据', param1)
        this.ExecDatabase(Data1).then(response => {
          var param = []
          param[0] = ['物料编号', this.selectedRow.物料编号]
          param[1] = ['订单编号', this.selectedRow.订单编号]
          var Data = this.CreateData('11', '工艺管理_生产工艺_查询生产工艺', param)
          this.ExecDatabase(Data).then(response => {
            this.tableData5 = response.data
            this.fninsertidx()
            this.processStatus = 0
          })
        })
      }
    },

    updateProcess(row) {
        var param1 = []
        // const 工卡量具 = Object.values(row.工卡量具);
        // const 指定机床 = Object.values(row.指定机床);
        let 工卡量具 = []
        if (row.工卡量具) {
          if (Array.isArray(row.工卡量具)) {
            // 如果已经是数组，直接使用
            工卡量具 = row.工卡量具
          } else if (typeof row.工卡量具 === 'object' && row.工卡量具 !== null) {
            // 如果是对象，转换为数组
            工卡量具 = Object.values(row.工卡量具)
          } else if (typeof row.工卡量具 === 'string') {
            // 如果是字符串，尝试解析或分割
            工卡量具 = row.工卡量具.split(',').filter(item => item.trim() !== '')
          }
        }
        
        // 安全处理指定机床
        let 指定机床 = []
        if (row.指定机床) {
          if (Array.isArray(row.指定机床)) {
            指定机床 = row.指定机床
          } else if (typeof row.指定机床 === 'object' && row.指定机床 !== null) {
            指定机床 = Object.values(row.指定机床)
          } else if (typeof row.指定机床 === 'string') {
            指定机床 = row.指定机床.split(',').filter(item => item.trim() !== '')
          }
        }
        param1[0] = ['idd', row.id]
        param1[1] = ['工艺要求', row.工艺要求]
        param1[2] = ['准备工时', row.准备工时]
        param1[3] = ['标准工时', row.标准工时]
        param1[4] = ['工时合计', row.工时合计]
        param1[5] = ['工卡量具', 工卡量具]
        param1[6] = ['指定机床', 指定机床]
        param1[7] = ['车间', row.车间]
        param1[8] = ['备注', row.备注]
        param1[9] = ['属性', row.属性]
        var Data1 = this.CreateData('11', '工艺管理_零件工序_生产工艺_编辑', param1)
        this.ExecDatabase(Data1).then(response => {
         
        })
      
    },
    fninsertidx(){

      this.tableData5.forEach(item => {
        if(!item.工艺名称){
          this.insertidx = item.id
        }
        if(item.工卡量具){
          item.工卡量具 = item.工卡量具.split(",").map(Number)
        }
        if(item.指定机床){
          item.指定机床 = item.指定机床.split(",").map(Number)
        }
      });
    },
    updateProcess2(row) {
      var Data1 = this.CreateData('11', '工艺管理_零件工序_生产工艺_编辑插入工序', row)
      this.ExecDatabase(Data1).then(response => {
        var param1 = []
        param1[0] = ['物料编号', this.selectedRow.物料编号]
        param1[1] = ['订单编号', this.selectedRow.订单编号]
        // 参数数量与名称要与存储过程对应
        var Data1 = this.CreateData('11', '工艺管理_生产工艺_查询生产工艺', param1)
        this.ExecDatabase(Data1).then(response => {
          this.tableData5 = response.data
          this.fninsertidx()
          this.insertidx = 0
          this.processStatus = 0
        })
      })
      
    },
    deleteOne(row) { // 删除行
      
        var param1 = []
        param1[0] = ['物料编号', this.selectedRow.物料编号]
        param1[1] = ['idd', row.id]
        param1[2] = ['订单编号', this.selectedRow.订单编号]
        // 参数数量与名称要与存储过程对应
        var Data1 = this.CreateData('11', '工艺管理_零件工序_生产工艺_删除工序', param1)
        this.ExecDatabase(Data1).then(response => {
          var param1 = []
          param1[0] = ['物料编号', this.selectedRow.物料编号]
          param1[1] = ['订单编号', this.selectedRow.订单编号]
          // 参数数量与名称要与存储过程对应
          var Data1 = this.CreateData('11', '工艺管理_生产工艺_查询生产工艺', param1)
          this.ExecDatabase(Data1).then(response => {
            this.tableData5 = response.data
            this.fninsertidx()
            this.processStatus = 0
          })
        })
      
    },
    upOne(row) { // 上移
      
        var param1 = []
        param1[0] = ['物料编号', this.selectedRow.物料编号]
        param1[1] = ['idd', row.id]
        param1[2] = ['订单编号', this.selectedRow.订单编号]
        // 参数数量与名称要与存储过程对应
        var Data1 = this.CreateData('11', '工艺管理_零件工序_生产工艺_上移工序', param1)
        this.ExecDatabase(Data1).then(response => {
          var param1 = []
          param1[0] = ['物料编号', this.selectedRow.物料编号]
          param1[1] = ['订单编号', this.selectedRow.订单编号]
          // 参数数量与名称要与存储过程对应
          var Data1 = this.CreateData('11', '工艺管理_生产工艺_查询生产工艺', param1)
          this.ExecDatabase(Data1).then(response => {
            this.tableData5 = response.data
            this.fninsertidx()
            this.processStatus = 0
          })
        })
      
    },
    downOne(row) { // 下移
      
        var param1 = []
        param1[0] = ['物料编号', this.selectedRow.物料编号]
        param1[1] = ['idd', row.id]
        param1[2] = ['订单编号', this.selectedRow.订单编号]
        // 参数数量与名称要与存储过程对应
        var Data1 = this.CreateData('11', '工艺管理_零件工序_生产工艺_下移工序', param1)
        this.ExecDatabase(Data1).then(response => {
          var param1 = []
          param1[0] = ['物料编号', this.selectedRow.物料编号]
          param1[1] = ['订单编号', this.selectedRow.订单编号]
          // 参数数量与名称要与存储过程对应
          var Data1 = this.CreateData('11', '工艺管理_生产工艺_查询生产工艺', param1)
          this.ExecDatabase(Data1).then(response => {
            this.tableData5 = response.data
            this.fninsertidx()
            this.processStatus = 0
          })
        })
      
    },
    insertOne(row) { // 插入行
      var param1 = []
      param1[0] = ['零件图号', this.selectedRow.物料编号]
      param1[1] = ['idd', row.id]
      param1[2] = ['订单编号', this.selectedRow.订单编号]
      var Data1 = this.CreateData('11', '工艺管理_零件工序_生产工艺_插入工序', param1)
      this.ExecDatabase(Data1).then(response => {
        var param1 = []
        param1[0] = ['物料编号', this.selectedRow.物料编号]
        param1[1] = ['订单编号', this.selectedRow.订单编号]
        // 参数数量与名称要与存储过程对应
        var Data1 = this.CreateData('11', '工艺管理_生产工艺_查询生产工艺', param1)
        this.ExecDatabase(Data1).then(response => {
          this.tableData5 = response.data
          this.fninsertidx()
          this.processStatus = 0
        })
      })
    },
    saveProcess(){
      var param1 = []
      param1[0] = ['订单编号', this.selectedRow.订单编号]
      var Data1 = this.CreateData('11', '工艺管理_生产工艺_启用', param1)
      this.ExecDatabase(Data1).then(response => {
        param1[0] = ['物料编号', this.selectedRow.物料编号]
        param1[1] = ['订单编号', this.selectedRow.订单编号]
        this.$message.success('操作成功')
        // 参数数量与名称要与存储过程对应
        // var Data3 = this.CreateData('11', '工艺管理_生产工艺_查询生产工艺', param1)
        // this.ExecDatabase(Data3).then(response => {
        //   this.tableData5 = response.data
        //   this.fninsertidx()
        //   this.processStatus = 0
        // })
      })
    }
  }
}

</script>

<style scoped>
.status-light {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.status-light-green {
  background-color: #67C23A;
}

.status-light-gray {
  background-color: #909399;
}

::v-deep .el-input--suffix .el-input__inner{
  padding-right: 0;
}
::v-deep .el-input__suffix{
  display: none;
}
::v-deep .el-select .el-tag{
  font-size: 14px;
}
.show-text {
  margin-right: 5px;
  line-height: 32px;
}
.show-head {
  margin-right: 5px;
  line-height: 32px;
  font-size: 15px;
}
.el-dialog__body {
  padding: 20px;
}
.el-form-item {
  margin-bottom: 15px;
}
.custom-tabs {
  margin-top: 20px;
}
.schedule-container {
  min-height: 67vh;
}

.schedule-container ::v-deep .fc-daygrid-day-frame {
  padding: 2px;
  min-height: auto;
}

.schedule-container ::v-deep .fc-event {
  font-size: 12px;
  padding: 1px 2px;
  margin-bottom: 1px;
  line-height: 1.4;
}

.schedule-container ::v-deep .fc-daygrid-event-harness {
  margin-bottom: 1px;
}

.schedule-container ::v-deep .fc-daygrid-day-top {
  padding: 2px;
}

.schedule-container ::v-deep .fc-daygrid-more-link {
  font-size: 12px;
  padding: 0 2px;
}
::v-deep .el-table__body-wrapper,::v-deep .el-table__footer-wrapper,::v-deep .el-table__header-wrapper {
    width: 90%;
}
</style>
