123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- var company = getApp().globalData.company;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- realname: '',
- // cardtype: '身份证', // 注释掉证件类型
- // idcard: '', // 注释掉身份证号码
- mobile: '',
- formctrl: {
- realname: '姓名',
- // cardtype: '证件类型', // 注释掉证件类型
- // idcard: '证件号码', // 注释掉身份证号码
- mobile: '手机号码'
- },
- showTypePicker: false,
- columns: ['身份证', '护照', '港澳通行证', '台胞证'], // 注释掉证件类型选择
- },
-
- selectCardtype() {
- // this.setData({
- // showTypePicker: true // 注释掉证件类型选择
- // })
- },
-
- typePickerEnter(event) {
- // const { picker, value, index } = event.detail;
- // console.log(picker, value, index);
- // console.log(`当前值:${value}, 当前索引:${index}`);
- // this.setData({
- // cardtype: value,
- // showTypePicker: false
- // })
- },
-
- typePickerCancel() {
- // console.log('取消');
- // this.setData({
- // showTypePicker: false
- // })
- },
-
- onChange() {
- console.log(this.data.realname);
- },
-
- checkform() {
- let formctrl = this.data.formctrl;
- let keys = Object.keys(formctrl);
- for (let index = 0; index < keys.length; index++) {
- let key = keys[index];
- if (this.data[key].trim() == '') {
- console.log(key, this.data[key]);
- wx.showToast({
- title: `请输入${formctrl[key]}`,
- icon: 'error'
- });
- return false;
- }
- }
-
- // 只检查姓名和手机号码
- let checkName = /[\u4e00-\u9fa5]/.test(this.data.realname);
- if (!checkName) {
- wx.showToast({
- title: '请输入正确姓名',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
-
- let checkMobile = /^1[34578]\d{9}$/.test(this.data.mobile);
- if (!checkMobile) {
- wx.showToast({
- title: '手机号码格式有误',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- return true;
- },
-
- async save() {
- let checked = this.checkform();
- if (!checked) {
- return false;
- }
-
- wx.showToast({
- title: '添加成功',
- icon: 'none',
- duration: 1000
- });
-
- let formdata = {
- realname: this.data.realname,
- // cardtype: this.data.cardtype, // 注释掉证件类型
- // idcard: this.data.idcard, // 注释掉身份证号码
- mobile: this.data.mobile
- };
-
- let customers = wx.getStorageSync("customers") || []; // 确保 customers 存在
- const existingCustomerIndex = customers.findIndex(customer => customer.realname === this.data.realname);
-
- if (existingCustomerIndex !== -1) {
- // 如果客户已经存在,则更新客户信息
- customers[existingCustomerIndex] = formdata;
- } else {
- // 如果客户不存在,则添加新的客户信息
- customers.push(formdata);
- }
-
- wx.setStorageSync("customers", customers);
- setTimeout(() => {
- wx.navigateBack({
- delta: 1,
- });
- }, 1000);
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log(options);
- let { type, name } = options;
- if (type == 'edit' && name) {
- this.initCustomerInfo(name);
- }
- },
-
- initCustomerInfo(name) {
- let customers = wx.getStorageSync("customers");
- if (customers) {
- console.log(customers);
- customers.forEach((customer, index) => {
- if (customer.realname == name) {
- this.setData({
- realname: customer.realname,
- // cardtype: customer.cardtype, // 注释掉证件类型
- // idcard: customer.idcard, // 注释掉身份证号码
- mobile: customer.mobile,
- });
- }
- });
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {},
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {},
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {},
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {},
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {},
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {}
- });
|