C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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