123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- const app = getApp();
- const url = require('../../utils/const.js');
- const APIClient = require('../../utils/APIClient.js');
- const login = require('../../utils/loginSchedule.js');
- const utils = require('../../utils/util.js');
- const HOST = url.apiUrl;
- Page({
-
- data: {
- tempFilePath: [],
- imgId: [],
- textValue: '',
- upload: true
-
-
- },
-
- bindKeyInput: function(e) {
- this.setData({
- textValue: e.detail.value
- })
- },
-
- uploading: function () {
- const that = this;
- const length = that.data.tempFilePath.length;
- if(length < 2) {
- wx.chooseImage({
- count: 2,
- sizeType: ['compressed'],
- sourceType: ['album', 'camera'],
- success: function (res) {
-
- var tempFilePaths = res.tempFilePaths;
-
- wx.showToast({
- title: '正在上传...',
- icon: 'loading',
- mask: true,
- duration: 1000
- })
- for(let item of tempFilePaths){
- that.data.tempFilePath.push(item);
- }
- that.setData({
- tempFilePath: that.data.tempFilePath
- })
- var uploadImgCount = 0;
- for (var i = 0, h = tempFilePaths.length; i < h; i++) {
-
- wx.uploadFile({
- url: HOST + '/cms/file/upload',
- filePath: tempFilePaths[i],
- name: 'uploadfile_ant',
- header: {
- "Content-Type": "multipart/form-data"
- },
- success: function (res) {
- uploadImgCount++;
- let data = JSON.parse(res.data);
- that.data.imgId.push(data.data)
- that.setData({
- imgId: that.data.imgId,
- })
- console.log(data)
-
- if (uploadImgCount == tempFilePaths.length) {
- wx.hideToast();
- }
- },
- fail: function (res) {
- wx.hideToast();
- wx.showModal({
- title: '错误提示',
- content: '上传图片失败',
- showCancel: false,
- success: function (res) { }
- })
- }
- });
- }
- }
- });
- }else {
- this.setData({
- upload: false
- })
- }
- },
-
- send: function() {
- const type = utils.getUrl().type;
- const columnType = utils.getUrl().columnType;
- const columnId = utils.column(columnType).columnId;
- const columnName = utils.column(columnType).columnName;
- if(this.data.imgId.length == 0 && type == 2){
- wx.showModal({
- title: '提示',
- content: '请上传分享的作品',
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- return false;
- }
- let data = {
- "title": this.data.textValue,
- "type": type,
- "category": columnId
- };
- if(type == 2){
- data.imagesStrList = this.data.imgId
- }
- login.getOpenidSessionKey(function(res) {
-
- APIClient.getSendSchedule({
- uid: res.data.data.uid
- }, data).success(res => {
- console.log(res)
- if(res.data.success) {
- wx.redirectTo({
- url: utils.url(columnType)
- })
- }
- })
- }, function() {
- wx.showModal({
- title: '提示',
- content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- console.log('用户点击确定')
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- });
-
- },
- cancel: function() {
- wx.navigateBack({ changed: true });
- },
-
- listenerButtonPreviewImage: function(e) {
- let index = e.target.dataset.index;
- let that = this;
- wx.previewImage({
- current: that.data.tempFilePath[index],
- urls: that.data.tempFilePath,
-
- success: function(res) {
-
- },
-
- fail: function() {
-
- }
- })
- },
-
- onLoad: function (options) {
- if(options.type == 2) {
- wx.setNavigationBarTitle({
- title: '作品展示'
- })
- }
- if(options.type == 1) {
- wx.setNavigationBarTitle({
- title: '答疑讨论'
- })
- }
- this.setData({
- type: options.type
- })
-
- },
-
- onReady: function () {
-
- },
-
- onShow: function () {
-
- },
-
- onHide: function () {
-
- },
-
- onUnload: function () {
-
- },
-
- onPullDownRefresh: function () {
-
- },
-
- onReachBottom: function () {
-
- },
-
- onShareAppMessage: function () {
-
- }
- })
|