activity.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. // pages/my/activity/activity.js
  2. const App = getApp();
  3. const util = require("../../utils/tool");
  4. let CityArray0 = [];
  5. let CityArray1 = [];
  6. let CityArray2 = [];
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. appAssetsUrl2: App.appAssetsUrl2,
  13. user: wx.getStorageSync("USER"),
  14. lng: null,
  15. lat: null,
  16. activityId: null,
  17. detail: {},
  18. region: [],
  19. // 负责人
  20. staffId: null,
  21. // 负责人联系电话
  22. teacherPhone: null,
  23. // 活动标题
  24. title: null,
  25. // 省
  26. province: null,
  27. // 市
  28. city: null,
  29. // 区
  30. area: null,
  31. // 活动地址
  32. address: null,
  33. // 坐标
  34. coordinate: null,
  35. // 活动时间
  36. startTime: null,
  37. endTime: null,
  38. startTimeDate: null,
  39. startTimeHS: null,
  40. endTimeDate: null,
  41. endTimeHS: null,
  42. // 报名截止
  43. registrationEnd: null,
  44. registrationEndDate: null,
  45. registrationEndHS: null,
  46. // 集合时间
  47. meetingTime: null,
  48. // 集合日期
  49. meetingTimeDate: null,
  50. // 集合日期时间
  51. meetingTimeHS: null,
  52. // 活动费用
  53. isNeedVip: 0,
  54. money: null,
  55. // 是否推荐至首页
  56. isTop: null,
  57. // 报名数
  58. willnum: null,
  59. // 负责老师
  60. principal: null,
  61. // 活动封面图
  62. thumbnailImg: null,
  63. // 兼职banner图
  64. bannerImg: null,
  65. // 活动详情
  66. content: null,
  67. // 联系二维码
  68. qrCodePicture: null,
  69. contactInstructions: null,
  70. multiArray: [],
  71. multiIndex: [],
  72. activityjs: null,
  73. activityyq: null,
  74. activitysx: null,
  75. auditStatus: null,
  76. labelListIndex: null,
  77. labelList: []
  78. },
  79. /**
  80. * 生命周期函数--监听页面加载
  81. */
  82. onLoad(options) {
  83. if (options.activityId) {
  84. this.setData({
  85. activityId: options.activityId,
  86. });
  87. this.getDetail();
  88. } else {
  89. this.getProvince();
  90. }
  91. this.setData({
  92. staffId: this.data.user.id,
  93. teacherPhone: this.data.user.phone,
  94. });
  95. this.getCoord();
  96. this.getLabel()
  97. },
  98. /**
  99. * 生命周期函数--监听页面初次渲染完成
  100. */
  101. onReady() {},
  102. /**
  103. * 生命周期函数--监听页面显示
  104. */
  105. onShow() {},
  106. // 获取经纬度
  107. getCoord() {
  108. wx.getFuzzyLocation({
  109. type: "gcj02",
  110. success: (res) => {
  111. const latitude = res.latitude;
  112. const longitude = res.longitude;
  113. this.setData({
  114. lng: Number(longitude),
  115. lat: Number(latitude),
  116. });
  117. },
  118. fail: (e) => {},
  119. });
  120. },
  121. // 获取省
  122. getProvince() {
  123. App._get("region/provinceList", {}, (res) => {
  124. let pId = "";
  125. let prov = "";
  126. if (res.code === 0) {
  127. let provice = res.data;
  128. this.data.multiArray[0] = provice;
  129. CityArray0 = provice;
  130. if (CityArray0.length) {
  131. for (let i = 0; i < CityArray0.length; i++) {
  132. if (CityArray0[i].id == this.data.province) {
  133. this.data.multiIndex[0] = i;
  134. break;
  135. } else {
  136. this.data.multiIndex[0] = 0;
  137. // break;
  138. }
  139. }
  140. }
  141. if (this.data.province) {
  142. pId = this.data.province;
  143. } else {
  144. //根据默认省,获取默认市
  145. if (this.data.multiArray[0].length) {
  146. pId = this.data.multiArray[0][0].id;
  147. }
  148. }
  149. this.getCity(pId);
  150. }
  151. });
  152. },
  153. //选择标签
  154. labelPickerChange(e){
  155. let labelListIndex = e.detail.value;
  156. this.setData({
  157. labelListIndex
  158. })
  159. },
  160. // labelList
  161. getLabel() {
  162. let that = this;
  163. App._post_form('bizcatelog/apiSelectBizcatelog/act_title', '', null,
  164. function(res) {
  165. if(res.code == 0){
  166. that.setData({
  167. labelList: res.dictList
  168. })
  169. }
  170. })
  171. },
  172. getCity(pId) {
  173. App._get(`region/urbanDistrictList?id=${pId}`, {}, (res) => {
  174. // App._get(`region/urbanDistrictList?id=420000`, {}, res => {
  175. if (res.code === 0) {
  176. let city = res.data;
  177. this.data.multiArray[1] = city;
  178. CityArray1 = city;
  179. if (CityArray1.length) {
  180. for (let i = 0; i < CityArray1.length; i++) {
  181. // console.log(CityArray1[i].id, pId, 222)
  182. if (CityArray1[i].pid === pId) {
  183. this.data.multiIndex[1] = i;
  184. break;
  185. }
  186. }
  187. }
  188. let cityId = "";
  189. if (this.data.city) {
  190. cityId = this.data.city;
  191. } else {
  192. if (this.data.multiArray[1].length) {
  193. cityId = this.data.multiArray[1][0].id;
  194. }
  195. }
  196. this.getArea(cityId);
  197. this.setData({
  198. multiArray: this.data.multiArray,
  199. multiIndex: this.data.multiIndex,
  200. });
  201. }
  202. });
  203. },
  204. // 获取区
  205. getArea(cityId) {
  206. for (let i = 0; i < this.data.multiArray[1].length; i++) {
  207. console.log(this.data.multiArray[1], cityId, "area");
  208. if (this.data.multiArray[1][i].id === cityId) {
  209. CityArray2 = this.data.multiArray[1][i].childRegionList;
  210. this.data.multiArray[2] = this.data.multiArray[1][i].childRegionList;
  211. this.data.multiIndex[2] = i;
  212. break;
  213. }
  214. }
  215. if (this.data.area) {
  216. for (let j = 0; j < this.data.multiArray[2].length; j++) {
  217. if (this.data.multiArray[2][j].id === this.data.area) {
  218. this.data.multiIndex[2] = j;
  219. break;
  220. }
  221. }
  222. }
  223. this.setData({
  224. multiArray: this.data.multiArray,
  225. multiIndex: this.data.multiIndex,
  226. });
  227. console.log(this.data.multiArray, this.data.multiIndex, 1111);
  228. },
  229. areaChange(e) {
  230. this.data.multiIndex[0] = e.detail.value[0];
  231. this.data.multiIndex[1] = e.detail.value[1];
  232. this.data.multiIndex[2] = e.detail.value[2];
  233. let province = CityArray0[e.detail.value[0]].id;
  234. let city = CityArray1[e.detail.value[1]].id;
  235. let area = CityArray2[e.detail.value[2]].id;
  236. this.setData({
  237. multiIndex: this.data.multiIndex,
  238. province: province,
  239. city: city,
  240. area: area,
  241. });
  242. },
  243. MultiPickerAreaChange(e) {
  244. if (e.detail.column == 0) {
  245. let pid = CityArray0[e.detail.value].id;
  246. this.data.multiIndex[0] = e.detail.value;
  247. this.getCity(pid);
  248. } else if (e.detail.column == 1) {
  249. let pid = CityArray1[e.detail.value].id;
  250. this.data.multiIndex[1] = e.detail.value;
  251. this.getArea(pid);
  252. } else {
  253. this.data.multiIndex[2] = e.detail.value;
  254. }
  255. this.setData({
  256. multiIndex: this.data.multiIndex,
  257. });
  258. },
  259. // 活动时间
  260. startTimeBindDateChange(e) {
  261. this.setData({
  262. startTimeDate: e.detail.value,
  263. });
  264. },
  265. startTimeBindTimeChange(e) {
  266. this.setData({
  267. startTimeHS: e.detail.value,
  268. });
  269. },
  270. endTimeBindDateChange(e) {
  271. this.setData({
  272. endTimeDate: e.detail.value,
  273. });
  274. },
  275. endTimeBindTimeChange(e) {
  276. this.setData({
  277. endTimeHS: e.detail.value,
  278. });
  279. },
  280. // 报名截止
  281. registrationEndBindDateChange(e) {
  282. this.setData({
  283. registrationEndDate: e.detail.value,
  284. });
  285. },
  286. registrationEndBindTimeChange(e) {
  287. this.setData({
  288. registrationEndHS: e.detail.value,
  289. });
  290. },
  291. // 集合时间
  292. meetingBindDateChange(e) {
  293. this.setData({
  294. meetingTimeDate: e.detail.value,
  295. });
  296. },
  297. meetingBindTimeChange(e) {
  298. this.setData({
  299. meetingTimeHS: e.detail.value,
  300. });
  301. },
  302. // 活动 免费
  303. freeRadioChange(e) {
  304. if (e.detail.value == 1) {
  305. this.data.money = 0;
  306. }
  307. this.setData({
  308. isNeedVip: e.detail.value,
  309. money: this.data.money,
  310. });
  311. },
  312. // 推荐首页
  313. recommendRadioChange(e) {
  314. this.setData({
  315. isTop: e.detail.value,
  316. });
  317. },
  318. changeAddress() {
  319. if (this.data.auditStatus == 1) {
  320. wx.showToast({
  321. icon: "none",
  322. title: "活动进行中",
  323. });
  324. return false;
  325. }
  326. wx.chooseLocation({
  327. success: (res) => {
  328. console.log(res, 1111);
  329. wx.showLoading({
  330. title: "获取位置中...",
  331. });
  332. App._get(
  333. "store/getDetailsAddress",
  334. {
  335. lon: res.longitude,
  336. lat: res.latitude,
  337. },
  338. (res2) => {
  339. if (res2.code === 0) {
  340. wx.hideLoading();
  341. this.setData({
  342. address: res2.data.street_number,
  343. coordinate: res.longitude + "," + res.latitude,
  344. });
  345. }
  346. }
  347. );
  348. },
  349. });
  350. // wx.navigateTo({
  351. // url: `/activity/map/map?lng=${this.data.lng}&lat=${this.data.lat}`,
  352. // })
  353. },
  354. uploadHandle(e) {
  355. if (this.data.auditStatus == 1) {
  356. wx.showToast({
  357. icon: "none",
  358. title: "活动进行中",
  359. });
  360. return false;
  361. }
  362. console.log(e, 11111111);
  363. let currentIndex = e.currentTarget.dataset.index;
  364. // if (this.data.list.length == 3) {
  365. // return false
  366. // }
  367. let _this = this;
  368. var tempFile;
  369. wx.showActionSheet({
  370. itemList: ["拍照上传", "从相册中选择"],
  371. success(res) {
  372. if (res.tapIndex === 0) {
  373. wx.chooseImage({
  374. count: 1,
  375. sizeType: ["original", "compressed"],
  376. sourceType: ["camera"],
  377. success(res) {
  378. const tempFilePaths = res.tempFilePaths;
  379. wx.uploadFile({
  380. url: App.apiRoot + "file/upload",
  381. filePath: tempFilePaths[0],
  382. name: "file",
  383. success: function (res) {
  384. if (res.errMsg === "uploadFile:ok") {
  385. wx.showToast({
  386. title: "上传成功",
  387. image: "",
  388. duration: 1500,
  389. mask: false,
  390. });
  391. let data = JSON.parse(res.data);
  392. if (currentIndex == 0) {
  393. _this.data.thumbnailImg = data.data;
  394. _this.setData({
  395. thumbnailImg: _this.data.thumbnailImg,
  396. });
  397. } else if (currentIndex == 1) {
  398. _this.data.bannerImg = data.data;
  399. _this.setData({
  400. bannerImg: _this.data.bannerImg,
  401. });
  402. } else {
  403. _this.data.qrCodePicture = data.data;
  404. _this.setData({
  405. qrCodePicture: _this.data.qrCodePicture,
  406. });
  407. }
  408. }
  409. },
  410. function() {
  411. wx.showToast({
  412. title: "上传失败",
  413. icon: "none",
  414. image: "",
  415. duration: 1500,
  416. mask: false,
  417. });
  418. },
  419. });
  420. },
  421. });
  422. } else if (res.tapIndex === 1) {
  423. wx.chooseImage({
  424. count: 1,
  425. sizeType: ["original", "compressed"],
  426. sourceType: ["album"],
  427. success(res) {
  428. const tempFilePaths = res.tempFilePaths;
  429. wx.uploadFile({
  430. url: App.apiRoot + "file/upload",
  431. filePath: tempFilePaths[0],
  432. name: "file",
  433. success: function (res) {
  434. if (res.errMsg === "uploadFile:ok") {
  435. wx.showToast({
  436. title: "上传成功",
  437. image: "",
  438. duration: 1500,
  439. mask: false,
  440. });
  441. let data = JSON.parse(res.data);
  442. if (currentIndex == 0) {
  443. _this.data.thumbnailImg = data.data;
  444. _this.setData({
  445. thumbnailImg: _this.data.thumbnailImg,
  446. });
  447. } else if (currentIndex == 1) {
  448. _this.data.bannerImg = data.data;
  449. _this.setData({
  450. bannerImg: _this.data.bannerImg,
  451. });
  452. } else {
  453. _this.data.qrCodePicture = data.data;
  454. _this.setData({
  455. qrCodePicture: _this.data.qrCodePicture,
  456. });
  457. }
  458. }
  459. },
  460. function() {
  461. wx.showToast({
  462. title: "上传失败",
  463. icon: "none",
  464. image: "",
  465. duration: 1500,
  466. mask: false,
  467. success: (result) => {},
  468. fail: () => {},
  469. complete: () => {},
  470. });
  471. },
  472. });
  473. },
  474. });
  475. }
  476. },
  477. fail(res) {},
  478. });
  479. },
  480. submit() {
  481. let startTime = this.data.startTimeDate + " " + this.data.startTimeHS;
  482. let endTime = this.data.endTimeDate + " " + this.data.endTimeHS;
  483. if (!this.data.title) {
  484. return util.alert("请先填写活动标题");
  485. }
  486. if (!this.data.city || !this.data.area) {
  487. return util.alert("请先选择所属区域");
  488. }
  489. if (!this.data.address) {
  490. return util.alert("请先选择活动地址");
  491. }
  492. // if (!startTime || !endTime) {
  493. // return util.alert("请先选择活动时间");
  494. // }
  495. if (!this.data.startTimeDate || !this.data.startTimeHS || !this.data.endTimeDate || !this.data.endTimeHS) {
  496. return util.alert("请先选择活动时间");
  497. }
  498. if (!this.data.registrationEndDate || !this.data.registrationEndHS) {
  499. return util.alert("请先选择报名截止时间");
  500. }
  501. if (!this.data.meetingTimeDate || !this.data.meetingTimeHS) {
  502. return util.alert("请先选择集合时间");
  503. }
  504. console.log(this.data.money,'this.data.money')
  505. if (this.data.money === null) {
  506. return util.alert("请填写活动费用");
  507. }
  508. if (!this.data.willnum) {
  509. return util.alert("请输入报名人数");
  510. }
  511. if (!this.data.thumbnailImg) {
  512. return util.alert("请先上传活动封面缩略图");
  513. }
  514. if (!this.data.bannerImg) {
  515. return util.alert("请先上传活动详情banner图");
  516. }
  517. if (!this.data.qrCodePicture) {
  518. return util.alert("请先上传联系二维码图");
  519. }
  520. if (!this.data.contactInstructions) {
  521. return util.alert("请先填写联系说明");
  522. }
  523. wx.showLoading({
  524. title: "提交中,请稍后",
  525. });
  526. let list = [
  527. this.data.activityjs,
  528. this.data.activityyq,
  529. this.data.activitysx,
  530. ];
  531. let obj = {
  532. address: this.data.address,
  533. area: this.data.area,
  534. bannerImg: this.data.bannerImg,
  535. city: this.data.city,
  536. activityAppletsDetailsList: list,
  537. coordinate: this.data.coordinate,
  538. // endTime: this.data.endTimeDate + ' ' + this.data.endTimeHS,
  539. endTime: endTime,
  540. isNeedVip: this.data.isNeedVip,
  541. isTop: this.data.isTop,
  542. meetingTime: this.data.meetingTimeDate + " " + this.data.meetingTimeHS,
  543. money: this.data.money,
  544. province: this.data.province,
  545. registrationEnd:
  546. this.data.registrationEndDate + " " + this.data.registrationEndHS,
  547. staffId: this.data.staffId,
  548. // startTime: this.data.startTimeDate + ' ' + this.data.startTimeHS,
  549. startTime: startTime,
  550. teacherPhone: this.data.teacherPhone,
  551. thumbnailImg: this.data.thumbnailImg,
  552. qrCodePicture: this.data.qrCodePicture,
  553. contactInstructions: this.data.contactInstructions,
  554. title: this.data.title,
  555. willnum: this.data.willnum,
  556. principal: this.data.principal,
  557. memberId: this.data.user.id,
  558. // is_applets_release 是否是小程序发布 1是 0否
  559. isAppletsRelease: 1,
  560. titleCode:this.data.labelList[this.data.labelListIndex].itemcode
  561. };
  562. wx.setStorageSync("activityDetail", obj);
  563. if (this.data.activityId) {
  564. wx.navigateTo({
  565. url: "/activity/detail/detail?activityId=" + this.data.activityId,
  566. });
  567. } else {
  568. wx.navigateTo({
  569. url: "/activity/detail/detail",
  570. });
  571. }
  572. return false;
  573. // if (this.data.activityId) {
  574. // App._put_form('activity/updateActivity', '', {
  575. // ...obj,
  576. // id: this.data.activityId
  577. // }, res => {
  578. // if (res.code === 0) {
  579. // wx.showToast({
  580. // title: '修改成功',
  581. // })
  582. // }
  583. // }, err => {}, complete => {
  584. // setTimeout(() => {
  585. // wx.hideLoading()
  586. // }, 300)
  587. // })
  588. // } else {
  589. // App._post_form('activity/saveActivity', '', obj, res => {
  590. // if (res.code === 0) {
  591. // wx.showToast({
  592. // title: '添加成功',
  593. // })
  594. // }
  595. // }, err => {}, complete => {
  596. // setTimeout(() => {
  597. // wx.hideLoading()
  598. // }, 300)
  599. // })
  600. // }
  601. },
  602. // 获取活动详情
  603. getDetail() {
  604. wx.showLoading({
  605. title: "努力加载中...",
  606. });
  607. App._post_form(
  608. "act/one",
  609. "",
  610. {
  611. id: this.data.activityId,
  612. stuId: this.data.user.id,
  613. },
  614. (res) => {
  615. if (res.code === 0) {
  616. this.setData({
  617. detail: res.data,
  618. title: res.data.title,
  619. province: res.data.province,
  620. city: res.data.city,
  621. area: res.data.area,
  622. // provincename: res.data.provincename,
  623. // cityname: res.data.cityname,
  624. // areaName: res.data.areaName,
  625. address: res.data.address,
  626. coordinate: res.data.coordinate,
  627. startTime: res.data.startTime,
  628. endTime: res.data.endTime,
  629. startTimeDate: res.data.startTime.split(" ")[0],
  630. startTimeHS: res.data.startTime.split(" ")[1],
  631. endTimeDate: res.data.endTime.split(" ")[0],
  632. endTimeHS: res.data.endTime.split(" ")[1],
  633. registrationEnd: res.data.registrationEnd,
  634. registrationEndDate: res.data.endTime.split(" ")[0],
  635. registrationEndHS: res.data.endTime.split(" ")[1],
  636. meetingTime: res.data.meetingTime,
  637. meetingTimeDate: res.data.endTime.split(" ")[0],
  638. meetingTimeHS: res.data.endTime.split(" ")[1],
  639. isNeedVip: res.data.isNeedVip,
  640. money: res.data.money,
  641. isTop: res.data.isTop,
  642. willnum: res.data.willnum,
  643. principal: res.data.principal,
  644. thumbnailImg: res.data.thumbnailImg,
  645. bannerImg: res.data.bannerImg,
  646. qrCodePicture: res.data.qrCodePicture,
  647. contactInstructions: res.data.contactInstructions,
  648. activityjs: res.data.activityAppletsDetailsList[0],
  649. activityyq: res.data.activityAppletsDetailsList[1],
  650. activitysx: res.data.activityAppletsDetailsList[2],
  651. auditStatus: res.data.auditStatus,
  652. });
  653. this.getProvince();
  654. }
  655. },
  656. (err) => {},
  657. (complete) => {
  658. setTimeout(() => {
  659. wx.hideLoading();
  660. }, 300);
  661. }
  662. );
  663. },
  664. // 取消活动
  665. // cancel() {
  666. // let parm = {
  667. // sid: this.data.user.id,
  668. // aid: this.data.activityId,
  669. // };
  670. // App._post_form(
  671. // "act/cancel",
  672. // "application/json",
  673. // JSON.stringify(parm),
  674. // (res) => {
  675. // if (res.code === 0) {
  676. // wx.showModal({
  677. // title: "温馨提示",
  678. // content: "取消成功",
  679. // showCancel: false,
  680. // });
  681. // wx.navigateBack();
  682. // }
  683. // }
  684. // );
  685. // },
  686. cancel() {
  687. // let parm = {
  688. // sid: this.data.user.id,
  689. // aid: this.data.activityId,
  690. // };
  691. App._put_form(
  692. "activity/cancelActivity/"+this.data.activityId,
  693. "",
  694. {},
  695. (res) => {
  696. if (res.code === 0) {
  697. wx.showModal({
  698. title: "温馨提示",
  699. content: "取消成功",
  700. showCancel: false,
  701. });
  702. wx.navigateBack();
  703. }
  704. },
  705. err => {
  706. wx.showToast({
  707. icon: 'error',
  708. title: '服务端异常',
  709. })
  710. }
  711. );
  712. },
  713. // 查看报名信息
  714. toApply() {
  715. wx.navigateTo({
  716. url:
  717. "/activity/activityInfo/activityInfo?activityId=" +
  718. this.data.activityId + "&willnum=" + this.data.willnum
  719. });
  720. },
  721. /**
  722. * 生命周期函数--监听页面隐藏
  723. */
  724. onHide() {},
  725. /**
  726. * 生命周期函数--监听页面卸载
  727. */
  728. onUnload() {},
  729. /**
  730. * 页面相关事件处理函数--监听用户下拉动作
  731. */
  732. onPullDownRefresh() {},
  733. /**
  734. * 页面上拉触底事件的处理函数
  735. */
  736. onReachBottom() {},
  737. /**
  738. * 用户点击右上角分享
  739. */
  740. onShareAppMessage() {},
  741. });