<template>
  <div>
    <van-button type="primary" @click="goPay">默认按钮</van-button>
    <pay-h5 :requestParam="requestParam"></pay-h5>
  </div>
</template>
<script>
import * as api from '@/api/pay.js'
import { getUser } from '@/api/account'
export default {
  components: {
  },
  data() {
    return {
      userId: '',
      requestParam: {
        product_id: '6684359515615264768', // 提前设定
        open_id: '', // 通过微信授权获取
        prepay_id: '', // 通过调用接口获取
        app_id: '', // 提前设定
        app_secret: '' // 提前设定
      }
    }
  },
  mounted() {
    this.getOpenid()
    this.getGoodsDetail()
  },
  methods: {
    getOpenid() {
      getUser().then(res => {
        api.getOpenid({ id: res.id, identity: 'transport' }).then(res => {
          if (res.code === 0) {
            this.requestParam.open_id = res.data.openid
          }
        })
      })
    },
    getGoodsDetail() {
      // api.getGoodsDetails('6682927830365372416').then(res => {
      //   console.log(res)
      // })
    },
    goPay () {
      this.VueEvent.$emit('pay-wx-h5', {
        data: {},
        callback: function (obj) {
          console.log(obj)
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
