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.

324 line
7.8 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. app.globalData.previewFlag = true
  84. let that = this;
  85. /**
  86. * sex
  87. * 0 保密
  88. * 1 男
  89. * 2 女
  90. */
  91. if (that.data.flagsex == 0) {
  92. var sex = 0;
  93. } else {
  94. var sex = that.data.sex;
  95. }
  96. if (that.data.addressStr) {
  97. var address = that.data.addressStr;
  98. } else {
  99. var address = null;
  100. }
  101. if (e.detail.value.username) {
  102. var username = e.detail.value.username;
  103. } else if (that.data.username) {
  104. var username = that.data.username;
  105. } else {
  106. var username = null;
  107. }
  108. if (that.data.flag == 2 && that.data.date) {
  109. var birthday = new Date(that.data.date).getTime();
  110. } else {
  111. var birthday = null;
  112. }
  113. //获得答案
  114. delete e.detail.value.username;
  115. let obj = e.detail.value;
  116. if (that.data&&that.data.question&&that.data.question.length>0){
  117. let valArr22;
  118. valArr22 = Object.keys(obj).map(function (item,index) {
  119. if (!obj[item]){
  120. wx.showToast({
  121. title: '问卷调查回答不完整,请补充',
  122. duration:2000,
  123. icon:"none"
  124. })
  125. that.setData({
  126. answerflag:"noanswer"
  127. })
  128. }else{
  129. that.setData({
  130. answerflag: "answer"
  131. })
  132. return { ques: that.data.question[index].ques, answer: obj[item] }
  133. }
  134. });
  135. this.setData({
  136. answer:valArr22
  137. });
  138. }
  139. if ((username == null && this.data.selectques.name == 1) || (sex == 0 && this.data.selectques.sex == 1) || (birthday == null && this.data.selectques.birthday == 1)) {
  140. wx.showToast({
  141. title: '请输入完整的用户信息',
  142. icon: "none"
  143. })
  144. }
  145. else {
  146. if (this.data.answerflag == 'noanswer'){
  147. }else{
  148. that.setData({
  149. disabled: true
  150. })
  151. let data ={};
  152. data = {
  153. sex: sex,
  154. address: address,
  155. name: username,
  156. birthday: birthday,
  157. answer: JSON.stringify(that.data.answer),
  158. activityId: that.data.activityId
  159. };
  160. if (that.data.receiptUrl){
  161. data.imgUrl = "[" + '"' + that.data.receiptUrl + '"' + "]";
  162. }
  163. Http.post({
  164. url: config.api.activityJoin,
  165. data: data
  166. })
  167. .then(res => {
  168. that.setData({
  169. disabled: false
  170. })
  171. wx.reLaunch({
  172. url: `/pages/radetail/success/index?activityId=${that.data.activityId}`,
  173. })
  174. })
  175. .catch(err => {
  176. that.setData({
  177. disabled: false
  178. })
  179. wx.showToast({
  180. title: err.message,
  181. icon: 'none',
  182. duration: 2000,
  183. mask: false
  184. })
  185. })
  186. }
  187. }
  188. },
  189. radioChange: function(e) {
  190. this.setData({
  191. sex: e.detail.value,
  192. flagsex: 1
  193. })
  194. },
  195. /**
  196. * 生命周期函数--监听页面加载
  197. */
  198. onLoad: function(options) {
  199. let that = this;
  200. that.getLocation();
  201. if (options && options.activityId) {
  202. that.setData({
  203. activityId: options.activityId
  204. })
  205. that.getDetail(options.activityId);
  206. }
  207. },
  208. uploadImg() {
  209. let that = this;
  210. wx.chooseImage({
  211. success(res) {
  212. const tempFilePaths = res.tempFilePaths
  213. wx.uploadFile({
  214. url: config.url+config.api.imgUpload,
  215. filePath: tempFilePaths[0],
  216. name: 'file',
  217. header: {
  218. 'token': app.globalData.token
  219. },
  220. success(res) {
  221. console.log(res)
  222. if (res.statusCode == 200) {
  223. that.setData({
  224. receiptUrl: JSON.parse(res.data).data.url,
  225. showReceiptUrl: true
  226. })
  227. } else if (res.statusCode == 413) {
  228. wx.showToast({
  229. title: '上传的图片太大,请重新上传',
  230. icon: "none"
  231. })
  232. that.setData({
  233. showReceiptUrl: false
  234. })
  235. } else {
  236. wx.showToast({
  237. title: '请上传正确的图片',
  238. icon: "none"
  239. })
  240. that.setData({
  241. showReceiptUrl: false
  242. })
  243. }
  244. },
  245. fail(error) {
  246. wx.showToast({
  247. title: "上传图片失败",
  248. icon: "none"
  249. })
  250. that.setData({
  251. showReceiptUrl: false
  252. })
  253. }
  254. })
  255. }
  256. })
  257. },
  258. getDetail(activityId) {
  259. let that = this;
  260. Http.get({
  261. url: config.api.acfindById,
  262. data: {
  263. id: activityId
  264. }
  265. }).then(res => {
  266. if (res && res.data && res.data.activity) {
  267. this.setData({
  268. useImg: res.data.activity.useImg,
  269. imgDetail: res.data.activity.imgDetail,
  270. selectques: JSON.parse(res.data.activity.selectques)
  271. })
  272. if (res.data && res.data.activity && res.data.activity.question) {
  273. that.setData({
  274. question: JSON.parse(res.data.activity.question)
  275. })
  276. }
  277. }
  278. }).catch(err => {
  279. wx.showToast({
  280. title: err.errMsg,
  281. icon: 'none',
  282. duration: 2000,
  283. mask: false
  284. })
  285. })
  286. },
  287. /**
  288. * 获得经纬度
  289. */
  290. getLocation() {
  291. let that = this;
  292. wx.getLocation({
  293. type: "wgs84",
  294. success: function (res) {
  295. console.log(res)
  296. if (res && res.longitude && res.latitude) {
  297. Http.post({
  298. url: config.api.updateLBS,
  299. data: {
  300. latitude: res.latitude,
  301. longitude: res.longitude
  302. }
  303. }).then(res => {
  304. console.log(res)
  305. })
  306. }
  307. },
  308. fail: error => {
  309. wx.showModal({
  310. title: '提醒',
  311. content: '您拒绝了地理位置的授权,将无法参加报名活动,请删除小程序重新登录,才可以继续参加该活动',
  312. showCancel:false,
  313. success:function(res){
  314. if (res.confirm){
  315. }
  316. }
  317. })
  318. }
  319. })
  320. },
  321. })