<template>
  <div>
    <!-- 海运流程图 -->
    <el-scrollbar :vertical="true" style="width: 100%;" viewClass="shipping-chart">
      <div v-for="(nodes,index) in chartData['sea']" :key="index" class="chart-nodes">
        <div class="node-area">
          <div v-for="node in nodes" :key="node.title" @click="nodeClick(node)" class="node-div">
            <template v-if="!node.unNode">
              <img :src="node.imgSrc" alt="">
              <p>{{node.title}}</p>
            </template>
            <template v-else-if="node.unNode">
              <el-button type="primary" @click="nodeClick(node)" style="width:100px;">{{node.title}}</el-button>
            </template>
          </div>
        </div>
        <div class="arrow-area" v-if="index !== (chartData['sea'].length-1)">
          <img src="@/assets/images/shipping/jt-start.png" alt="">
        </div>
      </div>
    </el-scrollbar>

    <!-- 弹窗 -->
    <el-dialog custom-class="shipping-dialog" :title="dialogConfig.title" :visible.sync="dialogConfig.dialogVisible" :width="dialogConfig.width" :fullscreen="dialogConfig.fullscreen" :close-on-click-modal=false :modal-append-to-body=false append-to-body destroy-on-close>
      <component v-bind:is="currentComponent" @closeDialog="closeDialog"></component>
    </el-dialog>
  </div>
</template>

<script>
import bookingWidget from "./nodePage/booking.vue";
import trailerWidget from "./nodePage/trailer.vue";
import preinstallWidget from "./nodePage/preinstall.vue";
import agentWidget from "./nodePage/agent.vue";
import cabinetWidget from "./nodePage/cabinet/index.vue";
import cusDeclarationWidget from "./nodePage/cusDeclaration.vue";
import shipWidget from "./nodePage/ship.vue";
import subMaterialWidget from "./nodePage/subMaterial.vue";
import bargeWidget from "./nodePage/barge.vue";
import departureWidget from "./nodePage/departure.vue";
import blCopyWidget from "./nodePage/blCopy.vue";
import clrDocumentWidget from "./nodePage/clrDocument.vue";
import arrivalWidget from "./nodePage/arrival.vue";
import cusClearanceWidget from "./nodePage/cusClearance.vue";
import unloadingWidget from "./nodePage/unloading/index.vue";

/**
 * 海运流程图
 */
export default {
  name: "shippingChart",
  components: {
    bookingWidget,
    trailerWidget,
    preinstallWidget,
    agentWidget,
    cabinetWidget,
    cusDeclarationWidget,
    shipWidget,
    subMaterialWidget,
    bargeWidget,
    departureWidget,
    blCopyWidget,
    clrDocumentWidget,
    arrivalWidget,
    cusClearanceWidget,
    unloadingWidget,
  },
  props: {
    shippingType: String,
    boxId: String,
  },
  data() {
    return {
      // 弹窗配置
      dialogConfig: {
        dialogVisible: false,
        title: "",
        width: "",
        fullscreen: false,
      },
      // 流程图节点
      chartData: {
        sea: [
          [
            {
              title: "订舱",
              imgSrc: require("@/assets/images/shipping/dc-start.png"),
              type: "booking",
            },
          ],
          [
            {
              title: "预装",
              imgSrc: require("@/assets/images/shipping/yz-start.png"),
              type: "preinstall",
            },
            {
              title: "拖车",
              imgSrc: require("@/assets/images/shipping/tc-start.png"),
              type: "trailer",
            },
            {
              unNode: true,
              type: "agent",
              title: "AGENT",
            },
          ],
          [
            {
              title: "装柜",
              imgSrc: require("@/assets/images/shipping/zg-start.png"),
              type: "cabinet",
            },
          ],
          [
            {
              title: "报关",
              imgSrc: require("@/assets/images/shipping/bg-start.png"),
              type: "cusDeclaration",
            },
            {
              title: "配船",
              imgSrc: require("@/assets/images/shipping/pc-start.png"),
              type: "ship",
            },
            {
              title: "提单材料",
              imgSrc: require("@/assets/images/shipping/tdcl-start.png"),
              type: "subMaterial",
            },
          ],
          [
            {
              title: "驳船",
              imgSrc: require("@/assets/images/shipping/bc-start.png"),
              type: "barge",
            },
          ],
          [
            {
              title: "起运",
              imgSrc: require("@/assets/images/shipping/qy-start.png"),
              type: "departure",
            },
          ],
          [
            /* {
              title: "清关文件",
              imgSrc: require("@/assets/images/shipping/qg-start.png"),
              type: "clearanceDocument",
            }, */
            {
              unNode: true,
              type: "blCopy",
              title: "提单Copy",
            },
            {
              unNode: true,
              type: "clrDocument",
              title: "清关文件",
            },
          ],
          [
            {
              title: "到港",
              imgSrc: require("@/assets/images/shipping/dg-start.png"),
              type: "arrival",
            },
          ],
          [
            {
              title: "清关",
              imgSrc: require("@/assets/images/shipping/qg-start.png"),
              type: "cusClearance",
            },
          ],
          [
            {
              title: "卸柜",
              imgSrc: require("@/assets/images/shipping/xg-start.png"),
              type: "unloading",
            },
          ],
          [
            {
              title: "结算",
              imgSrc: require("@/assets/images/shipping/js-start.png"),
              type: "settlement",
            },
          ],
        ],
      },
      // 当前组件
      currentComponent: "",
    };
  },
  methods: {
    /** 关闭弹窗 */
    closeDialog() {
      this.$set(this.dialogConfig, "dialogVisible", false);
    },
    /** 节点点击 */
    nodeClick(node) {
      this.currentComponent = `${node.type}Widget`;
      this.$set(this.dialogConfig, "width", "500px");
      this.$set(this.dialogConfig, "title", node.title);
      this.$set(this.dialogConfig, "fullscreen", false);
      switch (node.type) {
        // 订舱
        case "booking":
        // 驳船
        case "barge":
        // 清关文件
        case "clrDocument":
          this.$set(this.dialogConfig, "width", "700px");
          break;
        // AGENT
        case "agent":
          this.$set(this.dialogConfig, "title", "代理商设置");
          break;
        // 预装
        case "preinstall":
          this.$set(this.dialogConfig, "fullscreen", true);
          this.$set(this.dialogConfig, "title", "出货安排（预装）");
          break;
      }
      this.$set(this.dialogConfig, "dialogVisible", true);
    },
  },
};
</script>

<style lang="scss">
.shipping-chart {
  width: max-content;
  display: flex;
  justify-content: center;
  padding: 10px;
  .chart-nodes {
    display: flex;
    align-items: center;
    justify-content: center;
    .node-area {
      display: flex;
      flex-direction: column;
      align-items: center;

      .node-div {
        margin-top: 10px;
        cursor: pointer;
        p {
          margin-top: -10px;
          margin-bottom: 0px;
          text-align: center;
        }
      }
    }
    .arrow-area {
      margin: 0 10px;
    }
  }
}
</style>
