<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="任务编号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入任务编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="物料编码" prop="materialCode">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.materialCode"-->
      <!--          placeholder="请输入物料编码"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="输送带规格" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入输送带规格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择订单状态" clearable>
          <el-option
            v-for="dict in dict.type.order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="完成标识" prop="finishFlag">
        <el-select v-model="queryParams.finishFlag" placeholder="请选择完成标识" clearable>
          <el-option
            v-for="dict in dict.type.finish_flag"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="计划开始时间">
        <el-date-picker
          v-model="daterangeBeginDate"
          style="width: 340px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="下计划标识" prop="isRelease">
        <el-select v-model="queryParams.isRelease" placeholder="请选择下计划标识" clearable>
          <el-option
            v-for="dict in dict.type.is_release"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!--      <el-form-item label="工作中心" prop="workCenterCode">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.workCenterCode"-->
      <!--          placeholder="请输入工作中心"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="工艺路线" prop="routingCode">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.routingCode"-->
      <!--          placeholder="请输入工艺路线"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="primary"-->
      <!--          plain-->
      <!--          icon="el-icon-plus"-->
      <!--          size="mini"-->
      <!--          @click="handleAdd"-->
      <!--          v-hasPermi="['mes/prod:prodOrderInfo:add']"-->
      <!--        >新增-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mes/prod:prodOrderInfo:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleOrder"
          v-hasPermi="['mes/prod:prodOrderInfo:edit']"
        >同步订单
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          size="mini"
          :disabled="multiple"
          @click="handleSynchronizationPlan"
          v-hasPermi="['mes/prod:prodOrderInfo:edit']"
        >同步计划
        </el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="danger"-->
      <!--          plain-->
      <!--          icon="el-icon-delete"-->
      <!--          size="mini"-->
      <!--          :disabled="multiple"-->
      <!--          @click="handleDelete"-->
      <!--          v-hasPermi="['mes/prod:prodOrderInfo:remove']"-->
      <!--        >删除-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mes/prod:prodOrderInfo:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="prodOrderInfoList" @selection-change="handleSelectionChange"
              @sort-change="handleSortChange"
              :default-sort="{ prop: 'beginDate', order: 'descending' }"
    >
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键标识" align="center" prop="objId" v-if="columns[0].visible"/>
      <el-table-column label="任务编号" align="center" prop="orderCode" v-if="columns[1].visible" width="130" sortable="custom"/>
      <el-table-column label="销售任务编号" align="center" prop="saleOrderCode" v-if="columns[2].visible"/>
      <el-table-column label="销售订单行号" align="center" prop="saleOrderLineNumber" v-if="columns[3].visible"/>
      <el-table-column label="物料编码" align="center" prop="materialCode" v-if="columns[4].visible" width="100"/>
      <el-table-column label="输送带规格" align="center" prop="materialName" v-if="columns[5].visible" width="230"/>
      <el-table-column label="物料组" align="center" prop="matkl" v-if="columns[6].visible"/>
      <el-table-column label="BOM编号" align="center" prop="bomCode" v-if="columns[7].visible"/>
      <el-table-column label="订单计划数量" align="center" prop="orderAmount" v-if="columns[8].visible" width="100"/>
      <el-table-column label="完成数量" align="center" prop="completeAmount" v-if="columns[9].visible"/>
      <el-table-column label="订单类型" align="center" prop="orderType" v-if="columns[10].visible"/>
      <el-table-column label="订单状态" align="center" prop="orderStatus" v-if="columns[11].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_status" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="完成标识" align="center" prop="finishFlag" v-if="columns[12].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.finish_flag" :value="scope.row.finishFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="计划开始时间" align="center" prop="beginDate" width="180" v-if="columns[13].visible" sortable="custom">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划结束时间" align="center" prop="endDate" width="180" v-if="columns[14].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际开始时间" align="center" prop="realBeginDate" width="180" v-if="columns[15].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.realBeginDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际完成时间" align="center" prop="realEndDate" width="180" v-if="columns[16].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.realEndDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="工厂编号" align="center" prop="factoryCode" v-if="columns[17].visible"/>
      <el-table-column label="下计划标识" align="center" prop="isRelease" v-if="columns[18].visible" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_release" :value="scope.row.isRelease"/>
        </template>
      </el-table-column>
      <el-table-column label="工作中心" align="center" prop="workCenterCode" v-if="columns[19].visible"/>
      <el-table-column label="工艺路线" align="center" prop="routingCode" v-if="columns[20].visible"/>
      <el-table-column label="打印名称" align="center" prop="printName" v-if="columns[21].visible"/>
      <el-table-column label="预留标识" align="center" prop="isFlag" v-if="columns[22].visible"/>
      <el-table-column label="创建人" align="center" prop="createdBy" v-if="columns[23].visible"/>
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180" v-if="columns[24].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updatedBy" v-if="columns[25].visible"/>
      <el-table-column label="更新时间" align="center" prop="updatedTime" width="180" v-if="columns[26].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100" fixed="right">
        <template slot-scope="scope">
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-bottom"-->
          <!--            @click="handleReleasePlan(scope.row)"-->
          <!--          >订单下达-->
          <!--          </el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-right"
            @click="handlePlanDetails(scope.row)"
          >查看明细
          </el-button>
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-edit"-->
          <!--            @click="handleUpdate(scope.row)"-->
          <!--            v-hasPermi="['mes/prod:prodOrderInfo:edit']"-->
          <!--          >修改-->
          <!--          </el-button>-->
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-delete"-->
          <!--            @click="handleDelete(scope.row)"-->
          <!--            v-hasPermi="['mes/prod:prodOrderInfo:remove']"-->
          <!--          >删除-->
          <!--          </el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="任务编号" prop="orderCode">
          <el-input v-model="form.orderCode" placeholder="请输入任务编号"/>
        </el-form-item>
        <el-form-item label="物料编码" prop="materialCode">
          <el-input v-model="form.materialCode" placeholder="请输入物料编码"/>
        </el-form-item>
        <el-form-item label="输送带规格" prop="materialName">
          <el-input v-model="form.materialName" placeholder="请输入输送带规格"/>
        </el-form-item>
        <el-form-item label="物料组" prop="matkl">
          <el-input v-model="form.matkl" placeholder="请输入物料组"/>
        </el-form-item>
        <el-form-item label="BOM编号" prop="bomCode">
          <el-input v-model="form.bomCode" placeholder="请输入BOM编号"/>
        </el-form-item>
        <el-form-item label="订单计划数量" prop="orderAmount">
          <el-input v-model="form.orderAmount" placeholder="请输入订单计划数量"/>
        </el-form-item>
        <el-form-item label="完成数量" prop="completeAmount">
          <el-input v-model="form.completeAmount" placeholder="请输入完成数量"/>
        </el-form-item>
        <el-form-item label="订单类型" prop="orderType">
          <el-input v-model="form.orderType" placeholder="请输入订单类型"/>
        </el-form-item>
        <el-form-item label="订单状态" prop="orderStatus">
          <el-select v-model="form.orderStatus" placeholder="请选择订单状态">
            <el-option
              v-for="dict in dict.type.order_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="完成标识" prop="finishFlag">
          <el-radio-group v-model="form.finishFlag">
            <el-radio
              v-for="dict in dict.type.finish_flag"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="计划开始时间" prop="beginDate">
          <el-date-picker clearable
                          v-model="form.beginDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择计划开始时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="计划结束时间" prop="endDate">
          <el-date-picker clearable
                          v-model="form.endDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择计划结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="实际开始时间" prop="realBeginDate">
          <el-date-picker clearable
                          v-model="form.realBeginDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择实际开始时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="实际完成时间" prop="realEndDate">
          <el-date-picker clearable
                          v-model="form.realEndDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择实际完成时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="工厂编号" prop="factoryCode">
          <el-input v-model="form.factoryCode" placeholder="请输入工厂编号"/>
        </el-form-item>
        <el-form-item label="下计划标识" prop="isRelease">
          <el-radio-group v-model="form.isRelease">
            <el-radio
              v-for="dict in dict.type.is_release"
              :key="dict.value"
              :label="dict.value"
            >{{ dict.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="工作中心" prop="workCenterCode">
          <el-input v-model="form.workCenterCode" placeholder="请输入工作中心"/>
        </el-form-item>
        <el-form-item label="工艺路线" prop="routingCode">
          <el-input v-model="form.routingCode" placeholder="请输入工艺路线"/>
        </el-form-item>
        <el-form-item label="打印名称" prop="printName">
          <el-input v-model="form.printName" placeholder="请输入打印名称"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 下达计划对话框 -->
    <!--    <el-dialog :title="title" :visible.sync="releaseOpen" width="800px" append-to-body>-->
    <!--      <el-form ref="form" :model="form" :rules="rules" label-width="100px">-->
    <!--        <el-row :gutter="10">-->
    <!--          <el-col :span="12">-->
    <!--            <el-form-item label="任务编号" prop="orderCode">-->
    <!--              <el-input v-model="form.orderCode" disabled/>-->
    <!--            </el-form-item>-->
    <!--            <el-form-item label="物料编码" prop="materialCode">-->
    <!--              <el-input v-model="form.materialCode" disabled/>-->
    <!--            </el-form-item>-->
    <!--            <el-form-item label="计划开始时间" prop="beginDate">-->
    <!--              <el-date-picker clearable-->
    <!--                              v-model="form.beginDate"-->
    <!--                              type="date"-->
    <!--                              value-format="yyyy-MM-dd"-->
    <!--                              placeholder="请选择计划开始时间"-->
    <!--              >-->
    <!--              </el-date-picker>-->
    <!--            </el-form-item>-->
    <!--          </el-col>-->
    <!--          <el-col :span="12">-->
    <!--            <el-form-item label="订单计划数量" prop="orderAmount">-->
    <!--              <el-input v-model="form.orderAmount" placeholder="请输入订单计划数量" disabled/>-->
    <!--            </el-form-item>-->
    <!--            <el-form-item label="输送带规格" prop="materialName">-->
    <!--              <el-input v-model="form.materialName" disabled/>-->
    <!--            </el-form-item>-->
    <!--            <el-form-item label="计划结束时间" prop="endDate">-->
    <!--              <el-date-picker clearable-->
    <!--                              v-model="form.endDate"-->
    <!--                              type="date"-->
    <!--                              value-format="yyyy-MM-dd"-->
    <!--                              placeholder="请选择计划结束时间"-->
    <!--              >-->
    <!--              </el-date-picker>-->
    <!--            </el-form-item>-->
    <!--          </el-col>-->
    <!--        </el-row>-->
    <!--        <el-form-item label="选择BOM" prop="bomCode">-->
    <!--          <el-input v-model="form.bomCode" placeholder="请输入BOM编号"/>-->
    <!--        </el-form-item>-->

    <!--      </el-form>-->
    <!--      <div slot="footer" class="dialog-footer">-->
    <!--        <el-button type="primary" @click="submitReleaseForm">下 达</el-button>-->
    <!--        <el-button @click="cancel">取 消</el-button>-->
    <!--      </div>-->
    <!--    </el-dialog>-->

    <!-- 同步ERP订单信息对话框 -->
    <el-dialog :title="title" :visible.sync="orderOpen" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="订单编号" prop="orderCode">
          <el-input v-model="form.orderCode" placeholder="请输入任务编号"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="orderSubmitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listProdOrderInfo,
  getProdOrderInfo,
  delProdOrderInfo,
  addProdOrderInfo,
  updateProdOrderInfo, getERPProductionPlan, getERPWorkOrder
} from '@/api/mes/prod/prodOrderInfo'
import router from '@//router'

export default {
  name: 'ProdOrderInfo',
  dicts: ['finish_flag', 'order_status', 'is_release'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单信息表格数据
      prodOrderInfoList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      orderOpen: false,
      // 是否显示下达计划弹出层
      // releaseOpen: false,
      // 更新时间时间范围
      daterangeBeginDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'beginDate',
        isAsc: 'desc' ,
        orderCode: null,
        saleOrderCode: null,
        saleOrderLineNumber: null,
        materialCode: null,
        materialName: null,
        matkl: null,
        bomCode: null,
        orderAmount: null,
        completeAmount: null,
        orderType: null,
        orderStatus: null,
        finishFlag: null,
        beginDate: null,
        endDate: null,
        realBeginDate: null,
        realEndDate: null,
        factoryCode: null,
        isRelease: null,
        workCenterCode: null,
        routingCode: null,
        printName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        objId: [
          { required: true, message: '主键标识不能为空', trigger: 'blur' }
        ]
      },
      columns: [
        { key: 0, label: `主键标识`, visible: false },
        { key: 1, label: `任务编号`, visible: true },
        { key: 2, label: `销售任务编号`, visible: false },
        { key: 3, label: `销售订单行号`, visible: false },
        { key: 4, label: `物料编码`, visible: false },
        { key: 5, label: `输送带规格`, visible: true },
        { key: 6, label: `物料组`, visible: false },
        { key: 7, label: `BOM编号`, visible: false },
        { key: 8, label: `订单计划数量`, visible: true },
        { key: 9, label: `完成数量`, visible: true },
        { key: 10, label: `订单类型`, visible: false },
        { key: 11, label: `订单状态`, visible: true },
        { key: 12, label: `完成标识`, visible: true },
        { key: 13, label: `计划开始时间`, visible: true },
        { key: 14, label: `计划结束时间`, visible: true },
        { key: 15, label: `实际开始时间`, visible: true },
        { key: 16, label: `实际完成时间`, visible: true },
        { key: 17, label: `工厂编号`, visible: true },
        { key: 18, label: `下计划标识`, visible: true },
        { key: 19, label: `工作中心`, visible: false },
        { key: 20, label: `工艺路线`, visible: false },
        { key: 21, label: `打印名称`, visible: false },
        { key: 22, label: `预留标识`, visible: false },
        { key: 23, label: `创建人`, visible: false },
        { key: 24, label: `创建时间`, visible: false },
        { key: 25, label: `更新人`, visible: false },
        { key: 26, label: `更新时间`, visible: false }
      ]
    }
  },
  created() {
    if (this.$route.params != null) {
      this.queryParams.params = this.$route.params
    }
    this.getList()
  },
  methods: {
    /** 查询订单信息列表 */
    getList() {
      this.loading = true
      this.queryParams.params = {}
      if (null != this.daterangeBeginDate && '' != this.daterangeBeginDate) {
        this.queryParams.params['beginBeginDate'] = this.daterangeBeginDate[0]
        this.queryParams.params['endBeginDate'] = this.daterangeBeginDate[1]
      }
      listProdOrderInfo(this.queryParams).then(response => {
        this.prodOrderInfoList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 下达计划 */
    handleReleasePlan(row) {
      const objId = row.objId
      const orderCode = row.orderCode
      const params = { queryParams: this.queryParams }
      this.$tab.closeOpenPage(router.currentRoute)
      this.$tab.openPage('订单[' + orderCode + ']下达', '/mes/release-order/index/' + objId, {})
    },
    handleSortChange({ column, prop, order }) {
      this.queryParams = {
        ...this.queryParams,
        orderByColumn: prop || 'beginDate',
        isAsc: order === 'ascending' ? 'asc' : 'desc'
      }
      this.getList() // 重新获取数据
    },
    /** 查看明细 */
    handlePlanDetails(row) {
      const params = { orderCode: row.orderCode }
      // this.$tab.closeOpenPage(router.currentRoute);
      this.$tab.openPage('任务[' + row.orderCode + ']订单明细', '/mes/prodOrder-detail/index/' + row.orderCode, {})
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.releaseOpen = false
      this.orderOpen = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        objId: null,
        orderCode: null,
        saleOrderCode: null,
        saleOrderLineNumber: null,
        materialCode: null,
        materialName: null,
        matkl: null,
        bomCode: null,
        orderAmount: null,
        completeAmount: null,
        orderType: null,
        orderStatus: null,
        finishFlag: null,
        beginDate: null,
        endDate: null,
        realBeginDate: null,
        realEndDate: null,
        factoryCode: null,
        isRelease: null,
        workCenterCode: null,
        routingCode: null,
        printName: null,
        isFlag: null,
        createdBy: null,
        createdTime: null,
        updatedBy: null,
        updatedTime: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeBeginDate = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.objId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加订单信息'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const objId = row.objId || this.ids
      getProdOrderInfo(objId).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改订单信息'
      })
    },
    /** 同步ERP订单按钮操作 */
    handleOrder() {
      this.reset()
      this.orderOpen = true
      this.title = '同步ERP订单信息'
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.objId != null) {
            updateProdOrderInfo(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addProdOrderInfo(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 提交按钮 */
    orderSubmitForm() {
      getERPWorkOrder(this.form.orderCode).then(response => {
        this.$modal.msgSuccess('同步订单成功')
        this.orderOpen = false
        this.getList()
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const objIds = row.objId || this.ids
      this.$modal.confirm('是否确认删除订单信息编号为"' + objIds + '"的数据项？').then(function() {
        return delProdOrderInfo(objIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    handleSynchronizationPlan(row) {
      const objIds = row.objId || this.ids
      this.$modal.confirm('是否确认同步订单为"' + objIds + '"的数据项？').then(function() {
        return getERPProductionPlan(objIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('同步成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('mes/prod/prodOrderInfo/export', {
        ...this.queryParams
      }, `prodOrderInfo_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
