沙盘演示系统应用的微信小程序
zuoxiao
2024-11-01 ddbd8c7ea87b66d5a9c4362ce284d12a4ae970d1
pages/feedback/feedback.js
@@ -1,6 +1,10 @@
const audio = wx.createInnerAudioContext()
const recorderManager = wx.getRecorderManager()
const {
  get,
  post
} = require('../../api/request.js');
const {
  BASEURL
} = require('../../api/config')
const app = getApp()
@@ -23,14 +27,18 @@
      height: 160,
    },
    originFiles: [],
    feedBackList: Array(19).fill({
      createTime: "2023-05-06 12:36:25",
      responseTime: "2023-05-07 12:36:25"
    }),
    contentValue: '', //反馈详情
    accSavePath: '', //上传的音频文件接口返回的地址
    photoSavePath: [] //上传的照片文件返回的地址
    contentValue: '', //反馈详情
    accSavePath: [], //上传的音频文件接口返回的地址
    photoSavePath: [], //上传的照片文件返回的地址
    phoneNumber: "",
    lat: "",
    lng: "",
    loading: false,
    hasMore: true,
    pageCurr: 1,
    pageSize: 20,
    listData: [], //已提问题列表
  },
  onLoad() {
@@ -94,6 +102,22 @@
    recorderManager.onError((err) => {
      console.log('录音错误', err);
    });
    wx.getLocation({
      type: 'wgs84', // 返回可以用于 `wx.openLocation` 的经纬度
      success: (res) => {
        console.log('获取位置成功', res);
        this.setData({
          lat: res.latitude,
          lng: res.longitude,
        });
      },
      fail: function (err) {
        console.error('获取位置失败', err);
      }
    });
  },
  onReady() {
    this.getList();
  },
  //上传音频文件
  upACC(tempFilePath) {
@@ -106,8 +130,16 @@
        'tag': app.globalData.tag,
        'appId': app.globalData.AppID,
      },
      success: function (res) { //后台返回给前端识别后的文字
      success: (res) => { //后台返回给前端识别后的文字
        console.log('录音上传成功', res);
        let jsonData = JSON.parse(res.data)
        let audioObj = {
          webPath: jsonData.content.webPath,
          id: jsonData.content.id
        };
        this.setData({
          accSavePath: [audioObj]
        })
      },
      fail: (err) => {
        // 处理上传失败的逻辑  
@@ -115,6 +147,7 @@
      }
    })
  },
  //删除图片
  handleRemove(e) {
    console.log("handleRemove");
    const {
@@ -132,7 +165,7 @@
    });
    originFiles.splice(index, 1);
    this.setData({
      originFiles,
      originFiles: originFiles,
    });
  },
@@ -158,7 +191,7 @@
      return {
        ...item,
        status: 'loading',
        uploadTask: this.onUploadPhoto(e.detail.files[0].url)
        uploadTask: this.onUploadPhoto(item.url)
      }; // 保留所有其他字段,并添加 displayText 字段
    });
    // 更新列表数据
@@ -174,7 +207,7 @@
   */
  onUploadPhoto(imgPath) {
    const uploadTask = wx.uploadFile({
      url: BASEURL + "wx/webFile/upPhone", // 仅为示例,非真实的接口地址
      url: BASEURL + "wx/webFile/upPhoto", // 仅为示例,非真实的接口地址
      filePath: imgPath,
      name: 'file',
      header: {
@@ -183,6 +216,26 @@
      },
      success: (res) => {
        console.log('图片上传成功', res);
        let jsonData = JSON.parse(res.data)
        // 更新图片上传成功状态
        const updatedFiles = this.data.originFiles.map((file) => {
          console.log('图片上传成功》》updatedFiles', file + "++++++++++" + imgPath);
          if (file.url === imgPath) {
            return {
              ...file,
              status: undefined, // 上传成功状态
              uploadTask: undefined, // 清理上传任务
              webPath: jsonData.content.webPath,
              id: jsonData.content.id
            };
          }
          return file;
        });
        // 将创建的对象添加到images数组中
        this.setData({
          originFiles: updatedFiles,
        })
      },
      fail: (err) => {
        // 处理上传失败的逻辑  
@@ -342,47 +395,60 @@
    });
  },
  onPullDownRefresh() {
    this.setData({
      isRefreshing: false
    });
    this.getList(true);
  },
  feelBack() {
  //上传问题
  feelBackPost() {
    wx.showLoading({
      title: '正在提交...', // 加载提示文字
      mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false
    });
    this.data.originFiles.map((file) => {
      let imageObj = {
        webPath: file.webPath,
        id: file.id
      };
      this.setData({
        photoSavePath: [...this.data.photoSavePath, imageObj]
      })
    })
    const app = getApp();
    const data = {
      content: this.data.contentValue, //取水口ID
      image: this.data.vcId, //虚拟卡ID
      operator: app.globalData.sessionId, //操作员
      forceOpen: !!isforce // 使用逻辑非操作符 !! 来确保 isForce 是布尔值
      images: this.data.photoSavePath,
      audios: this.data.accSavePath,
      content: this.data.contentValue,
      lng: this.data.lng,
      lat: this.data.lat,
      clientId: app.globalData.clientId,
      phone: this.data.phoneNumber
    };
    post({
      url: "operation/feedback/add",
      url: "wx/issue/addIssueReport",
      data: data
    }).then(response => {
      // 处理成功响应
      console.log('请求成功:', response);
      // 加载完成后隐藏加载动画
      wx.hideLoading();
      //完成后回到首页
      wx.reLaunch({
        url: '/pages/home/home?param=true' // 首页的路径,根据实际情况填写
      wx.showToast({
        title: '提交成功',
        icon: 'success',
        duration: 2000,
        success() {}
      })
      setTimeout(() => {
        wx.navigateBack({
          delta: 1
      });
      }, 2000);
    }).catch(error => {
      // 加载完成后隐藏加载动画
      wx.hideLoading();
      // 处理错误响应
      console.error('请求失败:', error);
      // if (error.code === "10005") {
      //   this.setData({
      //     showDialog: false,
      //     showForceConfirm: true
      //   })
      // } else {
      this.setData({
        showErrorDialog: true,
        errorData: error.msg
@@ -396,19 +462,19 @@
      voiceTime: 0,
    })
  },
  //提交
  submit() {
    if (this.data.contentValue !== "" || this.data.photoSavePath.length>0 || this.data.accSavePath !== "") {
      if (this.data.phoneNumber !== "" && this.data.phoneNumber.length !== 11) {
      wx.showToast({
        title: '提交成功',
        icon: 'success',
          title: '联系电话错误',
          icon: 'error',
        duration: 2000,
        success() {}
      })
      setTimeout(() => {
        wx.navigateBack({
          delta: 1
        });
      }, 2000);
      } else {
        this.feelBackPost();
      }
    } else {
      wx.showToast({
        title: '请输入一项反馈内容',
@@ -418,6 +484,104 @@
      })
    }
  },
  //监听手机号的输入
  phoneInput(e) {
    this.setData({
      phoneNumber: e.detail.value
    });
  },
  //监听
  contentInput(e) {
    this.setData({
      contentValue: e.detail.value
    });
  },
  //获取已提问题列表
  getList(isRefresh) {
    if (isRefresh) {
      this.setData({
        isRefreshing: false,
        pageCurr: 1,
      });
    }
    const app = getApp();
    const params = {
      url: 'wx/issue/getIssueReports',
      data: {
        clientId: app.globalData.clientId
      }
    };
    get(params).then(data => {
      const updatedList = data.content.obj.map(item => {
        if (item.replyTime === "" || item.replyTime === null) {
          item.replyTime = "未回复"
        }
        return item;
      });
      this.setData({
        listData: [...this.data.listData, ...updatedList],
        isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        loading: false,
        hasMore: this.data.pageCurr < data.content.pageTotal
      })
      this.updateDisplayText();
    }).catch(err => {
      // 错误回调
      this.setData({
        isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成
        loading: false
      })
      wx.showToast({
        title: err.msg,
        icon: 'error',
        duration: 3000
      })
    });
  },
  //加载更多
  loadMore() {
    if (this.data.hasMore && !this.data.loading) {
      this.setData({
        loading: true,
        pageCurr: this.data.pageCurr + 1
      })
      this.getList();
    }
  },
  onDelete(e) {
    const item = e.currentTarget.dataset.item;
    const that = this;
    wx.showLoading({
      title: '正在强制删除请稍候...', // 加载提示文字
      mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false
    });
    that.setData({
      lastIntakeName: intakeName
    })
    const data = {
      vcNum: item.vcNum, //取水口ID
      rtuAddr: item.rtuAddr, //阀控器地址
    };
    post({
      url: "wx/issue/deleteIssueReport",
      data: data,
      timeout: 180000
    }).then(response => {
      // 处理成功响应
      console.log('请求成功:', response);
      // 加载完成后隐藏加载动画
      wx.hideLoading();
      //重新获取列表刷新数据
      this.getList();
    }).catch(error => {
      // 加载完成后隐藏加载动画
      wx.hideLoading();
      // 处理错误响应
      console.error('请求失败:', error);
    });
  }
});