<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="生产令号" prop="fHbytSclh">
        <el-input
          v-model="queryParams.fHbytSclh"
          placeholder="请输入生产令号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称" prop="fProductName">
        <el-input
          v-model="queryParams.fProductName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品编码" prop="fproductidFnumber">
        <el-input
          v-model="queryParams.fproductidFnumber"
          placeholder="请输入产品编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产订单数量" prop="fMOQty">
        <el-input
          v-model="queryParams.fMOQty"
          placeholder="请输入生产订单数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工序编号" prop="fOperNumber">
        <el-input
          v-model="queryParams.fOperNumber"
          placeholder="请输入工序编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作中心" prop="fworkcenteridFname">
        <el-input
          v-model="queryParams.fworkcenteridFname"
          placeholder="请输入工作中心"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工艺名称" prop="fprocessidFname">
        <el-input
          v-model="queryParams.fprocessidFname"
          placeholder="请输入工艺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工序描述" prop="fOperDescription">
        <el-input
          v-model="queryParams.fOperDescription"
          placeholder="请输入工序描述"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工序控制码" prop="fOptCtrlCodeidFname">
        <el-input
          v-model="queryParams.fOptCtrlCodeidFname"
          placeholder="请输入工序控制码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工序数量" prop="fOperQty">
        <el-input
          v-model="queryParams.fOperQty"
          placeholder="请输入工序数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工序计划开始时间" prop="fOperPlanStartTime">
        <el-date-picker clearable
                        v-model="queryParams.fOperPlanStartTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择工序计划开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="工序计划结束时间" prop="fOperPlanFinishTime">
        <el-date-picker clearable
                        v-model="queryParams.fOperPlanFinishTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择工序计划结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="计划开始时间" prop="fPlanStartTime">
        <el-date-picker clearable
                        v-model="queryParams.fPlanStartTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择计划开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="计划结束时间" prop="fPlanFinishTime">
        <el-date-picker clearable
                        v-model="queryParams.fPlanFinishTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择计划结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="材质" prop="fmaterialidFnumber">
        <el-input
          v-model="queryParams.fmaterialidFnumber"
          placeholder="请输入材质"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="子项单位" prop="funitid2ChildFname">
        <el-input
          v-model="queryParams.funitid2ChildFname"
          placeholder="请输入子项单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="父级物料编码" prop="fmaterialFnumber">
        <el-input
          v-model="queryParams.fmaterialFnumber"
          placeholder="请输入父级物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="子项物料名称" prop="fMaterialName1">
        <el-input
          v-model="queryParams.fMaterialName1"
          placeholder="请输入子项物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="子项物料编码" prop="fMaterialid2ChildFnumber">
        <el-input
          v-model="queryParams.fMaterialid2ChildFnumber"
          placeholder="请输入子项物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分子" prop="fNumerator">
        <el-input
          v-model="queryParams.fNumerator"
          placeholder="请输入分子"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分母" prop="fDenominator">
        <el-input
          v-model="queryParams.fDenominator"
          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="['system:routeTwo: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="['system:routeTwo: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="['system:routeTwo: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="['system:routeTwo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="routeTwoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" v-if="true"/>
      <el-table-column label="生产令号" align="center" prop="fhbytSclh" />
      <el-table-column label="产品名称" align="center" prop="fproductName" />
      <el-table-column label="产品编码" align="center" prop="fproductidFnumber" />
      <el-table-column label="生产订单数量" align="center" prop="fMOQty" />
      <el-table-column label="工序编号" align="center" prop="foperNumber" />
      <el-table-column label="工作中心" align="center" prop="fworkcenteridFname" />
      <el-table-column label="工艺名称" align="center" prop="fprocessidFname" />
      <el-table-column label="工序描述" align="center" prop="foperDescription" />
      <el-table-column label="工序控制码" align="center" prop="fOptCtrlCodeidFname" />
      <el-table-column label="工序数量" align="center" prop="foperQty" />
      <el-table-column label="工序计划开始时间" align="center" prop="foperPlanStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fOperPlanStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="工序计划结束时间" align="center" prop="foperPlanFinishTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fOperPlanFinishTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划开始时间" align="center" prop="fplanStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fPlanStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划结束时间" align="center" prop="fplanFinishTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fPlanFinishTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="材质" align="center" prop="fmaterialidFnumber" />
      <el-table-column label="子项单位" align="center" prop="funitid2ChildFname" />
      <el-table-column label="父级物料编码" align="center" prop="fmaterialFnumber" />
      <el-table-column label="子项物料名称" align="center" prop="fMaterialName1" />
      <el-table-column label="子项物料编码" align="center" prop="fmaterialid2ChildFnumber" />
      <el-table-column label="分子" align="center" prop="fNumerator" />
      <el-table-column label="分母" align="center" prop="fDenominator" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:routeTwo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:routeTwo: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-drawer title="计划详情" :visible.sync="drawer" :with-header="false" direction="rtl" size="50%">

      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span class="card-title">采购</span>
        </div>

        <el-table style="width: 100%;" max-height="300" v-loading="figureSaveLoading" :data="figureSaveList">
          <el-table-column label="生产名称" align="center" prop="drawingName" />
          <el-table-column label="材质" align="center" prop="fmaterialidFnumber" />
          <el-table-column label="子项单位" align="center" prop="funitid2ChildFname" />
          <el-table-column label="父级物料编码" align="center" prop="fmaterialFnumber" />
          <el-table-column label="子项物料名称" align="center" prop="fMaterialName1" />
          <el-table-column label="子项物料编码" align="center" prop="fMaterialid2ChildFnumber" />
          <el-table-column label="分子" align="center" prop="fNumerator" />
          <el-table-column label="分母" align="center" prop="fDenominator" />
          <!-- 操作列 -->
          <!-- <el-table-column prop="operation" label="操作" width="200px"> </el-table-column> -->
          <!-- 进度列 -->
          <!-- <el-table-column prop="operation" label="进度" width="300px"> </el-table-column> -->
        </el-table>
      </el-card>
    </el-drawer>
    <!-- 添加或修改工艺生产用表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="生产令号" prop="fHbytSclh">
          <el-input v-model="form.fHbytSclh" placeholder="请输入生产令号" />
        </el-form-item>
        <el-form-item label="产品名称" prop="fProductName">
          <el-input v-model="form.fProductName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="产品编码" prop="fproductidFnumber">
          <el-input v-model="form.fproductidFnumber" placeholder="请输入产品编码" />
        </el-form-item>
        <el-form-item label="生产订单数量" prop="fMOQty">
          <el-input v-model="form.fMOQty" placeholder="请输入生产订单数量" />
        </el-form-item>
        <el-form-item label="工序编号" prop="fOperNumber">
          <el-input v-model="form.fOperNumber" placeholder="请输入工序编号" />
        </el-form-item>
        <el-form-item label="工作中心" prop="fworkcenteridFname">
          <el-input v-model="form.fworkcenteridFname" placeholder="请输入工作中心" />
        </el-form-item>
        <el-form-item label="工艺名称" prop="fprocessidFname">
          <el-input v-model="form.fprocessidFname" placeholder="请输入工艺名称" />
        </el-form-item>
        <el-form-item label="工序描述" prop="fOperDescription">
          <el-input v-model="form.fOperDescription" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="工序控制码" prop="fOptCtrlCodeidFname">
          <el-input v-model="form.fOptCtrlCodeidFname" placeholder="请输入工序控制码" />
        </el-form-item>
        <el-form-item label="工序数量" prop="fOperQty">
          <el-input v-model="form.fOperQty" placeholder="请输入工序数量" />
        </el-form-item>
        <el-form-item label="工序计划开始时间" prop="fOperPlanStartTime">
          <el-date-picker clearable
                          v-model="form.fOperPlanStartTime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择工序计划开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="工序计划结束时间" prop="fOperPlanFinishTime">
          <el-date-picker clearable
                          v-model="form.fOperPlanFinishTime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择工序计划结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="计划开始时间" prop="fPlanStartTime">
          <el-date-picker clearable
                          v-model="form.fPlanStartTime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择计划开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="计划结束时间" prop="fPlanFinishTime">
          <el-date-picker clearable
                          v-model="form.fPlanFinishTime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择计划结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="材质" prop="fmaterialidFnumber">
          <el-input v-model="form.fmaterialidFnumber" placeholder="请输入材质" />
        </el-form-item>
        <el-form-item label="子项单位" prop="funitid2ChildFname">
          <el-input v-model="form.funitid2ChildFname" placeholder="请输入子项单位" />
        </el-form-item>
        <el-form-item label="父级物料编码" prop="fmaterialFnumber">
          <el-input v-model="form.fmaterialFnumber" placeholder="请输入父级物料编码" />
        </el-form-item>
        <el-form-item label="子项物料名称" prop="fMaterialName1">
          <el-input v-model="form.fMaterialName1" placeholder="请输入子项物料名称" />
        </el-form-item>
        <el-form-item label="子项物料编码" prop="fMaterialid2ChildFnumber">
          <el-input v-model="form.fMaterialid2ChildFnumber" placeholder="请输入子项物料编码" />
        </el-form-item>
        <el-form-item label="分子" prop="fNumerator">
          <el-input v-model="form.fNumerator" placeholder="请输入分子" />
        </el-form-item>
        <el-form-item label="分母" prop="fDenominator">
          <el-input v-model="form.fDenominator" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRouteTwo, getRouteTwo, delRouteTwo, addRouteTwo, updateRouteTwo } from "@/api/system/routeTwo";

export default {
  name: "RouteTwo",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工艺生产用表表格数据
      routeTwoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fHbytSclh: undefined,
        fProductName: undefined,
        fproductidFnumber: undefined,
        fMOQty: undefined,
        fOperNumber: undefined,
        fworkcenteridFname: undefined,
        fprocessidFname: undefined,
        fOperDescription: undefined,
        fOptCtrlCodeidFname: undefined,
        fOperQty: undefined,
        fOperPlanStartTime: undefined,
        fOperPlanFinishTime: undefined,
        fPlanStartTime: undefined,
        fPlanFinishTime: undefined,
        fmaterialidFnumber: undefined,
        funitid2ChildFname: undefined,
        fmaterialFnumber: undefined,
        fMaterialName1: undefined,
        fMaterialid2ChildFnumber: undefined,
        fNumerator: undefined,
        fDenominator: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        fHbytSclh: [
          { required: true, message: "生产令号不能为空", trigger: "blur" }
        ],
        fProductName: [
          { required: true, message: "产品名称不能为空", trigger: "blur" }
        ],
        fproductidFnumber: [
          { required: true, message: "产品编码不能为空", trigger: "blur" }
        ],
        fMOQty: [
          { required: true, message: "生产订单数量不能为空", trigger: "blur" }
        ],
        fOperNumber: [
          { required: true, message: "工序编号不能为空", trigger: "blur" }
        ],
        fworkcenteridFname: [
          { required: true, message: "工作中心不能为空", trigger: "blur" }
        ],
        fprocessidFname: [
          { required: true, message: "工艺名称不能为空", trigger: "blur" }
        ],
        fOperDescription: [
          { required: true, message: "工序描述不能为空", trigger: "blur" }
        ],
        fOptCtrlCodeidFname: [
          { required: true, message: "工序控制码不能为空", trigger: "blur" }
        ],
        fOperQty: [
          { required: true, message: "工序数量不能为空", trigger: "blur" }
        ],
        fOperPlanStartTime: [
          { required: true, message: "工序计划开始时间不能为空", trigger: "blur" }
        ],
        fOperPlanFinishTime: [
          { required: true, message: "工序计划结束时间不能为空", trigger: "blur" }
        ],
        fPlanStartTime: [
          { required: true, message: "计划开始时间不能为空", trigger: "blur" }
        ],
        fPlanFinishTime: [
          { required: true, message: "计划结束时间不能为空", trigger: "blur" }
        ],
        fmaterialidFnumber: [
          { required: true, message: "材质不能为空", trigger: "blur" }
        ],
        funitid2ChildFname: [
          { required: true, message: "子项单位不能为空", trigger: "blur" }
        ],
        fmaterialFnumber: [
          { required: true, message: "父级物料编码不能为空", trigger: "blur" }
        ],
        fMaterialName1: [
          { required: true, message: "子项物料名称不能为空", trigger: "blur" }
        ],
        fMaterialid2ChildFnumber: [
          { required: true, message: "子项物料编码不能为空", trigger: "blur" }
        ],
        fNumerator: [
          { required: true, message: "分子不能为空", trigger: "blur" }
        ],
        fDenominator: [
          { required: true, message: "分母不能为空", trigger: "blur" }
        ],
        createBy: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询工艺生产用表列表 */
    getList() {
      this.loading = true;
      listRouteTwo(this.queryParams).then(response => {
        this.routeTwoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        fHbytSclh: undefined,
        fProductName: undefined,
        fproductidFnumber: undefined,
        fMOQty: undefined,
        fOperNumber: undefined,
        fworkcenteridFname: undefined,
        fprocessidFname: undefined,
        fOperDescription: undefined,
        fOptCtrlCodeidFname: undefined,
        fOperQty: undefined,
        fOperPlanStartTime: undefined,
        fOperPlanFinishTime: undefined,
        fPlanStartTime: undefined,
        fPlanFinishTime: undefined,
        fmaterialidFnumber: undefined,
        funitid2ChildFname: undefined,
        fmaterialFnumber: undefined,
        fMaterialName1: undefined,
        fMaterialid2ChildFnumber: undefined,
        fNumerator: undefined,
        fDenominator: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加工艺生产用表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getRouteTwo(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改工艺生产用表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateRouteTwo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addRouteTwo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除工艺生产用表编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delRouteTwo(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/routeTwo/export', {
        ...this.queryParams
      }, `routeTwo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
