<template>
  <div class="app-container">
    <el-card class="topCard">
      <span style="font-size: 1rem">订单号：</span>
      <el-input v-model="order" size="small" clearable style="width: 200px" />
      <span style="font-size: 1rem;margin-left: 15px">生产日期：</span>
      <el-date-picker v-model="orderStartDate" :clearable="false" size="small" type="daterange" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 220px" @change="getTable" />
      <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 15px" @click="getTable">查询订单</el-button>
      <el-button type="primary" size="small" icon="el-icon-add" style="margin-left: 15px" @click="orderAdd">新增订单</el-button>
      <div class="topDiv" style="margin-top: 10px;">
        <span style="margin-left: 10px">随车单版本号：</span>
        <el-tag size="medium" type="success">{{ currentCarCardVersion }}</el-tag>
        <el-button type="primary" plain size="small" icon="el-icon-edit" style="margin-left: 5px" @click="editCarCardVersion()">修改</el-button>
        <span style="margin-left: 20px">发布日期：</span>
        <el-tag size="medium" type="warning">{{ currentPublishDate }}</el-tag>
        <el-button type="primary" plain size="small" icon="el-icon-edit" style="margin-left: 5px" @click="editPublishDate()">修改</el-button>
      </div>
      <div style="margin-top: 5px">
        <el-table
          :data="orderCompletion_table1"
          :header-cell-style="{ background: '#F5F5F5', fontSize: '24px' }"
          :expand-row-keys="expandsDetail"
          :row-key="getRowKeys"
          style="width: 90%; border: 1px solid #9e9b9b"
          border
          height="690px"
          tooltip-effect="dark"
          @expand-change="selectPlan"
        >
          <el-table-column align="center" type="expand" label="" fixed width="35">
            <template slot-scope="scope" >
              <div style="margin: 5px 10px;width: 1000px;z-index: 99;">
                <el-table
                  :data="tableDataPrintDetail"
                  :header-cell-style="{ background: '#e5e7f8', color: '#606266' }"
                  element-loading-text="数据加载中"
                  element-loading-spinner="el-icon-loading"
                  element-loading-background="rgba(0, 0, 0, 0.2)"
                  class="main"
                  tooltip-effect="dark"
                  style="width: 800px;z-index: 99;"
                  max-height="400px"
                  border
                  size="mini">
                  <el-table-column type="index" align="center" label="序号" width="80px"/>
                  <el-table-column align="center" label="产品编号">
                    <template slot-scope="scope">
                      {{ scope.row.发动机流水号 }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" label="电池仓码">
                    <template slot-scope="scope">
                      {{ scope.row.电池仓编号 }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" label="物料版本">
                    <template slot-scope="scope">
                      {{ scope.row.版本号 }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" label="上线时间" width="150px">
                    <template slot-scope="scope">
                      {{ scope.row.上线时间 ? scope.row.上线时间 : '' }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" label="下线时间" width="150px">
                    <template slot-scope="scope">
                      {{ scope.row.下线时间 ? scope.row.下线时间 : '' }}
                    </template>
                  </el-table-column>
                  <el-table-column align="center" label="状态" width="100px">
                    <template slot-scope="scope">
                      <el-tag v-if="scope.row.执行状态 === 2" type="warning" size="mini">生产中</el-tag>
                      <el-tag v-else-if="scope.row.执行状态 === 3" type="success" size="mini">已下线</el-tag>
                      <el-tag v-else-if="scope.row.执行状态 === 4" type="danger" size="mini">已拆解</el-tag>
                      <el-tag v-else-if="scope.row.执行状态 === 5" type="danger" size="mini">拉出中</el-tag>
                      <el-tag v-else-if="scope.row.执行状态 === 6" type="danger" size="mini">返修中</el-tag>
                      <el-tag v-else type="info" size="mini">未上线</el-tag>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </template>
          </el-table-column>
          <el-table-column type="index" align="center" label="序号" width="80px" />
          <el-table-column align="center" label="订单号" >
            <template slot-scope="scope">
              {{ scope.row.订单号 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="产品型号" width="100">
            <template slot-scope="scope">
              {{ scope.row.机型号 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="计划数量" width="100">
            <template slot-scope="scope">
              {{ scope.row.数量 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="生产日期" width="100">
            <template slot-scope="scope">
              {{ scope.row.上线日期 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="上线数量" width="80">
            <template slot-scope="scope">
              {{ scope.row.上线数量 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="下线数量" width="80">
            <template slot-scope="scope">
              {{ scope.row.下线数量 }}
            </template>
          </el-table-column>
          <!--          <el-table-column align="center" label="整机产品代码" width="100">-->
          <!--            <template slot-scope="scope">-->
          <!--              {{ scope.row.产品代码 }}-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <!--          <el-table-column align="center" label="整机配置代码" width="100">-->
          <!--            <template slot-scope="scope">-->
          <!--              {{ scope.row.配置代码 }}-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <el-table-column align="center" label="开发阶段" width="100">
            <template slot-scope="scope">
              {{ scope.row.开发阶段代码 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="电池仓产品代码" width="120">
            <template slot-scope="scope">
              {{ scope.row.电池材料代码 }}{{ scope.row.电量代码 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="产品代码" width="110">
            <template slot-scope="scope">
              {{ scope.row.产品代码 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="国家地区" width="80">
            <template slot-scope="scope">
              {{ scope.row.国家地区代码 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="智驾配置" width="80">
            <template slot-scope="scope">
              {{ scope.row.智驾配置代码 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="生产基地" width="80">
            <template slot-scope="scope">
              {{ scope.row.生产基地代码 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="状态" width="100">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.下发状态 === 0" size="mini" type="info">未下发</el-tag>
              <el-tag v-if="scope.row.下发状态 === 1 && scope.row.上线状态 !== 1" size="mini" type="primary">已下发</el-tag>
              <el-tag v-if="scope.row.下发状态 === 1 && scope.row.上线状态 === 1" size="mini" type="warning">生产中</el-tag>
              <el-tag v-if="scope.row.下发状态 === 1 && scope.row.上线状态 === 1 && scope.row.完工状态 === 1" size="mini" type="success">已完成</el-tag>
            </template>
          </el-table-column>
          <el-table-column align="center" label="操作" width="200">
            <template slot-scope="scope">
              <el-button v-if="scope.row.下发状态 === 0" type="text" size="mini" icon="el-icon-bottom" title="订单下发" style="font-size: 1rem" @click="orderWork(scope.row, 1)"/>
              <el-button v-if="scope.row.下发状态 === 1" :disabled="scope.row.上线状态 === 1" icon="el-icon-top" type="text" title="取消下发" size="mini" style="font-size: 1rem" @click="orderWork(scope.row, 0)"/>
              <el-button :disabled="parseInt(scope.row.下线数量) === 0" type="text" icon="el-icon-finish" size="mini" title="订单完工" style="font-size: 1rem;color: #00893d" @click="choose(scope.row)"/>
              <el-button :disabled="scope.row.下发状态 === 1" type="text" size="mini" icon="el-icon-edit" style="font-size: 1rem" title="编辑" @click="orderEdit(scope.row)"/>
              <el-button :disabled="scope.row.下发状态 === 1" type="text" size="mini" icon="el-icon-delete" style="font-size: 1rem;color: #ff0000" title="删除" @click="orderDeleteSubmit(scope.row)"/>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <!--    新增订单 -->
    <el-dialog :visible.sync="orderAddDialogVisible" :append-to-body="true" title="新增订单" center width="800px">
      <el-form ref="orderAddForm" :model="orderAddForm" :rules="orderAddRules" label-position="center" label-width="110px" class="demo-ruleForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="订单号" prop="orderCode">
              <el-input v-model="orderAddForm.orderCode" size="small" clearable style="width:200px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品型号" prop="EngineType">
              <el-select v-model="orderAddForm.EngineTypeID" size="small" placeholder="请选择产品型号" style="width: 200px;">
                <el-option
                  v-for="item in engineTypes"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生产数量" prop="orderCount">
              <el-input-number v-model="orderAddForm.orderCount" :min="1" :step="1" size="small" style="width:200px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产日期" prop="orderDate">
              <el-date-picker v-model="orderAddForm.orderDate" :clearable="false" type="date" size="small" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width:200px"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">其他信息</el-divider>
        <el-row>
          <el-col :span="7">
            <el-form-item label="电池材料" prop="materialType" >
              <el-select v-model="orderAddForm.materialType" size="small" placeholder="请选择电池材料" style="width: 150px;">
                <el-option
                  v-for="item in materialTypes"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="电量" prop="electricityType">
              <el-select v-model="orderAddForm.electricityType" size="small" placeholder="请选择电量" style="width: 150px;">
                <el-option
                  v-for="item in electricityTypes"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="开发阶段" prop="developType">
              <el-select v-model="orderAddForm.developType" size="small" placeholder="请选择开发阶段" style="width: 150px;">
                <el-option
                  v-for="item in developTypes"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">VIM码配置</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="产品代码" prop="productType">
              <el-select v-model="orderAddForm.productType" size="small" filterable allow-create default-first-option placeholder="请选择或输入(8位)" style="width: 200px;">
                <el-option label="CG1B6555" value="CG1B6555"/>
                <el-option label="CG1B6220" value="CG1B6220"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="国家地区" prop="vimCountry">
              <el-select v-model="orderAddForm.vimCountry" size="small" placeholder="请选择国家地区" style="width: 200px;">
                <el-option v-for="item in countryOptions" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="智驾配置" prop="vimDriveConfig">
              <el-select v-model="orderAddForm.vimDriveConfig" size="small" placeholder="请选择智驾配置" style="width: 200px;">
                <el-option v-for="item in driveConfigOptions" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产基地" prop="vimFactory">
              <el-select v-model="orderAddForm.vimFactory" size="small" placeholder="请选择生产基地" style="width: 200px;">
                <el-option v-for="item in factoryOptions" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="orderAddCancel('orderAddForm')">取消</el-button>
        <el-button type="primary" size="small" @click="orderAddSubmit('orderAddForm')">确定</el-button>
      </div>
    </el-dialog>
    <!--    编辑订单 -->
    <el-dialog :visible.sync="orderEditDialogVisible" :append-to-body="true" title="编辑订单" center width="800px">
      <el-form ref="orderEditForm" :model="orderEditForm" :rules="orderEditRules" label-position="center" label-width="110px" class="demo-ruleForm">
        <el-row>
          <el-col :span="12">
            <el-form-item label="订单号" prop="orderCode">
              <el-input v-model="orderEditForm.orderCode" size="small" disabled style="width:200px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品型号" prop="EngineType">
              <el-select v-model="orderEditForm.EngineTypeID" size="small" disabled placeholder="请选择产品型号" style="width: 200px;">
                <el-option v-for="item in engineTypes" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="生产数量" prop="orderCount">
              <el-input-number v-model="orderEditForm.orderCount" :min="1" :step="1" size="small" style="width:200px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产日期" prop="orderDate">
              <el-date-picker v-model="orderEditForm.orderDate" :clearable="false" type="date" size="small" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width:200px"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">VIM码配置</el-divider>
        <el-row>
          <el-col :span="12">
            <el-form-item label="产品代码">
              <el-select v-model="orderEditForm.productType" size="small" filterable allow-create default-first-option placeholder="请选择或输入(8位)" style="width: 200px;">
                <el-option label="CG1B6555" value="CG1B6555"/>
                <el-option label="CG1B6220" value="CG1B6220"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="国家地区">
              <el-select v-model="orderEditForm.vimCountry" size="small" placeholder="请选择国家地区" style="width: 200px;">
                <el-option v-for="item in countryOptions" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="智驾配置">
              <el-select v-model="orderEditForm.vimDriveConfig" size="small" placeholder="请选择智驾配置" style="width: 200px;">
                <el-option v-for="item in driveConfigOptions" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产基地">
              <el-select v-model="orderEditForm.vimFactory" size="small" placeholder="请选择生产基地" style="width: 200px;">
                <el-option v-for="item in factoryOptions" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="orderEditCancel('orderEditForm')">取消</el-button>
        <el-button type="primary" size="small" @click="orderEditSubmit('orderEditForm')">确定</el-button>
      </div>
    </el-dialog>
    <!-- 编辑随车单版本号对话框 -->
    <el-dialog :visible.sync="editCarCardVersionDialogVisible" title="编辑随车单版本号" center width="400px">
      <el-form ref="carCardVersionForm" :model="carCardVersionForm" :rules="carCardVersionRules" label-width="120px">
        <el-form-item label="随车单版本号:" prop="newVersion">
          <el-input v-model="carCardVersionForm.newVersion" placeholder="请输入新版本号" clearable size="small">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="editCarCardVersionDialogVisible = false">取消</el-button>
        <el-button type="primary" size="small" @click="submitCarCardVersionUpdate">确定</el-button>
      </div>
    </el-dialog>
    <!-- 编辑发布日期对话框 -->
    <el-dialog :visible.sync="editPublishDateDialogVisible" title="编辑发布日期" center width="400px">
      <el-form ref="publishDateForm" :model="publishDateForm" :rules="publishDateRules" label-width="100px">
        <el-form-item label="发布日期:" prop="newDate">
          <el-date-picker v-model="publishDateForm.newDate" type="date" placeholder="请选择发布日期" 
            format="yyyy-MM-dd" value-format="yyyy-MM-dd" size="small" style="width: 200px">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="editPublishDateDialogVisible = false">取消</el-button>
        <el-button type="primary" size="small" @click="submitPublishDateUpdate">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getNowTime2 } from '@/utils/tool'
export default {
  data() {
    return {
      orderAddDialogVisible: false,
      orderEditDialogVisible: false,
      orderAddRules: {
        orderCode: [{ required: true, message: '请输入订单号', trigger: 'blur' }],
        EngineType: [{ required: true, message: '请选择产品型号', trigger: 'change' }],
        orderCount: [{ required: true, message: '请输入计划数量', trigger: 'blur' }],
        orderDate: [{ required: true, message: '请选择生产日期', trigger: 'blur' }],
        productType: [{ required: true, message: '请选择或输入产品代码(8位)', trigger: 'change' }],
        vimCountry: [{ required: true, message: '请选择国家地区', trigger: 'change' }],
        vimDriveConfig: [{ required: true, message: '请选择智驾配置', trigger: 'change' }],
        vimFactory: [{ required: true, message: '请选择生产基地', trigger: 'change' }],
        developType: [{ required: true, message: '请选择开发阶段', trigger: 'change' }],
        materialType: [{ required: true, message: '请选择电池材料', trigger: 'change' }],
        electricityType: [{ required: true, message: '请选择电量', trigger: 'change' }]
      },
      orderAddForm: {
        orderCode: '',
        orderDate: '',
        EngineType: '',
        EngineTypeID: '',
        orderCount: '',
        productType: '',
        configType: '',
        developType: '',
        materialType: '',
        electricityType: '',
        developType1: '',
        vimCountry: '',
        vimDriveConfig: '',
        vimFactory: ''
      },
      orderEditRules: {
        orderCount: [{ required: true, message: '请输入计划数量', trigger: 'blur' }],
        orderDate: [{ required: true, message: '请选择生产日期', trigger: 'blur' }]
      },
      orderEditForm: {
        orderCode: '',
        orderCount: '',
        orderDate: '',
        EngineTypeID: '',
        productType: '',
        vimCountry: '',
        vimDriveConfig: '',
        vimFactory: ''
      },
      productTypes: [],
      configTypes: [],
      developTypes: [],
      materialTypes: [],
      electricityTypes: [],
      engineTypes: [],
      countryOptions: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').map(c => ({ label: c, value: c })),
      driveConfigOptions: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').map(c => ({ label: c, value: c })),
      factoryOptions: 'ABCDEFGHJKLMNPQRSTUVWXYZ'.split('').map(c => ({ label: c, value: c })),
      engineType: '',
      checked: false,
      Type: [{ label: '', value: '' }],
      count: true,
      order: '',
      orderStartDate: [],
      intdex: true,
      xianshou: '',
      expandsDetail: [],
      orderCompletion_table1: [],
      tableDataPrintDetail: [],
      PersonaSex: [],
      jixingName: [],
      Sex: [],
      title: '',
      publication: {
        topic: '',
        qos: 0,
        payload: ''
      },
      dialogFormVisible1: false,
      form1: {
        订单号: '',
        产品型号: '',
        零件号: '',
        计划数量: '',
        完成数量: '',
        计划时间: '',
        状态: ''
      },
      rules: {
        排序: [{ required: true, message: '序号为空', trigger: 'change' }],
        订单号: [{ required: true, message: '订单号为空', trigger: 'change' }],
        产品机型: [{ required: true, message: '产品机型为空', trigger: 'change' }],
        零件号: [{ required: true, message: '机型代码为空', trigger: 'change' }],
        计划数量: [{ required: true, message: '计划数量为空', trigger: 'change' }],
        完成数量: [{ required: true, message: '完成数量为空', trigger: 'change' }],
        计划时间: [{ required: true, message: '计划时间为空', trigger: 'change' }],
        状态: [{ required: true, message: '状态为空', trigger: 'change' }]
      },
      editCarCardVersionDialogVisible: false,
      carCardVersionForm: {
        newVersion: ''
      },
      carCardVersionRules: {
        newVersion: [{ required: true, message: '请输入新版本号', trigger: 'blur' }]
      },
      editPublishDateDialogVisible: false,
      publishDateForm: {
        newDate: ''
      },
      publishDateRules: {
        newDate: [{ required: true, message: '请选择发布日期', trigger: 'blur' }]
      },
      currentCarCardVersion: '',
      currentPublishDate: ''
    }
  },
  created() {
    this.orderStartDate = [getNowTime2(), getNowTime2()]
    this.getEelectricityType()
    this.getMaterialType()
    this.getDevelopType()
    this.getConfigType()
    this.getProductType()
    this.getEngineType()
    this.getVersionInfo()
  },
  mounted() {
    this.getTable()
  },
  methods: {
    getProductType() {
      const param = []
      this.productTypes = []
      const Data = this.CreateData('11', 'CATL_基础_整机_产品代码_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.productTypes.push({
            label: response.data[i]['产品名称'],
            value: response.data[i]['产品代码']
          })
        }
      })
    },
    getConfigType() {
      const param = []
      this.configTypes = []
      const Data = this.CreateData('11', 'CATL_基础_整机_配置代码_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.configTypes.push({
            label: response.data[i]['配置名称'],
            value: response.data[i]['配置代码']
          })
        }
      })
    },
    getDevelopType() {
      const param = []
      this.developTypes = []
      const Data = this.CreateData('11', 'CATL_基础_整机_开发阶段_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.developTypes.push({
            label: response.data[i]['开发阶段名称'],
            value: response.data[i]['开发阶段代码']
          })
        }
      })
    },
    getMaterialType() {
      const param = []
      this.materialTypes = []
      const Data = this.CreateData('11', 'CATL_基础_电池仓_电池材料_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.materialTypes.push({
            label: response.data[i]['电池材料名称'],
            value: response.data[i]['电池材料代码']
          })
        }
      })
    },
    getEelectricityType() {
      const param = []
      this.electricityTypes = []
      const Data = this.CreateData('11', 'CATL_基础_电池仓_电量_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.electricityTypes.push({
            label: response.data[i]['电量'],
            value: response.data[i]['电量']
          })
        }
      })
    },
    getEngineType() {
      const param = []
      this.engineTypes = []
      const Data = this.CreateData('11', 'CATL_基础信息_机型信息_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.engineTypes.push({
            label: response.data[i]['机型号'],
            value: response.data[i]['机型ID']
          })
        }
        console.log(this.engineTypes)
        this.engineType = response.data[0]['机型ID']
      })
    },
    // 订单下发
    orderWork(row, flag) {
      let msg = ``
      let msg1 = ``
      if (flag === 1) {
        msg = `是否下发订单：【${row.订单号}】`
        msg1 = `下发订单`
      }
      if (flag === 0) {
        msg = `是否取消下发订单：【${row.订单号}】`
        msg1 = `取消下发`
      }
      this.$confirm(msg, msg1, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const param = []
        param[0] = ['订单号', row.订单号]
        param[1] = ['下发标识', flag]
        const Data = this.CreateData('11', 'CATL_生产计划_计划下发', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data.length > 0) {
            if (response.data[0]['ErrMessage'] === '') {
              if (flag === 1) {
                this.$message.success('订单下发成功！')
              }
              if (flag === 0) {
                this.$message.success('取消下发成功！')
              }
            } else {
              this.$message.error(response.data[0]['ErrMessage'])
            }
            this.getTable()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作！'
        })
      })
    },
    orderAdd() {
      this.orderAddForm.orderCode = ''
      this.orderAddForm.EngineType = this.engineTypes[0]['label']
      this.orderAddForm.EngineTypeID = this.engineTypes[0]['value']
      this.orderAddForm.orderCount = 1
      this.orderAddForm.orderDate = getNowTime2()
      this.orderAddForm.productType = 'CG1B6555'
      this.orderAddForm.vimCountry = 'C'
      this.orderAddForm.vimDriveConfig = 'A'
      this.orderAddForm.vimFactory = 'A'
      this.orderAddDialogVisible = true
    },
    // 新增订单提交
    orderAddSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const param = []
          param[0] = ['订单号', this.orderAddForm.orderCode]
          param[1] = ['上线日期', this.orderAddForm.orderDate]
          param[2] = ['机型ID', this.orderAddForm.EngineTypeID]
          param[3] = ['机型号', this.orderAddForm.EngineType]
          param[4] = ['数量', this.orderAddForm.orderCount]
          param[5] = ['创建人', this.$store.state.user.name]
          param[6] = ['产品代码', this.orderAddForm.productType]
          param[7] = ['配置代码', this.orderAddForm.configType]
          param[8] = ['开发阶段', this.orderAddForm.developType]
          param[9] = ['电池材料', this.orderAddForm.materialType]
          param[10] = ['电量', this.orderAddForm.electricityType]
          param[11] = ['开发阶段1', this.orderAddForm.developType1]
          param[12] = ['国家地区代码', this.orderAddForm.vimCountry]
          param[13] = ['智驾配置代码', this.orderAddForm.vimDriveConfig]
          param[14] = ['生产基地代码', this.orderAddForm.vimFactory]
          const Data = this.CreateData('11', 'CATL_生产计划_增加', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data.length > 0) {
              if (response.data[0].result === 1) {
                this.$message.success(response.data[0]['msg'])
                this.orderAddDialogVisible = false
                this.getTable()
              } else {
                this.$message.error(response.data[0]['msg'])
              }
            } else {
              this.$message.error('新增订单失败！')
            }
          })
        }
      })
    },
    //  新增订单取消
    orderAddCancel(formName) {
      if (this.$refs[formName] !== undefined) {
        this.$refs[formName].resetFields()
      }
      this.orderAddDialogVisible = false
    },
    orderEdit(row) {
      this.orderEditForm.orderCode = row.订单号
      this.orderEditForm.EngineType = row.机型号
      this.orderEditForm.EngineTypeID = row.机型ID
      this.orderEditForm.orderCount = row.数量
      this.orderEditForm.orderDate = row.上线日期
      this.orderEditForm.productType = row.产品代码 || 'CG1B6555'
      this.orderEditForm.vimCountry = row.国家地区代码 || 'C'
      this.orderEditForm.vimDriveConfig = row.智驾配置代码 || 'A'
      this.orderEditForm.vimFactory = row.生产基地代码 || 'A'
      this.orderEditDialogVisible = true
    },
    // 编辑订单提交
    orderEditSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const param = []
          param[0] = ['订单号', this.orderEditForm.orderCode]
          param[1] = ['上线日期', this.orderEditForm.orderDate]
          param[2] = ['数量', this.orderEditForm.orderCount]
          param[3] = ['上线序号', 1]
          param[4] = ['操作者', this.$store.state.user.name]
          param[5] = ['产品代码', this.orderEditForm.productType]
          param[6] = ['国家地区代码', this.orderEditForm.vimCountry]
          param[7] = ['智驾配置代码', this.orderEditForm.vimDriveConfig]
          param[8] = ['生产基地代码', this.orderEditForm.vimFactory]
          const Data = this.CreateData('11', 'CATL_生产计划_修改', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data.length > 0) {
              if (response.data[0].result === 1) {
                this.$message.success(response.data[0]['msg'])
                this.orderEditDialogVisible = false
                this.getTable()
              } else {
                this.$message.error(response.data[0]['msg'])
              }
            } else {
              this.$message.error('修改订单失败！')
            }
          })
        }
      })
    },
    //  编辑订单取消
    orderEditCancel(formName) {
      if (this.$refs[formName] !== undefined) {
        this.$refs[formName].resetFields()
      }
      this.orderEditDialogVisible = false
    },
    // 删除订单提交
    orderDeleteSubmit(row) {
      this.$confirm('此操作将永久删除该订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const param = []
        param[0] = ['订单号', row.订单号]
        const Data = this.CreateData('11', 'CATL_生产计划_删除', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data.length > 0) {
            if (response.data[0].result === 1) {
              this.$message.success(response.data[0]['msg'])
              this.getTable()
            } else {
              this.$message.error(response.data[0]['msg'])
            }
          } else {
            this.$message.error('修改订单失败！')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    tableRowClassName({ row }) {
      if (row.上线状态 === 1) {
        return 'success-row'
      }
    },
    getQualityData(row) {
      const param = []
      param[0] = ['工位号', this.$store.state.station.stationName]
      param[1] = ['发动机号', row.发动机号]
      const Data = this.CreateData('11', '测量数据合格_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.qualityData = response.data
      })
    },
    changeRadio() {
      if (this.checked) {
        this.intdex = false
        if (this.xianshou === 1) {
          this.count = true
        }
      } else if (!this.checked) {
        this.intdex = true
        if (this.xianshou === 1) {
          this.count = false
        }
      }
    },
    cancel() {
      this.dialogFormVisible1 = false
    },
    confirm11(form) {
      const param = []
      param[0] = ['工位号', this.$store.state.station.stationName]
      param[1] = ['订单号', this.form1.订单号]
      const Data2 = this.CreateData('12', '测量数据工位_监控系统_订单号_增加', param)
      this.ExecDatabase(Data2).then(response => {
        if (response.data[0].result === '1') {
          this.$notify.success({
            title: '提示',
            message: '订单选择成功！',
            position: 'bottom-right',
            offset: 170
          })
        } else {
          this.$message.error('订单选择失败')
        }
        this.getTable()
      })
      // this.publication.topic = window.g.mqttPublishTopic
      // this.publication.payload  = 'WEB|SetMoby|' + this.$store.state.station.stationName + '|' + '1'
      // const result = window.g.mqttClient.doPublish(this.publication)
      // if (result === true) {
      //   this.$notify.success({
      //     title: '提示',
      //     message: '订单增加传递成功！',
      //     position: 'bottom-right',
      //     offset: 170
      //   })
      // } else {
      //   this.$notify.error({
      //     title: '提示',
      //     message: '订单增加传递失败！',
      //     position: 'bottom-right',
      //     offset: 170
      //   })
      // }
      this.dialogFormVisible1 = false
    },
    getTable() {
      this.orderCompletion_table1 = []
      const param = []
      param[0] = ['订单号', this.order]
      param[1] = ['上线日期', this.orderStartDate[0]]
      param[2] = ['上线日期1', this.orderStartDate[1]]
      const Data = this.CreateData('11', 'CATL_生产计划_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.orderCompletion_table1 = response.data
      })
    },
    // 获取展开列的工单号
    getRowKeys(row) {
      return row.订单号
    },
    // 控制展开列
    selectPlan(row, expandedRows) {
      if (expandedRows.length) {
        this.expandsDetail = []
        if (row) {
          this.tableDataPrintDetail = []
          var param = []
          param[0] = ['订单号', row.订单号]
          var Data = this.CreateData('11', 'CATL_生产计划_执行计划_查询', param)
          this.ExecDatabase(Data).then(response => {
            console.log(response.data)
            if (response.data.length !== 0) {
              this.tableDataPrintDetail = response.data
            }
            this.expandsDetail.push(row.订单号)
          })
        }
      } else {
        this.expandsDetail = []
      }
    },
    choose(row) {
      if (this.qualityData) {
        this.qualityData = []
      }
      this.getQualityData(row)
      this.dialogFormVisible1 = true
    },
    editCarCardVersion() {
      this.carCardVersionForm.newVersion = this.currentCarCardVersion
      this.editCarCardVersionDialogVisible = true
    },
    submitCarCardVersionUpdate() {
      this.$refs['carCardVersionForm'].validate((valid) => {
        if (valid) {
          const param = []
          param[0] = ['值', this.carCardVersionForm.newVersion]
          param[1] = ['type', '随车单版本']
          const Data = this.CreateData('12', '电子看板_装配零件_选择版本号_修改', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data.length > 0) {
              if (response.data[0].result === '1') {
                this.$message.success('随车单版本号修改成功！')
                this.editCarCardVersionDialogVisible = false
                this.getVersionInfo()
              } else {
                this.$message.error('随车单版本号修改失败！')
              }
            } else {
              this.$message.error('随车单版本号修改失败！')
            }
          })
        }
      })
    },
    editPublishDate() {
      this.publishDateForm.newDate = this.currentPublishDate
      this.editPublishDateDialogVisible = true
    },
    submitPublishDateUpdate() {
      this.$refs['publishDateForm'].validate((valid) => {
        if (valid) {
          const param = []
          param[0] = ['值', this.publishDateForm.newDate]
          param[1] = ['type', '发布日期']
          const Data = this.CreateData('12', '电子看板_装配零件_选择版本号_修改', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data.length > 0) {
              if (response.data[0].result === '1') {
                this.$message.success('发布日期修改成功！')
                this.editPublishDateDialogVisible = false
                this.getVersionInfo()
              } else {
                this.$message.error('发布日期修改失败！')
              }
            } else {
              this.$message.error('发布日期修改失败！')
            }
          })
        }
      })
    },
    getVersionInfo() {
      const param = []
      const Data = this.CreateData('11', '电子看板_装配零件_选择版本号_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data && response.data.length > 0) {
          this.currentCarCardVersion = response.data[0].随车单版本号 || ''
          this.currentPublishDate = response.data[0].发布日期 || ''
        }
      })
    }
  }
}
</script>

<style scoped>
::v-deep.el-table .success-row {
  background-color: #7fe1e9;
}

.topCard {
  margin: 5px;
}

.topDiv {
  margin-bottom: 10px;
}

::v-deep.el-input.is-disabled .el-input__inner {
  color: #606266 !important;
}

::v-deep.el-input.is-disabled .el-input__inner {
  background-color: white !important;
}
</style>

