<!--
 * @Author: zwq
 * @Date: 2021-11-18 14:16:25
 * @LastEditors: zwq
 * @LastEditTime: 2023-04-10 15:25:32
 * @Description:
-->
<template>
  <div class="baseDialog">
  <el-dialog
    :fullscreen="true"
    :before-close="cancle"
    :visible.sync="visible"
  >
      <template #title>
        <slot name="title">
          <div class="titleStyle">{{ !productId ? '新增' : '修改' }}</div>
        </slot>
      </template>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-steps :active="active" align-center finish-status="success" process-status="finish">
          <el-step title="基础信息"></el-step>
          <el-step title="工艺流程"></el-step>
          <el-step title="产品特性"></el-step>
          <el-step title="控制特性"></el-step>
        </el-steps>
      </div>
      <div>
        <one-step
          v-if="oneStepVisible"
          ref="oneStepRef"
          :product-id="productId"
          @nextStep="nextStep"
          @setPrductId="setPrductId"
          @setInspectionStage="setInspectionStage"
        ></one-step>
        <two-step
          v-if="twoStepVisible"
          ref="twoStepRef"
          :product-id="productId"
          @nextStep="nextStep"
        ></two-step>
        <three-step
          v-if="threeStepVisible"
          ref="threeStepRef"
          :product-id="productId"
          @nextStep="nextStep"
        ></three-step>
        <four-step
          v-if="fourStepVisible"
          ref="fourStepRef"
          :product-id="productId"
          :inspection-stage-arr="inspectionStageArr"
          @nextStep="nextStep"
        ></four-step>
      </div>
    </el-card>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancle">取消</el-button>
      <el-button @click="preStep" v-show="active > 0" :disabled="submitBtn">上一步</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :loading="submitBtn">{{
        active >= 3 ? "确定" : "下一步"
      }}</el-button>
    </span>
  </el-dialog>
  </div>
</template>

<script>
import oneStep from "./productList-one";
import twoStep from "./productList-two";
import threeStep from "./productList-three";
import fourStep from "./productList-four";

export default {
  data() {
    return {
      visible: false,
      active: 0,
      productId: "",
      dataForm: {},
      inspectionStageArr: [], //检验阶段
      submitBtn: false,
      oneStepVisible: false,
      twoStepVisible: false,
      threeStepVisible: false,
      fourStepVisible: false,
      stepShowObj: ["oneStepVisible", "twoStepVisible", "threeStepVisible", "fourStepVisible"],
      stepArr: ["oneStepRef", "twoStepRef", "threeStepRef", "fourStepRef"],
    };
  },
  components: {
    oneStep,
    twoStep,
    threeStep,
    fourStep,
  },
  methods: {
    init(id) {
      this.productId = id || "";
      this.active = 0;
      this.oneStepVisible = true;
      this.$nextTick(() => {
        this.$refs.oneStepRef.init(id);
      });
      this.submitBtn = false;
      this.visible = true;
    },
    // 表单提交
    dataFormSubmit() {
      if (this.active >= 3) {
        this.active += 1;
        this.submitBtn = true;
        this[this.stepShowObj[0]] = false;
        this[this.stepShowObj[1]] = false;
        this[this.stepShowObj[2]] = false;
        this[this.stepShowObj[3]] = false;
        this.visible = false;
        this.$emit("successSubmit");
      } else {
        this.$refs[this.stepArr[this.active]].dataFormSubmit();
      }
    },
    nextStep() {
      this[this.stepShowObj[this.active]] = false;
      this.active += 1;
      this[this.stepShowObj[this.active]] = true;
      this.$nextTick(() => {
        this.$refs[this.stepArr[this.active]].init();
      });
    },
    preStep() {
      this[this.stepShowObj[this.active]] = false;
      this.active -= 1;
      this[this.stepShowObj[this.active]] = true;
      this.$nextTick(() => {
        this.$refs[this.stepArr[this.active]].init();
      });
    },
    cancle() {
      this[this.stepShowObj[0]] = false;
      this[this.stepShowObj[1]] = false;
      this[this.stepShowObj[2]] = false;
      this[this.stepShowObj[3]] = false;
      this.visible = false;
      this.$emit("successSubmit");
    },
    setPrductId(id) {
      this.productId = id;
    },
    setInspectionStage(arr) {
      this.inspectionStageArr = arr;
    },
  },
};
</script>

<style>
.aui-card--fill .el-card__header {
  height: 90px;
}
</style>

<style>
.baseDialog .el-dialog__header {
  font-size: 16px;
  color: rgba(0, 0, 0, 0.85);
  font-weight: 500;
  padding: 13px 24px;
  border-bottom: 1px solid #e9e9e9;
}
.baseDialog .el-dialog__header .titleStyle::before{
  content: '';
  display: inline-block;
  width: 4px;
  height: 16px;
  background-color: #0B58FF;
  border-radius: 1px;
  margin-right: 8px;
  position: relative;
  top: 2px;
}
.baseDialog .el-dialog__body {
  padding-left: 24px;
  padding-right: 24px;
}
</style>
