ts_aimz/pages/mine/mineAccount/makeInvoice/makeInvoice.js

337 lines
11 KiB
JavaScript

// pages/mine/mineAccount/makeInvoice/makeInvoice.js
import InvoiceApi from '../../../../net/api/invoiceApi'
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
imgAssets: app.globalData.imgAssetsUrl,
msgType: 'error',
msgHint: '',
msgShow: false,
typeList: [], //开票类型
contentList: [], //开票内容
rateList: [], //开票税率
typeId: '',
contentId: '',
rateId: '',
invoiceInfo: null, //开票信息
invoiceMoney: 0, //开票金额
showInvoiceInfo: false,
invoiceInfoList: [], //开票信息
payOrderIds: '', //开票记录id
remark: '', //备注信息
editBean: null, //编辑页面传递过来的
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.setNavigationBarTitle({
title: '开发票',
})
wx.setNavigationBarColor({
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
animation: { // 可选项
duration: 500,
timingFunc: 'easeIn'
}
})
const ids = options.ids
if (ids) {
this.setData({
invoiceMoney: options.money,
payOrderIds: options.ids
})
} else {
const beanStr = options.bean
const bean = JSON.parse(beanStr)
this.setData({
editBean: bean,
rateId: bean.invoiceTaxrate,
contentId: bean.invoicePurpose,
typeId: bean.invoiceClassify,
invoiceMoney: bean.invoiceRechargeMoney,
payOrderIds: bean.invoiceRechargeIds,
remark: bean.invoiceRecord,
invoiceInfo: {
invoiceId: bean.invoiceId,
invoiceName: bean.invoiceName,
invoiceNumber: bean.invoiceNumber,
invoiceOrgaddress: bean.invoiceOrgaddress,
invoiceOrgtel: bean.invoiceOrgtel
}
})
}
//获取开票类型
//获取开票内容
//获取开票税率
this.getPageData()
},
//获取页面数据
getPageData() {
wx.showLoading({
title: '加载中...',
})
const _self = this
const type = InvoiceApi.doGetDicListByPId('e0251d55-cd52-4f57-be92-b2bef8a6dd62')
const content = InvoiceApi.doGetDicListByPId('b67d5208-db1d-4d0e-99de-cc22d9d50041')
const rate = InvoiceApi.doGetDicListByPId('e4808c45-64ee-42fa-a413-a470fbdc0aea')
const list = [type, content, rate]
Promise.all(list)
.then(res => {
wx.hideLoading()
_self.setData({
contentList: res[0],
rateList: res[1],
typeList: res[2]
})
})
.catch(err => {
wx.hideLoading()
console.log(err)
_self.setData({
msgHint: '数据有误,请稍后重试',
msgType: 'error',
msgShow: true
})
setTimeout(() => {
wx.navigateBack()
}, 1800);
})
},
inputRemark(e) {
this.setData({
remark: e.detail.value
})
},
changeContent(e) {
this.setData({
contentId: e.detail.value
})
},
changeType(e) {
this.setData({
typeId: e.detail.value
})
},
changeRate(e) {
this.setData({
rateId: e.detail.value
})
},
changeInvoiceInfo(e) {
console.log('groupChange', e)
const index = e.detail.value;
const selectedItem = this.data.invoiceInfoList[index];
this.setData({
invoiceInfo: selectedItem,
showInvoiceInfo: false
});
},
onInvoiceItemClick(e) {
console.log(e)
this.setData({
invoiceInfo: e.currentTarget.dataset.value,
showInvoiceInfo: false
})
},
openCreateInvoiceInfo() {
this.setData({
showInvoiceInfo: false
})
wx.navigateTo({
url: '/pages/mine/mineAccount/invoiceInfo/invoiceInfo',
})
},
//获取开票信息
doGetInvoiceInfoList() {
const _self = this
wx.showLoading({
title: '加载中...',
})
const pageData = {
page: 1,
rows: 100
}
InvoiceApi.doGetMineInvoiceList(pageData)
.then(res => {
console.log(res)
wx.hideLoading()
if (res.rows && res.rows.length > 0) {
_self.setData({
invoiceInfoList: res.rows,
showInvoiceInfo: true
})
} else {
_self.setData({
invoiceInfoList: [],
msgShow: true,
msgType: 'error',
msgHint: '您暂无开票信息,请添加信息后,再进行开票操作',
showInvoiceInfo: false
})
}
})
.catch(err => {
wx.hideLoading()
_self.setData({
msgShow: true,
msgType: 'error',
msgHint: err.msg ? err.msg : '网络错误,请稍后重试',
showInvoiceInfo: false
})
})
},
//构建提交参数
buildParams() {
const data = {
invoiceId: this.data.invoiceInfo.invoiceId,
invoiceTaxrate: this.data.rateId,
invoicePurpose: this.data.contentId,
invoiceClassify: this.data.typeId,
invoiceRecord: this.data.remark,
accountRechargeIds: this.data.payOrderIds
}
return data
},
doSaveInfo() {
//判断编辑 新增
const isLegal = this.checkParams()
if (isLegal) {
wx.showLoading({
title: '提交中...',
})
const _self = this
const data = _self.buildParams()
InvoiceApi.doSaveInvoiceRecord(data)
.then(res => {
wx.hideLoading()
console.log(res)
if (res.data && res.data != '') {
this.setData({
msgType: 'success',
msgHint: '开票信息提交成功!我们会以最快速度完成开票,还请耐心等待!',
msgShow: true
})
setTimeout(() => {
_self.backPageRefresh()
}, 1800);
} else {
this.setData({
msgType: 'error',
msgHint: '发票开取失败,请稍后重试',
msgShow: true
})
}
})
.catch(err => {
wx.hideLoading()
this.setData({
msgType: 'error',
msgHint: err.msg ? err.msg : '发票开取失败,请稍后重试',
msgShow: true
})
})
}
},
//校验参数
checkParams() {
if (this.data.invoiceInfo == null) {
this.setData({
msgType: 'error',
msgHint: '请选择开票信息',
msgShow: true
})
return false
}
if (this.data.typeId == '') {
this.setData({
msgType: 'error',
msgHint: '请选择开票类型',
msgShow: true
})
return false
}
if (this.data.contentId == '') {
this.setData({
msgType: 'error',
msgHint: '请选择开票内容',
msgShow: true
})
return false
}
if (this.data.rateId == '') {
this.setData({
msgType: 'error',
msgHint: '请选择开票税率',
msgShow: true
})
return false
}
return true
},
//提交
confirmSubmit() {
if (this.data.bean != null && this.data.bean.invoiceRechargeId != '') {
this.doSaveInfo()
} else {
this.doEditInfo()
}
},
//编辑
doEditInfo() {
const isLegal = this.checkParams()
if (isLegal) {
const data = this.buildParams()
const _self = this
wx.showLoading({
title: '提交中...',
})
InvoiceApi.doUpdateInvoiceRecord(_self.data.editBean.invoiceRechargeId, data)
.then(res => {
wx.hideLoading()
if (res.data && res.data != '') {
this.setData({
msgType: 'success',
msgHint: '开票信息编辑成功!我们会以最快速度完成开票,还请耐心等待!',
msgShow: true
})
setTimeout(() => {
_self.backPageRefresh()
}, 1800);
} else {
this.setData({
msgType: 'error',
msgHint: '发票信息编辑失败,请稍后重试',
msgShow: true
})
}
})
.catch(err => {
wx.hideLoading()
this.setData({
msgType: 'error',
msgHint: err.msg ? err.msg : '发票信息编辑失败,请稍后重试',
msgShow: true
})
})
}
},
backPageRefresh() {
const _self = this
let pages = getCurrentPages();
let beforePage = pages[pages.length - 2];
beforePage.doRefreshList()
wx.navigateBack()
},
closeDialog(e) {
this.setData({
showInvoiceInfo: false
})
}
})