1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import { value, switchs, date } from "./config"
- const app = getApp();
- Page({
- data: {
- CustomBar: app.globalData.CustomBar,
- value,
- active: '',
- activeObject: {},
- activeIndex: [],
- switchB: false,
- endDate: date(),
- switchs,
- },
- // 提交
- submitFunc () {
- let { value } = this.data, msgs = [], data = {};
- value = value[2][6]['value'] == 0 ? [...value[0], ...value[1], ...value[2]] : [...value[0], ...value[1], ...value[2], ...value[3]];
- console.log(value)
- value.forEach(item => {
- // 判断是否为空
- if (!item.value) { msgs.push(`${item.title}不能为空!`); return false; };
- // 数字类型
- if (item.type == 'number' && !/^\d+.?\d*$/.test(item.value)) { msgs.push(`${item.title}必须是数字!`); return false; }
- // 正则判断
- console.log(item)
- if (item.reg && item.reg.test(item.value)) { msgs.push(`${item.title}格式不正确!`); return false; };
- data[item.name] = item.value;
- })
- console.log(data);
- console.log(msgs);
- },
- // 输入
- inputFunc (e) {
- let { value } = this.data, { index } = e.currentTarget.dataset;
- value[index[0]][index[1]]['value'] = e.detail.value;
- this.setData({ value })
- },
- // switch
- switchFunc (e) {
- let { value, switchs } = this.data, { index } = e.currentTarget.dataset;
- let { name } = value[index[0]][index[1]];
- if (switchs.hasOwnProperty(name)) {
- this.setData({ switchB: true, active: name, activeIndex: index })
- } else {
- let obj = Object.fromEntries([[`${name}Show`, true]])
- this.setData({ ...obj });
- }
- },
- // 隐藏单选框
- hideModal () { this.setData({ switchB: false }) },
- // 单选框赋值
- changeFunc (e) {
- let { activeIndex, value } = this.data;
- let _value = e.detail.value * 1;
- value[activeIndex[0]][activeIndex[1]]['value'] = _value;
- this.setData({ value })
- },
- // 日期
- DateChange (e) {
- let { value } = this.data, { index } = e.currentTarget.dataset;
- value[index[0]][index[1]]['value'] = e.detail.value;
- this.setData({ value })
- },
- onLoad: function (options) {
- },
- onReady: function () {
- },
- onShow: function () {
- },
- onHide: function () {
- },
- onUnload: function () {
- },
- onPullDownRefresh: function () {
- },
- onReachBottom: function () {
- },
- })
|