// pages/mine/mineAccount/invoiceInfo/invoiceInfo.js import InvoiceApi from '../../../../net/api/invoiceApi' import { isValidPhone } from '../../../../utils/validator' const app = getApp() Page({ /** * 页面的初始数据 */ data: { imgAssets: app.globalData.imgAssetsUrl, localAssets: app.globalData.localAssets, keywords: '', pageData: { page: 1, rows: 10, keywords: '' }, msgShow: false, msgHint: '', msgType: 'error', loadingState: 'loading', listRefreshTrig: false, isLoadMore: false, hasMore: true, createDialog: false, title: '开票信息', isCreate: true, //区别是创建 or 编辑 companyName: '', //公司名称 companyAddress: '', //公司地址 companyPhone: '', //公司电话 companyBank: '', //公司开户行 bankNum: '', //开户行账号 tinNum: '', //纳税人识别号 btnTxt: '提交', invoiceInfoList: [], //开票信息列表 tempItem: null, slideButtons: app.globalData.slideBtns }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { wx.setNavigationBarTitle({ title: '开票信息', }) wx.setNavigationBarColor({ frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000 backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色 animation: { // 可选项 duration: 500, timingFunc: 'easeIn' } }) this.doRefreshList() }, closeDialog(e){ this.setData({ createDialog:false }) }, inputKeywords(e) { this.setData({ keywords: e.detail.value }) }, //清除搜索内容 clearSearch() { const _self = this _self.setData({ keywords: '' }) _self.doRefreshList() }, //发起搜索 doSearchKeyWord() { const _self = this _self.doRefreshList() }, doGetInvoiceInfoList(isRefresh) { const _self = this _self.setData({ invoiceInfoList: isRefresh ? [] : _self.data.invoiceInfoList, loadingState: isRefresh ? 'loading' : '' }) InvoiceApi.doGetMineInvoiceList(_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 : '', invoiceInfoList: _self.data.invoiceInfoList.concat(res.rows), listRefreshTrig: false, isLoadMore: false }) _self.setData({ hasMore: _self.data.invoiceInfoList.length < res.total }) }, err => { _self.setData({ loadingState: 'error', listRefreshTrig: false, isLoadMore: false, hasMore: true }) }) }, 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.doGetInvoiceInfoList(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.doGetInvoiceInfoList(false) }, inputCompanyName(e) { this.setData({ companyName: e.detail.value }) }, inputTinNum(e) { this.setData({ tinNum: e.detail.value }) }, inputAddress(e) { this.setData({ companyAddress: e.detail.value }) }, inputPhone(e) { this.setData({ companyPhone: e.detail.value }) }, inputBank(e) { this.setData({ companyBank: e.detail.value }) }, inputBankNum(e) { this.setData({ bankNum: e.detail.value }) }, showCreateDialog() { this.setData({ title: '开票信息', isCreate: true, createDialog: !this.data.createDialog }) }, //显示编辑 showEditDialog(item) { const _self = this _self.setData({ tempItem: item, companyName: item.invoiceName, tinNum: item.invoiceNumber, companyAddress: item.invoiceOrgaddress, companyPhone: item.invoiceOrgtel, companyBank: item.invoiceBank, bankNum: item.invoiceBanknumber, isCreate: false, createDialog: true }) }, //删除 showDelDialog(item) { wx.showModal({ title: '警告', content: '您确定要删除该开票信息吗?', complete: (res) => { if (res.confirm) { this.doDeleteInvoiceInfo(item) } } }) }, //删除开票信息 doDeleteInvoiceInfo(item) { const _self = this wx.showLoading({ title: '删除中...', }) InvoiceApi.doDelMineInvoiceInfo(item.invoiceId) .then(res => { wx.hideLoading() _self.setData({ msgHint: '删除成功', msgType: 'success', msgShow: true }) _self.doRefreshList() }) .catch(err => { wx.hideLoading() _self.setData({ msgHint: err.msg ? err.msg : '删除失败,请稍后重试', msgType: 'error', msgShow: true }) }) }, //编辑开票信息 editInvoiceInfo() { const isLegl = this.checkParams() if (isLegl) { const _self = this wx.showLoading({ title: '修改中...', }) const data = _self.buildParams() InvoiceApi.doUpdateMineInvoiceInfo(_self.data.tempItem.invoiceId, data) .then(res => { wx.hideLoading() _self.setData({ tempItem: null, msgType: 'success', msgHint: '修改开票信息成功', msgShow: true, companyName: '', tinNum: '', companyAddress: '', companyPhone: '', companyBank: '', bankNum: '', isCreate: true, createDialog: false }) _self.doRefreshList() }) .catch(err => { wx.hideLoading() _self.setData({ msgType: 'error', msgHint: err.msg ? err.msg : '修改开票信息失败,请稍后重试', msgShow: true }) }) } }, buildParams() { const _self = this const data = { invoiceType: "企业", invoiceName: _self.data.companyName, invoiceNumber: _self.data.tinNum, invoiceOrgaddress: _self.data.companyAddress, invoiceOrgtel: _self.data.companyPhone, invoiceBank: _self.data.companyBank, invoiceBanknumber: _self.data.bankNum, } return data }, //新增开票信息 saveInvoiceInfo() { const _self = this var isLegal = _self.checkParams() if (isLegal) { wx.showLoading({ title: '提交中...', }) const data = _self.buildParams() InvoiceApi.doSaveMineInvoiceInfo(data) .then(res => { wx.hideLoading() _self.setData({ msgType: 'success', msgHint: '新增开票信息成功', msgShow: true, companyName: '', tinNum: '', companyAddress: '', companyPhone: '', companyBank: '', bankNum: '', createDialog: false }) _self.doRefreshList() }) .catch(err => { wx.hideLoading() _self.setData({ msgType: 'error', msgHint: err.msg ? err.msg : '新增开票信息失败,请稍后重试', msgShow: true }) }) } }, checkParams() { var _self = this if (_self.data.companyName == '') { _self.setData({ msgType: 'error', msgHint: '请输入公司名称', msgShow: true }) return false } if (_self.data.tinNum == '') { _self.setData({ msgType: 'error', msgHint: '请输入纳税人识别号', msgShow: true }) return false } if (_self.data.companyPhone != '') { if (!isValidPhone(_self.data.companyPhone)) { _self.setData({ msgType: 'error', msgHint: '公司电话号码有误,请核查', msgShow: true }) return false } } return true }, show() { console.log('show') }, hide() { console.log('hide') }, slideButtonTap(e) { console.log(e) const item = e.currentTarget.dataset.value const btn = e.detail.index if (btn == 0) { //编辑 this.showEditDialog(item) } else { //删除 this.showDelDialog(item) } } })