123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- // pages/forBack/forBack.js
- const app = getApp()
- const util = require("../../utils/util")
- const urlDef = require("../../utils/urls")
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- radioList: [
- { name: '学校不满意', type: 'school', value: '8df20e39d0e94a95bc35f020cc2e4b84' },
- { name: '课程不满意', type: 'school', value: '00901101530549789799899a113d46e8' },
- { name: '产品建议/功能优化', type: 'select', value: '325ef70d708a46d094ef3eaefebaf254' },
- { name: '其他问题', type: 'select', value: 'f9b1ecb1bd1943739082552dc68af535' },
- ],
- curRadioIndex: '-1',
- plateList: [],
- plateIndex: 0,
- radioType: '',
- curStu: null,
- content: '',
- imgList: []
- },
- getRadio:function(e){
- const type = this.data.radioList[e.currentTarget.dataset.index].type
- this.setData({
- curRadioIndex: e.currentTarget.dataset.index,
- radioType: type
- })
- },
- bindPickerChange: function(e) {
- this.setData({
- plateIndex: e.detail.value
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- let stu = wx.getStorageSync('student');
- this.setData({ curStu: stu })
- let urls = urlDef.urls;
- util.apiPost(urls.get_suggest_moudles).then((rs) => {
- let list = []
- rs.forEach(v => {
- list.push({ id: v.id, name: v.detailName })
- });
- this.setData({ plateList: list })
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- doInput: function (e) {
- this.setData({ content: e.detail.value })
- },
- len(s) {
- return (s == null ? 0 : s.length);
- },
- doSave: function () {
- let urls = urlDef.urls
- if (this.len(this.data.content) === 0) {
- wx.showToast({ title: '请输入建议或投诉内容', icon: 'none' });
- return;
- }
- let t = this.data.radioList[this.data.curRadioIndex]
- let typeId = t ? t.value : '';
- let moduleId = this.data.plateList[this.data.plateIndex].id
- if ((typeId !== '8df20e39d0e94a95bc35f020cc2e4b84' && typeId !== '00901101530549789799899a113d46e8')
- && (this.len(moduleId) === 0)) {
- wx.showToast({ title: '请选择模块', icon: 'none' });
- return;
- }
- let entity = {}
- entity.studentId = this.data.curStu.studentId
- entity.submitDate = new Date();
- entity.status = 1;
- entity.orgId = this.data.curStu.orgId
- entity.remarks = this.data.content
- entity.telephone = wx.getStorageSync('phone')
- entity.typeId = typeId
- entity.moduleId = moduleId
- util.apiPost(urls.suggest_save, entity, 'application/json').then((rs) => {
- wx.showToast({ title: '提交成功', icon: 'success' });
- entity.id = rs.id;
- const body = { 'id': rs.id, 'orgId': this.data.curStu.orgId, 'studentId': this.data.curStu.studentId }
- util.apiPost(urls.suggest_send_message, body, 'application/json').then((rs) => {
- console.log('发送通知 ' + JSON.stringify(rs));
- });
- // 保存图片
- let imgs = [];
- let delList = []
- this.data.imgList.forEach(r => {
- if (r.delete && r.delete == 1) {
- delList.push(r.url.substring(r.url.lastIndexOf('/') + 1))
- } else {
- imgs.push({ feedbackId: rs.id, feedbackImageUrl: r.url })
- }
- });
- // 删除文件
- if (delList.length > 0) {
- const params = { 'keys': delList }
- util.apiPost(urls.file_delete, params).then((rs) => {
- console.log('删除文件 ... ');
- });
- }
- if (imgs.length > 0) {
- console.log('保存关联图片 ... ');
- util.apiPost(urls.suggest_image_save, imgs, 'application/json').then((rs) => {
- })
- }
- setTimeout(() => {
- wx.navigateBack({
- delta: 1, // 返回上一级页面。
- success: function () {
- console.log('成功!')
- }
- })
- }, 1000)
- })
- },
- uploadTap: function () {
- const that = this
- const urls = urlDef.urls;
- wx.chooseImage({
- count: 6,
- sourceType: ['album', 'camera'],
- success(res) {
- wx.showLoading({
- title: '上传中...',
- })
- for (var i in res.tempFilePaths) {
- wx.uploadFile({
- filePath: res.tempFilePaths[i],
- name: 'name',
- url: urls.file_upload,
- header: util.getHeaders(),
- success(res) {
- wx.showToast({
- title: '上传成功',
- })
- const rs = JSON.parse(JSON.parse(JSON.stringify(res.data)))
- const list = [{ url: rs.data[0].url }]
- that.setData({
- imgList: that.data.imgList.concat(list)
- })
- },
- fail(res) {
- wx.showToast({
- title: '上传失败',
- icon: none
- })
- },
- complete(res) {
- wx.hideLoading({
- success: (res) => { },
- })
- }
- })
- }
- }
- })
- },
- showImg: function (e) {
- const index = e.currentTarget.dataset.index
- let images = this.data.imgList;
- let imgs = []
- images.map(i => {
- imgs.push(i.url)
- })
- wx.previewImage({
- current: images[index].url,
- urls: imgs,
- })
- },
- delImg: function (e) {
- const index = e.currentTarget.dataset.index
- let images = this.data.imgList;
- let image = images[index]
- image.delete = 1
- this.setData({
- imgList: images
- })
- },
- })
|