C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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