244 lines
7.3 KiB
JavaScript
244 lines
7.3 KiB
JavaScript
|
// pages/mine/mineAccount/makeInvoice/makeInvoice.js
|
||
|
import InvoiceApi from '../../../../net/api/invoiceApi'
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
msgType: 'error',
|
||
|
msgHint: '',
|
||
|
msgShow: false,
|
||
|
typeList: [], //开票类型
|
||
|
contentList: [], //开票内容
|
||
|
rateList: [], //开票税率
|
||
|
typeId: '',
|
||
|
contentId: '',
|
||
|
rateId: '',
|
||
|
invoiceInfo: null, //开票信息
|
||
|
invoiceMoney: 0, //开票金额
|
||
|
showInvoiceInfo: false,
|
||
|
invoiceInfoList: [], //开票信息
|
||
|
payOrderIds: '', //开票记录id
|
||
|
remark: '', //备注信息
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad(options) {
|
||
|
wx.setNavigationBarTitle({
|
||
|
title: '开发票',
|
||
|
})
|
||
|
wx.setNavigationBarColor({
|
||
|
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
|
||
|
backgroundColor: '#F0F0F0', // 传递的颜色值,仅支持十六进制颜色
|
||
|
animation: { // 可选项
|
||
|
duration: 500,
|
||
|
timingFunc: 'easeIn'
|
||
|
}
|
||
|
})
|
||
|
this.setData({
|
||
|
invoiceMoney: options.money,
|
||
|
payOrderIds: options.ids
|
||
|
})
|
||
|
//获取开票类型
|
||
|
//获取开票内容
|
||
|
//获取开票税率
|
||
|
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]
|
||
|
})
|
||
|
console.log(res)
|
||
|
})
|
||
|
.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() {
|
||
|
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
|
||
|
})
|
||
|
} else {
|
||
|
this.setData({
|
||
|
msgType: 'error',
|
||
|
msgHint: '发票开取失败,请稍后重试',
|
||
|
msgShow: true
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
.catch(err => {
|
||
|
wx.hideLoading()
|
||
|
console.log(err)
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
//校验参数
|
||
|
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
|
||
|
}
|
||
|
|
||
|
})
|