C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

320 рядки
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. that.setData({
  82. disabled:true
  83. })
  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 || address == null || sex == 0 || birthday == null) {
  139. wx.showToast({
  140. title: '请输入完整的用户信息',
  141. icon: "none"
  142. })
  143. } else {
  144. console.log(that.data.answer)
  145. if (this.data.answerflag == 'noanswer'){
  146. }else{
  147. let data ={};
  148. data = {
  149. sex: sex,
  150. address: address,
  151. name: username,
  152. birthday: birthday,
  153. answer: JSON.stringify(that.data.answer),
  154. activityId: that.data.activityId
  155. };
  156. if (that.data.receiptUrl){
  157. data.imgUrl = "[" + '"' + that.data.receiptUrl + '"' + "]";
  158. }
  159. Http.post({
  160. url: config.api.activityJoin,
  161. data: data
  162. })
  163. .then(res => {
  164. that.setData({
  165. disabled: false
  166. })
  167. wx.reLaunch({
  168. url: `/pages/radetail/success/index?activityId=${that.data.activityId}`,
  169. })
  170. })
  171. .catch(err => {
  172. that.setData({
  173. disabled: false
  174. })
  175. wx.showToast({
  176. title: err.message,
  177. icon: 'none',
  178. duration: 2000,
  179. mask: false
  180. })
  181. })
  182. }
  183. }
  184. },
  185. radioChange: function(e) {
  186. this.setData({
  187. sex: e.detail.value,
  188. flagsex: 1
  189. })
  190. },
  191. /**
  192. * 生命周期函数--监听页面加载
  193. */
  194. onLoad: function(options) {
  195. let that = this;
  196. that.getLocation();
  197. if (options && options.activityId) {
  198. that.setData({
  199. activityId: options.activityId
  200. })
  201. that.getDetail(options.activityId);
  202. }
  203. },
  204. uploadImg() {
  205. let that = this;
  206. wx.chooseImage({
  207. success(res) {
  208. const tempFilePaths = res.tempFilePaths
  209. wx.uploadFile({
  210. url: config.url+config.api.imgUpload,
  211. filePath: tempFilePaths[0],
  212. name: 'file',
  213. header: {
  214. 'token': app.globalData.token
  215. },
  216. success(res) {
  217. console.log(res)
  218. if (res.statusCode == 200) {
  219. that.setData({
  220. receiptUrl: JSON.parse(res.data).data.url,
  221. showReceiptUrl: true
  222. })
  223. } else if (res.statusCode == 413) {
  224. wx.showToast({
  225. title: '上传的图片太大,请重新上传',
  226. icon: "none"
  227. })
  228. that.setData({
  229. showReceiptUrl: false
  230. })
  231. } else {
  232. wx.showToast({
  233. title: '请上传正确的图片',
  234. icon: "none"
  235. })
  236. that.setData({
  237. showReceiptUrl: false
  238. })
  239. }
  240. },
  241. fail(error) {
  242. wx.showToast({
  243. title: "上传图片失败",
  244. icon: "none"
  245. })
  246. that.setData({
  247. showReceiptUrl: false
  248. })
  249. }
  250. })
  251. }
  252. })
  253. },
  254. getDetail(activityId) {
  255. let that = this;
  256. Http.get({
  257. url: config.api.acfindById,
  258. data: {
  259. id: activityId
  260. }
  261. }).then(res => {
  262. if (res && res.data && res.data.activity) {
  263. this.setData({
  264. useImg: res.data.activity.useImg,
  265. imgDetail: res.data.activity.imgDetail
  266. })
  267. if (res.data && res.data.activity && res.data.activity.question) {
  268. that.setData({
  269. question: JSON.parse(res.data.activity.question)
  270. })
  271. }
  272. }
  273. }).catch(err => {
  274. wx.showToast({
  275. title: err.errMsg,
  276. icon: 'none',
  277. duration: 2000,
  278. mask: false
  279. })
  280. })
  281. },
  282. /**
  283. * 获得经纬度
  284. */
  285. getLocation() {
  286. let that = this;
  287. wx.getLocation({
  288. type: "wgs84",
  289. success: function (res) {
  290. console.log(res)
  291. if (res && res.longitude && res.latitude) {
  292. Http.post({
  293. url: config.api.updateLBS,
  294. data: {
  295. latitude: res.latitude,
  296. longitude: res.longitude
  297. }
  298. }).then(res => {
  299. console.log(res)
  300. })
  301. }
  302. },
  303. fail: error => {
  304. console.log(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. })