onDoorClock.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../api/api.js');
  3. var check = require('../../../utils/check.js');
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. clockInfo: {
  11. },
  12. clockImgFront: '',
  13. clockImgBack: ''
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad(options) {
  19. let dt = app.globalData.clockInfo;
  20. console.log(dt);
  21. this.setData({
  22. clockInfo: dt
  23. })
  24. },
  25. submitClock() {
  26. let req = this.data.clockInfo;
  27. if (req.channelId == 112) { //花王渠道
  28. if (this.data.clockImgFront == '') {
  29. wx.showToast({
  30. title: '花王工单,需上传工作半身照',
  31. icon: 'none'
  32. });
  33. return;
  34. }
  35. if (this.data.clockImgBack == '') {
  36. wx.showToast({
  37. title: '花王渠道,需上传工具摆放照',
  38. icon: 'none'
  39. });
  40. return;
  41. }
  42. }
  43. if (this.data.clockImgFront != '') {
  44. req.ondoorImg = this.data.clockImgFront;
  45. }
  46. if (this.data.clockImgBack != '') {
  47. if (req.ondoorImg.length > 0) {
  48. req.ondoorImg = req.ondoorImg + "," + this.data.clockImgBack;
  49. } else {
  50. req.ondoorImg = this.data.clockImgBack;
  51. }
  52. }
  53. console.log(req);
  54. util.request(api.arrivedByMerchantNew, req, 'GET').then(res => {
  55. if (res.errno === 0) {
  56. wx.showToast({
  57. title: '操作成功'
  58. });
  59. setTimeout(() => {
  60. wx.navigateBack({
  61. delta: 1
  62. });
  63. }, 2000);
  64. } else {
  65. wx.showToast({
  66. title: res.errmsg,
  67. icon: 'none'
  68. })
  69. }
  70. });
  71. },
  72. chooseImg(e) {
  73. let type = e.currentTarget.dataset.type;
  74. var that = this;
  75. wx.chooseMedia({
  76. count: 1,
  77. mediaType: ['image'],
  78. sourceType: ['camera'],
  79. camera: type == 1 ? 'front' : 'back',
  80. sizeType: ['original', 'compressed'],
  81. success: function (res) {
  82. let file = res.tempFiles[0].tempFilePath
  83. wx.compressImage({
  84. src: file, // 图片路径
  85. quality: 75, // 压缩质量
  86. success(res) {
  87. console.log(res);
  88. // res.tempFilePath
  89. that.upload(res.tempFilePath, type);
  90. },
  91. fail: (err) => {
  92. console.error(err);
  93. wx.showToast({
  94. title: '微信压缩图片失败:' + err,
  95. icon: 'none'
  96. })
  97. }
  98. })
  99. }
  100. })
  101. },
  102. upload: function (path, type) {
  103. var that = this;
  104. const uploadTask = wx.uploadFile({
  105. url: api.StorageUpload(),
  106. filePath: path, //res.tempFilePaths[0],
  107. name: 'file',
  108. success: function (res) {
  109. var _res = JSON.parse(res.data);
  110. if (_res.errno === 0) {
  111. var url = _res.data.fileUrl
  112. if (type == 1) {
  113. that.setData({
  114. clockImgFront: url,
  115. });
  116. } else {
  117. that.setData({
  118. clockImgBack: url
  119. });
  120. }
  121. }
  122. }
  123. })
  124. },
  125. /**
  126. * 生命周期函数--监听页面初次渲染完成
  127. */
  128. onReady() {
  129. },
  130. /**
  131. * 生命周期函数--监听页面显示
  132. */
  133. onShow() {
  134. },
  135. /**
  136. * 生命周期函数--监听页面隐藏
  137. */
  138. onHide() {
  139. },
  140. /**
  141. * 生命周期函数--监听页面卸载
  142. */
  143. onUnload() {
  144. },
  145. /**
  146. * 页面相关事件处理函数--监听用户下拉动作
  147. */
  148. onPullDownRefresh() {
  149. },
  150. /**
  151. * 页面上拉触底事件的处理函数
  152. */
  153. onReachBottom() {
  154. },
  155. /**
  156. * 用户点击右上角分享
  157. */
  158. onShareAppMessage() {
  159. }
  160. })