riku
2022-10-12 741d1f7b2e2ac1c3f89d80dfac7625e3427e2367
pages/m_user/behaviors/b_inputCheck.js
@@ -1,5 +1,7 @@
/**
 *
 * 信息输入逻辑
 * 包括输入信息存储、输入规范性检测、错误提示等
 * @see "/data/sceneInfo.js"
 */
module.exports = Behavior({
  data: {
@@ -10,6 +12,33 @@
    attached: function () {}
  },
  methods: {
    selectChange(e) {
      const index = e.currentTarget.dataset.index
      const options = e.detail.options
      this.setData({
        [`msg[${index}].options`]: options
      })
    },
    pickerChange(e) {
      console.log(e);
      const {
        index,
        mode
      } = e.currentTarget.dataset
      let i = e.detail.value.concat(e.detail.code)
      if (mode == 'region') {
        this.setData({
          [`msg[${index}].value`]: i
        })
      } else if (mode == 'selector') {
        this.setData({
          [`msg[${index}].selectIndex`]: i,
          [`msg[${index}].value`]: this.data.msg[index].options[i].value
        })
      }
    },
    changeMsg(e) {
      let id = e.detail.params.id
      let value = e.detail.params.value
@@ -24,30 +53,6 @@
            [nPath]: false
          })
        }
      }
    },
    onSubmit: function () {
      console.log('onSubmit');
      if (!this.submitCheck()) return
      let msg = this.data.msg
      if (msg) {
        let info = {}
        msg.forEach(m => {
          info[m.id] = m.value
        });
        // console.log(info);
        this.setData({info})
        this.triggerEvent('onSubmit', info)
        // wx.showToast({
        //   title: 'onSubmit',
        //   duration: 1000,
        //   icon: 'none',
        //   success: (res) => {},
        //   fail: (res) => {},
        //   complete: (res) => {},
        // })
      }
    },
@@ -109,7 +114,7 @@
          }
        }
        //输入框
        else if (m.value === "") {
        else if (m.value === "" || m.value === null || m.value === undefined) {
          this.showErrorMsg(i)
          return false
        }
@@ -164,6 +169,22 @@
          })
        }).exec();
      }).exec();
    },
    onSubmit: function () {
      console.log('onSubmit');
      if (!this.submitCheck()) return
      let msg = this.data.msg
      if (msg) {
        let info = {}
        msg.forEach(m => {
          info[m.id] = m.value
        });
        this.setData({info})
        this.triggerEvent('onSubmit', info)
        this.submit()
    }
    },
  }
})