C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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