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.

318 lines
7.4 KiB

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