From 9b09d13712c0c005891450a3bf4b6d848ec0ff37 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 29 十一月 2023 10:28:24 +0800
Subject: [PATCH] 2023.11.29
---
base/behaviors/bInputCheck.js | 200 ++++++++++++++++++++++++++++---------------------
1 files changed, 113 insertions(+), 87 deletions(-)
diff --git a/base/behaviors/bInputCheck.js b/base/behaviors/bInputCheck.js
index 8a1a48c..c23799e 100644
--- a/base/behaviors/bInputCheck.js
+++ b/base/behaviors/bInputCheck.js
@@ -1,60 +1,76 @@
+import moment from '../../utils/moment.min';
+
/**
* 淇℃伅杈撳叆閫昏緫
* 鍖呮嫭杈撳叆淇℃伅瀛樺偍銆佽緭鍏ヨ鑼冩�ф娴嬨�侀敊璇彁绀虹瓑
* @see "/data/sceneInfo.js"
*/
module.exports = Behavior({
+ properties: {
+ form: {
+ type: Array,
+ observer(value) {
+ this.setData({ msg: value });
+ },
+ },
+ },
data: {
msg: [],
- info: {}
+ info: {},
+ start: moment().format('YYYY骞碝M鏈圖D鏃�'),
},
lifetimes: {
- attached: function () {}
+ attached: function () {},
},
methods: {
selectChange(e) {
- const index = e.currentTarget.dataset.index
- const options = e.detail.options
+ const index = e.currentTarget.dataset.index;
+ const options = e.detail.options;
this.setData({
- [`msg[${index}].options`]: options
- })
+ [`msg[${index}].options`]: options,
+ });
+ this.onItemChange();
},
pickerChange(e) {
console.log(e);
- const {
- index,
- mode
- } = e.currentTarget.dataset
+ const { index, mode } = e.currentTarget.dataset;
if (mode == 'region') {
- const i = e.detail.value.concat(e.detail.code)
+ const i = e.detail.value.concat(e.detail.code);
this.setData({
- [`msg[${index}].value`]: i
- })
+ [`msg[${index}].value`]: i,
+ });
} else if (mode == 'selector') {
- const i = e.detail.value
+ const i = e.detail.value;
this.setData({
[`msg[${index}].selectIndex`]: i,
- [`msg[${index}].value`]: this.data.msg[index].options[i].value
- })
+ [`msg[${index}].value`]: this.data.msg[index].options[i].value,
+ });
+ } else if (mode == 'date') {
+ const i = e.detail.value;
+ this.setData({
+ [`msg[${index}].value`]: i,
+ });
}
+ this.onItemChange();
},
changeMsg(e) {
- let id = e.detail.params.id
- let value = e.detail.params.value
- let msg = this.data.msg
- let msgLength = msg.length
+ let id = e.detail.params.id;
+ let value = e.detail.params.value;
+ let msg = this.data.msg;
+ let msgLength = msg.length;
for (let i = 0; i < msgLength; i++) {
if (msg[i].id === id) {
- let path = "msg[" + i + "].value"
- let nPath = "msg[" + i + "].noValue"
+ let path = 'msg[' + i + '].value';
+ let nPath = 'msg[' + i + '].noValue';
this.setData({
[path]: value,
- [nPath]: false
- })
+ [nPath]: false,
+ });
}
}
+ this.onItemChange();
},
/**
@@ -62,139 +78,149 @@
*/
submitCheck() {
//娓呯┖缂撳瓨鐨勫瘑鐮�
- this.lastPW = ''
+ this.lastPW = '';
- let msg = this.data.msg
+ let msg = this.data.msg;
//纭淇℃伅瀹屾暣搴�
for (let i = 0; i < msg.length; i++) {
- const m = msg[i]
+ const m = msg[i];
//閫夊~椤圭洿鎺ョ暐杩�
- if (m.required == false) continue
+ if (m.required == false) continue;
//澶嶉�夋鍜屽崟閫夋锛堝閫夋鐨勯�昏緫鍖呭惈浜嗗崟閫夋锛�
if (m.type == 'checkbox' || m.type == 'radio') {
// console.log('m.options', m.options);
- m.value = ''
+ m.value = '';
for (let t = 0; t < m.options.length; t++) {
const o = m.options[t];
if (o.checked) {
if (m.value != '') {
- m.value += ';'
+ m.value += ';';
}
if (o.hasRemark) {
// console.log('o.remark', o.remark);
if (o.remark == '') {
this.setData({
- [`msg[${i}].options[${t}].noValue`]: true
- })
- this.showErrorMsg(i, '澶囨敞淇℃伅涓嶈兘涓虹┖')
- return false
+ [`msg[${i}].options[${t}].noValue`]: true,
+ });
+ this.showErrorMsg(i, '澶囨敞淇℃伅涓嶈兘涓虹┖');
+ return false;
} else {
- m.value += o.remark
+ m.value += o.remark;
}
} else {
- m.value += o.name
+ m.value += o.name;
}
}
}
if (m.value == '') {
- this.showErrorMsg(i)
- return false
+ this.showErrorMsg(i);
+ return false;
}
}
//涓嬫媺閫夋嫨妗�
else if (m.type == 'picker') {
if (m.pickerMode == 'selector') {
if (m.selectIndex == 0) {
- this.showErrorMsg(i, `${this.data.msg[i].name}鏈�夋嫨`)
- return false
+ this.showErrorMsg(i, `${this.data.msg[i].name}鏈�夋嫨`);
+ return false;
} else {
- m.value = m.options[m.selectIndex].name
+ m.value = m.options[m.selectIndex].name;
}
} else if (m.pickerMode == 'region') {
if (m.value.length == 0) {
- this.showErrorMsg(i, `${this.data.msg[i].name}鏈�夋嫨`)
- return false
+ this.showErrorMsg(i, `${this.data.msg[i].name}鏈�夋嫨`);
+ return false;
}
}
}
//杈撳叆妗�
//蹇呭~椤圭┖鐧芥娴�
- else if (m.value === "" || m.value === null || m.value === undefined) {
- this.showErrorMsg(i)
- return false
- }
+ else if (m.value === '' || m.value === null || m.value === undefined) {
+ this.showErrorMsg(i);
+ return false;
+ }
//杈撳叆妗嗕笅鐨勫瘑鐮佺被鍨嬫娴�
else if (m.type == 'password') {
//瀵嗙爜涓�鑷存�х‘璁�
if (this.lastPW == '') {
- this.lastPW = m.value
+ this.lastPW = m.value;
} else if (this.lastPW != m.value) {
- let error = "涓ゆ杈撳叆鐨勫瘑鐮佷笉涓�鑷�"
+ let error = '涓ゆ杈撳叆鐨勫瘑鐮佷笉涓�鑷�';
this.setData({
errorMsg: error,
- })
- return false
+ });
+ return false;
}
//瀵嗙爜澶嶆潅搴︾‘璁�
- var pwError
- var pw = m.value
- var regex1 = /[a-zA-Z]/
- var regex2 = /[0-9]/
- var r = regex1.test(pw) && regex2.test(pw)
+ var pwError;
+ var pw = m.value;
+ var regex1 = /[a-zA-Z]/;
+ var regex2 = /[0-9]/;
+ var r = regex1.test(pw) && regex2.test(pw);
console.log('regex:' + r);
if (pw.length < 6) {
- pwError = '瀵嗙爜浣嶆暟鏈�灏�6浣�'
+ pwError = '瀵嗙爜浣嶆暟鏈�灏�6浣�';
} else if (!r) {
- pwError = '瀵嗙爜蹇呴』鍖呭惈瀛楁瘝鍜屾暟瀛�'
+ pwError = '瀵嗙爜蹇呴』鍖呭惈瀛楁瘝鍜屾暟瀛�';
}
if (pwError) {
this.setData({
errorMsg: pwError,
- })
- return false
+ });
+ return false;
}
-
}
}
- return true
+ return true;
},
showErrorMsg(index, err = `${this.data.msg[index].name}涓嶅彲涓虹┖`) {
this.setData({
errorMsg: err,
- [`msg[${index}].noValue`]: true
- })
- const id = "#" + this.data.msg[index].id
- wx.createSelectorQuery().select('.page').boundingClientRect(res1 => {
- const top1 = res1.top
- wx.createSelectorQuery().in(this).select(id).boundingClientRect(res => {
- const h = res.top - top1 - 60
- // console.log(h);
- wx.pageScrollTo({
- // duration: 300,
- scrollTop: h,
- // selector: id,
- // offsetTop: -60,
- })
- }).exec();
- }).exec();
+ [`msg[${index}].noValue`]: true,
+ });
+ const id = '#' + this.data.msg[index].id;
+ wx.createSelectorQuery()
+ .select('.page')
+ .boundingClientRect(res1 => {
+ const top1 = res1.top;
+ wx.createSelectorQuery()
+ .in(this)
+ .select(id)
+ .boundingClientRect(res => {
+ const h = res.top - top1 - 60;
+ // console.log(h);
+ wx.pageScrollTo({
+ // duration: 300,
+ scrollTop: h,
+ // selector: id,
+ // offsetTop: -60,
+ });
+ })
+ .exec();
+ })
+ .exec();
},
onSubmit: function () {
console.log('onSubmit');
- if (!this.submitCheck()) return
+ if (!this.submitCheck()) return;
- let msg = this.data.msg
+ let msg = this.data.msg;
if (msg) {
- const info = this.data.info
+ const info = this.data.info;
msg.forEach(m => {
- info[m.id] = m.value
+ info[m.id] = m.value;
});
- this.setData({info})
- this.triggerEvent('onSubmit', info)
- if (typeof this._submit === 'function') this._submit(info)
+ this.setData({ info });
+ this.triggerEvent('onSubmit', info);
+ if (typeof this._submit === 'function') this._submit(info);
}
},
- }
-})
\ No newline at end of file
+
+ onItemChange() {
+ this.triggerEvent('itemChange', this.data.msg);
+ },
+ },
+});
--
Gitblit v1.9.3