bug
litian
2024-07-12 1951e6ccf8dff46e6f8c671308f6e4db694fc800
packageDomain/pages/sampleBookList/applicationForm/index.js
@@ -5,18 +5,18 @@
Page({
  data: {
    userInfo: null,
    active: 0,
    active: '0',
    description: "", //申请规则
    teacherInfo: {
      workInfo: null,
      schoolName: "",
      courseName: "",
      detailedAddress: ""
      address: ""
    },
    contactInfo: {
      fullName: "",
      user: "",
      phone: "",
      detailedAddress: ""
      address: ""
    },
    phoneError: false,
    paperBookList: [], //样书单纸质书
@@ -48,9 +48,9 @@
        that.setData({
          'teacherInfo.schoolName': JSON.parse(that.data.userInfo.data).schoolName,
          'teacherInfo.courseName': JSON.parse(that.data.userInfo.data).courseName,
          'contactInfo.fullName': JSON.parse(that.data.userInfo.data).fullName,
          'contactInfo.user': JSON.parse(that.data.userInfo.data).fullName,
          'contactInfo.phone': JSON.parse(that.data.userInfo.data).phone,
          'contactInfo.detailedAddress': JSON.parse(that.data.userInfo.data).detailedAddress,
          'contactInfo.address': JSON.parse(that.data.userInfo.data).detailedAddress,
        })
      } else {
        wx.showModal({
@@ -68,19 +68,48 @@
        })
      }
      if (wx.getStorageSync("paperBookList")) {
        const paperBookList = JSON.parse(wx.getStorageSync("paperBookList"))
        for (let index = 0; index < paperBookList.length; index++) {
          const item = paperBookList[index];
          if (item.publicationDate)
            item.publicationDate = this.formatDate(item.publicationDate)
        }
        that.setData({
          paperBookList: JSON.parse(wx.getStorageSync("paperBookList")),
          bookList: JSON.parse(wx.getStorageSync("paperBookList"))
          paperBookList: paperBookList,
          bookList: paperBookList
        })
      }
      if (wx.getStorageSync("electronicBookList")) {
        const electronicBookList = JSON.parse(wx.getStorageSync("electronicBookList"))
        for (let index = 0; index < electronicBookList.length; index++) {
          const item = electronicBookList[index];
          if (item.publicationDate)
            item.publicationDate = this.formatDate(item.publicationDate)
        }
        that.setData({
          electronicBookList: JSON.parse(wx.getStorageSync("electronicBookList"))
          electronicBookList: electronicBookList
        })
      }
      that.getSelectBookCount();
      that.getSelectPaperBookCount();
      that.getPaperType();
    }
  },
  formatDate(inputDate) {
    // 使用正则表达式匹配日期部分
    const dateMatch = inputDate.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2})/);
    if (dateMatch) {
      // 提取年、月、日
      const year = dateMatch[1];
      const month = dateMatch[2].padStart(2, '0'); // 确保月份为两位数
      const day = dateMatch[3].padStart(2, '0'); // 确保日期为两位数
      // 拼接并返回格式化后的日期
      return `${year}-${month}-${day}`;
    } else {
      // 如果没有匹配到日期部分,则返回原始输入或抛出错误
      return inputDate; // 或者 throw new Error('Invalid date format');
    }
  },
@@ -125,6 +154,7 @@
          'teacherInfo.workInfo': res[0].cmsTypeLinks[0].children,
        })
      }
    })
  },
  //获取当前已申请次数(电子)
@@ -158,7 +188,7 @@
  //姓名
  onFullNameInput(e) {
    this.setData({
      "contactInfo.fullName": e.detail.value,
      "contactInfo.user": e.detail.value,
    });
  },
  //输入手机号
@@ -180,13 +210,11 @@
      });
    }
  },
  onAddressInput() {
  onAddressInput(e) {
    this.setData({
      "contactInfo.detailedAddress": e.detail.value,
      "contactInfo.address": e.detail.value,
    });
  },
  submit() {
    let that = this;
    if (that.data.bookList.length > 0) {
@@ -224,7 +252,7 @@
          refType: 'applyBook'
        }
      } else {
        if (!(that.data.contactInfo.fullName && that.data.contactInfo.phone && that.data.contactInfo.detailedAddress)) {
        if (!(that.data.contactInfo.user && that.data.contactInfo.phone && that.data.contactInfo.address)) {
          wx.showToast({
            title: "请将收货人信息填写完整!",
            icon: 'none',
@@ -234,7 +262,7 @@
        }
        const mailAddress = JSON.stringify(that.data.contactInfo)
        that.setData({
          'teacherInfo.detailedAddress': mailAddress
          'teacherInfo.address': mailAddress
        })
        data = {
@@ -310,7 +338,7 @@
            that.setData({
              bookList: eList
            })
            wx.setStorageSync("electronicBookList", eList);
            wx.setStorageSync("electronicBookList", JSON.stringify(eList));
          } else {
            let pList = that.data.paperBookList;
            pList.forEach((obj, index) => {
@@ -321,7 +349,7 @@
            that.setData({
              bookList: pList
            })
            wx.setStorageSync("paperBookList", pList);
            wx.setStorageSync("paperBookList", JSON.stringify(pList));
          }
        } else if (res.cancel) {}
      }