// pages/mine/mineAccount/mineInvoice/mineInvoice.js // 发票管理首页 import InvoiceApi from '../../../../net/api/invoiceApi' const app = getApp() Page({ /** * 页面的初始数据 */ data: { keywords: '', pageData: { page: 1, rows: 10, keywords: '' }, msgShow: false, msgHint: '', msgType: 'error', loadingState: 'loading', listRefreshTrig: false, isLoadMore: false, hasMore: true, recordList: [], //开票记录 slideBtns: [{ text: '删除', src: app.globalData.localAssets + "/ic_delete_red.png" // icon的路径 }] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { wx.setNavigationBarTitle({ title: '发票管理', }) wx.setNavigationBarColor({ frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000 backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色 animation: { // 可选项 duration: 500, timingFunc: 'easeIn' } }) this.doRefreshList() }, openInvoiceInfo() { wx.navigateTo({ url: '/pages/mine/mineAccount/invoiceInfo/invoiceInfo', }) }, inputKeywords(e) { this.setData({ keywords: e.detail.value }) }, //清除搜索内容 clearSearch() { const _self = this _self.setData({ keywords: '' }) _self.doRefreshList() }, //发起搜索 doSearchKeyWord() { const _self = this _self.doRefreshList() }, doRefreshList() { console.log('正在刷新...') const _self = this _self.setData({ listRefreshTrig: true, loadingState: 'loading', hasMore: true, 'pageData.page': 1, 'pageData.keywords': _self.data.keywords, isLoadMore: false }) _self.doGetInvoiceRecordList(true) }, doLoadMore() { //判断是否正在加载中 与是否存在更多数据 const _self = this if (_self.data.isLoadMore || !_self.data.hasMore) { return } _self.setData({ isLoadMore: true, 'pageData.page': ++_self.data.pageData.page, 'pageData.keywords': _self.data.keywords }) _self.doGetInvoiceRecordList(false) }, doGetInvoiceRecordList(isRefresh) { const _self = this _self.setData({ recordList: isRefresh ? [] : _self.data.recordList, loadingState: isRefresh ? 'loading' : '' }) InvoiceApi.doGetInvoiceRecordList(_self.data.pageData) .then(res => { console.log(res) var status = 'success' status = res.rows && res.rows.length > 0 ? 'success' : 'empty' _self.setData({ loadingState: isRefresh ? status : '', recordList: _self.data.recordList.concat(res.rows), listRefreshTrig: false, isLoadMore: false }) _self.setData({ hasMore: _self.data.recordList.length < res.total }) }, err => { _self.setData({ loadingState: 'error', listRefreshTrig: false, isLoadMore: false, hasMore: true }) }) }, //跳转可以开具发票订单列表 openMake() { wx.navigateTo({ url: '/pages/mine/mineAccount/invoiceOrder/invoiceOrder', }) }, //取消开票 cancelRecord(e) { const item = e.currentTarget.dataset.value const _self = this wx.showModal({ title: '警告', content: '请问您是否真的想要取消此次开票操作?', complete: (res) => { if (res.confirm) { _self.doCancelInvoiceRecord(item) } } }) }, //取消开票 doCancelInvoiceRecord(item) { const _self = this wx.showLoading({ title: '取消中...', }) InvoiceApi.doCancelInvoiceRecord(item.invoiceRechargeId) .then(res => { wx.hideLoading() console.log(res) _self.setData({ msgHint: '取消成功', msgType: 'success', msgShow: true }) _self.doRefreshList() }) .catch(err => { wx.hideLoading() _self.setData({ msgHint: err.msg ? err.msg : '取消出错了,请稍后重试', msgShow: true, msgType: 'error' }) }) }, //去修改 doUpdate(e) { const item = e.currentTarget.dataset.value const params = JSON.stringify(item) const _self = this wx.navigateTo({ url: '/pages/mine/mineAccount/makeInvoice/makeInvoice?bean=' + params, events: { refreshData: function (data) { console.log('刷新') _self.doRefreshList() } } }) }, openDetail(e) { const item = e.currentTarget.dataset.value const params = JSON.stringify(item) wx.navigateTo({ url: '/pages/mine/mineAccount/invoiceRecordDetail/invoiceRecordDetail?bean=' + params, }) }, slideButtonTap(e) { const item = e.currentTarget.dataset.value const btn = e.detail.index console.log(item) if (btn == 0) { //删除,先判断状态 用户取消-1,开票失败:0,开票中:1,开票完成:2 if (item.invoiceStatus != '1') { this.showDelDialog(item) } else { this.setData({ msgHint: '当前发票处于开具流程中,暂不支持删除', msgType: 'error', msgShow: true }) } } }, showDelDialog(item) { const _self = this wx.showModal({ title: '警告', content: '该开票记录删除后不可恢复,是否确认执行删除操作?请谨慎抉择', complete: (res) => { if (res.confirm) { _self.doDelRecord(item) } } }) }, //删除记录 doDelRecord(item) { } })