index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // pages/application/index.js
  2. import {
  3. ajax,
  4. ele_height
  5. } from "../../utils/util";
  6. import {
  7. base
  8. } from "../../config/index"
  9. const {
  10. globalData: {
  11. systemInfo
  12. }
  13. } = getApp();
  14. Page({
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. multiIndex: [0, 0, 0],
  20. multiArray: [],
  21. uploadheight: 0,
  22. local_image_url: '',
  23. group_class: '幼儿组',
  24. works_class: '中国画',
  25. author: "",
  26. phone: wx.getStorageSync('phone') || "",
  27. schoolClass: "",
  28. teacher: "",
  29. teacherPhone: "",
  30. area: "",
  31. article: "",
  32. brief: ""
  33. },
  34. area: [],
  35. changeSelectArea: [0, 0, 0],
  36. change(e) {
  37. const key = e.target.dataset.key || '';
  38. const value = e.detail.value;
  39. const p = {};
  40. p[key] = value;
  41. this.setData(p);
  42. },
  43. bindMultiPickerChange: function (e) {
  44. this.setData({
  45. multiIndex: e.detail.value
  46. })
  47. },
  48. uploadimg(e) {
  49. this.setData({
  50. uploadheight: ele_height(e, systemInfo.screenWidth * 0.8)
  51. })
  52. },
  53. upload() {
  54. wx.chooseMedia({
  55. count: 1,
  56. mediaType: ['image'],
  57. success: e => {
  58. this.setData({
  59. local_image_url: e.tempFiles[0].tempFilePath
  60. })
  61. },
  62. })
  63. },
  64. delimg() {
  65. wx.showModal({
  66. title: "确定删除该图片?",
  67. content: "删除后需重新选择图片",
  68. success: (res) => {
  69. if (res.confirm) {
  70. this.setData({
  71. local_image_url: ''
  72. })
  73. }
  74. }
  75. })
  76. },
  77. bindMultiPickerColumnChange(e) {
  78. const {
  79. detail: {
  80. column,
  81. value
  82. }
  83. } = e;
  84. this.changeSelectArea[column] = value;
  85. const a0 = this.area[this.changeSelectArea[0]] || {
  86. child: []
  87. }
  88. const multiArray1 = a0.child.map(v => v.name);
  89. let multiArray2 = ((a0.child[this.changeSelectArea[1]] || {
  90. child: []
  91. }).child || []).map(v => v.name);
  92. this.setData({
  93. multiArray: [this.data.multiArray[0], multiArray1, multiArray2]
  94. })
  95. },
  96. getArea() {
  97. ajax({
  98. urlType: "fileurl",
  99. api: "/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/narea.json?data=" +
  100. Date.now()
  101. }).then(res => {
  102. this.area = res || [];
  103. this.initArea();
  104. })
  105. },
  106. initArea() {
  107. const a0 = this.area[0] || {
  108. child: []
  109. }
  110. const multiArray0 = this.area.map(v => v.name);
  111. const multiArray1 = a0.child.map(v => v.name);
  112. const multiArray2 = (a0.child[0] || {
  113. child: []
  114. }).child.map(v => v.name);
  115. this.setData({
  116. multiArray: [multiArray0, multiArray1, multiArray2]
  117. })
  118. },
  119. updata() {
  120. const {
  121. group_class,
  122. works_class,
  123. author,
  124. phone,
  125. schoolClass,
  126. teacher,
  127. teacherPhone,
  128. area,
  129. local_image_url,
  130. article,
  131. brief
  132. } = this.data;
  133. const Authorization = wx.getStorageSync('token') || undefined;
  134. if (Authorization) return wx.showToast({
  135. title: '请登录后在提交',
  136. icon: "none"
  137. })
  138. let baseArea = this.data.multiArray[0][this.data.multiIndex[0]] + this.data.multiArray[1][this.data.multiIndex[1]];
  139. if (this.data.multiArray[2] && this.data.multiArray[2][this.data.multiIndex[2]]) baseArea += this.data.multiArray[2][this.data.multiIndex[2]]
  140. if (isNaN(phone)) return wx.showToast({
  141. title: '手机号需填入数字',
  142. icon: "none"
  143. })
  144. if (!group_class || !works_class || !author || !schoolClass || !area || !local_image_url || !article || !brief) return wx.showToast({
  145. title: '请输入完整信息',
  146. icon: "none"
  147. })
  148. wx.showLoading({
  149. title: '加载中',
  150. })
  151. wx.uploadFile({
  152. filePath: local_image_url,
  153. name: 'file',
  154. header: {
  155. Authorization
  156. },
  157. formData: {
  158. name: author,
  159. teacherPhone,
  160. school: schoolClass,
  161. teacher,
  162. area: baseArea + area,
  163. articleGroup: works_class,
  164. birthday: group_class,
  165. articleName: article,
  166. articleDescribe: brief,
  167. phone
  168. },
  169. url: base.apiurl + '/article/save',
  170. complete: () => {
  171. wx.hideLoading()
  172. },
  173. success: res => {
  174. if (res.statusCode !== 200) {
  175. const data = JSON.parse(res.data || "{}")
  176. wx.showToast({
  177. title: data.message || "保存失败",
  178. icon: "error"
  179. })
  180. return
  181. }
  182. wx.showToast({
  183. title: '报名成功',
  184. icon: "none"
  185. });
  186. },
  187. fail(err) {
  188. wx.showToast({
  189. title: err.message || "上传失败",
  190. icon: "error"
  191. });
  192. }
  193. })
  194. },
  195. /**
  196. * 生命周期函数--监听页面加载
  197. */
  198. onLoad(options) {
  199. if (!wx.getStorageSync('phone')) {
  200. const pages = getCurrentPages();
  201. const thisPage = pages[pages.length - 1];
  202. wx.reLaunch({
  203. url: "/pages/login/index?backurl=" + thisPage.route
  204. })
  205. return
  206. }
  207. this.getArea();
  208. },
  209. /**
  210. * 生命周期函数--监听页面初次渲染完成
  211. */
  212. onReady() {
  213. },
  214. /**
  215. * 生命周期函数--监听页面显示
  216. */
  217. onShow() {
  218. },
  219. /**
  220. * 生命周期函数--监听页面隐藏
  221. */
  222. onHide() {
  223. },
  224. /**
  225. * 生命周期函数--监听页面卸载
  226. */
  227. onUnload() {
  228. },
  229. /**
  230. * 页面相关事件处理函数--监听用户下拉动作
  231. */
  232. onPullDownRefresh() {
  233. },
  234. /**
  235. * 页面上拉触底事件的处理函数
  236. */
  237. onReachBottom() {
  238. },
  239. /**
  240. * 用户点击右上角分享
  241. */
  242. onShareAppMessage() {
  243. return {
  244. title: __wxConfig.accountInfo.nickname,
  245. path: "/pages/index/index"
  246. }
  247. }
  248. })