|
@@ -0,0 +1,281 @@
|
|
|
+// 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: ""
|
|
|
+ },
|
|
|
+ id: undefined,
|
|
|
+ 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(call) {
|
|
|
+ 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 || [];
|
|
|
+ call && call();
|
|
|
+ }).catch(() => {
|
|
|
+ call && call();
|
|
|
+ })
|
|
|
+ },
|
|
|
+ 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(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: '加载中',
|
|
|
+ })
|
|
|
+ wx.getImageInfo({
|
|
|
+ src: local_image_url
|
|
|
+ }).then((res) => {
|
|
|
+ wx.uploadFile({
|
|
|
+ filePath: res.path,
|
|
|
+ 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,
|
|
|
+ phone,
|
|
|
+ id: this.id
|
|
|
+ },
|
|
|
+ url: base.apiurl + '/article/save',
|
|
|
+ complete: () => {
|
|
|
+ wx.hideLoading()
|
|
|
+ },
|
|
|
+ success: res => {
|
|
|
+ if (res.statusCode !== 200) {
|
|
|
+ const data = JSON.parse(res.data || "{}")
|
|
|
+ wx.showToast({
|
|
|
+ title: data.message || "保存失败",
|
|
|
+ icon: "error"
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ wx.navigateBack()
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ wx.showToast({
|
|
|
+ title: err.message || "上传失败",
|
|
|
+ icon: "error"
|
|
|
+ });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ getIndex(text, indexs, arr) {
|
|
|
+ let add = "";
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
+ const rex = new RegExp(arr[i].name);
|
|
|
+ if (rex.test(text)) {
|
|
|
+ indexs.push({
|
|
|
+ index: i,
|
|
|
+ name: arr[i].name,
|
|
|
+ areaList: arr.map(item => item.name)
|
|
|
+ });
|
|
|
+ add = text.replace(arr[i].name, "")
|
|
|
+ if (arr[i].child) return this.getIndex(add, indexs, arr[i].child);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ indexs,
|
|
|
+ add
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onLoad(options) {
|
|
|
+ this.getArea(() => {
|
|
|
+ const obj = JSON.parse(decodeURIComponent(options.data));
|
|
|
+ this.id = obj.id;
|
|
|
+ const index = this.getIndex(obj.area, [], this.area);
|
|
|
+ const multiIndex = index.indexs.map(v => v.index);
|
|
|
+ this.setData({
|
|
|
+ local_image_url: obj.articleUrl || '',
|
|
|
+ group_class: obj.birthday || '',
|
|
|
+ works_class: obj.articleGroup || '',
|
|
|
+ author: obj.name || "",
|
|
|
+ phone: obj.phone || "",
|
|
|
+ schoolClass: obj.school || "",
|
|
|
+ teacher: obj.teacher || "",
|
|
|
+ teacherPhone: obj.teacherPhone || "",
|
|
|
+ article: obj.articleName || "",
|
|
|
+ brief: obj.articleDescribe || "",
|
|
|
+ multiIndex,
|
|
|
+ area: index.add || "",
|
|
|
+ multiArray: index.indexs.map(v => v.areaList)
|
|
|
+ })
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ onReachBottom() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage() {
|
|
|
+ return {
|
|
|
+ title: __wxConfig.accountInfo.nickname,
|
|
|
+ path: "/pages/index/index"
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|