<template>
  <card :title="title" :option="options" footer="协议" @option-click="openIframe(6)">
    <compactCellGroup :cell-data="cellData" />
    <slot></slot>
    <template v-slot:footer>
      <div class="insure-form-pact" slot="footer">
        <cr-field name="pact" :rules="[{ required: true, message: '请阅读协议并确认' }]">
          <template #input>
            <cr-checkbox shape="round" icon-size="13px" v-model="pact" checked-color="#FFC842">
              投保前请阅读
            </cr-checkbox>
          </template>
        </cr-field>
        <div class="insure-form-pact-link">
          <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 ["查看完整费率表"];
      }
    },
    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) {
      this.$emit(CELL_CLICK_EVENT, idx);
    }
  }
};
</script>
<style lang="less" scoped>
@import "../../../../style/var.less";
.insure-form {
  &-pact {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    .cr-cell {
      padding: 0;
      width: auto;
      &::after {
        display: none;
      }
    }
    @{deep} .cr-checkbox__label {
      font-size: @font-size-11;
      color: @gray-4;
      margin-left: 5px;
    }
    &-link {
      margin-top: -3.5px;
      display: flex;
      padding-top: 3px;
      align-items: center;
      a {
        font-size: @font-size-11;
        &::after {
          display: inline-block;
          content: " ";
          width: 0;
          height: 12px;
          border-right: 1px @blue solid;
          margin: 0 3px 0 1px;
          vertical-align: -2px;
        }
        &:last-child::after {
          display: none;
        }
      }
    }
  }
}
</style>
