修复发票编辑时候异常

This commit is contained in:
qiaomu 2024-05-08 17:18:11 +08:00
parent b673d0c994
commit 6d35c78da9
6 changed files with 456 additions and 77 deletions

View File

@ -70,14 +70,21 @@
title-width="132rpx" title-width="132rpx"
border="{{ false }}" border="{{ false }}"
/> />
<van-field
wx:elif="{{editType === 'edit' && formData.headerType === 0 }}"
value="{{formData.name || '--'}}"
label="发票抬头"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{true}}"
disabled="{{true}}"
title-width="132rpx"
border="{{ true }}"
/>
<van-field <van-field
wx:else wx:else
value="{{formData.name}}" value="{{formData.name}}"
label="发票抬头" label="发票抬头"
custom-style="padding-left: 0; padding-right: 0;" custom-style="padding-left: 0; padding-right: 0;"
disabled="{{formData.headerType !== 1}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx" title-width="132rpx"
bind:change="onChangeText" bind:change="onChangeText"
data-name="name" data-name="name"
@ -102,8 +109,6 @@
placeholder="{{editType === 'edit' ? '请输入发票税号' : ''}}" placeholder="{{editType === 'edit' ? '请输入发票税号' : ''}}"
custom-style="padding-left: 0; padding-right: 0;" custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}" readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx" title-width="132rpx"
bind:change="onChangeText" bind:change="onChangeText"
data-name="tin" data-name="tin"
@ -126,8 +131,6 @@
wx:if="{{editType === 'edit' && formData.headerType === 0}}" wx:if="{{editType === 'edit' && formData.headerType === 0}}"
placeholder="{{'请输入开户行'}}" placeholder="{{'请输入开户行'}}"
custom-style="padding-left: 0; padding-right: 0;" custom-style="padding-left: 0; padding-right: 0;"
autosize="{{true}}"
type="textarea"
title-width="132rpx" title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}" border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText" bind:change="onChangeText"
@ -154,8 +157,6 @@
placeholder="{{editType === 'edit' ? '请输入银行账号' : ''}}" placeholder="{{editType === 'edit' ? '请输入银行账号' : ''}}"
custom-style="padding-left: 0; padding-right: 0;" custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}" readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx" title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}" border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText" bind:change="onChangeText"
@ -182,8 +183,6 @@
placeholder="{{editType === 'edit' ? '请输入地址' : ''}}" placeholder="{{editType === 'edit' ? '请输入地址' : ''}}"
custom-style="padding-left: 0; padding-right: 0;" custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}" readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx" title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}" border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText" bind:change="onChangeText"
@ -210,8 +209,6 @@
placeholder="{{editType === 'edit' ? '请输入电话' : ''}}" placeholder="{{editType === 'edit' ? '请输入电话' : ''}}"
custom-style="padding-left: 0; padding-right: 0;" custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}" readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx" title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}" border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText" bind:change="onChangeText"
@ -237,8 +234,6 @@
placeholder="{{editType === 'edit' ? '请输入备注' : ''}}" placeholder="{{editType === 'edit' ? '请输入备注' : ''}}"
custom-style="padding-left: 0; padding-right: 0;" custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}" readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx" title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}" border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText" bind:change="onChangeText"
@ -269,8 +264,6 @@
label="电子邮箱" label="电子邮箱"
custom-style="padding-left: 0; padding-right: 0;" custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}" readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx" title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}" border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText" bind:change="onChangeText"

View File

@ -69,7 +69,7 @@ Page({
}, },
jumpToUpdateInvoice() { jumpToUpdateInvoice() {
wx.navigateTo({ wx.navigateTo({
url: '/pages/updateInvoice/index', url: '/pages/invoiceList/index?tab=2',
}) })
}, },
async getUnReadNumber() { async getUnReadNumber() {

View File

@ -1,66 +1,118 @@
// pages/updateInvoice/index.js import { getInvoiceInfo, updateInvoiceInfo } from "../../service/invoice"
Page({ 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: { data: {
detail: { },
formData: {headerType: 0, name: wx.getStorageSync('tenement')?.name},
editType: "detail"
}, },
/** /**
* 生命周期函数--监听页面加载 * 组件的方法列表
*/ */
onLoad(options) { 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 });
*/
onReady() {
}, },
changeEditType() {
/** this.setData({ editType: 'edit', formData: {...this.data.detail, tenement: wx.getStorageSync('tenement')?.id} })
* 生命周期函数--监听页面显示
*/
onShow() {
}, },
cancelEdit() {
/** this.setData({ editType: 'detail', formData: {} })
* 生命周期函数--监听页面隐藏
*/
onHide() {
}, },
onChangeType(e) {
/** const { formData } = this.data;
* 生命周期函数--监听页面卸载 this.setData({ formData: {...formData, type: e.detail} })
*/
onUnload() {
}, },
onChangeHeaderType(e) {
/** const { formData } = this.data;
* 页面相关事件处理函数--监听用户下拉动作 this.setData({ formData: {...formData, headerType: e.detail} })
*/
onPullDownRefresh() {
}, },
onChangeText(e) {
/** const { name } = e.currentTarget.dataset;
* 页面上拉触底事件的处理函数 const { formData } = this.data;
*/ this.setData({ formData: {...formData, [name]: e.detail} })
onReachBottom() {
}, },
async submit() {
/** const { formData } = this.data;
* 用户点击右上角分享 const { tin, address, phone, bank, account, email, type, headerType, name } = formData;
*/ if (type !== 0 && type !== 1) {
onShareAppMessage() { 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()
}
} }
}) })

View File

@ -1,7 +1,13 @@
{ {
"usingComponents": { "usingComponents": {
"navigator": "/components/navigator/index", "navigator": "/components/navigator/index",
"info": "/pages/invoiceList/components/info/index" "info": "/pages/invoiceList/components/info/index",
"card": "/components/card/index",
"van-icon": "@vant/weapp/icon/index",
"van-field": "@vant/weapp/field/index",
"van-radio": "@vant/weapp/radio/index",
"van-radio-group": "@vant/weapp/radio-group/index",
"van-button": "@vant/weapp/button/index"
}, },
"navigationStyle": "custom" "navigationStyle": "custom"
} }

View File

@ -1,3 +1,298 @@
<!--pages/updateInvoice/index.wxml--> <!--pages/updateInvoice/index.wxml-->
<navigator title="发票抬头" canBack="{{true}}" /> <navigator title="发票抬头" canBack="{{true}}" />
<info /> <view class="cardWrapper">
<card title="发票详情">
<view
slot="operate"
class="cardOperate"
wx:if="{{editType === 'detail' && user.isAdmin}}"
bind:tap="changeEditType"
>
<van-icon name="edit" />
<view class="editContent">修改</view>
</view>
<view slot="content">
<van-field
label="发票类型"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
custom-style="padding-left: 0; padding-right: 0;"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
>
<view slot="input" style="margin-top: 16rpx;" wx:if="{{editType === 'edit'}}">
<van-radio-group direction="horizontal" value="{{formData.type}}" bind:change="onChangeType">
<van-radio name="{{0}}" icon-size="30rpx" style="font-size: 30rpx;margin-bottom: 20rpx;">普通电子</van-radio>
<van-radio name="{{1}}" icon-size="30rpx" style="font-size: 30rpx;">增值税专用电子</van-radio>
</van-radio-group>
</view>
<view wx:else slot="input" style="margin-top: -10rpx;">
<view wx:if="{{detail.type === 0}}"> 普通电子发票 </view>
<view wx:elif="{{detail.type === 1}}"> 增值税专用电子发票 </view>
<view wx:else>-</view>
</view>
</van-field>
<van-field
label="抬头类型"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
custom-style="padding-left: 0; padding-right: 0;"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
>
<view slot="input" style="margin-top: 16rpx;" wx:if="{{editType === 'edit'}}">
<van-radio-group direction="horizontal" bind:change="onChangeHeaderType" value="{{formData.headerType}}">
<van-radio name="{{0}}" icon-size="30rpx" style="font-size: 30rpx;margin-bottom: 20rpx;">企业单位</van-radio>
<van-radio name="{{1}}" icon-size="30rpx" style="font-size: 30rpx;">个人/非企业单位</van-radio>
</van-radio-group>
</view>
<view
wx:else
slot="input"
style="margin-top: -10rpx;"
>
<view wx:if="{{detail.headerType === 0}}"> 企业单位 </view>
<view wx:elif="{{detail.headerType === 1}}"> 个人/非企业单位 </view>
<view wx:else>-</view>
</view>
</van-field>
<van-field
wx:if="{{editType === 'detail'}}"
value="{{detail.name || '--'}}"
label="发票抬头"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{true}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ false }}"
/>
<van-field
wx:elif="{{editType === 'edit' }}"
value="{{detail.name || '--'}}"
label="发票抬头"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{true}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ false }}"
/>
<van-field
wx:else
value="{{formData.name}}"
label="发票抬头"
custom-style="padding-left: 0; padding-right: 0;"
disabled="{{formData.headerType !== 1}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
bind:change="onChangeText"
data-name="name"
bind:change="onChangeText"
border="{{ true }}"
/>
<van-field
value="{{detail.tin|| '--'}}"
label="发票税号"
wx:if="{{editType === 'detail' && detail.headerType === 0}}"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
/>
<van-field
value="{{formData.tin }}"
label="发票税号"
wx:if="{{editType === 'edit' && formData.headerType === 0}}"
placeholder="{{editType === 'edit' ? '请输入发票税号' : ''}}"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
bind:change="onChangeText"
data-name="tin"
border="{{ editType === 'detail' ? false : true }}"
/>
<van-field
value="{{detail.bank || '--'}}"
label="开户行"
wx:if="{{editType === 'detail' && detail.headerType === 0}}"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
/>
<van-field
value="{{formData.bank}}"
label="开户行"
wx:if="{{editType === 'edit' && formData.headerType === 0}}"
placeholder="{{'请输入开户行'}}"
custom-style="padding-left: 0; padding-right: 0;"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText"
data-name="bank"
/>
<van-field
value="{{detail.account || '--'}}"
label="银行账号"
wx:if="{{(editType === 'detail' && detail.headerType === 0)}}"
placeholder="{{editType === 'edit' ? '请输入银行账号' : ''}}"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText"
data-name="account"
/>
<van-field
value="{{formData.account}}"
label="银行账号"
wx:if="{{(editType === 'edit' && formData.headerType === 0) }}"
placeholder="{{editType === 'edit' ? '请输入银行账号' : ''}}"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText"
data-name="account"
/>
<van-field
value="{{detail.address || '--'}}"
label="地址"
wx:if="{{(editType === 'detail' && detail.headerType === 0)}}"
placeholder="{{editType === 'edit' ? '请输入地址' : ''}}"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText"
data-name="address"
/>
<van-field
value="{{formData.address}}"
label="地址"
wx:if="{{(editType === 'edit' && formData.headerType === 0)}}"
placeholder="{{editType === 'edit' ? '请输入地址' : ''}}"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText"
data-name="address"
/>
<van-field
value="{{detail.phone || '--'}}"
label="电话"
wx:if="{{(editType === 'detail' && detail.headerType === 0)}}"
placeholder="{{editType === 'edit' ? '请输入电话' : ''}}"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText"
data-name="phone"
/>
<van-field
value="{{formData.phone }}"
label="电话"
wx:if="{{(editType === 'edit' && formData.headerType === 0) }}"
placeholder="{{editType === 'edit' ? '请输入电话' : ''}}"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText"
data-name="phone"
/>
<van-field
value="{{detail.remark || '--'}}"
label="备注"
wx:if="{{editType === 'detail' }}"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText"
data-name="remark"
/>
<van-field
value="{{formData.remark}}"
label="备注"
wx:else
placeholder="{{editType === 'edit' ? '请输入备注' : ''}}"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText"
data-name="remark"
/>
</view>
</card>
</view>
<view class="cardWrapper" style="margin-bottom: 40rpx;">
<card title="接收信息">
<view slot="content">
<van-field
value="{{detail.email || '--'}}"
wx:if="{{editType === 'detail'}}"
label="电子邮箱"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText"
data-name="email"
/>
<van-field
value="{{formData.email}}"
wx:else
label="电子邮箱"
custom-style="padding-left: 0; padding-right: 0;"
readonly="{{editType === 'detail'}}"
autosize="{{true}}"
type="textarea"
title-width="132rpx"
border="{{ editType === 'detail' ? false : true }}"
bind:change="onChangeText"
data-name="email"
/>
</view>
</card>
</view>
<view class="submit" wx:if="{{editType === 'edit'}}">
<van-button block class="cancelEdit" bind:click="cancelEdit">取消编辑</van-button>
<van-button type="info" block class="save" bind:click="submit">保存</van-button>
</view>

View File

@ -1 +1,34 @@
/* pages/updateInvoice/index.wxss */ /* pages/updateInvoice/index.wxss *//* pages/invoiceList/components/info/index.wxss */
.cardOperate {
display: flex;
align-items: center;
font-size: 32rpx;
}
.cardWrapper {
margin-top: 30rpx;
}
.editContent {
margin-left: 20rpx;
}
.van-cell {
padding-left: 0rpx !important;
padding-right: 0rpx !important;
}
.submit {
margin: 32rpx;
margin-bottom: 50rpx;
display: flex;
align-items: center;
}
.cancelEdit, .save {
flex: 1;
}
.cancelEdit {
margin-right: 40rpx;
}