| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- // pages/deviceCheck/report/edit/checkReportEdit.js
- var app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- placeholder: '请录入处理意见',
- processSuggest: '',
- photos: [],
- checkId: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- var checkId = options.checkId;
- const img = "/images/add.png";
- var tmpphoto = this.data.photos;
- var tp = {};
- tp['path'] = img;
- tp['type'] = 0;
- tp['fileName'] = '';
- tmpphoto.push(tp);
- this.setData({
- photos: tmpphoto,
- checkId: checkId
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- toReportHandle: function (e) {
- if (this.data.processSuggest.length > 0) {
- var that = this;
- try {
- wx.showModal({
- title: '提示',
- content: '确定提交巡检处理意见?',
- success: function (res) {
- if (res.confirm) {
- wx.showNavigationBarLoading()
- var data = {};
- data['checkId'] = that.data.checkId;
- var openid = wx.getStorageSync('openid')
- if (openid) {
- data['openid'] = openid;
- }
- data['processSuggest'] = that.data.processSuggest;
- var photos = that.data.photos;
- var tmpphotos = [];
- for (var i = 0; i < photos.length; i++) {
- var photo = photos[i];
- if (photo.type !== 0) {
- var photoobj = {
- id: photo.fileId,
- showBoxId: 0
- }
- tmpphotos.push(photoobj);
- }
- }
- data['photos'] = tmpphotos;
- wx.request({
- url: app.globalData.cloudBase + "/Dev/Wx/check/process/" + that.data.checkId,
- data: data,
- method: "POST",
- header: {
- 'content-type': 'application/json' // 默认值
- },
- success: function (res) {
- wx.hideNavigationBarLoading();
- if (res.data.code === '0') {
- wx.showModal({
- title: '提示',
- content: '提交成功!',
- showCancel: false,
- success: function (res) {
- if (res.confirm) {
- wx.navigateBack({
- delta: 1
- })
- }
- }
- })
- } else {
- wx.showModal({
- title: '提示',
- content: '提交失败!',
- showCancel: false,
- success: function (res) {}
- })
- }
- },
- fail: function (res) {
- console.log(res.errMsg)
- wx.hideNavigationBarLoading();
- }
- })
- } else {
- console.log('用户点击取消')
- }
- }
- });
- } catch (e) {
- console.log(e);
- }
- } else {
- wx.showToast({
- title: '请检查是否正确录入处理意见!',
- icon: 'none',
- duration: 3000
- })
- }
- },
- processSuggestInput: function (e) {
- this.setData({
- processSuggest: e.detail.value
- })
- },
- takePhoto: function (event) {
- var that = this;
- wx.showActionSheet({
- itemList: ['拍摄', '相册'],
- success: function (res) {
- if (!res.cancel) {
- console.log(res.tapIndex);
- if (res.tapIndex == 0) {
- wx.chooseImage({
- // 默认9
- count: 1,
- // 可以指定是原图还是压缩图,默认二者都有
- sizeType: ['compressed'],
- // 可以指定来源是相册还是相机,默认二者都有
- sourceType: ['camera'],
- success: function (res) {
- // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
- var tempFilePaths = res.tempFilePaths
- console.debug(tempFilePaths);
- wx.uploadFile({
- url: app.globalData.cloudBase + "/Dev/Wx/check/upload/image",
- filePath: tempFilePaths[0],
- name: 'image',
- success: function (res) {
- var data = res.data;
- var jsonStr = data.replace(" ", "");
- var json;
- if (typeof jsonStr != 'object') {
- jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
- json = JSON.parse(jsonStr);
- }
- if (json.code == "0") {
- var tmpphoto = that.data.photos;
- var img = tempFilePaths[0];
- console.log("path " + img);
- var tp = {};
- tp['path'] = img;
- tp['type'] = 1;
- tp['fileId'] = json.fileId;
- tmpphoto.unshift(tp);
- that.setData({
- photos: tmpphoto
- })
- // wx.setStorageSync('report_cache_photos', JSON.stringify(tmpphoto));
- }
- }
- })
- }
- })
- } else if (res.tapIndex == 1) {
- wx.chooseImage({
- count: 1, // 默认9
- sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
- success: function (res) {
- // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
- var tempFilePaths = res.tempFilePaths
- console.debug(tempFilePaths);
- wx.uploadFile({
- url: app.globalData.cloudBase + "/Dev/Wx/check/upload/image",
- filePath: tempFilePaths[0],
- name: 'image',
- success: function (res) {
- var data = res.data;
- var jsonStr = data.replace(" ", "");
- var json;
- if (typeof jsonStr != 'object') {
- jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
- json = JSON.parse(jsonStr);
- }
- if (json.code == "0") {
- console.log(json);
- var tmpphoto = that.data.photos;
- var img = tempFilePaths[0];
- console.log("path " + img);
- var tp = {};
- tp['path'] = img;
- tp['type'] = 1;
- tp['fileId'] = json.fileId;
- tmpphoto.unshift(tp);
- that.setData({
- photos: tmpphoto
- })
- // wx.setStorageSync('report_cache_photos', JSON.stringify(tmpphoto));
- }
- }
- })
- }
- })
- }
- }
- }
- })
- },
- editPhoto: function (event) {
- },
- deleteImage: function (event) {
- var that = this;
- var type = event.currentTarget.dataset.type;
- if (type == '1') {
- var images = that.data.photos;
- var index = event.currentTarget.dataset.index; //获取当前长按图片下标
- wx.showModal({
- title: '提示',
- content: '确定要删除此图片吗?',
- success: function (res) {
- if (res.confirm) {
- images.splice(index, 1);
- } else if (res.cancel) {
- return false;
- }
- that.setData({
- photos: images
- });
- }
- })
- }
- },
- })
|