添加基础资料下的页面功能
This commit is contained in:
109
miniprogram/pages/base/orderStep/edit/edit.ts
Normal file
109
miniprogram/pages/base/orderStep/edit/edit.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import { loginStatusPage, post } from '@/utils/https';
|
||||
import {
|
||||
cloneLite,
|
||||
getAuthInfo,
|
||||
getDataSet,
|
||||
sleep,
|
||||
toastError,
|
||||
toastSuccess,
|
||||
toObject,
|
||||
} from '@/utils/util';
|
||||
|
||||
const defaultParams = { comments: '', order_step_name: '', if_default: 2 };
|
||||
|
||||
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.order_step_name) {
|
||||
post(this.data.mode == 'new' ? 'OrderStep/add' : 'OrderStep/edit', this.data.params).then(
|
||||
() => {
|
||||
toastSuccess('保存成功');
|
||||
sleep(() => {
|
||||
wx.navigateBack();
|
||||
}, 1000);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
toastError('阶段名称必填');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad(_options) {
|
||||
const eventChannel: any = this.getOpenerEventChannel();
|
||||
|
||||
eventChannel?.on('orderStepEdit', (e: any) => {
|
||||
const data = toObject(e.data);
|
||||
wx.setNavigationBarTitle({
|
||||
title: data.order_step_id ? `${data.order_step_name} 修改` : '新增订单阶段',
|
||||
});
|
||||
this.setData({ params: data, mode: data.order_step_id ? 'edit' : 'new' });
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
loginStatusPage(this);
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {},
|
||||
});
|
||||
Reference in New Issue
Block a user