C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

211 řádky
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. /**
  77. * sex
  78. * 0 保密
  79. * 1 男
  80. * 2 女
  81. */
  82. if (that.data.flagsex == 0) {
  83. var sex = 0;
  84. } else {
  85. var sex = that.data.sex;
  86. }
  87. if (that.data.addressStr) {
  88. var address = that.data.addressStr;
  89. } else {
  90. var address = null;
  91. }
  92. if (e.detail.value.username) {
  93. var username = e.detail.value.username;
  94. } else if (that.data.username) {
  95. var username = that.data.username;
  96. } else {
  97. var username = null;
  98. }
  99. if (that.data.flag == 2 && that.data.date) {
  100. var birthday = new Date(that.data.date).getTime();
  101. } else {
  102. var birthday = null;
  103. }
  104. //获得答案
  105. delete e.detail.value.username;
  106. let obj = e.detail.value;
  107. if (that.data&&that.data.question&&that.data.question.length>0){
  108. let valArr22;
  109. valArr22 = Object.keys(obj).map(function (item,index) {
  110. if (!obj[item]){
  111. wx.showToast({
  112. title: '问卷调查回答不完整,请补充',
  113. duration:2000,
  114. icon:"none"
  115. })
  116. that.setData({
  117. answerflag:"noanswer"
  118. })
  119. }else{
  120. that.setData({
  121. answerflag: "answer"
  122. })
  123. return { ques: that.data.question[index].ques, answer: obj[item] }
  124. }
  125. });
  126. this.setData({
  127. answer:valArr22
  128. });
  129. }
  130. if (username == null || address == null || sex == 0 || birthday == null) {
  131. wx.showToast({
  132. title: '请输入完整的用户信息',
  133. icon: "none"
  134. })
  135. } else {
  136. console.log(that.data.answer)
  137. if (this.data.answerflag == 'noanswer'){
  138. }else{
  139. Http.post({
  140. url: config.api.activityJoin,
  141. data: {
  142. sex: sex,
  143. address: address,
  144. name: username,
  145. birthday: birthday,
  146. answer: JSON.stringify(that.data.answer),
  147. activityId: that.data.activityId
  148. }
  149. })
  150. .then(res => {
  151. wx.redirectTo({
  152. url: '/pages/radetail/success/index',
  153. })
  154. })
  155. .catch(err => {
  156. wx.showToast({
  157. title: err.message,
  158. icon: 'none',
  159. duration: 2000,
  160. mask: false
  161. })
  162. })
  163. }
  164. }
  165. },
  166. radioChange: function(e) {
  167. this.setData({
  168. sex: e.detail.value,
  169. flagsex: 1
  170. })
  171. },
  172. /**
  173. * 生命周期函数--监听页面加载
  174. */
  175. onLoad: function(options) {
  176. let that = this;
  177. if (options && options.activityId) {
  178. that.setData({
  179. activityId: options.activityId
  180. })
  181. that.getDetail(options.activityId);
  182. }
  183. },
  184. getDetail(activityId) {
  185. let that = this;
  186. Http.get({
  187. url: config.api.acfindById,
  188. data: {
  189. id: activityId
  190. }
  191. }).then(res => {
  192. if (res && res.data && res.data.activity) {
  193. if (res.data && res.data.activity && res.data.activity.question) {
  194. that.setData({
  195. question: JSON.parse(res.data.activity.question)
  196. })
  197. }
  198. }
  199. }).catch(err => {
  200. wx.showToast({
  201. title: err.errMsg,
  202. icon: 'none',
  203. duration: 2000,
  204. mask: false
  205. })
  206. })
  207. }
  208. })