// import { // getVideoList // } from "../../api/common" import {httpRequest} from "../../utils/httpReques"; const { getPlayletManager } = tt; Component({ pm: undefined, data: { videoResult: {}, adType: '', platform: '', unlockAllFlag: false, unlockAllKb: 0, emitTimesCharge: 0, egold: 0, payList: [], time: "", action:0, iosStatus: 0, iosIm: '', payLiClass: { 1: "pay_li_class_1", 2: "pay_li_class_2", 4: "pay_li_class_4", }, useBytePayment: true,//是否使用抖音支付组件 canIUsePaymentChannel: tt.canIUse('payment-channel-select'), showPaymentChannelSelect: false, dySkuList:[], //从接口获取的skulist skuList:[],//传给支付组件的skulist }, inject: ["chargeTap"], observers: { // 点击组件 A 的 button 后,触发该监听器的执行 chargeTap(val) { this.setData({ emitTimesCharge: val }) }, }, async ready() { tt.getSystemInfo({ success: (res) => { // console.log(res) this.setData({ platform: res.platform, }) } }) console.log('payment-channel-select',this.data.canIUsePaymentChannel) const pm = getPlayletManager(this); this.pm = pm; pm.onPlay(() => { console.error('在charge中监听onPlay') }) // //记录解锁信息 // const { // playletPluginList // } = await getVideoList(); // // console.log("playletPluginList",playletPluginList) // for (let i = 0; i < playletPluginList.length; i++) { // console.log(playletPluginList[i].ablum_id) // console.log(this.data.tt_album_id) // if (playletPluginList[i].ablum_id === this.properties.albumId) { // // this.setData({ // allUnlock: playletPluginList[i].allUnlock // }) // } // } }, detached() { console.log('charge关闭') }, attached() { this.getPayList() const watchInfo = tt.getStorageSync('watchInfo') this.setData({ videoResult: watchInfo }) // console.log(this.data.videoResult) }, methods: { getPayList() { httpRequest('/paysetting', 'post', {new_pay:1,is_unit:1}).then((res) => { if (res.status == 1) { this.setData({ egold: res?.data?.egold, payList: res?.data?.list, dySkuList: [...res?.data?.dy_config?.sku_list] }) } this.setCurrentItem() // //支持且需要官方支付组件时 if(tt.canIUse('payment-channel-select')&&this.data.useBytePayment){ //设置面板 this.setSkuList(this.setCurrentItem()); //显示面板 this.setData({ showPaymentChannelSelect: true }) // this.data.showPaymentChannelSelect = true; } // this.data.time = res?.data?.time; this.setData({ time: res?.data?.time }) const videoResult = this.data.videoResult; if (videoResult.chackpay === 2 || videoResult.chackpay == 3) { const unlockAllFlag = res.data.list.some((m) => { if (m.type == 4) { let unlockAllKb = (videoResult.unlock_data.total_price / parseFloat(m.price)).toFixed(2); // this.data.unlockAllKb = unlockAllKb; this.setData({ unlockAllKb: unlockAllKb }) } return m.type == 4; }); this.setData({ unlockAllFlag: unlockAllFlag }) } //ios支付 httpRequest('/bs', 'post', {new_pay:1}).then((res) => { if (res.status == 1) { this.setData({ iosStatus: res?.data?.status, }) } }); //用户数据 httpRequest('/user', 'post', ).then((res) => { if (res.status == 1) { this.setData({ iosIm: res?.data?.info.im, }) } }); }); }, //选中商品 setCurrentItem(inx){ let cacheInx //有下标时,直接设置 if(inx){ cacheInx = inx }else { //没有下标时,从数据def_select设置页面 for (let i = 0; i < this.data.payList.length; i++) { if (this.data.payList[i].def_select) { cacheInx = i } } } this.setData({ action: cacheInx ? cacheInx : 0 }) // this.data.action = cacheInx ? cacheInx : 0; return this.data.action; }, //点击商品 payItem(item,index) { // this.data.action = index this.setData({ action: index }) //调用抖音支付组件 if(tt.canIUse('payment-channel-select')&&this.data.useBytePayment&&this.data.showPaymentChannelSelect){ // console.log('item',item) this.setSkuList(index) }else{ //打开原tt支付 this.openTtPay(index) } }, //设置抖音支付面板数据 setSkuList(inx){ const item = this.data.dySkuList[inx]; let skuList = []; skuList.push(item); this.setData({ skuList: skuList }) console.log('skuList',this.data.skuList) }, //组件支付下单 async handleRequestOrderByte(event) { // 下单 // 返回一个 promise return new Promise(resolve => { const launchsite = tt.getStorageSync('launchsite') || 1; const payCurrent = this.data.payList[this.data.action] const params = { id: payCurrent.id, isback: payCurrent.isback === 1 ? 1 : 0, launchsite, sid: this.data.videoResult.sid || "", jid: this.data.videoResult.id || "", new_pay: 1 } httpRequest('/Newplaceanorder', 'post', params).then((res) => { if (res.status == 1) { const orderData = { data: res.data.data, byteAuthorization: res.data.byteAuthorization, } resolve(orderData); } }); }); }, //组件支付状态 handleGetPaymentResult(event) { const { status, result } = event.detail; console.log('handleGetPaymentResult',event.detail) if (status === 'success') { const { code } = result; if (code === 0) { tt.showToast({ icon: 'none', title: '支付成功', }); this.emitChargeInfoToParent('charge','success') // uni.$emit('chargePaySuccess') } else if( code === 9) { // code 为 9,开发者自行查询订单状态 } else { // 支付失败、超时、取消、关闭 tt.showToast({ icon: 'none', title: '支付失败', }); } } else { // 支付失败 tt.showToast({ icon: 'none', title: '支付失败', }); } }, //组件支付报错 handleGetPaymentError(event){ // errNo(错误码,对应某种具体报错原因) // errMsg(报错信息) const { errNo, errMsg } = event.detail console.log('errMsg',errMsg) console.log('errNo',errNo) const componentInitError = [169007, 20000] const payError = [169015, 169016, 169017, 169018, 169019, 169020, 20] if (componentInitError.includes(errNo)) { //组件初始化错误 this.setData({ showPaymentChannelSelect: false }) // this.data.showPaymentChannelSelect = false; } else if(payError.includes(errNo)) { // 支付流程错误 // 使用 tt.requestOrder + tt.getOrderPayment // this.showPaymentChannelSelect = false; this.openTtPay(this.data.action); } }, //打开原tt支付 openTtPay(index){ const that = this; const item = this.data.payList[index]; tt.showLoading({ title: "正在拉起支付", }); const launchsite = tt.getStorageSync('launchsite') || 1; if (this.data.platform === "ios" && this.data.iosStatus === 1) { tt.hideLoading({}); tt.showToast({ title: "暂不支持ios支付", duration: 2000, icon: "none", }); return; } else { if (tt.canIUse("getOrderPayment") && tt.canIUse("requestOrder")) { const params = { id: item.id, isback: item.isback === 1 ? 1 : 0, launchsite, sid: this.data.videoResult.sid || "", jid: this.data.videoResult.id || "", } httpRequest('/Newplaceanorder', 'post', params).then((res) => { if (res.status == 1) { tt.hideLoading({}); tt.requestOrder({ data: res.data.data, byteAuthorization: res.data.byteAuthorization, payScene: this.data.platform === "ios" ? "IM" : "", success: (e) => { tt.showLoading({ title: "拉起支付中...", }); tt.getOrderPayment({ orderId: e.orderId, imId: this.data.platform === "ios" ? this.data.iosIm : "", success: (payRes) => { tt.hideLoading({}); tt.showToast({ title: "支付成功", duration: 2000, }); that.emitChargeInfoToParent('charge','success') }, fail: (payError) => { tt.hideLoading({}); // console.log(payError); }, }); }, fail: (e) => { console.log(e); }, }); } }); } else { const params = { id: item.id, isback: item.isback === 1 ? 1 : 0, launchsite, sid: this.data.videoResult.sid || "", jid: this.data.videoResult.id || "", } httpRequest('/getTiktokpay', 'post', params).then((res) => { if (res.status == 1) { tt.hideLoading({}); const orderInfo = { outOrderNo: res.data.outOrderNo, totalAmount: res.data.totalAmount, }; tt.pay({ orderInfo, service: 5, success: (res) => { if (res.code == 0) { tt.showToast({ title: "支付成功", duration: 2000, }); that.emitChargeInfoToParent('charge','success') // paysetting().then((res) => { // this.egold = res.egold; // uni.setStorageSync("isPopup", false); // this.show = false; // // this.$emit("paySuccess", "paySuccess"); // uni.$emit('chargePaySuccess') // }); // 支付成功处理逻辑,只有res.code=0时,才表示支付成功 // 但是最终状态要以商户后端结果为准 } }, fail: () => { tt.showToast({ title: "支付失败,请重新支付", duration: 2000, }); }, }); } }); } } }, //接收页面点击 handlePayItem(e){ const item = e.currentTarget.dataset.item const index = e.currentTarget.dataset.index // this.emitChargeInfoToParent('charge','success') this.payItem(item,index) }, //向父组件传值 emitChargeInfoToParent(val,data) { const instance = this.selectOwnerComponent(); instance.emitChargeInfoFromChildren(val,data); this.close() }, close(){ this.pm.toggleCustomDialog() }, //支付区域 payThis(e) { this.pm.toggleCustomDialog('close'); this.pm.setCurrentUnlock(); }, payAll(e) { this.pm.toggleCustomDialog('close'); this.pm.setCatalog(this.data.allUnlock); }, adThis(e) { console.log('广告解锁当前集', e); this.setData({ adType: 'this', }) this.ad.show(); // 监听视频播放完成 }, adAll(e) { console.log('广告解锁全集', e); this.setData({ adType: 'all', }) this.ad.show(); }, } })