微信小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

128 行
4.2 KiB

  1. import SignaturePad from '../../../../utils/signature_pad';
  2. import * as UTIL from '../../../../utils/util.js';
  3. import * as API from '../../../../utils/API.js';
  4. let signaturePad = {};
  5. let pix = 7;
  6. let penColor = 'black';
  7. let lineWidth = 0.6;
  8. Page({
  9. data: {
  10. penColor: 'black',
  11. lineWidth: 0.6,
  12. isEmpty: true,
  13. baseItem:"",
  14. item:{},
  15. },
  16. onLoad: function(options) {
  17. this.setData({baseItem:options.item});
  18. this.setData({item:JSON.parse(options.item)});
  19. console.log(this.data.item);
  20. var ctx = wx.createCanvasContext('handWriting');
  21. const data = {
  22. devicePixelRatio: pix,
  23. };
  24. signaturePad = new SignaturePad(ctx, data);
  25. },
  26. uploadScaleStart(e) {
  27. const item = {
  28. penColor: penColor,
  29. lineWidth: lineWidth
  30. };
  31. signaturePad._handleTouchStart(e, item);
  32. },
  33. back:function(){
  34. wx.navigateBack({
  35. delta: 1
  36. })
  37. },
  38. uploadScaleMove(e) {
  39. signaturePad._handleTouchMove(e);
  40. },
  41. uploadScaleEnd: function(e) {
  42. signaturePad._handleTouchEnd(e);
  43. const isEmpty = signaturePad.isEmpty();
  44. this.setData({
  45. isEmpty: isEmpty
  46. })
  47. },
  48. retDraw: function() {
  49. signaturePad.clear();
  50. const isEmpty = signaturePad.isEmpty();
  51. this.setData({
  52. isEmpty: isEmpty
  53. })
  54. },
  55. getSysInfo: function() {
  56. var that = this
  57. wx.getSystemInfo({
  58. success: function(res) {
  59. pix = res.pixelRatio
  60. that.setData({
  61. width: res.windowWidth * pix,
  62. height: res.windowHeight * pix
  63. })
  64. }
  65. })
  66. },
  67. //保存canvas图像
  68. subCanvas: function() {
  69. let _this = this
  70. if (this.data.isEmpty) {
  71. return false
  72. }
  73. wx.canvasToTempFilePath({
  74. canvasId: 'handWriting',
  75. success: function(res) {
  76. console.log(res);
  77. wx.uploadFile({
  78.       url: API.URL_POST_UPLOADFILE, //服务器地址
  79.       filePath:res.tempFilePath,//本地照片地址
  80.       name: 'file',
  81. header: {
  82. 'Content-Type': 'multipart/form-data',
  83. 'Authorization':'Bearer '+getApp().globalData.userInfo.token, //如果需要token的话要传
  84. },
  85.       success (res){
  86. let dd = JSON.parse(res.data)
  87. // console.log(dd);
  88. // let a = _this.data.item
  89. // a.electronicSignature = dd.fileName
  90. // _this.setData({item:a});
  91. // _this.saveESign(JSON.stringify(_this.data.item));
  92. if(dd.code==200){
  93. wx.showToast({
  94. title: dd.msg,
  95. duration: 2000,
  96. icon:"success"
  97. })
  98. setTimeout(() => {
  99. _this.back()
  100. }, 2000);
  101. }else{
  102. wx.showToast({
  103. title: dd.msg,
  104. duration: 2000,
  105. icon:"none"
  106. })
  107. }
  108.       }
  109.     })
  110. },
  111. fail: function(res) {
  112. console.log(res)
  113. }
  114. })
  115. },
  116. // 保存电子签名
  117. saveESign : function(item){
  118. UTIL.httpRequest(API.URL_POST_USEREDIT,item,{
  119. success: (res) => {
  120. console.log(res);
  121. if (res.code == API.SUCCESS_CODE) {
  122. console.log(res);
  123. }
  124. }
  125. })
  126. }
  127. })