camera.js 9.5 KB

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