123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- // 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: "",
- 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]
- })
- },
- updata() {
- const {
- group_class,
- works_class,
- author,
- phone,
- schoolClass,
- teacher,
- teacherPhone,
- area,
- local_image_url,
- article,
- brief
- } = this.data;
- 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(teacherPhone) || isNaN(phone)) return wx.showToast({
- title: '手机号需填入数字',
- icon: "none"
- })
- console.log("group_class:", !group_class);
- console.log("works_class:", !works_class);
- console.log("author:", !author);
- console.log("schoolClass:", !schoolClass);
- console.log("area:", !area);
- console.log("local_image_url:", !local_image_url);
- console.log("article:", !article);
- console.log("brief:", !brief);
- if (!group_class || !works_class || !author || !schoolClass || !area || !local_image_url || !article || !brief) return wx.showToast({
- title: '请输入完整信息',
- icon: "none"
- })
- wx.showLoading({
- title: '加载中',
- })
- wx.uploadFile({
- filePath: local_image_url,
- name: 'file',
- header: {
- Authorization: wx.getStorageSync('token') || undefined,
- },
- formData: {
- name: author,
- teacherPhone,
- school: schoolClass,
- teacher,
- area: baseArea + area,
- articleGroup: works_class,
- birthday: group_class,
- articleName: article,
- articleDescribe: brief
- },
- url: base.apiurl + '/article/save',
- complete: () => {
- wx.hideLoading()
- },
- success: res => {
- if (res.code === 0) return wx.showToast({
- title: '上传成功',
- icon: "none"
- });
- else return wx.showToast({
- title: res.message || "上传失败",
- icon: "error"
- });
- },
- fail() {
- wx.showToast({
- title: res.message || "上传失败",
- icon: "error"
- });
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.getArea();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|