123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- // pages/add/index.js
- import util from '../../utils/util'
- var dateTimePicker = require('../../utils/dateTimePicker');
- const QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
- const qqmapsdk = new QQMapWX({
- key: '36IBZ-VI53O-FJHW2-SV2NP-USSAE-GFBUS'
- })
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- form: {
- key1: '', //活动名称
- key2: '', //活动地点
- key3: '', //活动开始时间
- key4: '', //活动结束时间
- key5: '' //活动描述
- },
- isShowForm: {
- key1: false,
- key2: false,
- key5: false
- },
- inputFocus: {
- key1: false,
- key2: false,
- key5: false
- },
- date: '2018-10-01',
- time: '12:00',
- dateTimeArray: null,
- dateTime: null,
- dateTimeArray1: null,
- dateTime1: null,
- startYear: null,
- endYear: null,
- BASEIMGURL: '', //图片域名
- imgList: [],
- userInfo: {}
- },
- async getPhoneNumber(e) {
- const that = this;
- console.log(e.detail.errMsg == "getPhoneNumber:ok");
- if (e.detail.errMsg == "getPhoneNumber:ok") {
- let res = await app.globalData.api.bindphone({
- "openid": app.globalData.userInfo.openid,
- "encryptedData": e.detail.encryptedData,
- "iv": e.detail.iv,
- "invitor": app.globalData.shareOpenId
- });
- app.globalData.userInfo.phone = res.data.phone;
- this.setData({
- userInfo: {
- ...this.data.userInfo,
- phone: res.data.phone
- }
- })
- that.createBtn();
- console.log(res);
- } else {
- wx.showToast({
- title: '请授权您的手机号!',
- icon: 'none'
- })
- }
- },
- async createBtn() {
- if (!this.data.form.key1) return util.myShowToast('请输入活动名称!');
- if (!this.data.form.key2) return util.myShowToast('请输入活动地点!');
- if (!this.data.form.key3) return util.myShowToast('请输入活动时间!');
- if (!this.data.form.key5) return util.myShowToast('请输入活动描述!');
- if (!this.data.imgList.length) return util.myShowToast('至少上传一张图片!');
- let params = {
- "title": this.data.form.key1,
- "location": this.data.form.key2,
- "starttime": this.data.form.key3,
- "endtime": this.data.form.key4 || this.data.form.key3,
- "deadline": this.data.form.key3,
- "capacity": 50,
- "content": this.data.form.key5,
- "images": this.data.imgList.length ? this.data.imgList.join(';') : '',
- "attendfee": 30,
- "organizer": app.globalData.userInfo.phone,
- "private": 0
- };
- try {
- let lngArr = await this.getLng();
- params = Object.assign({}, params, lngArr);
- } catch (error) {
- console.log(error)
- }
- let res = await app.globalData.api.createActivity(params);
- if (res.data == "OK") {
- util.myShowToast('创建成功!')
- setTimeout(() => {
- wx.reLaunch({
- url: '/pages/index/index?update=1',
- })
- }, 1500)
- }
- console.log(res)
- },
- getLng() {
- return new Promise((resolve, reject) => {
- qqmapsdk.geocoder({
- //获取表单传入地址
- address: this.data.form.key2, //地址参数,例:固定地址,address: '北京市海淀区彩和坊路海淀西大街74号'
- complete: (res) => {
- if (res.message == "query ok") {
- //根据地址解析在地图上标记解析地址位置
- resolve({
- lat: res.result.location.lat,
- lng: res.result.location.lng
- })
- } else {
- reject(res.message);
- }
- }
- })
- })
- },
- //删除图片
- removeImg(e) {
- const that = this;
- wx.showModal({
- title: '提示',
- content: '确定删除图片?',
- success(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- let item = e.currentTarget.dataset.item;
- let newImgList = that.data.imgList.filter(v => {
- return item != v;
- });
- that.setData({
- imgList: newImgList
- })
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- });
- },
- updateImg() {
- const that = this;
- wx.chooseImage({
- count: 1, // 默认9
- sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album', 'camera'],
- success: function (res) {
- var tempFilePaths = res.tempFilePaths;
- var tempFilesSize = res.tempFiles[0].size;
- wx.showLoading({
- title: '上传中...',
- });
- console.log('size:', tempFilesSize)
- if (tempFilesSize > 2000000) { //图片小于或者等于1M时 可以执行获取图片
- return wx.showToast({
- title: '上传图片不能大于2M!', //标题
- icon: 'none' //图标 none不使用图标,详情看官方文档
- })
- }
- console.log('tempFilePaths',tempFilePaths)
- wx.uploadFile({
- url: 'https://talk.cirray.cn/api/upload_image', //仅为示例,非真实的接口地址
- filePath: tempFilePaths[0],
- name: 'file',
- formData: {},
- success: function (res) {
- // wx.hideLoading()
- let imgList = [...that.data.imgList, that.data.BASEIMGURL + res.data];
- that.setData({
- imgList
- });
- wx.hideLoading()
- },
- fail(e) {
- console.log(e)
- wx.showToast({
- title: '上传失败,请稍后重试!',
- icon: 'none'
- })
- // wx.hideLoading()
- }
- })
- }
- })
- },
- back() {
- wx.navigateBack()
- },
- inputVal(e) {
- let value = e.detail.value;
- let key = e.currentTarget.dataset.key;
- let newKey = 'form.' + key;
- this.setData({
- [newKey]: value
- })
- },
- inputBlur(e) {
- let key = e.currentTarget.dataset.key;
- if (this.data.form[key]) {
- let newKey = 'isShowForm.' + key;
- this.setData({
- [newKey]: true
- })
- }
- },
- showInput(e) {
- let key = e.currentTarget.dataset.key;
- if (this.data.isShowForm[key]) {
- let newKey = 'isShowForm.' + key;
- let newInputFocus = Object.assign({
- key1: false,
- key2: false
- }, {
- [key]: true
- });
- this.setData({
- [newKey]: false,
- inputFocus: newInputFocus
- });
- }
- },
- changeDate(e) {
- this.setData({
- date: e.detail.value
- });
- },
- changeTime(e) {
- this.setData({
- time: e.detail.value
- });
- },
- changeDateTime(e) {
- const that = this;
- console.log("打印时间~~~~~~~~~~~~~~~~~~~~~", this.data.dateTimeArray);
- this.setData({
- dateTime: e.detail.value
- });
- console.log("打印时间", this.data.dateTime);
- var aaa1 = that.data.dateTime[0];
- var aaa2 = that.data.dateTime[1];
- var aaa3 = that.data.dateTime[2];
- var aaa4 = that.data.dateTime[3];
- var aaa5 = that.data.dateTime[4];
- var aaa6 = that.data.dateTime[5];
- var time1 = that.data.dateTimeArray[0][aaa1];
- var time2 = that.data.dateTimeArray[1][aaa2];
- var time3 = that.data.dateTimeArray[2][aaa3];
- var time4 = that.data.dateTimeArray[3][aaa4];
- var time5 = that.data.dateTimeArray[4][aaa5];
- var time6 = that.data.dateTimeArray[5][aaa6];
- var time = time1 + '-' + time2 + '-' + time3 + ' ' + time4 + ':' + time5 + ':' + time6;
- console.log("时间88888888888888888888888888888:", time);
- let key = e.currentTarget.dataset.key;
- let newKey = 'form.' + key;
- this.setData({
- [newKey]: time
- })
- },
- changeDateTime1(e) {
- this.setData({
- dateTime1: e.detail.value
- });
- },
- changeDateTimeColumn(e) {
- var arr = this.data.dateTime,
- dateArr = this.data.dateTimeArray;
- arr[e.detail.column] = e.detail.value;
- dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
- this.setData({
- dateTimeArray: dateArr,
- dateTime: arr
- });
- },
- changeDateTimeColumn1(e) {
- var arr = this.data.dateTime1,
- dateArr = this.data.dateTimeArray1;
- arr[e.detail.column] = e.detail.value;
- dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
- this.setData({
- dateTimeArray1: dateArr,
- dateTime1: arr
- });
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- // 获取完整的年月日 时分秒,以及默认显示的数组
- var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
- var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
- // 精确到分的处理,将数组的秒去掉
- var lastArray = obj1.dateTimeArray.pop();
- var lastTime = obj1.dateTime.pop();
- this.setData({
- dateTime: obj.dateTime,
- dateTimeArray: obj.dateTimeArray,
- dateTimeArray1: obj1.dateTimeArray,
- dateTime1: obj1.dateTime,
- BASEIMGURL: app.globalData.BASEIMGURL,
- userInfo: app.globalData.userInfo
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|