<template>
  <div class="inform-container">
    <div class="inform-notice">
      <cr-tag type="danger">重要</cr-tag>
      <div class="inform-notice-content">
        为保证被保险人的保险权益在理赔时不受影响，请确认被保险人健康状况是否符合以下投保条件：
      </div>
    </div>
    <card title="true" class="inform-content">
      <span slot="title" class="inform-content-title">
        请如实告知
        <strong>被保人</strong> 是否有以下情形之一
      </span>
      <iframe class="inform-frame" :src="url" frameborder="0" height="100%"></iframe>
    </card>
    <div class="inform-btns">
      <cr-button @click="$router.back()">不符合</cr-button>
      <cr-button type="warning" @click="conform">符合，立即投保</cr-button>
    </div>
  </div>
</template>

<script>
import card from "@/components/Card";
import { placeOrder } from "@/api/product";
import { payByWay } from "@/service/pay";

export default {
  name: "GoodsInform",
  components: {
    card
  },
  data() {
    return {
      formData: JSON.parse(sessionStorage.getItem("policyFormData") || "{}"),
      orderInfo: {},
      tradeType: "JSAPI",
      url: "http://mangguo-contract.qthbx.com/huatai-jian-kang-gao-zhi-v1/"
    };
  },
  methods: {
    conform() {
      this.generateOrder();
    },
    async generateOrder() {
      const res = await placeOrder.create();
      if (res) {
        this.orderInfo = res;
        this.goPay();
      }
    },
    async goPay() {
      const { tradeType, orderInfo } = this;
      const { payOrderNo, payType } = orderInfo;
      if (!payOrderNo) {
        this.$toast("请先生成订单");
        return;
      }
      const res = await placeOrder.pay({ payOrderNo, payType, tradeType });
      if (res) {
        let payInfo = {
          url: res.data.payUrl,
          params: {
            ...orderInfo,
            tradeType,
            state: 1
          }
        };
        if (tradeType === "JSAPI") {
          payInfo = res.data.payInfo;
        }
        payByWay(tradeType, payInfo).then(() => {
          this.payBack = 1;
        });
      }
    }
  }
};
</script>
<style lang="less" src="./index.less" scoped></style>
