修复发票编辑时候异常
This commit is contained in:
@@ -1,66 +1,118 @@
|
||||
// pages/updateInvoice/index.js
|
||||
Page({
|
||||
import { getInvoiceInfo, updateInvoiceInfo } from "../../service/invoice"
|
||||
import { getUserInfo } from "../../service/user";
|
||||
import { alertInfo, alertSuccess } from "../../utils/index";
|
||||
import request from '../../utils/request'
|
||||
const { OK } = request
|
||||
|
||||
// pages/invoiceList/components/info/index.js
|
||||
Component({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
* 组件的属性列表
|
||||
*/
|
||||
properties: {
|
||||
|
||||
},
|
||||
lifetimes: {
|
||||
attached() {
|
||||
this.getDetail();
|
||||
this.getUser();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 组件的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
detail: { },
|
||||
formData: {headerType: 0, name: wx.getStorageSync('tenement')?.name},
|
||||
editType: "detail"
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
* 组件的方法列表
|
||||
*/
|
||||
onLoad(options) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
|
||||
methods: {
|
||||
async getDetail() {
|
||||
const { code, message, data } = await getInvoiceInfo()
|
||||
if (code !== OK) {
|
||||
alertInfo(message)
|
||||
return;
|
||||
}
|
||||
this.setData({ detail: {...data,name: wx.getStorageSync('tenement')?.name, },editType: 'detail', })
|
||||
},
|
||||
async getUser() {
|
||||
const { code, message, data } = await getUserInfo()
|
||||
this.setData({ user: data });
|
||||
},
|
||||
changeEditType() {
|
||||
this.setData({ editType: 'edit', formData: {...this.data.detail, tenement: wx.getStorageSync('tenement')?.id} })
|
||||
},
|
||||
cancelEdit() {
|
||||
this.setData({ editType: 'detail', formData: {} })
|
||||
},
|
||||
onChangeType(e) {
|
||||
const { formData } = this.data;
|
||||
this.setData({ formData: {...formData, type: e.detail} })
|
||||
},
|
||||
onChangeHeaderType(e) {
|
||||
const { formData } = this.data;
|
||||
this.setData({ formData: {...formData, headerType: e.detail} })
|
||||
},
|
||||
onChangeText(e) {
|
||||
const { name } = e.currentTarget.dataset;
|
||||
const { formData } = this.data;
|
||||
this.setData({ formData: {...formData, [name]: e.detail} })
|
||||
},
|
||||
async submit() {
|
||||
const { formData } = this.data;
|
||||
const { tin, address, phone, bank, account, email, type, headerType, name } = formData;
|
||||
if (type !== 0 && type !== 1) {
|
||||
alertInfo("请选择发票类型");
|
||||
return;
|
||||
}
|
||||
if (headerType !== 0 && headerType !== 1) {
|
||||
alertInfo("请选择抬头类型");
|
||||
return;
|
||||
}
|
||||
if (headerType === 1) {
|
||||
if (!name) {
|
||||
alertInfo("请输入发票抬头")
|
||||
return
|
||||
}
|
||||
}
|
||||
if (!email || !/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email)) {
|
||||
alertInfo("邮箱格式不正确")
|
||||
return;
|
||||
}
|
||||
if (headerType === 0) {
|
||||
if (!tin) {
|
||||
alertInfo("请输入发票税号")
|
||||
return;
|
||||
}
|
||||
// if (!address) {
|
||||
// alertInfo("请输入地址")
|
||||
// return;
|
||||
// }
|
||||
if (!phone) {
|
||||
alertInfo("请输入电话")
|
||||
return;
|
||||
}
|
||||
if (!bank) {
|
||||
alertInfo("请输入开户行")
|
||||
return;
|
||||
}
|
||||
if (!account) {
|
||||
alertInfo("请输入银行账号")
|
||||
return;
|
||||
}
|
||||
}
|
||||
const { code, message } = await updateInvoiceInfo(formData)
|
||||
if (code !== OK) {
|
||||
alertInfo(message)
|
||||
return;
|
||||
}
|
||||
alertSuccess("编辑成功")
|
||||
this.getDetail()
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user