index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. let baseArea = this.data.multiArray[0][this.data.multiIndex[0]] + this.data.multiArray[1][this.data.multiIndex[1]];
  134. if (this.data.multiArray[2] && this.data.multiArray[2][this.data.multiIndex[2]]) baseArea += this.data.multiArray[2][this.data.multiIndex[2]]
  135. if (isNaN(phone)) return wx.showToast({
  136. title: '手机号需填入数字',
  137. icon: "none"
  138. })
  139. if (!group_class || !works_class || !author || !schoolClass || !area || !local_image_url || !article || !brief) return wx.showToast({
  140. title: '请输入完整信息',
  141. icon: "none"
  142. })
  143. wx.showLoading({
  144. title: '加载中',
  145. })
  146. wx.uploadFile({
  147. filePath: local_image_url,
  148. name: 'file',
  149. header: {
  150. Authorization: wx.getStorageSync('token') || undefined,
  151. },
  152. formData: {
  153. name: author,
  154. teacherPhone,
  155. school: schoolClass,
  156. teacher,
  157. area: baseArea + area,
  158. articleGroup: works_class,
  159. birthday: group_class,
  160. articleName: article,
  161. articleDescribe: brief,
  162. phone
  163. },
  164. url: base.apiurl + '/article/save',
  165. complete: () => {
  166. wx.hideLoading()
  167. },
  168. success: res => {
  169. if(res.statusCode !== 200) {
  170. const data = JSON.parse(res.data || "{}")
  171. wx.showToast({
  172. title: data.message || "保存失败",
  173. icon: "error"
  174. })
  175. return
  176. }
  177. wx.showToast({
  178. title: '报名成功',
  179. icon: "none"
  180. });
  181. },
  182. fail(err) {
  183. wx.showToast({
  184. title: err.message || "上传失败",
  185. icon: "error"
  186. });
  187. }
  188. })
  189. },
  190. /**
  191. * 生命周期函数--监听页面加载
  192. */
  193. onLoad(options) {
  194. this.getArea();
  195. },
  196. /**
  197. * 生命周期函数--监听页面初次渲染完成
  198. */
  199. onReady() {
  200. },
  201. /**
  202. * 生命周期函数--监听页面显示
  203. */
  204. onShow() {
  205. },
  206. /**
  207. * 生命周期函数--监听页面隐藏
  208. */
  209. onHide() {
  210. },
  211. /**
  212. * 生命周期函数--监听页面卸载
  213. */
  214. onUnload() {
  215. },
  216. /**
  217. * 页面相关事件处理函数--监听用户下拉动作
  218. */
  219. onPullDownRefresh() {
  220. },
  221. /**
  222. * 页面上拉触底事件的处理函数
  223. */
  224. onReachBottom() {
  225. },
  226. /**
  227. * 用户点击右上角分享
  228. */
  229. onShareAppMessage() {
  230. }
  231. })