微信小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.js 5.0 KiB

há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
há 3 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. url:"",
  16. isShow:false
  17. },
  18. onLoad: function(options) {
  19. this.getUserInfo();
  20. this.getBaseUrl()
  21. },
  22. /* 获取用户信息*/
  23. getUserInfo(){
  24. UTIL.httpRequest(API.URL_GET_GETINFO, {method:'GET'}, {
  25. success: (res) => {
  26. if (res.code == API.SUCCESS_CODE) {
  27. this.setData({item:res.user})
  28. if(this.data.item.electronicSignature==null||this.data.item.electronicSignature==""){
  29. this.setData({isShow:false})
  30. var ctx = wx.createCanvasContext('handWriting');
  31. const data = {
  32. devicePixelRatio: pix,
  33. };
  34. signaturePad = new SignaturePad(ctx, data);
  35. }else{
  36. this.setData({isShow:true})
  37. }
  38. }
  39. }
  40. })
  41. },
  42. getBaseUrl:function(){
  43. let params={
  44. configKey: "system.attachment.url"}
  45. UTIL.httpRequest(API.URL_GET_SYSCONFIG,params,{
  46. success: (res) => {
  47. if (res.code == API.SUCCESS_CODE) {
  48. this.setData({url:res.rows[0].configValue+this.data.item.electronicSignature})
  49. }
  50. }
  51. })
  52. },
  53. uploadScaleStart(e) {
  54. const item = {
  55. penColor: penColor,
  56. lineWidth: lineWidth
  57. };
  58. signaturePad._handleTouchStart(e, item);
  59. },
  60. back:function(){
  61. wx.navigateBack({
  62. delta: 1
  63. })
  64. },
  65. uploadScaleMove(e) {
  66. signaturePad._handleTouchMove(e);
  67. },
  68. uploadScaleEnd: function(e) {
  69. signaturePad._handleTouchEnd(e);
  70. const isEmpty = signaturePad.isEmpty();
  71. this.setData({
  72. isEmpty: isEmpty
  73. })
  74. },
  75. retDraw: function() {
  76. this.setData({isShow:false})
  77. var ctx = wx.createCanvasContext('handWriting');
  78. const data = {
  79. devicePixelRatio: pix,
  80. };
  81. signaturePad = new SignaturePad(ctx, data);
  82. signaturePad.clear();
  83. const isEmpty = signaturePad.isEmpty();
  84. this.setData({
  85. isEmpty: isEmpty
  86. })
  87. },
  88. getSysInfo: function() {
  89. var that = this
  90. wx.getSystemInfo({
  91. success: function(res) {
  92. pix = res.pixelRatio
  93. that.setData({
  94. width: res.windowWidth * pix,
  95. height: res.windowHeight * pix
  96. })
  97. }
  98. })
  99. },
  100. //保存canvas图像
  101. subCanvas: function() {
  102. let _this = this
  103. if (this.data.isEmpty) {
  104. return false
  105. }
  106. wx.canvasToTempFilePath({
  107. canvasId: 'handWriting',
  108. success: function(res) {
  109. wx.uploadFile({
  110.       url: API.URL_POST_UPLOADFILE, //服务器地址
  111.       filePath:res.tempFilePath,//本地照片地址
  112.       name: 'file',
  113. header: {
  114. 'Content-Type': 'multipart/form-data',
  115. 'Authorization':'Bearer '+getApp().globalData.userInfo.token, //如果需要token的话要传
  116. },
  117.       success (res){
  118. let dd = JSON.parse(res.data)
  119. if(dd.code==200){
  120. wx.showToast({
  121. title: dd.msg,
  122. duration: 2000,
  123. icon:"success"
  124. })
  125. setTimeout(() => {
  126. _this.back()
  127. }, 2000);
  128. }else{
  129. wx.showToast({
  130. title: dd.msg,
  131. duration: 2000,
  132. icon:"none"
  133. })
  134. }
  135.       }
  136.     })
  137. },
  138. fail: function(res) {
  139. console.log(res)
  140. }
  141. })
  142. },
  143. // 保存电子签名
  144. saveESign : function(item){
  145. UTIL.httpRequest(API.URL_POST_USEREDIT,item,{
  146. success: (res) => {
  147. if (res.code == API.SUCCESS_CODE) {
  148. wx.showToast({
  149. title: "保存成功!",
  150. duration: 2000,
  151. icon:"success"
  152. })
  153. }
  154. }
  155. })
  156. }
  157. })