<template>
  <card :title="title" :option="options" footer="协议" @option-click="openIframe(6)">
    <compactCellGroup :cell-data="cellData" :text-bold="true" font-size="14" @click="openIframe" />
    <slot></slot>
    <template v-slot:footer>
      <div class="insure-form-pact" slot="footer">
        <cr-field name="pact" v-show="showRadio">
          <template #input>
            <cr-checkbox shape="round" icon-size="13px" v-model="pact" checked-color="#FFC842">
              投保前请阅读
            </cr-checkbox>
          </template>
        </cr-field>
        <div v-show="!showRadio"></div>
        <div class="insure-form-pact-link" :style="{ paddingLeft: showRadio ? 'inherit' : 0 }">
          <a
            href="javascript:;"
            @click="openIframe(item.id)"
            v-for="(item, index) in protocolData"
            :key="index"
          >
            {{ item.title }}
          </a>
        </div>
      </div>
    </template>
  </card>
</template>

<script>
import Card from "@/components/Card";
import CompactCellGroup from "@/components/CompactCellGroup";
const DATA_CHANGE_EVENT = "input";
const CELL_CLICK_EVENT = "cell-click";
export default {
  name: "ProtocolRead",
  components: {
    CompactCellGroup,
    Card
  },
  props: {
    title: {
      type: String,
      default() {
        return "投保须知";
      }
    },
    options: {
      type: Array,
      default() {
        return ["查看完整费率表"];
      }
    },
    showRadio: {
      type: Boolean,
      default: true
    },
    protocolData: {
      type: Array,
      default() {
        return [
          { title: "保险条款", id: 0 },
          { title: "健康告知", id: 1 },
          { title: "投保须知与声明", id: 2 },
          { title: "服务协议", id: 3 }
        ];
      }
    },
    value: null,
    cellData: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      pact: false
    };
  },
  watch: {
    value: {
      immediate: true,
      handler(val) {
        this.pact = val;
      }
    },
    pact: {
      handler(val) {
        this.$emit(DATA_CHANGE_EVENT, val);
      }
    }
  },
  methods: {
    openIframe(idx) {
      if (typeof idx === "object") {
        this.$emit(CELL_CLICK_EVENT, 8);
        return;
      }
      this.$emit(CELL_CLICK_EVENT, idx);
    }
  }
};
</script>
<style lang="less" scoped>
@import "../../../../style/var.less";
.insure-form {
  &-pact {
    padding: 14px 0;
    .cr-cell {
      padding: 0;
      width: auto;
      &::after {
        display: none;
      }
    }
    @{deep} .cr-checkbox__label {
      font-size: @font-size-14;
      color: #999;
      margin-left: 5px;
    }
    &-link {
      margin-top: 3px;
      display: flex;
      padding-top: 3px;
      padding-left: 17px;
      align-items: center;
      a {
        font-size: @font-size-12 + 1;
        &::after {
          display: inline-block;
          content: " ";
          width: 0;
          height: 13px;
          border-right: 1px @blue solid;
          margin: 0 3px 0 1px;
          vertical-align: -2px;
        }
        &:last-child::after {
          display: none;
        }
      }
    }
  }
}
</style>
