C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

320 行
7.5 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  2. const util = require("../../../utils/util.js");
  3. const Http = require("../../../utils/HttpBasics");
  4. const config = require("../../../config/config");
  5. let app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. navigationBarHeight,
  12. date: '1988-03-12',
  13. flag: 1,
  14. answerflag: "",
  15. flagsex: 0,
  16. useImg:0,
  17. disabled:false,
  18. showReceiptUrl:false,
  19. receiptUrl:"",
  20. items: [{
  21. name: 1,
  22. value: '男',
  23. checked: false
  24. },
  25. {
  26. name: 2,
  27. value: '女',
  28. checked: false
  29. },
  30. ],
  31. username: "",
  32. array: ['上班族', '学生', '企业高管', '个体户', '自由职业', '其他'],
  33. array1: ['附近住户', '距离2km', '距离3km', '更远'],
  34. index: 0,
  35. index1: 0,
  36. showPage: false
  37. },
  38. /**
  39. * 获得生日
  40. */
  41. bindDateChange: function(e) {
  42. this.setData({
  43. date: e.detail.value,
  44. flag: 2
  45. })
  46. },
  47. /**
  48. * 职业
  49. */
  50. bindPickerChange: function(e) {
  51. this.setData({
  52. index: e.detail.value
  53. })
  54. },
  55. /**
  56. * 生活半径
  57. */
  58. bindPickerChange1: function(e) {
  59. this.setData({
  60. index1: e.detail.value
  61. })
  62. },
  63. // address: function() {
  64. // let that = this;
  65. // wx.chooseLocation({
  66. // success: function(res) {
  67. // that.setData({
  68. // address: res.name + '(' + res.address + ')',
  69. // addressStr: JSON.stringify(res)
  70. // })
  71. // },
  72. // fail: function(error) {
  73. // console.log(error)
  74. // },
  75. // complete: function(data) {}
  76. // })
  77. // },
  78. change(value){
  79. console.log(value)
  80. },
  81. formSubmit: function(e) {
  82. let that = this;
  83. /**
  84. * sex
  85. * 0 保密
  86. * 1 男
  87. * 2 女
  88. */
  89. if (that.data.flagsex == 0) {
  90. var sex = 0;
  91. } else {
  92. var sex = that.data.sex;
  93. }
  94. // if (that.data.addressStr) {
  95. // var address = that.data.addressStr;
  96. // } else {
  97. // var address = null;
  98. // }
  99. if (e.detail.value.username) {
  100. var username = e.detail.value.username;
  101. } else if (that.data.username) {
  102. var username = that.data.username;
  103. } else {
  104. var username = null;
  105. }
  106. if (that.data.flag == 2 && that.data.date) {
  107. var birthday = new Date(that.data.date).getTime();
  108. } else {
  109. var birthday = null;
  110. }
  111. //获得答案
  112. delete e.detail.value.username;
  113. let obj = e.detail.value;
  114. if (that.data&&that.data.question&&that.data.question.length>0){
  115. let valArr22;
  116. valArr22 = Object.keys(obj).map(function (item,index) {
  117. if (!obj[item]){
  118. wx.showToast({
  119. title: '问卷调查回答不完整,请补充',
  120. duration:2000,
  121. icon:"none"
  122. })
  123. that.setData({
  124. answerflag:"noanswer"
  125. })
  126. }else{
  127. that.setData({
  128. answerflag: "answer"
  129. })
  130. return { ques: that.data.question[index].ques, answer: obj[item] }
  131. }
  132. });
  133. this.setData({
  134. answer:valArr22
  135. });
  136. }
  137. if (username == null || sex == 0 || birthday == null) {
  138. wx.showToast({
  139. title: '请输入完整的用户信息',
  140. icon: "none"
  141. })
  142. } else {
  143. if (this.data.answerflag == 'noanswer'){
  144. }else{
  145. that.setData({
  146. disabled: true
  147. })
  148. let data ={};
  149. data = {
  150. sex: sex,
  151. // address: address,
  152. name: username,
  153. birthday: birthday,
  154. answer: JSON.stringify(that.data.answer),
  155. activityId: that.data.activityId
  156. };
  157. if (that.data.receiptUrl){
  158. data.imgUrl = "[" + '"' + that.data.receiptUrl + '"' + "]";
  159. }
  160. Http.post({
  161. url: config.api.activityJoin,
  162. data: data
  163. })
  164. .then(res => {
  165. that.setData({
  166. disabled: false
  167. })
  168. wx.reLaunch({
  169. url: `/pages/radetail/success/index?activityId=${that.data.activityId}`,
  170. })
  171. })
  172. .catch(err => {
  173. that.setData({
  174. disabled: false
  175. })
  176. wx.showToast({
  177. title: err.message,
  178. icon: 'none',
  179. duration: 2000,
  180. mask: false
  181. })
  182. })
  183. }
  184. }
  185. },
  186. radioChange: function(e) {
  187. this.setData({
  188. sex: e.detail.value,
  189. flagsex: 1
  190. })
  191. },
  192. /**
  193. * 生命周期函数--监听页面加载
  194. */
  195. onLoad: function(options) {
  196. let that = this;
  197. that.getLocation();
  198. if (options && options.activityId) {
  199. that.setData({
  200. activityId: options.activityId
  201. })
  202. that.getDetail(options.activityId);
  203. }
  204. },
  205. uploadImg() {
  206. let that = this;
  207. wx.chooseImage({
  208. success(res) {
  209. const tempFilePaths = res.tempFilePaths
  210. wx.uploadFile({
  211. url: config.url+config.api.imgUpload,
  212. filePath: tempFilePaths[0],
  213. name: 'file',
  214. header: {
  215. 'token': app.globalData.token
  216. },
  217. success(res) {
  218. console.log(res)
  219. if (res.statusCode == 200) {
  220. that.setData({
  221. receiptUrl: JSON.parse(res.data).data.url,
  222. showReceiptUrl: true
  223. })
  224. } else if (res.statusCode == 413) {
  225. wx.showToast({
  226. title: '上传的图片太大,请重新上传',
  227. icon: "none"
  228. })
  229. that.setData({
  230. showReceiptUrl: false
  231. })
  232. } else {
  233. wx.showToast({
  234. title: '请上传正确的图片',
  235. icon: "none"
  236. })
  237. that.setData({
  238. showReceiptUrl: false
  239. })
  240. }
  241. },
  242. fail(error) {
  243. wx.showToast({
  244. title: "上传图片失败",
  245. icon: "none"
  246. })
  247. that.setData({
  248. showReceiptUrl: false
  249. })
  250. }
  251. })
  252. }
  253. })
  254. },
  255. getDetail(activityId) {
  256. let that = this;
  257. Http.get({
  258. url: config.api.acfindById,
  259. data: {
  260. id: activityId
  261. }
  262. }).then(res => {
  263. if (res && res.data && res.data.activity) {
  264. this.setData({
  265. useImg: res.data.activity.useImg,
  266. imgDetail: res.data.activity.imgDetail
  267. })
  268. if (res.data && res.data.activity && res.data.activity.question) {
  269. that.setData({
  270. question: JSON.parse(res.data.activity.question)
  271. })
  272. }
  273. }
  274. }).catch(err => {
  275. wx.showToast({
  276. title: err.errMsg,
  277. icon: 'none',
  278. duration: 2000,
  279. mask: false
  280. })
  281. })
  282. },
  283. /**
  284. * 获得经纬度
  285. */
  286. getLocation() {
  287. let that = this;
  288. wx.getLocation({
  289. type: "wgs84",
  290. success: function (res) {
  291. console.log(res)
  292. if (res && res.longitude && res.latitude) {
  293. Http.post({
  294. url: config.api.updateLBS,
  295. data: {
  296. latitude: res.latitude,
  297. longitude: res.longitude
  298. }
  299. }).then(res => {
  300. console.log(res)
  301. })
  302. }
  303. },
  304. fail: error => {
  305. wx.showModal({
  306. title: '提醒',
  307. content: '您拒绝了地理位置的授权,将无法参加报名活动,请删除小程序重新登录,才可以继续参加该活动',
  308. showCancel:false,
  309. success:function(res){
  310. if (res.confirm){
  311. }
  312. }
  313. })
  314. }
  315. })
  316. },
  317. })