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

124 lines
2.6 KiB
TypeScript
Raw Normal View History

2026-03-09 14:21:52 +08:00
import { loginStatusPage, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
getDataSet,
sleep,
toastError,
toastSuccess,
toObject,
} from '@/utils/util';
const defaultParams = { comments: '', crm_name: '', crm_type: 1 };
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 });
},
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.params.crm_name) {
if (this.data.params.crm_phone && this.data.params.crm_phone.length != 11) {
toastError('手机号码需11位');
return;
}
post(this.data.mode == 'new' ? 'ErpCrm/add' : 'ErpCrm/edit', this.data.params).then(() => {
toastSuccess('保存成功');
sleep(() => {
wx.navigateBack();
}, 1000);
});
} else {
toastError('项目名称必填');
}
},
/**
* --
*/
onLoad(_options) {
const eventChannel: any = this.getOpenerEventChannel();
eventChannel?.on('customerEdit', (e: any) => {
const data = toObject(e.data);
Object.keys(data).forEach((key) => {
if (data[key] === null) {
data[key] = '';
}
});
// console.log(data);
wx.setNavigationBarTitle({
title: data.crm_id
? `${data.crm_name} 修改`
: data.crm_type == 1
? '新增经销商'
: '新增供应商',
});
this.setData({ params: data, mode: data.crm_id ? 'edit' : 'new' });
});
},
/**
* --
*/
onReady() {},
/**
* --
*/
onShow() {
loginStatusPage(this);
},
/**
* --
*/
onHide() {},
/**
* --
*/
onUnload() {},
/**
* --
*/
onPullDownRefresh() {},
/**
*
*/
onReachBottom() {},
/**
*
*/
// onShareAppMessage() {},
});