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

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