wait-for-do-preview.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. var sysT = require('../../../../tool/sys-tool.js')
  2. var businessT = require('../../../../tool/business-tool.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. adapter: {
  9. suffix: ''
  10. },
  11. img: [],
  12. type: 'display',
  13. upload: {
  14. maxC: 0,
  15. addC: 0
  16. },
  17. status: 0,//0正常展示1删除
  18. },
  19. deleteAction: businessT.action(function (sender) {
  20. if (this.data.type == 'display') {
  21. return
  22. }
  23. var that = this
  24. wx.showModal({
  25. title: '提示',
  26. content: '确定删除该图片',
  27. confirmColor: '#3296FB',
  28. cancelColor: '#3296FB',
  29. confirmText: '确定',
  30. cancelText: '取消',
  31. success: function (res) {
  32. if (res.confirm) {
  33. that.data.img.splice(Number(sender.currentTarget.id), 1)
  34. if (that.data.img.length == 0) {
  35. wx.navigateBack({
  36. })
  37. } else {
  38. that.data.upload.addC = that.data.upload.maxC - that.data.img.length
  39. that.setData({
  40. img: that.data.img,
  41. upload: that.data.upload
  42. })
  43. }
  44. }
  45. }
  46. })
  47. }),
  48. finishDeleteAction: businessT.action(function (sender) {
  49. if (this.data.type == 'display') {
  50. return
  51. }
  52. this.data.status = 0
  53. this.setData({
  54. status: this.data.status
  55. })
  56. businessT.debugLog('finishDeleteAction')
  57. }),
  58. changeDelete: businessT.action(function (sender) {
  59. if (this.data.type == 'display') {
  60. return
  61. }
  62. this.data.status = 1
  63. this.setData({
  64. status: this.data.status
  65. })
  66. businessT.debugLog('changeDelete')
  67. }),
  68. detailsAction: businessT.action(function (sender) {
  69. if (this.data.status == 1) {
  70. return
  71. }
  72. businessT.debugLog('detailsAction')
  73. wx.previewImage({
  74. current: this.data.img[sender.currentTarget.id],
  75. urls: this.data.img,
  76. })
  77. }),
  78. addImg: businessT.action(function (sender) {
  79. if (this.data.type == 'display') {
  80. return
  81. }
  82. var that = this
  83. wx.chooseImage({
  84. sizeType: ['compressed'],
  85. count: this.data.upload.addC,
  86. success: function (res) {
  87. that.data.img = that.data.img.concat(res.tempFilePaths)
  88. that.data.upload.addC = that.data.upload.maxC - that.data.img.length
  89. that.setData({
  90. img: that.data.img,
  91. upload: that.data.upload
  92. })
  93. },
  94. })
  95. }),
  96. submitAction: businessT.action(function (sender) {
  97. if (this.data.img.length == 0) {
  98. wx.showToast({
  99. title: '请选择图片',
  100. })
  101. return
  102. }
  103. wx.navigateBack({
  104. })
  105. var pages = getCurrentPages()
  106. pages[pages.length - 2].finishUploadPhoto(this.data.img)
  107. }),
  108. /**
  109. * 生命周期函数--监听页面加载
  110. */
  111. onLoad: function (options) {
  112. this.data.type = options.type
  113. wx.setNavigationBarTitle({
  114. title: this.data.type == 'upload' ? '上传资料' : '详情',
  115. })
  116. var pages = getCurrentPages()
  117. this.data.img = pages[pages.length - 2].data.img
  118. businessT.debugLog(this.data.img)
  119. if (this.data.type == 'upload') {
  120. this.data.upload.maxC = options.max
  121. this.data.upload.addC = this.data.upload.maxC - this.data.img.length
  122. }
  123. this.data.adapter = {
  124. suffix: sysT.suffixOfClass()
  125. }
  126. businessT.debugLog(this.data.upload)
  127. this.setData({
  128. type: this.data.type,
  129. adapter: this.data.adapter,
  130. img: this.data.img,
  131. upload: this.data.upload
  132. })
  133. },
  134. /**
  135. * 生命周期函数--监听页面初次渲染完成
  136. */
  137. onReady: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面隐藏
  146. */
  147. onHide: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面卸载
  151. */
  152. onUnload: function () {
  153. },
  154. /**
  155. * 页面相关事件处理函数--监听用户下拉动作
  156. */
  157. onPullDownRefresh: function () {
  158. },
  159. /**
  160. * 页面上拉触底事件的处理函数
  161. */
  162. onReachBottom: function () {
  163. },
  164. /**
  165. * 用户点击右上角分享
  166. */
  167. onShareAppMessage: function () {
  168. return {
  169. path: '/page/home/index',
  170. imageUrl: '../../../../icon/public/share_img.png',
  171. title: '自助缴社保公积金,覆盖200多个城市,专业团队操作'
  172. }
  173. }
  174. })