Riku
2024-08-12 7c3c82d429f86358142adceb080e8922f6a18aa0
components/form/index.js
@@ -40,9 +40,6 @@
    onSwitchChange(e) {
      const { index } = e.currentTarget.dataset;
      const { value } = e.detail;
      // const { formArray } = this.data;
      // formArray[index].value = value;
      // this.setData({ formArray });
      this.setData({
        [`formArray[${index}].value`]: value,
      });
@@ -57,6 +54,7 @@
      const { label, value } = e.detail;
      this.setData({
        [`formArray[${index}].visible`]: false,
        [`formArray[${index}]._value`]: value,
        [`formArray[${index}].value`]: {
          label: label[0],
          value: value[0],
@@ -75,9 +73,18 @@
      this.setData({ [`formArray[${index}].visible`]: true });
    },
    onCascaderChange(e) {
      const { index } = e.currentTarget.dataset;
      const { selectedOptions, value } = e.detail;
      console.log(selectedOptions);
      console.log(value);
      const note = this._note(selectedOptions);
      const v = selectedOptions.map(v => {
        return { label: v.label, value: v.value };
      });
      this.setData({
        [`formArray[${index}].visible`]: false,
        [`formArray[${index}]._value`]: value,
        [`formArray[${index}].note`]: note,
        [`formArray[${index}].value`]: v,
      });
    },
    // 保存
@@ -85,7 +92,7 @@
      const formObj = {};
      this.data.formArray.forEach(e => {
        if (e.inputType == 'picker') {
          formObj[e.name] = e.value.value;
          formObj[e.name] = e.value ? e.value.value : e.value;
        } else {
          formObj[e.name] = e.value;
        }
@@ -100,7 +107,7 @@
    _note(v) {
      let note = '';
      v.forEach(o => {
        if (note != o.label && o.value > 0) {
        if (note != o.label) {
          if (note != '') {
            note += '/';
          }