Files
FreeERP.Applet/miniprogram/pages/base/account/edit/edit.ts

122 lines
2.7 KiB
TypeScript
Raw Normal View History

2026-03-06 17:18:27 +08:00
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
getDataSet,
sleep,
toastError,
toastSuccess,
toNumber,
toObject,
} from '@/utils/util';
const defaultParams = { comments: '', account_name: '' };
Page({
/**
*
*/
data: {
params: cloneLite(defaultParams) as any,
mode: 'new' as 'new' | 'edit',
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
},
onChange(e: any) {
const key = getDataSet(e).key;
const val = e.detail.value;
this.data.params[key] = val;
this.setData({ params: this.data.params });
},
onBlur(e: any) {
const key = getDataSet(e).key;
if (key == 'init_amount') {
const val = e.detail.value;
this.data.params[key] = val ? toNumber(val).toFixed(2) : val;
this.setData({ params: this.data.params });
}
},
onCheckboxChange(e: any) {
const key = getDataSet(e).key;
this.data.params[key] = e.detail.checked ? 1 : 2;
this.setData({ params: this.data.params });
},
onSave() {
// console.log(this.data.params);
if (this.data.mode == 'new') {
this.data.params.current_amount = this.data.params.init_amount;
}
if (this.data.params.account_name) {
post(this.data.mode == 'new' ? 'ErpAccount/add' : 'ErpAccount/edit', this.data.params).then(
() => {
toastSuccess('保存成功');
sleep(() => {
wx.navigateBack();
}, 1000);
},
);
} else {
2026-03-09 14:21:52 +08:00
toastError('账户名称必填');
2026-03-06 17:18:27 +08:00
}
},
/**
* --
*/
onLoad(_options) {
const eventChannel: any = this.getOpenerEventChannel();
eventChannel?.on('accountEdit', (e: any) => {
const data = toObject(e.data);
wx.setNavigationBarTitle({
title: data.account_id ? `${data.account_name} 修改` : '新增结算账户',
});
this.setData({ params: data, mode: data.account_id ? 'edit' : 'new' });
});
},
/**
* --
*/
onReady() {},
/**
* --
*/
onShow() {
loginStatusPage(this);
},
/**
* --
*/
onHide() {},
/**
* --
*/
onUnload() {},
/**
* --
*/
onPullDownRefresh() {},
/**
*
*/
onReachBottom() {},
/**
*
*/
onShareAppMessage() {},
});