index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. // pages/add/index.js
  2. import util from '../../utils/util'
  3. var dateTimePicker = require('../../utils/dateTimePicker');
  4. const QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
  5. const qqmapsdk = new QQMapWX({
  6. key: '36IBZ-VI53O-FJHW2-SV2NP-USSAE-GFBUS'
  7. })
  8. const app = getApp();
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. form: {
  15. key1: '', //活动名称
  16. key2: '', //活动地点
  17. key3: '', //活动开始时间
  18. key4: '', //活动结束时间
  19. key5: '' //活动描述
  20. },
  21. isShowForm: {
  22. key1: false,
  23. key2: false,
  24. key5: false
  25. },
  26. inputFocus: {
  27. key1: false,
  28. key2: false,
  29. key5: false
  30. },
  31. date: '2018-10-01',
  32. time: '12:00',
  33. dateTimeArray: null,
  34. dateTime: null,
  35. dateTimeArray1: null,
  36. dateTime1: null,
  37. startYear: null,
  38. endYear: null,
  39. BASEIMGURL: '', //图片域名
  40. imgList: [],
  41. userInfo: {}
  42. },
  43. async getPhoneNumber(e) {
  44. const that = this;
  45. console.log(e.detail.errMsg == "getPhoneNumber:ok");
  46. if (e.detail.errMsg == "getPhoneNumber:ok") {
  47. let res = await app.globalData.api.bindphone({
  48. "openid": app.globalData.userInfo.openid,
  49. "encryptedData": e.detail.encryptedData,
  50. "iv": e.detail.iv,
  51. "invitor": app.globalData.shareOpenId
  52. });
  53. app.globalData.userInfo.phone = res.data.phone;
  54. this.setData({
  55. userInfo: {
  56. ...this.data.userInfo,
  57. phone: res.data.phone
  58. }
  59. })
  60. that.createBtn();
  61. console.log(res);
  62. } else {
  63. wx.showToast({
  64. title: '请授权您的手机号!',
  65. icon: 'none'
  66. })
  67. }
  68. },
  69. async createBtn() {
  70. if (!this.data.form.key1) return util.myShowToast('请输入活动名称!');
  71. if (!this.data.form.key2) return util.myShowToast('请输入活动地点!');
  72. if (!this.data.form.key3) return util.myShowToast('请输入活动时间!');
  73. if (!this.data.form.key5) return util.myShowToast('请输入活动描述!');
  74. if (!this.data.imgList.length) return util.myShowToast('至少上传一张图片!');
  75. let params = {
  76. "title": this.data.form.key1,
  77. "location": this.data.form.key2,
  78. "starttime": this.data.form.key3,
  79. "endtime": this.data.form.key4 || this.data.form.key3,
  80. "deadline": this.data.form.key3,
  81. "capacity": 50,
  82. "content": this.data.form.key5,
  83. "images": this.data.imgList.length ? this.data.imgList.join(';') : '',
  84. "attendfee": 30,
  85. "organizer": app.globalData.userInfo.phone,
  86. "private": 0
  87. };
  88. try {
  89. let lngArr = await this.getLng();
  90. params = Object.assign({}, params, lngArr);
  91. } catch (error) {
  92. console.log(error)
  93. }
  94. let res = await app.globalData.api.createActivity(params);
  95. if (res.data == "OK") {
  96. util.myShowToast('创建成功!')
  97. setTimeout(() => {
  98. wx.reLaunch({
  99. url: '/pages/index/index?update=1',
  100. })
  101. }, 1500)
  102. }
  103. console.log(res)
  104. },
  105. getLng() {
  106. return new Promise((resolve, reject) => {
  107. qqmapsdk.geocoder({
  108. //获取表单传入地址
  109. address: this.data.form.key2, //地址参数,例:固定地址,address: '北京市海淀区彩和坊路海淀西大街74号'
  110. complete: (res) => {
  111. if (res.message == "query ok") {
  112. //根据地址解析在地图上标记解析地址位置
  113. resolve({
  114. lat: res.result.location.lat,
  115. lng: res.result.location.lng
  116. })
  117. } else {
  118. reject(res.message);
  119. }
  120. }
  121. })
  122. })
  123. },
  124. //删除图片
  125. removeImg(e) {
  126. const that = this;
  127. wx.showModal({
  128. title: '提示',
  129. content: '确定删除图片?',
  130. success(res) {
  131. if (res.confirm) {
  132. console.log('用户点击确定')
  133. let item = e.currentTarget.dataset.item;
  134. let newImgList = that.data.imgList.filter(v => {
  135. return item != v;
  136. });
  137. that.setData({
  138. imgList: newImgList
  139. })
  140. } else if (res.cancel) {
  141. console.log('用户点击取消')
  142. }
  143. }
  144. });
  145. },
  146. updateImg() {
  147. const that = this;
  148. wx.chooseImage({
  149. count: 1, // 默认9
  150. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  151. sourceType: ['album', 'camera'],
  152. success: function (res) {
  153. var tempFilePaths = res.tempFilePaths;
  154. var tempFilesSize = res.tempFiles[0].size;
  155. wx.showLoading({
  156. title: '上传中...',
  157. });
  158. console.log('size:', tempFilesSize)
  159. if (tempFilesSize > 2000000) { //图片小于或者等于1M时 可以执行获取图片
  160. return wx.showToast({
  161. title: '上传图片不能大于2M!', //标题
  162. icon: 'none' //图标 none不使用图标,详情看官方文档
  163. })
  164. }
  165. console.log('tempFilePaths',tempFilePaths)
  166. wx.uploadFile({
  167. url: 'https://talk.cirray.cn/api/upload_image', //仅为示例,非真实的接口地址
  168. filePath: tempFilePaths[0],
  169. name: 'file',
  170. formData: {},
  171. success: function (res) {
  172. // wx.hideLoading()
  173. let imgList = [...that.data.imgList, that.data.BASEIMGURL + res.data];
  174. that.setData({
  175. imgList
  176. });
  177. wx.hideLoading()
  178. },
  179. fail(e) {
  180. console.log(e)
  181. wx.showToast({
  182. title: '上传失败,请稍后重试!',
  183. icon: 'none'
  184. })
  185. // wx.hideLoading()
  186. }
  187. })
  188. }
  189. })
  190. },
  191. back() {
  192. wx.navigateBack()
  193. },
  194. inputVal(e) {
  195. let value = e.detail.value;
  196. let key = e.currentTarget.dataset.key;
  197. let newKey = 'form.' + key;
  198. this.setData({
  199. [newKey]: value
  200. })
  201. },
  202. inputBlur(e) {
  203. let key = e.currentTarget.dataset.key;
  204. if (this.data.form[key]) {
  205. let newKey = 'isShowForm.' + key;
  206. this.setData({
  207. [newKey]: true
  208. })
  209. }
  210. },
  211. showInput(e) {
  212. let key = e.currentTarget.dataset.key;
  213. if (this.data.isShowForm[key]) {
  214. let newKey = 'isShowForm.' + key;
  215. let newInputFocus = Object.assign({
  216. key1: false,
  217. key2: false
  218. }, {
  219. [key]: true
  220. });
  221. this.setData({
  222. [newKey]: false,
  223. inputFocus: newInputFocus
  224. });
  225. }
  226. },
  227. changeDate(e) {
  228. this.setData({
  229. date: e.detail.value
  230. });
  231. },
  232. changeTime(e) {
  233. this.setData({
  234. time: e.detail.value
  235. });
  236. },
  237. changeDateTime(e) {
  238. const that = this;
  239. console.log("打印时间~~~~~~~~~~~~~~~~~~~~~", this.data.dateTimeArray);
  240. this.setData({
  241. dateTime: e.detail.value
  242. });
  243. console.log("打印时间", this.data.dateTime);
  244. var aaa1 = that.data.dateTime[0];
  245. var aaa2 = that.data.dateTime[1];
  246. var aaa3 = that.data.dateTime[2];
  247. var aaa4 = that.data.dateTime[3];
  248. var aaa5 = that.data.dateTime[4];
  249. var aaa6 = that.data.dateTime[5];
  250. var time1 = that.data.dateTimeArray[0][aaa1];
  251. var time2 = that.data.dateTimeArray[1][aaa2];
  252. var time3 = that.data.dateTimeArray[2][aaa3];
  253. var time4 = that.data.dateTimeArray[3][aaa4];
  254. var time5 = that.data.dateTimeArray[4][aaa5];
  255. var time6 = that.data.dateTimeArray[5][aaa6];
  256. var time = time1 + '-' + time2 + '-' + time3 + ' ' + time4 + ':' + time5 + ':' + time6;
  257. console.log("时间88888888888888888888888888888:", time);
  258. let key = e.currentTarget.dataset.key;
  259. let newKey = 'form.' + key;
  260. this.setData({
  261. [newKey]: time
  262. })
  263. },
  264. changeDateTime1(e) {
  265. this.setData({
  266. dateTime1: e.detail.value
  267. });
  268. },
  269. changeDateTimeColumn(e) {
  270. var arr = this.data.dateTime,
  271. dateArr = this.data.dateTimeArray;
  272. arr[e.detail.column] = e.detail.value;
  273. dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
  274. this.setData({
  275. dateTimeArray: dateArr,
  276. dateTime: arr
  277. });
  278. },
  279. changeDateTimeColumn1(e) {
  280. var arr = this.data.dateTime1,
  281. dateArr = this.data.dateTimeArray1;
  282. arr[e.detail.column] = e.detail.value;
  283. dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
  284. this.setData({
  285. dateTimeArray1: dateArr,
  286. dateTime1: arr
  287. });
  288. },
  289. /**
  290. * 生命周期函数--监听页面加载
  291. */
  292. onLoad: function (options) {
  293. // 获取完整的年月日 时分秒,以及默认显示的数组
  294. var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
  295. var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
  296. // 精确到分的处理,将数组的秒去掉
  297. var lastArray = obj1.dateTimeArray.pop();
  298. var lastTime = obj1.dateTime.pop();
  299. this.setData({
  300. dateTime: obj.dateTime,
  301. dateTimeArray: obj.dateTimeArray,
  302. dateTimeArray1: obj1.dateTimeArray,
  303. dateTime1: obj1.dateTime,
  304. BASEIMGURL: app.globalData.BASEIMGURL,
  305. userInfo: app.globalData.userInfo
  306. });
  307. },
  308. /**
  309. * 生命周期函数--监听页面初次渲染完成
  310. */
  311. onReady: function () {
  312. },
  313. /**
  314. * 生命周期函数--监听页面显示
  315. */
  316. onShow: function () {
  317. },
  318. /**
  319. * 生命周期函数--监听页面隐藏
  320. */
  321. onHide: function () {
  322. },
  323. /**
  324. * 生命周期函数--监听页面卸载
  325. */
  326. onUnload: function () {
  327. },
  328. /**
  329. * 页面相关事件处理函数--监听用户下拉动作
  330. */
  331. onPullDownRefresh: function () {
  332. },
  333. /**
  334. * 页面上拉触底事件的处理函数
  335. */
  336. onReachBottom: function () {
  337. },
  338. /**
  339. * 用户点击右上角分享
  340. */
  341. onShareAppMessage: function () {
  342. }
  343. })