<template>
  <div class="customer-css">
    <el-dialog title="生产订单-工艺路线维护" v-drag v-bind="$attrs" v-on="$listeners" width="800px" class="customer-dialog" >
      <el-form :inline="true"  label-position="top" label-width="100px" style="margin-top: -5px;">
        <el-form-item :label="'订单号：'">
          <el-input v-model="searchData.orderNo" class="customer-input-color-red" readonly  style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="'物料编码：'">
          <el-input v-model="searchData.partNo" class="customer-input-color-red" readonly style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="'物料名称/规格：'">
          <el-input v-model="searchData.partDesc" class="customer-input-color-red" readonly style="width: 260px"></el-input>
        </el-form-item>
        <el-form-item :label="'工厂编号：'">
          <el-input v-model="searchData.site" class="customer-input-color-red" readonly  style="width: 130px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true"  label-position="top" label-width="100px" style="margin-top: 0px;">
        <el-button class="customer-bun-min" type="primary" @click="addModel" style="margin-left: 0px; margin-bottom: 0px;">新增</el-button>
        <el-button class="customer-bun-min" type="primary" @click="updateModel" style="margin-left: 0px; margin-bottom: 0px;">编辑</el-button>
        <el-button class="customer-bun-min" type="primary" @click="deleteSORoutingData" style="margin-left: 0px; margin-bottom: 0px;">删除</el-button>
        <el-button @click="getResourceModel()" type="primary" style="margin-left: 2px;margin-top: 0px">{{'可用机台'}}</el-button>
      </el-form>
      <el-table
        :height="height"
        :data="dataList"
        border
        @row-click="clickData"
        highlight-current-row
        v-loading="dataListLoading"
        style="width: 100%;">
        <el-table-column
          v-for="(item,index) in columnList" :key="index"
          :sortable="item.columnSortable"
          :prop="item.columnProp"
          :header-align="item.headerAlign"
          :show-overflow-tooltip="item.showOverflowTooltip"
          :align="item.align"
          :fixed="item.fixed==''?false:item.fixed"
          :width="item.columnWidth"
          :label="item.columnLabel">
          <template slot-scope="scope">
            <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                               style="width: 100px; height: 80px"/></span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog title="维护工艺路线明细" :close-on-click-modal="false" v-drag :visible.sync="addModelFlag" width="660px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item :label="'工序号：'">
          <el-input v-model="detailData.itemNo" class="customer-input-color-red" :disabled="addInputFlag"  style="width: 130px;text-align: right" type="number"></el-input>
        </el-form-item>
        <el-form-item :label="'工序名称：'">
          <el-input v-model="detailData.operationDesc" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item >
          <span slot="label" style="" @click="getBaseList(24)"><a herf="#">加工中心编码：</a></span>
          <el-input v-model="detailData.workCenterNo" style="width: 150px"></el-input>
        </el-form-item>
        <el-form-item :label="'准备时间：'">
          <el-input v-model="detailData.machSetupTime" style="width: 150px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item :label="'单位产出量：'">
          <el-input v-model="detailData.machRunFactor"  type="number" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="'产出单位：'">
          <el-select filterable v-model="detailData.factorUnit" style="width: 130px">
            <el-option label="单位/小时" value="单位/小时"></el-option>
            <el-option label="小时" value="小时"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="'计划开工时间：'">
          <el-date-picker
            v-model="detailData.planStartTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 150px"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="'计划完工时间：'">
          <el-date-picker
            v-model="detailData.planFinishTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 150px"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
        <el-form-item :label="'效率：'">
          <el-input v-model="detailData.efficiency" type="number" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="'操作工人数：'">
          <el-input v-model="detailData.crewsize" type="number" style="width: 130px"></el-input>
        </el-form-item>
        <el-form-item :label="'备注：'">
          <el-input v-model="detailData.remark" style="width: 150px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer  style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="saveSORoutingData()">保存</el-button>
        <el-button type="primary" @click="addModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
    <el-dialog title="可用机台" :close-on-click-modal="false" v-drag :visible.sync="routingModelFlag" width="800px">
      <el-container>
        <el-main style="width: 300px">
          <span  style="" >可选机台：</span>
          <el-table
            height="300px"
            :data="resourceList1"
            border
            @row-click="clickData2"
            highlight-current-row
            v-loading="dataListLoading"
            style="width: 100%">
            <el-table-column
              v-for="(item,index) in columnList2" :key="index"
              :sortable="item.columnSortable"
              :prop="item.columnProp"
              :header-align="item.headerAlign"
              :show-overflow-tooltip="item.showOverflowTooltip"
              :align="item.align"
              :fixed="item.fixed==''?false:item.fixed"
              :min-width="item.columnWidth"
              :label="item.columnLabel">
              <template slot-scope="scope">
                <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span>
                <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                                   style="width: 100px; height: 80px"/></span>
              </template>
            </el-table-column>
          </el-table>
        </el-main>
        <el-main style="width: 100px">
          <div style="margin-top: 100px">
            <el-button type="primary" @click="addResource()">添加机台>></el-button>
          </div>
          <div style="margin-top: 20px">
            <el-button type="primary" @click="deleteResource()">删除机台<<</el-button>
          </div>
        </el-main>
        <el-main style="width: 300px">
          <span  style="" >已选机台：</span>
          <el-table
            height="300px"
            :data="resourceList2"
            border
            @row-click="clickData3"
            highlight-current-row
            v-loading="dataListLoading"
            style="width: 100%">
            <el-table-column
              v-for="(item,index) in columnList3" :key="index"
              :sortable="item.columnSortable"
              :prop="item.columnProp"
              :header-align="item.headerAlign"
              :show-overflow-tooltip="item.showOverflowTooltip"
              :align="item.align"
              :fixed="item.fixed==''?false:item.fixed"
              :min-width="item.columnWidth"
              :label="item.columnLabel">
              <template slot-scope="scope">
                <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span>
                <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                                   style="width: 100px; height: 80px"/></span>
              </template>
            </el-table-column>
          </el-table>
        </el-main>
      </el-container>
    </el-dialog>
  </div>
</template>

<script>
  import Chooselist from '@/views/modules/common/Chooselist'
  import {
    getSORoutingData,
    saveSORoutingData,
    deleteSORoutingData,
    searchAllResource,
    searchSORoutingResource,
    addSORoutingResource,
    deleteSORoutingResource
  }from "@/api/base/site.js"
    export default {
      name: "updateProductRouting",
      components: {
        Chooselist
      },
      data () {
        return {
          searchData:{
            orderNo:'',
            partNo:'',
            partDesc:'',
            site:'',
            user:this.$store.state.user.name,
          },
          addInputFlag:'',
          tagNo:'',
          addModelFlag:false,
          height:350,
          dataList:[],
          resourceList1:[],
          resourceList2:[],
          dataListLoading:false,
          currentRow:null,
          currentRow2:null,
          currentRow3:null,
          columnList:[
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableItemNo',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "itemNo",
              headerAlign: "center",
              align: "right",
              columnLabel: "工序号",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 60
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableOperationDesc',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "operationDesc",
              headerAlign: "center",
              align: "left",
              columnLabel: "工序名称",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 300
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableWorkCenterNo',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "workCenterNo",
              headerAlign: "center",
              align: "left",
              columnLabel: "加工中心编码",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 100
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableWorkCenterDesc',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "workCenterDesc",
              headerAlign: "center",
              align: "left",
              columnLabel: "加工中心名称",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 100
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableMachSetupTime',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "machSetupTime",
              headerAlign: "center",
              align: "right",
              columnLabel: "准备时间(小时)",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 100
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableMachRunFactor',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "machRunFactor",
              headerAlign: "center",
              align: "right",
              columnLabel: "单位产出量",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 100
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableFactorUnit',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "factorUnit",
              headerAlign: "center",
              align: "left",
              columnLabel: "产出单位",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 100
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableTimeRequired',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "timeRequired",
              headerAlign: "center",
              align: "right",
              columnLabel: "需求时间",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 80
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableTimeReported',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "timeReported",
              headerAlign: "center",
              align: "right",
              columnLabel: "报告时间",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 80
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableEfficiency',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "efficiency",
              headerAlign: "center",
              align: "right",
              columnLabel: "效率(%)",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 80
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableRemark',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "remark",
              headerAlign: "center",
              align: "left",
              columnLabel: "备注",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 160
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableQtyRequired',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "qtyRequired",
              headerAlign: "center",
              align: "right",
              columnLabel: "需求数量",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 80
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableQtyReported',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "qtyReported",
              headerAlign: "center",
              align: "right",
              columnLabel: "计价单位",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 80
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableQtyApprove',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "qtyApprove",
              headerAlign: "center",
              align: "right",
              columnLabel: "合格数量",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 80
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TablePlanStartTime',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "planStartTime",
              headerAlign: "center",
              align: "left",
              columnLabel: "计划开工时间",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 140
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TablePlanFinishTime',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "planFinishTime",
              headerAlign: "center",
              align: "left",
              columnLabel: "计划完工时间",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 140
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableBarcodeID',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "barcodeID",
              headerAlign: "center",
              align: "left",
              columnLabel: "条形码",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 120
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableCrewsize',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "crewsize",
              headerAlign: "center",
              align: "left",
              columnLabel: "操作工人数",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 100
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableWXPartNo',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "wxPartNo",
              headerAlign: "center",
              align: "left",
              columnLabel: "费用结算料号",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 120
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099TableWXSpec',
              tableId: "6099Table",
              tableName: "维护工艺路线工序表",
              columnProp: "wxSpec",
              headerAlign: "center",
              align: "left",
              columnLabel: "费用结算物料名称/规格",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 250
            },


          ],
          detailData:{
            itemNo:'',
            operationDesc:'',
            workCenterNo:'',
            machSetupTime:'',
            machRunFactor:'',
            factorUnit:'单位/小时',
            planStartTime:'',
            planFinishTime:'',
            efficiency:'',
            crewsize:'',
            remark:'',
            site:'',
            partNo:'',
            add:'',
            user:'',
          },
          detailmodelInputFlag:false,
          routingModelFlag:false,
          columnList2:[
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099Table2ResourceID',
              tableId: "6099Table2",
              tableName: "维护工艺路线可用机台表",
              columnProp: "resourceID",
              headerAlign: "center",
              align: "left",
              columnLabel: "机台编码",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 70
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099Table2ResourceDesc',
              tableId: "6099Table2",
              tableName: "维护工艺路线可用机台表",
              columnProp: "resourceDesc",
              headerAlign: "center",
              align: "left",
              columnLabel: "机台名称",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 160
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099Table2Active',
              tableId: "6099Table2",
              tableName: "维护工艺路线可用机台表",
              columnProp: "active",
              headerAlign: "center",
              align: "left",
              columnLabel: "在用",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 50
            },
          ],
          columnList3:[
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099Table3ResourceID',
              tableId: "6099Table3",
              tableName: "维护工艺路线已选机台表",
              columnProp: "resourceID",
              headerAlign: "center",
              align: "left",
              columnLabel: "机台编码",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 70
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099Table3ResourceDesc',
              tableId: "6099Table3",
              tableName: "维护工艺路线已选机台表",
              columnProp: "resourceDesc",
              headerAlign: "center",
              align: "left",
              columnLabel: "机台名称",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 160
            },
            {
              userId: this.$store.state.user.name,
              functionId: 6099,
              serialNumber: '6099Table3Active',
              tableId: "6099Table3",
              tableName: "维护工艺路线已选机台表",
              columnProp: "active",
              headerAlign: "center",
              align: "left",
              columnLabel: "在用",
              columnHidden: false,
              columnImage: false,
              columnSortable: false,
              sortLv: 0,
              status: true,
              fixed: '',
              columnWidth: 50
            },
          ],
        }
      },
      mounted() {
      },
      watch: {
        '$route' (to, from) {
          // if(localStorage.getItem('calendar')!=undefined){
          //   this.jump();
          // }
        }
      },
      methods: {
        getBaseData(val){
          if (this.tagNo === 24){
            this.detailData.workCenterNo = val.WorkCenterNo
          }

        },
        // 获取基础数据列表
        getBaseList(val){
          this.tagNo = val
          this.$nextTick(() => {
            let strVal = "";
            if (val === 24){
              strVal = this.detailData.workCenterNo
            }
            this.$refs.baseList.init(val,strVal)
          })
        },
        init(searchData){
          //设置参数
          this.searchData = searchData;

          //调用方法
          this.getData();
        },
        getData(){
          getSORoutingData(this.searchData).then(({data}) => {
            this.dataList = data.rows;
            if(data.total==0){
              this.dataList =[];
            }
          })
        },
        clickData(row){
          this.currentRow = JSON.parse(JSON.stringify(row));
        },
        addModel(){
          this.detailData={
            itemNo:'',
            operationDesc:'',
            workCenterNo:'',
            machSetupTime:0,
            machRunFactor:1,
            factorUnit:'单位/小时',
            planStartTime:this.dayjs().format("YYYY-MM-DD HH:mm:ss"),
            planFinishTime:this.dayjs().format("YYYY-MM-DD HH:mm:ss"),
            efficiency:100,
            crewsize:1,
            remark:'',
            site:this.searchData.site,
            partNo:this.searchData.partNo,
            add:0,
            user:this.$store.state.user.name,
          };
          if(this.dataList===[]){
            this.detailData.itemNo=10;
          }else {
            this.detailData.itemNo=this.dataList[0].itemNo;
            for (let i = 0; i < this.dataList.length; i++) {
                if(this.detailData.itemNo<this.dataList[i].itemNo){
                  this.detailData.itemNo=this.dataList[i].itemNo
                }
            }
            this.detailData.itemNo+=10;
          }
          this.addInputFlag=false;
          this.addModelFlag=true;

        },
        updateModel(){
          if(this.currentRow==null){
            this.$alert('请选择工序', '错误', {
              confirmButtonText: '确定'
            })
            return false;
          }
          this.detailData={
            itemNo:this.currentRow.itemNo,
            operationDesc:this.currentRow.operationDesc,
            workCenterNo:this.currentRow.workCenterNo,
            machSetupTime:this.currentRow.machSetupTime,
            machRunFactor:this.currentRow.machRunFactor,
            factorUnit:this.currentRow.factorUnit,
            planStartTime:this.currentRow.planStartTime,
            planFinishTime:this.currentRow.planFinishTime,
            efficiency:this.currentRow.efficiency,
            crewsize:this.currentRow.crewsize,
            remark:this.currentRow.remark,
            site:this.currentRow.site,
            partNo:this.currentRow.partNo,
            add:1,
            user:this.$store.state.user.name,
          }
          this.addInputFlag=true;
          this.addModelFlag=true;
        },
        saveSORoutingData(){
          if(this.detailData.itemNo==''||this.detailData.itemNo==null){
            this.$alert("请输入工序号！",'错误',{
              confirmButtonText:'确定'
            })
            return false;
          }
          if(this.detailData.operationDesc==''||this.detailData.operationDesc==null){
            this.$alert("请输入工序名称！",'错误',{
              confirmButtonText:'确定'
            })
            return false;
          }
          if(this.detailData.machSetupTime===''||this.detailData.machSetupTime==null){
            this.$alert("请输入准备时间！",'错误',{
              confirmButtonText:'确定'
            })
            return false;
          }
          if(this.detailData.workCenterNo==''||this.detailData.workCenterNo==null){
            this.$alert("请输入加工中心编码！",'错误',{
              confirmButtonText:'确定'
            })
            return false;
          }
          if(this.detailData.crewsize===''||this.detailData.crewsize==null){
            this.$alert("请输入操作员人数！",'错误',{
              confirmButtonText:'确定'
            })
            return false;
          }
          if(this.detailData.efficiency===''||this.detailData.efficiency==null){
            this.$alert("请输入效率！",'错误',{
              confirmButtonText:'确定'
            })
            return false;
          }
          if(this.detailData.machRunFactor===''||this.detailData.machRunFactor==null){
            this.$alert("请输入单位产出量！",'错误',{
              confirmButtonText:'确定'
            })
            return false;
          }
          if(this.detailData.machRunFactor<=0){
            this.$alert("单位产出量必须大于0！",'错误',{
              confirmButtonText:'确定'
            })
            return false;
          }

          if(this.detailData.efficiency<=0){
            this.$alert("效率必须大于0！",'错误',{
              confirmButtonText:'确定'
            })
            return false;
          }
          let inData={
            itemNo:this.detailData.itemNo,
            operationDesc:this.detailData.operationDesc,
            workCenterNo:this.detailData.workCenterNo,
            machSetupTime:this.detailData.machSetupTime,
            machRunFactor:this.detailData.machRunFactor,
            factorUnit:this.detailData.factorUnit,
            planStartTime:this.detailData.planStartTime,
            planFinishTime:this.detailData.planFinishTime,
            efficiency:this.detailData.efficiency,
            crewsize:this.detailData.crewsize,
            remark:this.detailData.remark,
            site:this.detailData.site,
            partNo:this.detailData.partNo,
            orderNo:this.searchData.orderNo,
            add:this.detailData.add,
            user:this.$store.state.user.name,
          }
          saveSORoutingData(inData).then(({data}) => {
            this.currentRow=null;
            if (data && data.code == 200) {
              this.addModelFlag = false
              this.getData();
             this.$message.success('操作成功')
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        },
        deleteSORoutingData(){
          if(this.currentRow==null){
            this.$alert("请选择工序！", '错误', {
              confirmButtonText: '确定'
            })
            return false;
          }
          this.$confirm(`是否删除此工艺路线工序?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'

          }).then(() => {
            deleteSORoutingData(this.currentRow).then(({data}) => {
              this.currentRow=null;
              if (data && data.code == 200) {
                this.getData();
                this.$message.success('删除成功')
              } else {
                this.$alert(data.msg, '错误', {
                  confirmButtonText: '确定'
                })
              }
            })
          })
        },
        clickData3(row){
          this.currentRow3 = JSON.parse(JSON.stringify(row));
        },
        clickData2(row){
          this.currentRow2 = JSON.parse(JSON.stringify(row));
        },
        getResourceModel(){
          if(this.currentRow==null){
            this.$alert("请选择工艺路线工序！", '错误', {
              confirmButtonText: '确定'
            })
            return false;
          }
          let data1={
            site:this.searchData.site,
            workCenterNo:this.currentRow.workCenterNo,
          }
          searchAllResource(data1).then(({data}) => {
            this.resourceList1 = data.rows
          })
          let data2={
            site:this.searchData.site,
            orderNo:this.searchData.orderNo,
            itemNo:this.currentRow.itemNo
          }
          searchSORoutingResource(data2).then(({data}) => {
            this.resourceList2 = data.rows
          })
          this.routingModelFlag=true;
        },
        addResource(){
          if(this.currentRow2==null){
            this.$alert("请选择可选机台！", '错误', {
              confirmButtonText: '确定'
            })
            return false;
          }
          let inData={
            site: this.currentRow.site,
            orderNo:this.currentRow.orderNo,
            itemNo:this.currentRow.itemNo,
            resourceID:this.currentRow2.resourceID
          }
          addSORoutingResource(inData).then(({data}) => {

            if (data && data.code == 200) {
              let data2={
                site:this.searchData.site,
                orderNo:this.searchData.orderNo,
                itemNo:this.currentRow.itemNo
              }
              searchSORoutingResource(data2).then(({data}) => {
                this.resourceList2 = data.rows
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        },
        deleteResource(){
          if(this.currentRow3==null){
            this.$alert("请选择已选机台！", '错误', {
              confirmButtonText: '确定'
            })
            return false;
          }
          this.$confirm(`是否删除此机台?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'

          }).then(() => {
            let inData = {
              site: this.currentRow.site,
              orderNo:this.currentRow.orderNo,
              itemNo:this.currentRow.itemNo,
              resourceID: this.currentRow3.resourceID
            }
            deleteSORoutingResource(inData).then(({data}) => {
              if (data && data.code == 200) {
                this.currentRow3 = null;
                let data2={
                  site:this.searchData.site,
                  orderNo:this.searchData.orderNo,
                  itemNo:this.currentRow.itemNo
                }
                searchSORoutingResource(data2).then(({data}) => {
                  this.resourceList2 = data.rows
                })
              } else {
                this.$alert(data.msg, '错误', {
                  confirmButtonText: '确定'
                })
              }
            })
          })
        },
      },
      created() {

      }
    }
</script>

<style scoped>
  /*统一的input内容颜色样式*/
  .customer-input-color-red /deep/ .el-input__inner {
    color: red;
  }
</style>
