change-photo.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. var businessT = require('../../../tool/business-tool.js')
  2. var sysT = require('../../../tool/sys-tool.js')
  3. var url = require('../../../constant/url.js')
  4. var app = getApp()
  5. import Net from '../../../tool/net.js'
  6. var net = new Net()
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. cHeight: '',
  13. windowWidth: ''
  14. },
  15. cancelAction() {
  16. app.idCard.loaclPath = ''
  17. swan.navigateBack()
  18. },
  19. finishAction() {
  20. swan.showLoading({
  21. title: '上传中...',
  22. mask: true,
  23. })
  24. swan.compressImage({
  25. src: app.idCard.loaclPath,
  26. quality: 70,
  27. success: res => {
  28. if (this.data.status == 'edit') {
  29. if (this.data.imgStatus == 'front') {
  30. net.uploadImage({
  31. url: url.www_host + url.uploadIdcardById,
  32. imgPath: res.tempFilePath,
  33. imgName: 'file1',
  34. data: { sbuId: this.data.id, pos: 0 },
  35. success: (err, res) => {
  36. swan.hideLoading();
  37. app.idCard.front = url.img_host + res.data + '?' + new Date()
  38. swan.navigateBack({
  39. delta: 2
  40. })
  41. },
  42. fail: (err, res) => {
  43. swan.hideLoading();
  44. swan.showToast({
  45. title: '上传失败',
  46. icon: 'none',
  47. });
  48. swan.navigateBack({
  49. delta: 2
  50. })
  51. }
  52. }, true)
  53. } else {
  54. net.uploadImage({
  55. url: url.www_host + url.uploadIdcardById,
  56. imgPath: res.tempFilePath,
  57. imgName: 'file2',
  58. data: { sbuId: this.data.id, pos: 1 },
  59. success: (err, res) => {
  60. swan.hideLoading();
  61. app.idCard.back = url.img_host + res.data + '?' + new Date()
  62. swan.navigateBack({
  63. delta: 2
  64. })
  65. },
  66. fail: (err, res) => {
  67. swan.hideLoading();
  68. swan.showToast({
  69. title: '上传失败',
  70. icon: 'none',
  71. });
  72. swan.navigateBack({
  73. delta: 2
  74. })
  75. }
  76. }, true)
  77. }
  78. } else {
  79. if (this.data.imgStatus == 'front') {
  80. net.uploadImage({
  81. url: url.www_host + url.uploadIdcardByNumber,
  82. imgPath: res.tempFilePath,
  83. imgName: 'file1',
  84. data: { id_card: this.data.idCard, pos: 0 },
  85. success: (err, res) => {
  86. swan.hideLoading()
  87. app.idCard.front = url.img_host + res.data + '?' + new Date()
  88. swan.navigateBack({
  89. delta: 2
  90. })
  91. },
  92. fail: (err, res) => {
  93. swan.hideLoading()
  94. swan.showToast({
  95. title: '上传失败',
  96. icon: 'none',
  97. })
  98. swan.navigateBack({
  99. delta: 2
  100. })
  101. }
  102. }, true)
  103. } else {
  104. net.uploadImage({
  105. url: url.www_host + url.uploadIdcardByNumber,
  106. imgPath: res.tempFilePath,
  107. imgName: 'file2',
  108. data: { id_card: this.data.idCard, pos: 1 },
  109. success: (err, res) => {
  110. swan.hideLoading()
  111. app.idCard.back = url.img_host + res.data + '?' + new Date()
  112. swan.navigateBack({
  113. delta: 2
  114. })
  115. },
  116. fail: (err, res) => {
  117. swan.hideLoading()
  118. swan.showToast({
  119. title: '上传失败',
  120. icon: 'none',
  121. })
  122. swan.navigateBack({
  123. delta: 2
  124. })
  125. }
  126. }, true)
  127. }
  128. }
  129. }
  130. })
  131. app.idCard.loaclPath = ''
  132. },
  133. canvasHeight() {
  134. // var ctx = swan.createCanvasContext('myCanvas')
  135. // var windowWidth = sysT.sysInfo().windowWidth
  136. // swan.getImageInfo({
  137. // src: app.idCard.loaclPath,
  138. // success: res => {
  139. // var cHeight = windowWidth * (res.height / res.width)
  140. // console.log(res)
  141. // ctx.drawImage(app.idCard.loaclPath, 0, 0, 800, cHeight)
  142. // ctx.draw()
  143. // },
  144. // })
  145. var viewWidth = sysT.sysInfo().windowWidth
  146. var viewHeight = sysT.sysInfo().windowWidth / 1.58
  147. var cameraHeight = sysT.usableHeight(316)//相机可是高度rpx
  148. if (sysT.suffixOfClass() == '-X') {
  149. var cameraHeight = sysT.usableHeight(500)//相机可是高度rpx
  150. }
  151. var widthBorder = 40 * sysT.rpxToPx()//取景框横边距
  152. var borderWidth = sysT.sysInfo().windowWidth - widthBorder * 2//取景框宽
  153. var borderHeight = borderWidth / 1.58//取景框高
  154. var heightBorder = (cameraHeight * sysT.rpxToPx() - borderHeight) / 2//取景框竖边距
  155. var proportion = viewWidth / borderWidth //放大比例
  156. var bigWidthBorder = widthBorder * proportion//放大后图片的横边距
  157. var bigHeightBorder = heightBorder * proportion//放大后图片的竖边距
  158. var bigImageWidth = sysT.sysInfo().windowWidth * proportion//放大后图片宽
  159. var bigImageHeight = cameraHeight * sysT.rpxToPx() * proportion//放大后图片高
  160. this.setData({ viewWidth, viewHeight })
  161. var ctx = swan.createCanvasContext('myCanvas')
  162. ctx.drawImage(app.idCard.loaclPath, -bigWidthBorder, -bigHeightBorder, bigImageWidth, bigImageHeight)
  163. ctx.draw()
  164. },
  165. /**
  166. * 生命周期函数--监听页面加载
  167. */
  168. onLoad: function (res) {
  169. this.canvasHeight()
  170. this.setData({
  171. suffix: sysT.suffixOfClass(),
  172. imgStatus: res.type,
  173. id: res.id,
  174. idCard: res.idCard,
  175. status: res.status
  176. })
  177. },
  178. /**
  179. * 生命周期函数--监听页面初次渲染完成
  180. */
  181. onReady: function () {
  182. },
  183. /**
  184. * 生命周期函数--监听页面显示
  185. */
  186. onShow: function () {
  187. swan.setPageInfo && swan.setPageInfo({
  188. title: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
  189. keywords: '我的社保,我的社保网,我的社保APP,社会保障,社保,社保代缴,公积金代缴,社会保险,五险一金,医保,医疗保险,公积金,养老,生育,工伤,失业,住房公积金,社保代理,代缴社保,公积金代理,查悦社保,大社保,亲亲小保,社保掌上通,招聘求职,创业,买房,贷款,计算器,人社局,摇号',
  190. description: '我的社保APP是为个人、企业提供社保代缴代扣、公积金代扣代缴、社保查询、公积金查询服务的名牌产品。解决个体工商户、自由职业者、待业人员、全职妈妈、创业者等的个人社保公积金断缴难题,同时解决贷款, 买房, 买车, 养老, 医疗, 生育, 医疗报销等难题。同时为企业提供全国专业社保代理和公积金代理。',
  191. articleTitle: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
  192. release_date: '2019-02-23 20:00:00',
  193. success: function () {
  194. console.log('页面基础信息设置完成');
  195. },
  196. fail: function (res) {
  197. console.log('设置失败');
  198. },
  199. })
  200. },
  201. /**
  202. * 生命周期函数--监听页面隐藏
  203. */
  204. onHide: function () {
  205. },
  206. /**
  207. * 生命周期函数--监听页面卸载
  208. */
  209. onUnload: function () {
  210. },
  211. /**
  212. * 页面相关事件处理函数--监听用户下拉动作
  213. */
  214. onPullDownRefresh: function () {
  215. },
  216. /**
  217. * 页面上拉触底事件的处理函数
  218. */
  219. onReachBottom: function () {
  220. },
  221. /**
  222. * 用户点击右上角分享
  223. */
  224. // onShareAppMessage: function () {
  225. // }
  226. })