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.

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