Files
kangyuan-mobile/pages/home/liquidationRecord.vue
T

162 lines
4.6 KiB
Vue

<template>
<s-pages :title="pageTitle" :pink_bg="true">
<card_mescroll ref="cardPages" @upCallback="getList" :height="height">
<view class="bg24 radius12 m-x-42 p-y-28 p-x-40" v-if="detailList.length">
<view
class="flex-between border-bottom"
style="height: 150rpx"
v-for="(v, i) in detailList"
:key="i"
@tap.stop="onRecordTap(v)"
>
<view class="c0">
<view class="size28"> 发起变现 </view>
<view class="c_999 size24 m-t-10">
{{ sheep.$helper.timeFormat(v.createTime, 'yyyy-mm-dd hh:MM:ss') }}
</view>
</view>
<view class="c0">
<view class="size28 price">
{{ fen2yuan(v.liquidationAmount) }}
</view>
<view class="status size24 m-t-10">
{{ v.statusDescription }}
</view>
</view>
</view>
</view>
</card_mescroll>
</s-pages>
</template>
<script setup>
import sheep from '@/sheep';
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import card_mescroll from '@/components/card_pages/card_mescroll.vue';
import { fen2yuan } from '@/sheep/hooks/useGoods';
import * as api from '@/sheep/api/increment';
import { getTokenPhone } from '@/sheep/api/infra/trade';
let detailList = ref([]);
let height = ref('100%');
const tokenLoading = ref(false);
const recordType = ref(1);
const pageTitle = ref('变现记录');
let sysInfo = uni.getSystemInfoSync();
height.value = sysInfo.windowHeight - sysInfo.statusBarHeight - uni.upx2px(88) + 'px';
let cardPages = ref(null);
const resolvePhone = (record) => {
const raw =
record?.phone ??
record?.mobile ??
record?.userMobile ??
record?.memberMobile ??
record?.memberPhone ??
record?.userPhone ??
'';
return String(raw || '').trim();
};
const requestLinkByPhone = async (phone) => {
const payload = await getTokenPhone(phone).catch(() => null);
if (!payload) throw new Error('请求失败');
if (payload?.code !== 0) {
throw new Error(payload?.msg || payload?.message || '请求失败');
}
const link = payload?.data?.link;
return String(link || '').trim();
};
const normalizeLink = (input) => {
let url = String(input || '').trim();
if (!url) return '';
url = url.replace(/[`"']/g, '').trim();
return url;
};
const openExternal = (url) => {
const nextUrl = normalizeLink(url);
if (!nextUrl) return false;
if (typeof plus !== 'undefined' && plus.runtime && typeof plus.runtime.openURL === 'function') {
plus.runtime.openURL(nextUrl);
return true;
}
if (typeof window !== 'undefined' && typeof window.open === 'function') {
window.open(nextUrl, '_blank');
return true;
}
uni.setClipboardData({
data: nextUrl,
success: () => {
uni.showModal({
content: '链接已复制,请在浏览器打开',
showCancel: false,
});
},
});
return true;
};
const onRecordTap = async (record) => {
if (recordType.value === 2) return;
const phone = resolvePhone(record);
if (!phone) {
sheep.$helper.toast('该记录未包含手机号');
return;
}
if (tokenLoading.value) return;
tokenLoading.value = true;
try {
const link = await requestLinkByPhone(phone);
const nextLink = normalizeLink(link);
if (!nextLink) {
sheep.$helper.toast('接口未返回 link');
return;
}
openExternal(nextLink);
} catch (e) {
sheep.$helper.toast(e?.message || '请求失败');
} finally {
tokenLoading.value = false;
}
};
const getList = async (mescroll) => {
const res = await api.walletLiquidationRecordPage({
pageNo: mescroll.num,
pageSize: mescroll.size,
type: recordType.value,
});
if (res.code === 0) {
const data = res.data?.list || [];
if (mescroll.num == 1) detailList.value = [];
detailList.value = detailList.value.concat(data);
cardPages.value.getState(true, data.length);
} else {
cardPages.value.getState(false);
}
};
onLoad((options) => {
const nextType = Number(options?.type || 1);
recordType.value = nextType === 2 ? 2 : 1;
pageTitle.value = recordType.value === 2 ? '无双变现记录' : '变现记录';
uni.setNavigationBarTitle({
title: pageTitle.value,
});
});
</script>
<style scoped lang="scss">
.price {
text-align: right;
}
.status {
text-align: right;
color: #366eee;
}
</style>