ts_aimz/pages/mine/mineIndex/mine.js

432 lines
14 KiB
JavaScript
Raw Normal View History

2025-03-21 18:05:54 +08:00
// pages/mine/mine.js
2025-03-31 18:23:29 +08:00
import UserApi from '../../../net/api/userApi'
2025-04-14 15:59:06 +08:00
import ProApi from '../../../net/api/projectApi'
2025-04-03 17:40:39 +08:00
import {
copyrightUrl
} from '../../../net/http'
2025-04-03 10:44:12 +08:00
const Utils = require('../../../utils/util')
2025-03-21 18:05:54 +08:00
const app = getApp()
2025-03-24 18:05:54 +08:00
const deviceInfo = wx.getDeviceInfo()
const screenInfo = wx.getWindowInfo();
const statusBarHeight = screenInfo.statusBarHeight; // 状态栏高度
const navBarHeight = deviceInfo.platform == 'IOS' ? 48 : 50; // 导航栏高度iOS 为 44pxAndroid 为 48px
2025-04-14 15:59:06 +08:00
const tabBarHeight = screenInfo.screenHeight - (screenInfo.safeArea ? screenInfo.safeArea.bottom : 50);
const screenHeight = screenInfo.screenHeight
const screenWidth = screenInfo.screenWidth
2025-03-24 18:05:54 +08:00
const windowHeight = screenInfo.windowHeight - navBarHeight - statusBarHeight; //可用内容高度
2025-03-21 18:05:54 +08:00
Page({
/**
* 页面的初始数据
*/
data: {
localAssets: app.globalData.localAssets,
2025-05-06 17:55:29 +08:00
imgAssets: app.globalData.imgAssetsUrl,
2025-05-06 14:04:00 +08:00
appTitle: app.globalData.appTitle,
2025-03-21 18:05:54 +08:00
statusBarHeight: statusBarHeight,
navBarHeight: navBarHeight,
totalHeight: navBarHeight, // 导航栏总高度
contentHeight: windowHeight,
2025-04-14 15:59:06 +08:00
screenHeight: screenHeight, //屏幕高度
screenWidth: screenWidth, //屏幕宽度
tabBarHeight: tabBarHeight, //tabbar高度
2025-03-31 18:23:29 +08:00
allCount: 0,
materialCount: 0,
accountInfo: {},
2025-03-21 18:05:54 +08:00
menuList: [{
2025-04-27 18:07:06 +08:00
icon: "ic-user",
title: "个人信息",
path: "/pages/mine/mineAccount/mineInfo/mineInfo"
2025-05-06 17:55:29 +08:00
}, {
icon: 'ic-msg',
title: '消息通知',
path: '/pages/mine/mineAccount/mineMsgNotice/mineMsgNotice'
2025-05-08 08:57:38 +08:00
}, {
icon: 'ic-refund',
title: '退款项目',
path: '/pages/copyright/refund/refund'
}, {
icon: 'ic-repair',
title: '补正项目',
path: '/pages/copyright/repair/repair'
}, {
2025-04-27 18:07:06 +08:00
icon: 'ic-invoice-info',
title: '开票信息',
path: '/pages/mine/mineAccount/invoiceInfo/invoiceInfo'
2025-03-21 18:05:54 +08:00
}, {
2025-04-27 18:07:06 +08:00
icon: "ic-pay-record",
title: "资金流水",
path: "/pages/mine/mineAccount/minePayRecord/minePayRecord"
2025-03-21 18:05:54 +08:00
}, {
2025-04-27 18:07:06 +08:00
icon: "ic-order",
title: "我的订单",
path: "/pages/mine/mineAccount/mineOrder/mineOrder"
2025-03-21 18:05:54 +08:00
}, {
2025-04-27 18:07:06 +08:00
icon: "ic-invoice",
title: "发票管理",
path: "/pages/mine/mineAccount/mineInvoice/mineInvoice"
}, {
2025-04-27 18:07:06 +08:00
icon: "ic-contact",
title: "产权联系人",
path: "/pages/mine/mineAccount/mineContact/mineContact"
}, {
icon: "ic-unbind",
title: "微信解绑",
path: ""
2025-04-07 11:04:08 +08:00
}],
buttons: [{
text: '知道了'
}],
hintTxt: '',
2025-04-09 11:31:24 +08:00
showHint: false,
showError: false,
errorHint: '',
animationData: {}, //刷新动画
animation: null,
2025-04-14 15:59:06 +08:00
tabList: [{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": app.globalData.localAssets + "/ic_home_normal.png",
"selectedIconPath": app.globalData.localAssets + "/ic_home_select.png",
2025-05-06 17:55:29 +08:00
"selected": false,
"hasMsg": false
2025-04-14 15:59:06 +08:00
},
{
"pagePath": "pages/mine/mineIndex/mine",
"text": "我的",
"iconPath": app.globalData.localAssets + "/ic_mine_normal.png",
"selectedIconPath": app.globalData.localAssets + "/ic_mine_select.png",
2025-05-06 17:55:29 +08:00
"selected": true,
"hasMsg": false
2025-04-14 15:59:06 +08:00
}
],
allPrice: 0, //全托管价格
materialPrice: 0, //写材料价格
urgent: 0, //加急价格
2025-03-21 18:05:54 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
2025-03-31 18:23:29 +08:00
const _self = this
_self.getMineAccount()
_self.getMinePackageCount()
2025-04-09 11:31:24 +08:00
// 创建一个动画实例
const animation = wx.createAnimation({
duration: 1000,
timingFunction: 'ease'
});
this.setData({
animation: animation
})
2025-04-14 15:59:06 +08:00
this.countViewHeight()
this.doGetPrice()
},
2025-05-06 17:55:29 +08:00
//消息通知
getMsgNotice() {
const data = {
page: 1,
rows: 1,
isRead: 0,
keywords: ''
}
const _self = this
UserApi.doGetMineMsgNotice(data)
.then(res => {
if (res.rows && res.rows.length > 0) {
_self.setData({
'tabList[1].hasMsg': true,
'menuList[1].hasMsg': true
})
} else {
_self.setData({
'tabList[1].hasMsg': false,
'menuList[1].hasMsg': false
})
console.log('是否有消息', _self.data.menuList[1].hasMsg)
console.log('是否有消息', _self.data.tabList[1].hasMsg)
}
})
.catch(err => {
_self.setData({
'tabList[1].hasMsg': false,
'menuList[1].hasMsg': false
})
})
},
2025-04-14 15:59:06 +08:00
//计算高度
countViewHeight() {
//
const query = wx.createSelectorQuery();
const _self = this
// 指定要查询的 view 元素
query.select('#func-box').boundingClientRect();
query.exec((res) => {
if (res[0]) {
const height = res[0].height;
//屏幕高度-内容高度-tabbar高度
const contentHeight = _self.data.screenHeight - height - 50
const h = Utils.pxToRpx(contentHeight, _self.data.screenWidth)
const tempH = h - 140
_self.setData({
contentHeight: tempH
})
} else {
console.log('未找到指定的 view 元素');
}
})
},
//跳转创建项目页面
openCreate(e) {
//计算价格
const _self = this
const type = e.currentTarget.dataset.type
if (type == 'ALL') {
if (_self.data.allCount > 0) {
_self.doGetPackage(type)
} else {
//提示充值
_self.setData({
errorHint: '您的账户当前无套餐包,为正常使用请及时充值。',
showError: true
})
}
} else {
if (_self.data.materialCount > 0) {
_self.doGetPackage(type)
} else {
//提示充值
_self.setData({
errorHint: '您的账户当前无套餐包,为正常使用请及时充值。',
showError: true
})
}
}
},
//获取套餐包详情
doGetPackage(type) {
const _self = this
const data = {
page: 1,
rows: 10,
packageType: type,
keyong: 1,
}
ProApi.doGetPackageList(data)
.then(res => {
console.log(res.rows)
if (res.rows && res.rows.length > 0) {
const packageId = res.rows[0].packageInfoId
const price = type == 'ALL' ? _self.data.allPrice : _self.data.materialPrice
wx.navigateTo({
url: '../../copyright/createProjectInfo/createProjectInfo?type=' + type + '&price=' + price + '&isUrgent=false&pId=' + packageId,
})
} else {
_self.setData({
errorHint: '您的账户当前无套餐包,为正常使用请及时充值。',
showError: true
})
}
})
.catch(err => {
_self.setData({
errorHint: '获取套餐包失败,请稍后重试',
showError: true
})
})
},
//获取单价
doGetPrice() {
wx.showLoading({
title: '加载中...',
})
const _self = this
ProApi.doGetPrice()
.then(res => {
wx.hideLoading()
console.log(res)
res.projTypes.forEach(el => {
if (el.type == 'ALL') {
_self.setData({
allPrice: el.price
})
} else if (el.type == 'MATERIAL') {
_self.setData({
materialPrice: el.price
})
}
});
_self.setData({
urgent: res.additional.urgent, //加急办理
})
}, err => {
wx.hideLoading()
wx.showToast({
2025-04-16 16:16:35 +08:00
title: '数据有误,请刷新页面',
icon: 'error'
2025-04-14 15:59:06 +08:00
})
})
2025-04-09 11:31:24 +08:00
},
//刷新账户
doRefresh() {
const _self = this
_self.playAnimation()
_self.getMineAccount() //获取账户信息
_self.getMinePackageCount() //获取套餐包信息
2025-04-14 15:59:06 +08:00
_self.doGetPrice() //获取单价
2025-04-09 11:31:24 +08:00
},
//播放刷新动画
playAnimation() {
const _self = this
// 重置动画
_self.data.animation.scale(1, 1).rotate(0).step({
duration: 0
});
_self.setData({
animationData: _self.data.animation.export()
});
_self.data.animation.scale(0.8, 0.8).rotate(180).step()
// 定义新的动画
_self.data.animation.scale(1, 1).rotate(360).step()
_self.setData({
animationData: _self.data.animation.export()
});
setTimeout(() => {
_self.setData({
animationData: {}
})
}, 1100);
2025-04-03 10:44:12 +08:00
},
onShow(options) {
2025-05-06 17:55:29 +08:00
console.log('页面显示')
2025-04-14 15:59:06 +08:00
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const tabList = this.data.tabList;
tabList.forEach(item => {
item.selected = item.pagePath === currentPage.route;
});
this.setData({
tabList
});
2025-04-03 10:44:12 +08:00
this.getMineAccount() //获取账户信息
this.getMinePackageCount() //获取套餐包信息
2025-05-06 17:55:29 +08:00
this.getMsgNotice()
2025-03-31 18:23:29 +08:00
},
getMineAccount() {
const _self = this
UserApi.doGetMineAccount()
.then(res => {
_self.setData({
accountInfo: res
})
}, err => {
console.log(err)
2025-04-09 11:31:24 +08:00
_self.setData({
errorHint: err.msg ? err.msg : '网络信号开小差啦,请您稍后再试,给您添麻烦~',
showError: true
})
2025-03-31 18:23:29 +08:00
})
},
//获取账户余额
2025-03-31 18:23:29 +08:00
getMinePackageCount() {
2025-04-03 10:44:12 +08:00
const _self = this
2025-03-31 18:23:29 +08:00
UserApi.doGetMinePackageCount()
.then(res => {
2025-04-03 10:44:12 +08:00
_self.setData({
allCount: res.ALL,
materialCount: res.MATERIAL
})
2025-04-09 11:31:24 +08:00
})
.catch(err => {
2025-03-31 18:23:29 +08:00
console.log(err)
2025-04-03 10:44:12 +08:00
_self.setData({
allCount: 0,
materialCount: 0
})
2025-04-09 11:31:24 +08:00
_self.setData({
errorHint: err.msg ? err.msg : '网络信号开小差啦,请您稍后再试,给您添麻烦~',
showError: true
})
2025-03-31 18:23:29 +08:00
})
},
//优惠卷
doCoupons() {
wx.navigateTo({
url: '/pages/mine/mineAccount/mineCoupons/mineCoupons',
})
2025-03-21 18:05:54 +08:00
},
2025-03-24 18:05:54 +08:00
//跳转充值页面
doPay() {
wx.navigateTo({
url: '/pages/copyright/payment/payment',
})
2025-04-03 17:40:39 +08:00
},
//条目点击
itemClick(e) {
const path = e.currentTarget.dataset.path
const title = e.currentTarget.dataset.title
2025-04-27 18:07:06 +08:00
if (title == '微信解绑') {
this.unbindPhone()
2025-04-03 17:40:39 +08:00
} else {
wx.navigateTo({
url: path,
})
}
2025-04-07 11:04:08 +08:00
},
//提示解绑
unbindPhone() {
const _self = this
wx.showModal({
title: '警告',
content: '您确定要解除绑定?如想继续使用本账号,请重新绑定.',
complete: (res) => {
if (res.confirm) {
_self.doUnbindWx()
}
}
})
},
doUnbindWx() {
const _self = this
wx.showLoading({
title: '解绑中...',
})
UserApi.doUnbindWx()
.then(res => {
wx.hideLoading()
_self.showExit()
})
.catch(err => {
wx.hideLoading()
_self.setData({
errorHint: err.msg ? err.msg : '解绑失败,请稍后重试',
showError: true
})
})
},
showExit() {
wx.showModal({
title: '提示',
content: `绑定已解除,立即退出小程序`,
showCancel: false,
complete: (res) => {
if (res.confirm) {
wx.exitMiniProgram()
}
}
})
},
2025-04-07 11:04:08 +08:00
closeHint(e) {
this.setData({
showHint: false,
hintTxt: ''
})
2025-04-09 11:31:24 +08:00
},
//下拉刷新
onPullDownRefresh() {
this.getMineAccount() //获取账户信息
this.getMinePackageCount() //获取套餐包信息
wx.stopPullDownRefresh()
2025-03-24 18:05:54 +08:00
}
2025-03-21 18:05:54 +08:00
})