ts_aimz/pages/mine/mineIndex/mine.js
2025-05-08 08:57:38 +08:00

432 lines
14 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/mine/mine.js
import UserApi from '../../../net/api/userApi'
import ProApi from '../../../net/api/projectApi'
import {
copyrightUrl
} from '../../../net/http'
const Utils = require('../../../utils/util')
const app = getApp()
const deviceInfo = wx.getDeviceInfo()
const screenInfo = wx.getWindowInfo();
const statusBarHeight = screenInfo.statusBarHeight; // 状态栏高度
const navBarHeight = deviceInfo.platform == 'IOS' ? 48 : 50; // 导航栏高度iOS 为 44pxAndroid 为 48px
const tabBarHeight = screenInfo.screenHeight - (screenInfo.safeArea ? screenInfo.safeArea.bottom : 50);
const screenHeight = screenInfo.screenHeight
const screenWidth = screenInfo.screenWidth
const windowHeight = screenInfo.windowHeight - navBarHeight - statusBarHeight; //可用内容高度
Page({
/**
* 页面的初始数据
*/
data: {
localAssets: app.globalData.localAssets,
imgAssets: app.globalData.imgAssetsUrl,
appTitle: app.globalData.appTitle,
statusBarHeight: statusBarHeight,
navBarHeight: navBarHeight,
totalHeight: navBarHeight, // 导航栏总高度
contentHeight: windowHeight,
screenHeight: screenHeight, //屏幕高度
screenWidth: screenWidth, //屏幕宽度
tabBarHeight: tabBarHeight, //tabbar高度
allCount: 0,
materialCount: 0,
accountInfo: {},
menuList: [{
icon: "ic-user",
title: "个人信息",
path: "/pages/mine/mineAccount/mineInfo/mineInfo"
}, {
icon: 'ic-msg',
title: '消息通知',
path: '/pages/mine/mineAccount/mineMsgNotice/mineMsgNotice'
}, {
icon: 'ic-refund',
title: '退款项目',
path: '/pages/copyright/refund/refund'
}, {
icon: 'ic-repair',
title: '补正项目',
path: '/pages/copyright/repair/repair'
}, {
icon: 'ic-invoice-info',
title: '开票信息',
path: '/pages/mine/mineAccount/invoiceInfo/invoiceInfo'
}, {
icon: "ic-pay-record",
title: "资金流水",
path: "/pages/mine/mineAccount/minePayRecord/minePayRecord"
}, {
icon: "ic-order",
title: "我的订单",
path: "/pages/mine/mineAccount/mineOrder/mineOrder"
}, {
icon: "ic-invoice",
title: "发票管理",
path: "/pages/mine/mineAccount/mineInvoice/mineInvoice"
}, {
icon: "ic-contact",
title: "产权联系人",
path: "/pages/mine/mineAccount/mineContact/mineContact"
}, {
icon: "ic-unbind",
title: "微信解绑",
path: ""
}],
buttons: [{
text: '知道了'
}],
hintTxt: '',
showHint: false,
showError: false,
errorHint: '',
animationData: {}, //刷新动画
animation: null,
tabList: [{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": app.globalData.localAssets + "/ic_home_normal.png",
"selectedIconPath": app.globalData.localAssets + "/ic_home_select.png",
"selected": false,
"hasMsg": false
},
{
"pagePath": "pages/mine/mineIndex/mine",
"text": "我的",
"iconPath": app.globalData.localAssets + "/ic_mine_normal.png",
"selectedIconPath": app.globalData.localAssets + "/ic_mine_select.png",
"selected": true,
"hasMsg": false
}
],
allPrice: 0, //全托管价格
materialPrice: 0, //写材料价格
urgent: 0, //加急价格
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const _self = this
_self.getMineAccount()
_self.getMinePackageCount()
// 创建一个动画实例
const animation = wx.createAnimation({
duration: 1000,
timingFunction: 'ease'
});
this.setData({
animation: animation
})
this.countViewHeight()
this.doGetPrice()
},
//消息通知
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
})
})
},
//计算高度
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({
title: '数据有误,请刷新页面',
icon: 'error'
})
})
},
//刷新账户
doRefresh() {
const _self = this
_self.playAnimation()
_self.getMineAccount() //获取账户信息
_self.getMinePackageCount() //获取套餐包信息
_self.doGetPrice() //获取单价
},
//播放刷新动画
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);
},
onShow(options) {
console.log('页面显示')
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
});
this.getMineAccount() //获取账户信息
this.getMinePackageCount() //获取套餐包信息
this.getMsgNotice()
},
getMineAccount() {
const _self = this
UserApi.doGetMineAccount()
.then(res => {
_self.setData({
accountInfo: res
})
}, err => {
console.log(err)
_self.setData({
errorHint: err.msg ? err.msg : '网络信号开小差啦,请您稍后再试,给您添麻烦~',
showError: true
})
})
},
//获取账户余额
getMinePackageCount() {
const _self = this
UserApi.doGetMinePackageCount()
.then(res => {
_self.setData({
allCount: res.ALL,
materialCount: res.MATERIAL
})
})
.catch(err => {
console.log(err)
_self.setData({
allCount: 0,
materialCount: 0
})
_self.setData({
errorHint: err.msg ? err.msg : '网络信号开小差啦,请您稍后再试,给您添麻烦~',
showError: true
})
})
},
//优惠卷
doCoupons() {
wx.navigateTo({
url: '/pages/mine/mineAccount/mineCoupons/mineCoupons',
})
},
//跳转充值页面
doPay() {
wx.navigateTo({
url: '/pages/copyright/payment/payment',
})
},
//条目点击
itemClick(e) {
const path = e.currentTarget.dataset.path
const title = e.currentTarget.dataset.title
if (title == '微信解绑') {
this.unbindPhone()
} else {
wx.navigateTo({
url: path,
})
}
},
//提示解绑
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()
}
}
})
},
closeHint(e) {
this.setData({
showHint: false,
hintTxt: ''
})
},
//下拉刷新
onPullDownRefresh() {
this.getMineAccount() //获取账户信息
this.getMinePackageCount() //获取套餐包信息
wx.stopPullDownRefresh()
}
})