123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- var businessT = require('../../../tool/business-tool.js')
- var sysT = require('../../../tool/sys-tool.js')
- var url = require('../../../constant/url.js')
- var app = getApp()
- import Net from '../../../tool/net.js'
- var net = new Net()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- cHeight: '',
- windowWidth: ''
- },
- cancelAction() {
- app.idCard.loaclPath = ''
- swan.navigateBack()
- },
- finishAction() {
- swan.showLoading({
- title: '上传中...',
- mask: true,
- })
- swan.compressImage({
- src: app.idCard.loaclPath,
- quality: 70,
- success: res => {
- if (this.data.status == 'edit') {
- if (this.data.imgStatus == 'front') {
- net.uploadImage({
- url: url.www_host + url.uploadIdcardById,
- imgPath: res.tempFilePath,
- imgName: 'file1',
- data: { sbuId: this.data.id, pos: 0 },
- success: (err, res) => {
- swan.hideLoading();
- app.idCard.front = url.img_host + res.data + '?' + new Date()
- swan.navigateBack({
- delta: 2
- })
- },
- fail: (err, res) => {
- swan.hideLoading();
- swan.showToast({
- title: '上传失败',
- icon: 'none',
- });
- swan.navigateBack({
- delta: 2
- })
- }
- }, true)
- } else {
- net.uploadImage({
- url: url.www_host + url.uploadIdcardById,
- imgPath: res.tempFilePath,
- imgName: 'file2',
- data: { sbuId: this.data.id, pos: 1 },
- success: (err, res) => {
- swan.hideLoading();
- app.idCard.back = url.img_host + res.data + '?' + new Date()
- swan.navigateBack({
- delta: 2
- })
- },
- fail: (err, res) => {
- swan.hideLoading();
- swan.showToast({
- title: '上传失败',
- icon: 'none',
- });
- swan.navigateBack({
- delta: 2
- })
- }
- }, true)
- }
- } else {
- if (this.data.imgStatus == 'front') {
- net.uploadImage({
- url: url.www_host + url.uploadIdcardByNumber,
- imgPath: res.tempFilePath,
- imgName: 'file1',
- data: { id_card: this.data.idCard, pos: 0 },
- success: (err, res) => {
- swan.hideLoading()
- app.idCard.front = url.img_host + res.data + '?' + new Date()
- swan.navigateBack({
- delta: 2
- })
- },
- fail: (err, res) => {
- swan.hideLoading()
- swan.showToast({
- title: '上传失败',
- icon: 'none',
- })
- swan.navigateBack({
- delta: 2
- })
- }
- }, true)
- } else {
- net.uploadImage({
- url: url.www_host + url.uploadIdcardByNumber,
- imgPath: res.tempFilePath,
- imgName: 'file2',
- data: { id_card: this.data.idCard, pos: 1 },
- success: (err, res) => {
- swan.hideLoading()
- app.idCard.back = url.img_host + res.data + '?' + new Date()
- swan.navigateBack({
- delta: 2
- })
- },
- fail: (err, res) => {
- swan.hideLoading()
- swan.showToast({
- title: '上传失败',
- icon: 'none',
- })
- swan.navigateBack({
- delta: 2
- })
- }
- }, true)
- }
- }
- }
- })
- app.idCard.loaclPath = ''
- },
- canvasHeight() {
- // var ctx = swan.createCanvasContext('myCanvas')
- // var windowWidth = sysT.sysInfo().windowWidth
- // swan.getImageInfo({
- // src: app.idCard.loaclPath,
- // success: res => {
- // var cHeight = windowWidth * (res.height / res.width)
- // console.log(res)
- // ctx.drawImage(app.idCard.loaclPath, 0, 0, 800, cHeight)
- // ctx.draw()
- // },
- // })
- var viewWidth = sysT.sysInfo().windowWidth
- var viewHeight = sysT.sysInfo().windowWidth / 1.58
- var cameraHeight = sysT.usableHeight(316)//相机可是高度rpx
- if (sysT.suffixOfClass() == '-X') {
- var cameraHeight = sysT.usableHeight(500)//相机可是高度rpx
- }
- var widthBorder = 40 * sysT.rpxToPx()//取景框横边距
- var borderWidth = sysT.sysInfo().windowWidth - widthBorder * 2//取景框宽
- var borderHeight = borderWidth / 1.58//取景框高
- var heightBorder = (cameraHeight * sysT.rpxToPx() - borderHeight) / 2//取景框竖边距
- var proportion = viewWidth / borderWidth //放大比例
- var bigWidthBorder = widthBorder * proportion//放大后图片的横边距
- var bigHeightBorder = heightBorder * proportion//放大后图片的竖边距
- var bigImageWidth = sysT.sysInfo().windowWidth * proportion//放大后图片宽
- var bigImageHeight = cameraHeight * sysT.rpxToPx() * proportion//放大后图片高
- this.setData({ viewWidth, viewHeight })
- var ctx = swan.createCanvasContext('myCanvas')
- ctx.drawImage(app.idCard.loaclPath, -bigWidthBorder, -bigHeightBorder, bigImageWidth, bigImageHeight)
- ctx.draw()
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (res) {
- this.canvasHeight()
- this.setData({
- suffix: sysT.suffixOfClass(),
- imgStatus: res.type,
- id: res.id,
- idCard: res.idCard,
- status: res.status
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- swan.setPageInfo && swan.setPageInfo({
- title: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
- keywords: '我的社保,我的社保网,我的社保APP,社会保障,社保,社保代缴,公积金代缴,社会保险,五险一金,医保,医疗保险,公积金,养老,生育,工伤,失业,住房公积金,社保代理,代缴社保,公积金代理,查悦社保,大社保,亲亲小保,社保掌上通,招聘求职,创业,买房,贷款,计算器,人社局,摇号',
- description: '我的社保APP是为个人、企业提供社保代缴代扣、公积金代扣代缴、社保查询、公积金查询服务的名牌产品。解决个体工商户、自由职业者、待业人员、全职妈妈、创业者等的个人社保公积金断缴难题,同时解决贷款, 买房, 买车, 养老, 医疗, 生育, 医疗报销等难题。同时为企业提供全国专业社保代理和公积金代理。',
- articleTitle: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页',
- release_date: '2019-02-23 20:00:00',
- success: function () {
- console.log('页面基础信息设置完成');
- },
- fail: function (res) {
- console.log('设置失败');
- },
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- // onShareAppMessage: function () {
- // }
- })
|