123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- // pages/welfareMall/feedback/feedback.js
- import WelfareMall from '../../../api/welfareMall'
- import Upload from '../../../api/upload'
- import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- t_length: 0,
- avatarUrl: [],
- avatarUrlShow: [],
- chooseViewShowBanner: true,
- content: '',
- basePath: '',
- },
- bindText: function (e) {
- var t_text = e.detail.value.length;
- var text = e.detail.value;
- this.setData({
- t_length: t_text,
- content: text,
- })
- },
- /** 图片选择 */
- bindViewTap: function(){
- var that = this;
- if(this.data.avatarUrlShow.length < 4){
- wx.chooseImage({
- // 设置最多可以选择的图片张数,默认9,如果我们设置了多张,那么接收时//就不在是单个变量了,
- count: 1,
- sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
- sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
- success: function(res){
- // 获取成功,将获取到的地址赋值给临时变量
- console.log(res);
- if (res.tempFilePaths.count == 0) {
- return;
- }
- //图片上传到金山云
- var tempFilePaths = res.tempFilePaths
-
- wx.uploadFile({
- url: Upload.uploadPic(),
- filePath: tempFilePaths[0],
- name: 'file',
- formData:{
- 'basePath':'welfareMall',
- },
- success: function (res) {
- //提交路径
- var urlImg = JSON.parse(res.data).data.url;
- //展示路径
- var destPath = JSON.parse(res.data).data.destPath;
- var imgArrNow = that.data.avatarUrl;
- var imgArrNowShow = that.data.avatarUrlShow;
- imgArrNow.push(urlImg);
- imgArrNowShow.push(destPath);
- if(that.data.avatarUrlShow.length > 4){
- wx.showToast({
- title: '最多添加4张图片',
- icon: 'none',
- duration: 1500
- })
- return
- }
- that.setData({
- //将临时变量赋值给已经在data中定义好的变量
- avatarUrl:imgArrNow,
- avatarUrlShow:imgArrNowShow
- })
- that.chooseViewShowBanner();
- },
- fail: function(err) {
- console.log(err);
- },
- })
-
- },
- fail: function(res) {
- // fail
- },
- complete: function(res) {
- // complete
- }
- })
- } else {
- wx.showToast({
- title: '最多添加4张图片',
- icon: 'none',
- duration: 1500
- })
- }
- },
-
- /** 删除图片Banner */
- deleteImvBanner: function(e) {
- var avatarUrlShow = this.data.avatarUrlShow;
- var itemIndex = e.currentTarget.dataset.id;
- avatarUrlShow.splice(itemIndex, 1);
- this.setData({
- avatarUrlShow: avatarUrlShow
- })
- //判断是否隐藏选择图片
- this.chooseViewShowBanner();
- },
- /** 是否隐藏图片选择Banner*/
- chooseViewShowBanner: function() {
- if (this.data.avatarUrlShow.length > 3) {
- this.setData({
- chooseViewShowBanner: false
- })
- } else {
- this.setData({
- chooseViewShowBanner: true
- })
- }
- },
- /** 图片预览 */
- previewImage: function(e){
- var that = this,
- //获取当前图片的下标
- index = e.currentTarget.dataset.index,
- //数据源
- avatarUrlShow = this.data.avatarUrlShow;
- wx.previewImage({
- //当前显示下标
- current: avatarUrlShow[index],
- //数据源
- urls: avatarUrlShow
- })
- },
- /**
- * 提交
- */
- toSubmit: function() {
- if(this.data.content == null || this.data.content == '' || this.data.content == undefined){
- wx.showToast({
- title: '意见内容必填',
- icon: 'none',
- duration: 1500
- })
- return
- }
- WelfareMall.feedBackAdd({
- mobile: getMobileCache(),
- photoList: this.data.avatarUrl,
- content: this.data.content,
- }).then(res => {
- if (res.code == 200) {
- wx.showToast({
- title: '反馈意见提交成功',
- icon: 'none',
- duration: 1500
- });
- wx.switchTab({
- url: "../personal/personal"
- })
- }
- this.data.lock = false
- }).catch(_ => {
- console.log(_)
- this.data.lock = false
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|