<template>
  <div class="container">
    <nav-tab :nav-list="navBarOptions" />
    <detail-header @click="goInsureState = true" :det="headerInfo" />
    <div class="det-body">
      <card title="保险计划" :option="['查看详情']" @option-click="openIframePupop(4)">
        <cr-radio-btn v-model="formData.planValue" :radio-data="planOptions" />
        <compactCellGroup :cell-data="planCellData" :text-bold="true" />
        <plan-tip :tip-list="planTipOptions" />
      </card>
      <div id="det_insure">
        <insure-person-form v-model="formData" :radio-options="personFormOptions" />
        <auto-deduct
          v-model="formData.auto"
          :cell-data="autoCellInfo"
          @cell-click="openIframePupop"
        />
        <protocol-read
          v-model="formData.pact"
          :cell-data="noticeCellData"
          @cell-click="openIframePupop"
        />
      </div>
      <card class="intro" id="det_intro">
        <cr-image
          :src="item"
          v-for="(item, index) in introImg"
          :key="index"
          width="100%"
          height="auto"
        />
      </card>
      <cps-case :case-data="caseInfo" />
      <div id="det_process">
        <cps-process :process-data="processDetail" @click="openIframePupop(5)" />
      </div>
      <cps-qa :qa-data="qaInfo" />
    </div>
    <detail-footer :company-info="companyInfo" />
    <copyright />
    <good-action @click="goInsureState = true" @leftClick="showLayer = true" />
    <popup-with-iframe
      v-model="popupShow"
      :title="pupopData.title"
      :content="pupopData.content"
      :url="pupopData.url"
    >
      <cps-process-detail v-if="currentPupopIndex === 5" :process-data="processDetail" />
      <cps-rate v-if="currentPupopIndex === 6" />
    </popup-with-iframe>
    <record-layer v-model="showLayer" desc="敬请期待" />
    <go-insure-dialog v-model="goInsureState" />
  </div>
</template>

<script>
import CrRadioBtn from "@/components/CrRadioBtn";
import Card from "@/components/Card";
import Copyright from "@/components/Copyright";
import GoodAction from "@/components/GoodAction";
import RecordLayer from "@/components/RecordLayer";
import Collapse from "@/components/Collapse";

import DetailHeader from "./modules/DetailHeader";
import DetailFooter from "./modules/DetailFooter";
import CompactCellGroup from "@/components/CompactCellGroup";
import CpsCase from "./modules/CpsCase";
import CpsProcess from "./modules/CpsProcess";
import CpsQa from "./modules/CpsQA";
import PopupWithIframe from "@/components/PopupWithIframe";
import GoInsureDialog from "./modules/GoInsureDialog";
import CpsProcessDetail from "./modules/CpsProcessDetail";
import CpsRate from "./modules/CpsRate";
import PlanTip from "./modules/PlanTip";
import InsurePersonForm from "./modules/InsurePersonForm";
import AutoDeduct from "./modules/AutoDeduct";
import ProtocolRead from "./modules/ProtocolRead";
import NavTab from "./modules/NavTab";

import Detail from "@/api/detail.huataizhongjixian";

export default {
  name: "GoodsDetail",
  components: {
    DetailHeader,
    DetailFooter,
    CompactCellGroup,
    CrRadioBtn,
    Card,
    // eslint-disable-next-line
    Collapse,
    CpsCase,
    CpsProcess,
    CpsQa,
    Copyright,
    PopupWithIframe,
    GoodAction,
    GoInsureDialog,
    CpsProcessDetail,
    CpsRate,
    RecordLayer,
    PlanTip,
    InsurePersonForm,
    AutoDeduct,
    ProtocolRead,
    NavTab
  },
  data() {
    return {
      ...Detail,
      popupShow: false,
      currentPupopIndex: null,
      formData: {
        planValue: "3",
        insured: "1",
        payway: "1",
        auto: false,
        pact: false
      },
      goInsureState: false,
      showLayer: false
    };
  },
  computed: {
    pupopData() {
      const { popupArray, currentPupopIndex } = this;
      return popupArray[currentPupopIndex] || {};
    },
    planCellData() {
      const { planValue } = this.formData;
      let _data = [
        { title: "100种重大疾病医疗保险金", value: "30万" },
        { title: "40种轻症保险金", value: "6万" },
        { title: "投保年龄", value: "30天~50周岁" },
        { title: "保险期限", value: "1年" }
      ];
      switch (planValue) {
        case "3":
          _data = [
            { title: "100种重大疾病医疗保险金", value: "30万" },
            { title: "40种轻症保险金", value: "6万" },
            { title: "投保年龄", value: "30天~50周岁" },
            { title: "保险期限", value: "1年" }
          ];
          break;
        case "2":
          _data = [
            { title: "100种重大疾病医疗保险金", value: "20万" },
            { title: "40种轻症保险金", value: "4万" },
            { title: "投保年龄", value: "30天~60周岁" },
            { title: "保险期限", value: "1年" }
          ];
          break;
        case "1":
          _data = [
            { title: "100种重大疾病医疗保险金", value: "10万" },
            { title: "40种轻症保险金", value: "2万" },
            { title: "投保年龄", value: "30天~60周岁" },
            { title: "保险期限", value: "1年" }
          ];
          break;
        default:
          break;
      }
      return _data;
    },
    noticeCellData() {
      const { planValue } = this.formData;
      return [
        { title: "投保年龄", value: `30~${planValue === "3" ? 5 : 6}0周岁` },
        { title: "保障期限", value: "1年（可续保至99周岁）" },
        { title: "等待期", value: "90天" },
        {
          title: "保费",
          value: {
            needSlot: true,
            tpl: "保费与保额、被保人年龄有关<br />首月3元，次月5.6元/月起",
            longTxt: true
          }
        }
      ];
    },
    personFormOptions() {
      const { insuredOptions, paywayOptions } = this;
      return {
        insuredOptions,
        paywayOptions
      };
    }
  },
  methods: {
    openIframePupop(index) {
      if (index === 4) {
        this.$router.push("/goods/plan");
        return;
      }
      this.currentPupopIndex = index;
      this.popupShow = true;
    }
  }
};
</script>
<style lang="less" src="./index.less" scoped></style>
