C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

240 satır
5.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. items: [{
  16. name: 1,
  17. value: '男',
  18. checked: false
  19. },
  20. {
  21. name: 2,
  22. value: '女',
  23. checked: false
  24. },
  25. ],
  26. username: "",
  27. array: ['上班族', '学生', '企业高管', '个体户', '自由职业', '其他'],
  28. array1: ['附近住户', '距离2km', '距离3km', '更远'],
  29. index: 0,
  30. index1: 0,
  31. showPage: false
  32. },
  33. /**
  34. * 获得生日
  35. */
  36. bindDateChange: function(e) {
  37. this.setData({
  38. date: e.detail.value,
  39. flag: 2
  40. })
  41. },
  42. /**
  43. * 职业
  44. */
  45. bindPickerChange: function(e) {
  46. this.setData({
  47. index: e.detail.value
  48. })
  49. },
  50. /**
  51. * 生活半径
  52. */
  53. bindPickerChange1: function(e) {
  54. this.setData({
  55. index1: e.detail.value
  56. })
  57. },
  58. address: function() {
  59. let that = this;
  60. wx.chooseLocation({
  61. success: function(res) {
  62. that.setData({
  63. address: res.name + '(' + res.address + ')',
  64. addressStr: JSON.stringify(res)
  65. })
  66. },
  67. fail: function(error) {
  68. console.log(error)
  69. },
  70. complete: function(data) {}
  71. })
  72. },
  73. change(value){
  74. console.log(value)
  75. },
  76. formSubmit: function(e) {
  77. let that = this;
  78. /**
  79. * sex
  80. * 0 保密
  81. * 1 男
  82. * 2 女
  83. */
  84. if (that.data.flagsex == 0) {
  85. var sex = 0;
  86. } else {
  87. var sex = that.data.sex;
  88. }
  89. if (that.data.addressStr) {
  90. var address = that.data.addressStr;
  91. } else {
  92. var address = null;
  93. }
  94. if (e.detail.value.username) {
  95. var username = e.detail.value.username;
  96. } else if (that.data.username) {
  97. var username = that.data.username;
  98. } else {
  99. var username = null;
  100. }
  101. if (that.data.flag == 2 && that.data.date) {
  102. var birthday = new Date(that.data.date).getTime();
  103. } else {
  104. var birthday = null;
  105. }
  106. //获得答案
  107. delete e.detail.value.username;
  108. let obj = e.detail.value;
  109. if (that.data&&that.data.question&&that.data.question.length>0){
  110. let valArr22;
  111. valArr22 = Object.keys(obj).map(function (item,index) {
  112. if (!obj[item]){
  113. wx.showToast({
  114. title: '问卷调查回答不完整,请补充',
  115. duration:2000,
  116. icon:"none"
  117. })
  118. that.setData({
  119. answerflag:"noanswer"
  120. })
  121. }else{
  122. that.setData({
  123. answerflag: "answer"
  124. })
  125. return { ques: that.data.question[index].ques, answer: obj[item] }
  126. }
  127. });
  128. this.setData({
  129. answer:valArr22
  130. });
  131. }
  132. if (username == null || address == null || sex == 0 || birthday == null) {
  133. wx.showToast({
  134. title: '请输入完整的用户信息',
  135. icon: "none"
  136. })
  137. } else {
  138. console.log(that.data.answer)
  139. if (this.data.answerflag == 'noanswer'){
  140. }else{
  141. Http.post({
  142. url: config.api.activityJoin,
  143. data: {
  144. sex: sex,
  145. address: address,
  146. name: username,
  147. birthday: birthday,
  148. answer: JSON.stringify(that.data.answer),
  149. activityId: that.data.activityId
  150. }
  151. })
  152. .then(res => {
  153. wx.redirectTo({
  154. url: `/pages/radetail/success/index?activityId=${that.data.activityId}`,
  155. })
  156. })
  157. .catch(err => {
  158. wx.showToast({
  159. title: err.message,
  160. icon: 'none',
  161. duration: 2000,
  162. mask: false
  163. })
  164. })
  165. }
  166. }
  167. },
  168. radioChange: function(e) {
  169. this.setData({
  170. sex: e.detail.value,
  171. flagsex: 1
  172. })
  173. },
  174. /**
  175. * 生命周期函数--监听页面加载
  176. */
  177. onLoad: function(options) {
  178. let that = this;
  179. if (options && options.activityId) {
  180. that.setData({
  181. activityId: options.activityId
  182. })
  183. that.getDetail(options.activityId);
  184. }
  185. },
  186. uploadImg() {
  187. let that = this;
  188. wx.chooseImage({
  189. success(res) {
  190. const tempFilePaths = res.tempFilePaths
  191. console.log(config.api.imgUpload)
  192. console.log(res)
  193. wx.uploadFile({
  194. url: config.api.imgUpload, // 仅为示例,非真实的接口地址
  195. filePath: tempFilePaths[0],
  196. name: 'file',
  197. header: {
  198. 'token': app.globalData.token
  199. },
  200. success(res) {
  201. const data = res.data
  202. that.setData({
  203. receiptUrl: JSON.parse(res.data).data.url
  204. })
  205. }
  206. })
  207. }
  208. })
  209. },
  210. getDetail(activityId) {
  211. let that = this;
  212. Http.get({
  213. url: config.api.acfindById,
  214. data: {
  215. id: activityId
  216. }
  217. }).then(res => {
  218. if (res && res.data && res.data.activity) {
  219. this.setData({
  220. useImg: res.data.activity.useImg
  221. })
  222. if (res.data && res.data.activity && res.data.activity.question) {
  223. that.setData({
  224. question: JSON.parse(res.data.activity.question)
  225. })
  226. }
  227. }
  228. }).catch(err => {
  229. wx.showToast({
  230. title: err.errMsg,
  231. icon: 'none',
  232. duration: 2000,
  233. mask: false
  234. })
  235. })
  236. }
  237. })