You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

234 lines
4.6 KiB

// pages/activity/huawei/upload/index.js
import commonApi from "../../../../utils/https/common"
Page({
/**
* 页面的初始数据
*/
data: {
id:null,
types:[],
typeIndex:-1,
title:"",
img:null,
desc:"",
date:null,
address:""
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
id:options.id
})
commonApi.user_post('actonline/act_online/getActTypeList',{
act_id:options.id
}).then(res=>{
this.setData({
types:res.data
})
})
},
changeType:function(e){
this.setData({
typeIndex:e.detail.value
})
},
changeTitle:function(e){
this.setData({
title:e.detail.value
})
},
changeContent:function(e){
this.setData({
desc:e.detail.value
})
},
uploadImg:function(){
let that = this;
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success (res) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = res.tempFilePaths[0]
if(tempFilePaths.substr(tempFilePaths.length-4,4)=='.gif'){
wx.showToast({
title: '图片格式错误',
icon:'none'
})
return;
}
wx.showLoading({
title: '图片上传中,请稍后'
})
wx.uploadFile({
url: 'https://api.cloud.sz-trip.com/api/pbservice.other/upload', //这里是上传的服务器地址
filePath: tempFilePaths,
header:{
token: wx.getStorageSync('jstrip_token'),
},
name: "file",
success: function (res) {
var res = JSON.parse(res.data);
let img = res.data.url;
that.setData({
img:img
})
wx.hideLoading();
},
fail:function(res){
wx.hideLoading();
}
})
}
})
},
bindDateChange:function(e){
this.setData({
date:e.detail.value
})
},
changeAddress:function(e){
this.setData({
address:e.detail.value
})
},
submit:function(){
if(!this.data.title){
wx.showToast({
title: '请输入作品标题',
icon:'none'
})
return;
}
if(this.getCNLen(this.data.title)>30){
wx.showToast({
title: '作品标题过长',
icon:'none'
})
return;
}
if(this.data.typeIndex==-1){
wx.showToast({
title: '请选择分类',
icon:'none'
})
return;
}
if(!this.data.date){
wx.showToast({
title: '请选择拍摄时间',
icon:'none'
})
return;
}
if(!this.data.address){
wx.showToast({
title: '请输入您所上传照片的拍摄地点',
icon:'none'
})
return;
}
if(!this.data.img){
wx.showToast({
title: '请上传图片',
icon:'none'
})
return;
}
if(!this.data.desc){
wx.showToast({
title: '请输入作品描述',
icon:'none'
})
return;
}
if(this.getCNLen(this.data.desc)>600){
wx.showToast({
title: '作品描述过长',
icon:'none'
})
return;
}
commonApi.user_post("actonline/act_online/uploadWork",{
title:this.data.title,
img:this.data.img,
desc:this.data.desc,
type_id:this.data.types[this.data.typeIndex].id,
id:this.data.id,
shot_time:this.data.date,
shot_address:this.data.address
}).then(res=>{
if(res.code==1){
wx.navigateTo({
url: '../uploadres/index?id='+this.data.id
})
}
})
},
getCNLen:function(str){
var len = 0;
for (var i=0; i<str.length; i++) {
if (str.charCodeAt(i)>127 || str.charCodeAt(i)==94) {
len += 2;
} else {
len ++;
}
}
return len;
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})