123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592 |
- // 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: '', //活动描述
- money: 0,
- num: '',
- key7: ''
- },
- isShowForm: {
- key1: false,
- key2: false,
- key5: false
- },
- inputFocus: {
- key1: false,
- key2: false,
- key5: false
- },
- date: '2018-10-01',
- time: '12:00',
- dateTimeArray1: null,
- dateTime1: null,
- dateTimeArray7: null,
- dateTime7: null,
- dateTimeArray2: null,
- dateTime2: null,
- startYear: null,
- endYear: null,
- BASEIMGURL: '', //图片域名
- imgList: [],
- userInfo: {},
- bigImgList: [],
- //编辑
- actid: '',
- actiddetail: {},
- switch1Checked: false
- },
- switch1Change(e) {
- this.setData({
- switch1Checked: e.detail.value
- })
- },
- async getPhoneNumber(e) {
- const that = this;
- 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();
- } else {
- wx.showToast({
- title: '请授权您的手机号!',
- icon: 'none'
- })
- }
- },
- async isOpen(privateObj) {
- let imgObj = {
- img: this.data.imgList,
- bigImg: this.data.bigImgList
- }
- let params = {
- "title": this.data.form.key1,
- "location": this.data.form.key2,
- "starttime": this.data.form.key3,
- "endtime": this.data.form.key7,
- "deadline": this.data.form.key4,
- "capacity": this.data.form.num ? this.data.form.num - 0 : 0,
- "content": this.data.form.key5.split('\n').join('&hc'),
- "images": JSON.stringify(imgObj),
- "attendfee": this.data.form.money ? (this.data.form.money - 0).toFixed(2) : 0,
- "organizer": app.globalData.userInfo.phone,
- "private": privateObj.private
- };
- try {
- let lngArr = await this.getLng();
- params = Object.assign({}, params, lngArr);
- } catch (error) {
- console.log(error)
- }
- if (this.data.actid) {
- params.actid = this.data.actid;
- let res = await app.globalData.api.activity_update(params);
- if (res.data == "OK") {
- util.myShowToast('修改成功!')
- setTimeout(() => {
- wx.reLaunch({
- url: '/pages/my/index?update=1',
- })
- }, 1500)
- }
- } else {
- let res = await app.globalData.api.createActivity(params);
- if (res.data == "OK") {
- util.myShowToast('创建成功!')
- setTimeout(() => {
- wx.reLaunch({
- url: '/pages/index/index?update=1',
- })
- }, 1500)
- }
- }
- },
- datetab(date1, date2) {
- var oDate1 = new Date(date1);
- var oDate2 = new Date(date2);
- if (oDate1.getTime() > oDate2.getTime()) {
- return true; //date1 > date2
- } else {
- return false;
- }
- },
- createBtn() {
- let reg = /[^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n]/g;
- if (!this.data.form.key1) return util.myShowToast('请输入活动名称!');
- if (this.data.form.key1.length > 30 || this.data.form.key1.length < 2) return util.myShowToast('活动名称应为2-30字!');
- if (this.data.form.key1.match(reg)) return util.myShowToast('活动名称不能包含表情!');
- if (!this.data.form.key2) return util.myShowToast('请输入活动地点!');
- if (this.data.form.key2.length > 30 || this.data.form.key2.length < 2) return util.myShowToast('活动地点应为2-30字!');
- if (this.data.form.key2.match(reg)) return util.myShowToast('活动地点不能包含表情!');
-
- if (!this.data.form.key3) return util.myShowToast('请输入活动开始时间!');
- // if (!this.data.form.key7) return util.myShowToast('请输入活动结束时间!');
- if(this.data.form.key7){
- if(this.datetab(this.data.form.key3,this.data.form.key7)) return util.myShowToast('活动开始时间不能大于结束时间!');
- }
- if (!this.data.form.key5) return util.myShowToast('请输入活动描述!');
- if (this.data.form.key5.length > 300 || this.data.form.key5.length < 2) return util.myShowToast('活动描述应为2-300字!');
- if (this.data.form.key5.match(reg)) return util.myShowToast('活动描述不能包含表情!');
- let reg1 = /^\d+(\.\d+)?$/;
- if (this.data.form.money && !reg1.test(this.data.form.money)) return util.myShowToast('请输入正确的金额!');
- let reg2 = /^[1-9]\d*$/;
- // if(!this.data.form.num) return util.myShowToast('请输入正确的报名人数!');
- // if(this.data.form.num < 2) return util.myShowToast('报名人数不应小于2人!');
- // if(this.data.form.num > 9999) return util.myShowToast('报名人数不应大于9999人!');
- if (this.data.form.num && !reg2.test(this.data.form.num)) return util.myShowToast('请输入正确的报名人数!');
- if (!this.data.imgList.length) return util.myShowToast('至少上传一张图片!');
- this.isOpen({
- private: this.data.switch1Checked ? 1 : 0 //不公开
- });
- // wx.showModal({
- // title: '提示',
- // content: '是否公开您发起的活动?',
- // cancelText: '否',
- // confirmText: '是',
- // success (res) {
- // if (res.confirm) {
- // that.isOpen({
- // private: 0 //不公开
- // });
- // } else if (res.cancel) {
- // that.isOpen({
- // private: 1
- // });
- // }
- // }
- // })
- },
- getLng() {
- return new Promise((resolve, reject) => {
- qqmapsdk.geocoder({
- //获取表单传入地址
- address: this.data.form.key2, //地址参数,例:固定地址,address: '北京市海淀区彩和坊路海淀西大街74号'
- complete: (res) => {
- if (res.message == "query ok") {
- //根据地址解析在地图上标记解析地址位置
- resolve({
- latitude: res.result.location.lat,
- longitude: res.result.location.lng
- })
- } else {
- resolve({
- latitude: 0,
- longitude: 0
- })
- }
- }
- })
- })
- },
- //删除图片
- removeImg(e) {
- const that = this;
- wx.showModal({
- title: '提示',
- content: '确定删除图片?',
- success(res) {
- if (res.confirm) {
- // let item = e.currentTarget.dataset.item;
- // let index = e.currentTarget.dataset.index;
- // console.log(index);
- // let newImgList = that.data.imgList.splice(index,1);
- // let newBigImglist = that.data.bigImgList.splice(index,1);
- // let newImgList = that.data.imgList.filter(v => {
- // return item != v;
- // });
- that.setData({
- imgList: [],
- bigImgList: []
- })
- } 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;
- const tempFilesSize = res.tempFiles[0].size;
- const src = res.tempFilePaths[0];
- wx.showLoading();
- if (tempFilesSize > 2000000) { //图片小于或者等于1M时 可以执行获取图片
- return wx.showToast({
- title: '上传图片不能大于2M!', //标题
- icon: 'none' //图标 none不使用图标,详情看官方文档
- })
- }
- wx.uploadFile({
- url: 'https://hw.cirray.cn/api/upload_image', //仅为示例,非真实的接口地址
- filePath: tempFilePaths[0],
- name: 'file',
- formData: {},
- success: function (res) {
- wx.navigateTo({
- url: '../upload/index?src=' + src + '&originimg=' + res.data
- })
- wx.hideLoading()
- },
- fail(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.actid && key == 'key1') return;
- 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
- });
- },
- changeDateTime2(e) {
- let dateTime = e.detail.value;
- let dateTimeArray = this.data.dateTimeArray2;
- this.setData({
- dateTime2: dateTime
- });
- let aaa1 = dateTime[0];
- let aaa2 = dateTime[1];
- let aaa3 = dateTime[2];
- let aaa4 = dateTime[3];
- let aaa5 = dateTime[4];
- let time1 = dateTimeArray[0][aaa1];
- let time2 = dateTimeArray[1][aaa2];
- let time3 = dateTimeArray[2][aaa3];
- let time4 = dateTimeArray[3][aaa4];
- let time5 = dateTimeArray[4][aaa5];
- let time = time1 + '-' + time2 + '-' + time3 + ' ' + time4 + ':' + time5;
- let key = e.currentTarget.dataset.key;
- let newKey = 'form.' + key;
- this.setData({
- [newKey]: time
- })
- },
- changeDateTime1(e) {
- let dateTime = e.detail.value;
- let dateTimeArray = this.data.dateTimeArray1;
- this.setData({
- dateTime1: dateTime
- });
- let aaa1 = dateTime[0];
- let aaa2 = dateTime[1];
- let aaa3 = dateTime[2];
- let aaa4 = dateTime[3];
- let aaa5 = dateTime[4];
- let time1 = dateTimeArray[0][aaa1];
- let time2 = dateTimeArray[1][aaa2];
- let time3 = dateTimeArray[2][aaa3];
- let time4 = dateTimeArray[3][aaa4];
- let time5 = dateTimeArray[4][aaa5];
- let time = time1 + '-' + time2 + '-' + time3 + ' ' + time4 + ':' + time5;
- let key = e.currentTarget.dataset.key;
- let newKey = 'form.' + key;
- this.setData({
- [newKey]: time
- })
- },
- changeDateTime7(e) {
- let dateTime = e.detail.value;
- let dateTimeArray = this.data.dateTimeArray7;
- this.setData({
- dateTime7: dateTime
- });
- let aaa1 = dateTime[0];
- let aaa2 = dateTime[1];
- let aaa3 = dateTime[2];
- let aaa4 = dateTime[3];
- let aaa5 = dateTime[4];
- let time1 = dateTimeArray[0][aaa1];
- let time2 = dateTimeArray[1][aaa2];
- let time3 = dateTimeArray[2][aaa3];
- let time4 = dateTimeArray[3][aaa4];
- let time5 = dateTimeArray[4][aaa5];
- let time = time1 + '-' + time2 + '-' + time3 + ' ' + time4 + ':' + time5;
- let key = e.currentTarget.dataset.key;
- let newKey = 'form.' + key;
- this.setData({
- [newKey]: time
- })
- },
- changeDateTimeColumn2(e) {
- var arr = this.data.dateTime2,
- dateArr = this.data.dateTimeArray2;
- arr[e.detail.column] = e.detail.value;
- dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
- this.setData({
- dateTimeArray2: dateArr,
- dateTime2: 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
- });
- },
- changeDateTimeColumn1(e) {
- var arr = this.data.dateTime7,
- dateArr = this.data.dateTimeArray7;
- arr[e.detail.column] = e.detail.value;
- dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
- this.setData({
- dateTimeArray7: dateArr,
- dateTime7: arr
- });
- },
- resetData(data) {
- console.log(data, 333)
- let form = this.data.form;
- let isShowForm = this.data.isShowForm;
- form.key1 = data.title;
- form.key2 = data.location;
- form.key3 = data.starttime.substr(0, 16);
- form.key4 = data.endtime.substr(0, 16);
- form.key5 = data.content && (data.content.split('&hc').join('\n'));
- form.num = data.capacity - 0;
- form.money = data.attendfee - 0;
- isShowForm.key1 = true;
- isShowForm.key2 = true;
- isShowForm.key5 = true;
- let imgList1 = JSON.parse(data.images);
- // 获取完整的年月日 时分秒,以及默认显示的数组
- var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear, data.starttime);
- var obj2 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear, data.endtime);
- // 精确到分的处理,将数组的秒去掉
- obj1.dateTimeArray.pop();
- obj1.dateTime.pop();
- obj2.dateTimeArray.pop();
- obj2.dateTime.pop();
- this.setData({
- form,
- isShowForm,
- imgList: imgList1.img,
- bigImgList: imgList1.bigImg,
- actiddetail: data,
- dateTime2: obj2.dateTime,
- dateTimeArray2: obj2.dateTimeArray,
- dateTimeArray1: obj1.dateTimeArray,
- dateTime1: obj1.dateTime,
- switch1Checked: data.private ? true : false
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (options.actid) {
- this.setData({
- actid: options.actid
- });
- app.globalData.api.activity_id(options.actid).then(res => {
- this.resetData(res.data);
- })
- }
- // 获取完整的年月日 时分秒,以及默认显示的数组
- var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
- var obj2 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
- var obj7 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
- // 精确到分的处理,将数组的秒去掉
- var lastArray = obj1.dateTimeArray.pop();
- var lastTime = obj1.dateTime.pop();
- obj2.dateTimeArray.pop();
- obj2.dateTime.pop();
- obj7.dateTimeArray.pop();
- obj7.dateTime.pop();
- this.setData({
- dateTime2: obj2.dateTime,
- dateTimeArray2: obj2.dateTimeArray,
- dateTimeArray1: obj1.dateTimeArray,
- dateTimeArray7: obj7.dateTimeArray,
- dateTime1: obj1.dateTime,
- dateTime7: obj7.dateTime,
- BASEIMGURL: app.globalData.BASEIMGURL,
- userInfo: app.globalData.userInfo
- });
- },
- clickImg() {
- wx.previewImage({
- urls: [this.data.BASEIMGURL + this.data.bigImgList[0]], //需要预览的图片http链接列表,注意是数组
- current: '', // 当前显示图片的http链接,默认是第一个
- success: function (res) {},
- fail: function (res) {},
- complete: function (res) {},
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {},
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- this.setData({
- actid: ''
- })
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return app.onShareAppMessage();
- }
- })
|