checkProcessReportEdit.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. // pages/deviceCheck/report/edit/checkReportEdit.js
  2. var app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. placeholder: '请录入处理意见',
  9. processSuggest: '',
  10. photos: [],
  11. checkId: ''
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad(options) {
  17. var checkId = options.checkId;
  18. const img = "/images/add.png";
  19. var tmpphoto = this.data.photos;
  20. var tp = {};
  21. tp['path'] = img;
  22. tp['type'] = 0;
  23. tp['fileName'] = '';
  24. tmpphoto.push(tp);
  25. this.setData({
  26. photos: tmpphoto,
  27. checkId: checkId
  28. });
  29. },
  30. /**
  31. * 生命周期函数--监听页面初次渲染完成
  32. */
  33. onReady() {
  34. },
  35. /**
  36. * 生命周期函数--监听页面显示
  37. */
  38. onShow() {
  39. },
  40. /**
  41. * 生命周期函数--监听页面隐藏
  42. */
  43. onHide() {
  44. },
  45. /**
  46. * 生命周期函数--监听页面卸载
  47. */
  48. onUnload() {
  49. },
  50. /**
  51. * 页面相关事件处理函数--监听用户下拉动作
  52. */
  53. onPullDownRefresh() {
  54. },
  55. /**
  56. * 页面上拉触底事件的处理函数
  57. */
  58. onReachBottom() {
  59. },
  60. /**
  61. * 用户点击右上角分享
  62. */
  63. onShareAppMessage() {
  64. },
  65. toReportHandle: function (e) {
  66. if (this.data.processSuggest.length > 0) {
  67. var that = this;
  68. try {
  69. wx.showModal({
  70. title: '提示',
  71. content: '确定提交巡检处理意见?',
  72. success: function (res) {
  73. if (res.confirm) {
  74. wx.showNavigationBarLoading()
  75. var data = {};
  76. data['checkId'] = that.data.checkId;
  77. var openid = wx.getStorageSync('openid')
  78. if (openid) {
  79. data['openid'] = openid;
  80. }
  81. data['processSuggest'] = that.data.processSuggest;
  82. var photos = that.data.photos;
  83. var tmpphotos = [];
  84. for (var i = 0; i < photos.length; i++) {
  85. var photo = photos[i];
  86. if (photo.type !== 0) {
  87. var photoobj = {
  88. id: photo.fileId,
  89. showBoxId: 0
  90. }
  91. tmpphotos.push(photoobj);
  92. }
  93. }
  94. data['photos'] = tmpphotos;
  95. wx.request({
  96. url: app.globalData.cloudBase + "/Dev/Wx/check/process/" + that.data.checkId,
  97. data: data,
  98. method: "POST",
  99. header: {
  100. 'content-type': 'application/json' // 默认值
  101. },
  102. success: function (res) {
  103. wx.hideNavigationBarLoading();
  104. if (res.data.code === '0') {
  105. wx.showModal({
  106. title: '提示',
  107. content: '提交成功!',
  108. showCancel: false,
  109. success: function (res) {
  110. if (res.confirm) {
  111. wx.navigateBack({
  112. delta: 1
  113. })
  114. }
  115. }
  116. })
  117. } else {
  118. wx.showModal({
  119. title: '提示',
  120. content: '提交失败!',
  121. showCancel: false,
  122. success: function (res) {}
  123. })
  124. }
  125. },
  126. fail: function (res) {
  127. console.log(res.errMsg)
  128. wx.hideNavigationBarLoading();
  129. }
  130. })
  131. } else {
  132. console.log('用户点击取消')
  133. }
  134. }
  135. });
  136. } catch (e) {
  137. console.log(e);
  138. }
  139. } else {
  140. wx.showToast({
  141. title: '请检查是否正确录入处理意见!',
  142. icon: 'none',
  143. duration: 3000
  144. })
  145. }
  146. },
  147. processSuggestInput: function (e) {
  148. this.setData({
  149. processSuggest: e.detail.value
  150. })
  151. },
  152. takePhoto: function (event) {
  153. var that = this;
  154. wx.showActionSheet({
  155. itemList: ['拍摄', '相册'],
  156. success: function (res) {
  157. if (!res.cancel) {
  158. console.log(res.tapIndex);
  159. if (res.tapIndex == 0) {
  160. wx.chooseImage({
  161. // 默认9
  162. count: 1,
  163. // 可以指定是原图还是压缩图,默认二者都有
  164. sizeType: ['compressed'],
  165. // 可以指定来源是相册还是相机,默认二者都有
  166. sourceType: ['camera'],
  167. success: function (res) {
  168. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  169. var tempFilePaths = res.tempFilePaths
  170. console.debug(tempFilePaths);
  171. wx.uploadFile({
  172. url: app.globalData.cloudBase + "/Dev/Wx/check/upload/image",
  173. filePath: tempFilePaths[0],
  174. name: 'image',
  175. success: function (res) {
  176. var data = res.data;
  177. var jsonStr = data.replace(" ", "");
  178. var json;
  179. if (typeof jsonStr != 'object') {
  180. jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
  181. json = JSON.parse(jsonStr);
  182. }
  183. if (json.code == "0") {
  184. var tmpphoto = that.data.photos;
  185. var img = tempFilePaths[0];
  186. console.log("path " + img);
  187. var tp = {};
  188. tp['path'] = img;
  189. tp['type'] = 1;
  190. tp['fileId'] = json.fileId;
  191. tmpphoto.unshift(tp);
  192. that.setData({
  193. photos: tmpphoto
  194. })
  195. // wx.setStorageSync('report_cache_photos', JSON.stringify(tmpphoto));
  196. }
  197. }
  198. })
  199. }
  200. })
  201. } else if (res.tapIndex == 1) {
  202. wx.chooseImage({
  203. count: 1, // 默认9
  204. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  205. sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有
  206. success: function (res) {
  207. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  208. var tempFilePaths = res.tempFilePaths
  209. console.debug(tempFilePaths);
  210. wx.uploadFile({
  211. url: app.globalData.cloudBase + "/Dev/Wx/check/upload/image",
  212. filePath: tempFilePaths[0],
  213. name: 'image',
  214. success: function (res) {
  215. var data = res.data;
  216. var jsonStr = data.replace(" ", "");
  217. var json;
  218. if (typeof jsonStr != 'object') {
  219. jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点
  220. json = JSON.parse(jsonStr);
  221. }
  222. if (json.code == "0") {
  223. console.log(json);
  224. var tmpphoto = that.data.photos;
  225. var img = tempFilePaths[0];
  226. console.log("path " + img);
  227. var tp = {};
  228. tp['path'] = img;
  229. tp['type'] = 1;
  230. tp['fileId'] = json.fileId;
  231. tmpphoto.unshift(tp);
  232. that.setData({
  233. photos: tmpphoto
  234. })
  235. // wx.setStorageSync('report_cache_photos', JSON.stringify(tmpphoto));
  236. }
  237. }
  238. })
  239. }
  240. })
  241. }
  242. }
  243. }
  244. })
  245. },
  246. editPhoto: function (event) {
  247. },
  248. deleteImage: function (event) {
  249. var that = this;
  250. var type = event.currentTarget.dataset.type;
  251. if (type == '1') {
  252. var images = that.data.photos;
  253. var index = event.currentTarget.dataset.index; //获取当前长按图片下标
  254. wx.showModal({
  255. title: '提示',
  256. content: '确定要删除此图片吗?',
  257. success: function (res) {
  258. if (res.confirm) {
  259. images.splice(index, 1);
  260. } else if (res.cancel) {
  261. return false;
  262. }
  263. that.setData({
  264. photos: images
  265. });
  266. }
  267. })
  268. }
  269. },
  270. })