123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- // pages/application/index.js
- import {
- ajax,
- ele_height
- } from "../../utils/util";
- import {
- base
- } from "../../config/index"
- const {
- globalData: {
- systemInfo
- }
- } = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- multiIndex: [0, 0, 0],
- multiArray: [],
- uploadheight: 0,
- local_image_url: '',
- group_class: '幼儿组',
- works_class: '中国画',
- author: "",
- phone: wx.getStorageSync('phone') || "",
- schoolClass: "",
- teacher: "",
- teacherPhone: "",
- area: "",
- article: "",
- brief: ""
- },
- area: [],
- changeSelectArea: [0, 0, 0],
- change(e) {
- const key = e.target.dataset.key || '';
- const value = e.detail.value;
- const p = {};
- p[key] = value;
- this.setData(p);
- },
- bindMultiPickerChange: function (e) {
- this.setData({
- multiIndex: e.detail.value
- })
- },
- uploadimg(e) {
- this.setData({
- uploadheight: ele_height(e, systemInfo.screenWidth * 0.8)
- })
- },
- upload() {
- wx.chooseMedia({
- count: 1,
- mediaType: ['image'],
- success: e => {
- this.setData({
- local_image_url: e.tempFiles[0].tempFilePath
- })
- },
- })
- },
- delimg() {
- wx.showModal({
- title: "确定删除该图片?",
- content: "删除后需重新选择图片",
- success: (res) => {
- if (res.confirm) {
- this.setData({
- local_image_url: ''
- })
- }
- }
- })
- },
- bindMultiPickerColumnChange(e) {
- const {
- detail: {
- column,
- value
- }
- } = e;
- this.changeSelectArea[column] = value;
- const a0 = this.area[this.changeSelectArea[0]] || {
- child: []
- }
- const multiArray1 = a0.child.map(v => v.name);
- let multiArray2 = ((a0.child[this.changeSelectArea[1]] || {
- child: []
- }).child || []).map(v => v.name);
- this.setData({
- multiArray: [this.data.multiArray[0], multiArray1, multiArray2]
- })
- },
- getArea() {
- ajax({
- urlType: "fileurl",
- 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=" +
- Date.now()
- }).then(res => {
- this.area = res || [];
- this.initArea();
- })
- },
- initArea() {
- const a0 = this.area[0] || {
- child: []
- }
- const multiArray0 = this.area.map(v => v.name);
- const multiArray1 = a0.child.map(v => v.name);
- const multiArray2 = (a0.child[0] || {
- child: []
- }).child.map(v => v.name);
- this.setData({
- multiArray: [multiArray0, multiArray1, multiArray2]
- })
- },
- onChange(e) {
- this.setData({
- group_class: e.detail
- })
- },
- onChangeWorks(e) {
- this.setData({
- works_class: e.detail
- })
- },
- updata() {
- const {
- group_class,
- works_class,
- author,
- phone,
- schoolClass,
- teacher,
- teacherPhone,
- area,
- local_image_url,
- article,
- brief
- } = this.data;
- const Authorization = wx.getStorageSync('token') || undefined;
- if (!Authorization) return wx.showToast({
- title: '请登录后在提交',
- icon: "none"
- })
- let baseArea = this.data.multiArray[0][this.data.multiIndex[0]] + this.data.multiArray[1][this.data.multiIndex[1]];
- if (this.data.multiArray[2] && this.data.multiArray[2][this.data.multiIndex[2]]) baseArea += this.data.multiArray[2][this.data.multiIndex[2]]
- if (isNaN(phone)) return wx.showToast({
- title: '手机号需填入数字',
- icon: "none"
- })
- if (!group_class || !works_class || !author || !schoolClass || !area || !local_image_url || !article || !brief) return wx.showToast({
- title: '请输入完整信息',
- icon: "none"
- })
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- wx.uploadFile({
- filePath: local_image_url,
- name: 'file',
- header: {
- Authorization
- },
- formData: {
- name: author,
- teacherPhone,
- school: schoolClass,
- teacher,
- area: baseArea + area,
- articleGroup: works_class,
- birthday: group_class,
- articleName: article,
- articleDescribe: brief,
- phone
- },
- url: base.apiurl + '/article/save',
- fail: () => {
- wx.hideLoading()
- },
- success: res => {
- wx.hideLoading()
- if (res.statusCode !== 200) {
- const data = JSON.parse(res.data || "{}")
- wx.showToast({
- title: data.message || "保存失败",
- icon: "error"
- })
- return
- }
- wx.showToast({
- title: '报名成功',
- icon: "none"
- });
- },
- fail(err) {
- wx.showToast({
- title: err.message || "上传失败",
- icon: "error"
- });
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- if (!wx.getStorageSync('phone')) {
- const pages = getCurrentPages();
- const thisPage = pages[pages.length - 1];
- wx.reLaunch({
- url: "/pages/login/index?backurl=" + thisPage.route
- })
- return
- }
- this.getArea();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- return {
- title: __wxConfig.accountInfo.nickname,
- path: "/pages/index/index"
- }
- }
- })
|