C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

212 wiersze
4.7 KiB

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