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.

358 line
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. wx.uploadFile({
  239. url: config.url+config.api.imgUpload,
  240. filePath: tempFilePaths[0],
  241. name: 'file',
  242. header: {
  243. 'token': app.globalData.token
  244. },
  245. success(res) {
  246. console.log(res)
  247. if (res.statusCode == 200) {
  248. that.setData({
  249. receiptUrl: JSON.parse(res.data).data.url,
  250. showReceiptUrl: true
  251. })
  252. } else if (res.statusCode == 413) {
  253. wx.showToast({
  254. title: '上传的图片太大,请重新上传',
  255. icon: "none"
  256. })
  257. that.setData({
  258. showReceiptUrl: false
  259. })
  260. } else {
  261. wx.showToast({
  262. title: '请上传正确的图片',
  263. icon: "none"
  264. })
  265. that.setData({
  266. showReceiptUrl: false
  267. })
  268. }
  269. },
  270. fail(error) {
  271. wx.showToast({
  272. title: "上传图片失败",
  273. icon: "none"
  274. })
  275. that.setData({
  276. showReceiptUrl: false
  277. })
  278. }
  279. })
  280. }
  281. })
  282. },
  283. getDetail(activityId) {
  284. let that = this;
  285. Http.get({
  286. url: config.api.acfindById,
  287. data: {
  288. id: activityId
  289. }
  290. }).then(res => {
  291. if (res && res.data && res.data.activity) {
  292. this.setData({
  293. useImg: res.data.activity.useImg,
  294. imgDetail: res.data.activity.imgDetail,
  295. selectques: JSON.parse(res.data.activity.selectques)
  296. })
  297. if (res.data && res.data.activity && res.data.activity.question) {
  298. that.setData({
  299. question: JSON.parse(res.data.activity.question)
  300. })
  301. }
  302. }
  303. }).catch(err => {
  304. wx.showToast({
  305. title: err.errMsg,
  306. icon: 'none',
  307. duration: 2000,
  308. mask: false
  309. })
  310. })
  311. },
  312. /**
  313. * 获得经纬度
  314. */
  315. getLocation() {
  316. let that = this;
  317. // wx.getLocation({
  318. // type: "wgs84",
  319. // success: function (res) {
  320. // console.log(res)
  321. // if (res && res.longitude && res.latitude) {
  322. // Http.post({
  323. // url: config.api.updateLBS,
  324. // data: {
  325. // latitude: res.latitude,
  326. // longitude: res.longitude
  327. // }
  328. // }).then(res => {
  329. // console.log(res)
  330. // })
  331. // }
  332. // },
  333. // fail: error => {
  334. // wx.showModal({
  335. // title: '提醒',
  336. // content: '您拒绝了地理位置的授权,将无法参加报名活动,请删除小程序重新登录,才可以继续参加该活动',
  337. // showCancel:false,
  338. // success:function(res){
  339. // if (res.confirm){
  340. // }
  341. // }
  342. // })
  343. // }
  344. // })
  345. },
  346. })