index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. onChange(e) {
  120. this.setData({
  121. group_class: e.detail
  122. })
  123. },
  124. onChangeWorks(e) {
  125. this.setData({
  126. works_class: e.detail
  127. })
  128. },
  129. updata() {
  130. const {
  131. group_class,
  132. works_class,
  133. author,
  134. phone,
  135. schoolClass,
  136. teacher,
  137. teacherPhone,
  138. area,
  139. local_image_url,
  140. article,
  141. brief
  142. } = this.data;
  143. const Authorization = wx.getStorageSync('token') || undefined;
  144. if (!Authorization) return wx.showToast({
  145. title: '请登录后在提交',
  146. icon: "none"
  147. })
  148. let baseArea = this.data.multiArray[0][this.data.multiIndex[0]] + this.data.multiArray[1][this.data.multiIndex[1]];
  149. if (this.data.multiArray[2] && this.data.multiArray[2][this.data.multiIndex[2]]) baseArea += this.data.multiArray[2][this.data.multiIndex[2]]
  150. if (isNaN(phone)) return wx.showToast({
  151. title: '手机号需填入数字',
  152. icon: "none"
  153. })
  154. if (!group_class || !works_class || !author || !schoolClass || !area || !local_image_url || !article || !brief) return wx.showToast({
  155. title: '请输入完整信息',
  156. icon: "none"
  157. })
  158. wx.showLoading({
  159. title: '加载中',
  160. mask: true
  161. })
  162. wx.uploadFile({
  163. filePath: local_image_url,
  164. name: 'file',
  165. header: {
  166. Authorization
  167. },
  168. formData: {
  169. name: author,
  170. teacherPhone,
  171. school: schoolClass,
  172. teacher,
  173. area: baseArea + area,
  174. articleGroup: works_class,
  175. birthday: group_class,
  176. articleName: article,
  177. articleDescribe: brief,
  178. phone
  179. },
  180. url: base.apiurl + '/article/save',
  181. fail: () => {
  182. wx.hideLoading()
  183. },
  184. success: res => {
  185. wx.hideLoading()
  186. if (res.statusCode !== 200) {
  187. const data = JSON.parse(res.data || "{}")
  188. wx.showToast({
  189. title: data.message || "保存失败",
  190. icon: "error"
  191. })
  192. return
  193. }
  194. wx.showToast({
  195. title: '报名成功',
  196. icon: "none"
  197. });
  198. },
  199. fail(err) {
  200. wx.showToast({
  201. title: err.message || "上传失败",
  202. icon: "error"
  203. });
  204. }
  205. })
  206. },
  207. /**
  208. * 生命周期函数--监听页面加载
  209. */
  210. onLoad(options) {
  211. if (!wx.getStorageSync('phone')) {
  212. const pages = getCurrentPages();
  213. const thisPage = pages[pages.length - 1];
  214. wx.reLaunch({
  215. url: "/pages/login/index?backurl=" + thisPage.route
  216. })
  217. return
  218. }
  219. this.getArea();
  220. },
  221. /**
  222. * 生命周期函数--监听页面初次渲染完成
  223. */
  224. onReady() {
  225. },
  226. /**
  227. * 生命周期函数--监听页面显示
  228. */
  229. onShow() {
  230. },
  231. /**
  232. * 生命周期函数--监听页面隐藏
  233. */
  234. onHide() {
  235. },
  236. /**
  237. * 生命周期函数--监听页面卸载
  238. */
  239. onUnload() {
  240. },
  241. /**
  242. * 页面相关事件处理函数--监听用户下拉动作
  243. */
  244. onPullDownRefresh() {
  245. },
  246. /**
  247. * 页面上拉触底事件的处理函数
  248. */
  249. onReachBottom() {
  250. },
  251. /**
  252. * 用户点击右上角分享
  253. */
  254. onShareAppMessage() {
  255. return {
  256. title: __wxConfig.accountInfo.nickname,
  257. path: "/pages/index/index"
  258. }
  259. }
  260. })