| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import Http from "../utils/http";
- import { host } from "../utils/constant";
- const userHttp = new Http(host);
- export function fetchProfile() {
- return userHttp.get("/user/me").then((res) => {
- getApp().globalData.user = res;
- return res;
- });
- }
- export function fetchCollectList() {
- if (getApp().globalData.collectIds) {
- return Promise.resolve(getApp().globalData.collectIds);
- }
- return userHttp
- .get<{
- data: {
- status: number;
- station_id: number;
- }[];
- }>("/user/collectList?page=1&page_size=999")
- .then((res) => {
- getApp().globalData.collectIds = res.data
- ? res.data
- .filter((item) => Number(item.status) === 1)
- .map((item) => {
- return Number(item.station_id);
- })
- : [];
- return getApp().globalData.collectIds;
- });
- }
- export function addCollectList(sid: number) {
- let ids = getApp().globalData.collectIds
- ? (getApp().globalData.collectIds as number[])
- : [];
- const status = ids.includes(sid) ? 2 : 1;
- return userHttp
- .post("/user/addCollect", {
- data: {
- station_id: sid,
- status,
- },
- })
- .then(() => {
- if (status === 1) {
- ids.push(sid);
- } else {
- ids = ids.filter((id) => id !== sid);
- }
- getApp().globalData.collectIds = ids;
- return status === 1;
- });
- }
- export function updateProfile(data: {
- nick_name?: string;
- avatar?: string;
- vin?: string;
- license_plate?: string;
- card_no?: string;
- }) {
- return userHttp.post("/user/update", {
- data,
- });
- }
- export function insertMoney(amount: number) {
- return userHttp
- .post<{
- appId: string;
- nonceStr: string;
- package: string;
- paySign: string;
- signType: string;
- timestamp: string;
- }>("/payment/pay", {
- data: {
- amount: parseInt(`${amount * 100}`),
- openid: getApp().globalData.user?.openid,
- },
- })
- .then((res: any) => {
- return new Promise((resolve, reject) => {
- uni.requestPayment({
- provider: "wxpay",
- orderInfo: {
- timeStamp: res.timestamp,
- nonceStr: res.nonceStr,
- package: res.package,
- signType: "MD5",
- paySign: res.paySign,
- },
- success(res: any) {
- resolve(res);
- },
- fail: reject,
- });
- });
- });
- }
- export function logout() {
- return userHttp.get("/user/logout");
- }
- export function fetchWallet(type: number, page: number, pageSize: number) {
- return userHttp
- .get<{
- data: any[];
- }>(`/account/wallet?page=${page}&page_size=${pageSize}&type=${type}`)
- .then((res) => {
- return res.data;
- });
- }
- export function fetchOrder(orderid: string) {
- return userHttp.get(`/charge/orderInfo?order_id=${orderid}`);
- }
|