176 lines
5.6 KiB
JavaScript
176 lines
5.6 KiB
JavaScript
// pages/mine/mineAccount/invoiceOrder/invoiceOrder.js
|
|
import InvoiceApi from '../../../../net/api/invoiceApi'
|
|
const app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
currentStatus: 'not', //可否开具发票tab not可以开 yes 已开
|
|
loadingState: 'loading',
|
|
isLoadMore: false,
|
|
listRefreshTrig: false,
|
|
orderList: [], //订单列表
|
|
pageData: {
|
|
page: 1,
|
|
rows: 10,
|
|
startTime: '',
|
|
endTime: '',
|
|
thirdParty: '', //充值方式 微信 支付宝 对公转账
|
|
},
|
|
hasMore: true,
|
|
startTime: '',
|
|
endTime: '',
|
|
checkList: [], //选中的可以开票的集合
|
|
money: 0, //开票金额
|
|
msgHint: '',
|
|
msgType: 'error',
|
|
msgShow: false,
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
wx.setNavigationBarTitle({
|
|
title: '开发票',
|
|
})
|
|
wx.setNavigationBarColor({
|
|
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
|
|
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
|
|
animation: { // 可选项
|
|
duration: 500,
|
|
timingFunc: 'easeIn'
|
|
}
|
|
})
|
|
this.doRefreshList()
|
|
},
|
|
//切换tab
|
|
doChangeStatus(e) {
|
|
this.setData({
|
|
currentStatus: e.currentTarget.dataset.value
|
|
})
|
|
this.doRefreshList()
|
|
},
|
|
//获取我的优惠卷
|
|
doGetMineInvoiceOrderList(isRefresh) {
|
|
const _self = this
|
|
_self.setData({
|
|
orderList: isRefresh ? [] : _self.data.orderList,
|
|
loadingState: isRefresh ? 'loading' : ''
|
|
})
|
|
InvoiceApi.doGetMineInvoiceOrderList(_self.data.pageData, _self.data.currentStatus)
|
|
.then(res => {
|
|
var status = 'success'
|
|
res.rows.map(item => {
|
|
item.checked = _self.data.checkList.find(value => item.accountRechargeId == value.accountRechargeId)
|
|
return item
|
|
})
|
|
status = res.rows && res.rows.length > 0 ? 'success' : 'empty'
|
|
_self.setData({
|
|
loadingState: isRefresh ? status : '',
|
|
orderList: _self.data.orderList.concat(res.rows),
|
|
listRefreshTrig: false,
|
|
isLoadMore: false
|
|
})
|
|
_self.setData({
|
|
hasMore: _self.data.orderList.length < res.total
|
|
})
|
|
}, err => {
|
|
_self.setData({
|
|
loadingState: 'error',
|
|
listRefreshTrig: false,
|
|
isLoadMore: false,
|
|
hasMore: true
|
|
})
|
|
})
|
|
},
|
|
//下拉刷新
|
|
doRefreshList() {
|
|
const _self = this
|
|
_self.setData({
|
|
listRefreshTrig: true,
|
|
loadingState: 'loading',
|
|
hasMore: true,
|
|
'pageData.page': 1,
|
|
'pageData.startTime': _self.data.startTime,
|
|
'pageData.endTime': _self.data.endTime,
|
|
isLoadMore: false
|
|
})
|
|
_self.doGetMineInvoiceOrderList(true)
|
|
},
|
|
|
|
//加载更多
|
|
doLoadMore() {
|
|
//判断是否正在加载中 与是否存在更多数据
|
|
const _self = this
|
|
if (_self.data.isLoadMore || !_self.data.hasMore) {
|
|
return
|
|
}
|
|
|
|
_self.setData({
|
|
isLoadMore: true,
|
|
'pageData.page': ++_self.data.pageData.page,
|
|
'pageData.startTime': _self.data.startTime,
|
|
'pageData.endTime': _self.data.endTime,
|
|
})
|
|
_self.doGetMineInvoiceOrderList(false)
|
|
},
|
|
//选中list
|
|
checkItem(e) {
|
|
if (this.data.currentStatus == 'yes') return;
|
|
const value = e.currentTarget.dataset.value;
|
|
// 查找当前选中项在 checkList 中的索引
|
|
const checkListIndex = this.data.checkList.findIndex(item => item.accountRechargeId === value.accountRechargeId);
|
|
const isHas = checkListIndex !== -1;
|
|
// 更新 orderList 中对应项的 checked 状态
|
|
const newOrderList = this.data.orderList.map(item => {
|
|
item.checked = item.accountRechargeId === value.accountRechargeId ? !isHas : item.checked;
|
|
return item;
|
|
});
|
|
// 更新 checkList
|
|
var newCheckList = [...this.data.checkList];
|
|
if (isHas) {
|
|
newCheckList.splice(checkListIndex, 1);
|
|
} else {
|
|
newCheckList.push(value);
|
|
}
|
|
// 使用 setData 更新数据
|
|
this.setData({
|
|
checkList: newCheckList,
|
|
orderList: newOrderList,
|
|
money: newCheckList.length > 0 ? newCheckList.map(item => {
|
|
let count = 0
|
|
count += item.rechargeMoney
|
|
return count
|
|
}) : 0
|
|
});
|
|
},
|
|
//去开票
|
|
goMakeInvoice() {
|
|
if (this.data.money <= 0) {
|
|
this.setData({
|
|
msgHint: '请先选择要开票的充值记录',
|
|
msgType: 'error',
|
|
msgShow: true
|
|
})
|
|
} else {
|
|
const idArray = this.data.checkList.map(item => item.accountRechargeId)
|
|
const ids = idArray.join(',')
|
|
wx.redirectTo({
|
|
url: `/pages/mine/mineAccount/makeInvoice/makeInvoice?money=${this.data.money}&ids=${ids}`,
|
|
})
|
|
}
|
|
},
|
|
show(e) {
|
|
|
|
},
|
|
hide(e) {
|
|
|
|
},
|
|
slideButtonTap(e) {
|
|
const item = e.currentTarget.dataset.value
|
|
const btn = e.detail.index
|
|
}
|
|
}) |