微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
5.6 KiB

  1. // pages/contract/add/add.js
  2. import * as UTIL from '../../../utils/util.js';
  3. import * as API from '../../../utils/API.js';
  4. import SignaturePad from '../../../utils/signature_pad';
  5. let signaturePad = {};
  6. let pix = 7;
  7. let penColor = 'black';
  8. let lineWidth = 0.6;
  9. const app = getApp();
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. isIPX: app.globalData.isIPX,
  16. id:null,
  17. autosize:{ maxHeight: 100, minHeight: 50 },
  18. form:{
  19. voteResult: '1'
  20. },
  21. penColor: 'black',
  22. lineWidth: 0.6,
  23. isEmpty: true,
  24. baseItem:"",
  25. item:{},
  26. url:"",
  27. isShow:false
  28. },
  29. back:function(){
  30. wx.navigateBack({
  31. delta: 2
  32. })
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad(options) {
  38. this.setData({id:options.id})
  39. this.getUserInfo();
  40. this.getBaseUrl()
  41. //获取收入合同状态
  42. },
  43. /**
  44. * 生命周期函数--监听页面初次渲染完成
  45. */
  46. onReady() {
  47. },
  48. /**
  49. * 生命周期函数--监听页面显示
  50. */
  51. onShow() {
  52. },
  53. /**
  54. * 生命周期函数--监听页面隐藏
  55. */
  56. onHide() {
  57. },
  58. /**
  59. * 生命周期函数--监听页面卸载
  60. */
  61. onUnload() {
  62. },
  63. /**
  64. * 页面相关事件处理函数--监听用户下拉动作
  65. */
  66. onPullDownRefresh() {
  67. },
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom() {
  72. },
  73. /**
  74. * 用户点击右上角分享
  75. */
  76. onShareAppMessage() {
  77. },
  78. onChange(event) {
  79. console.log(event.detail);
  80. this.setData({
  81. [event.currentTarget.dataset.value]: event.detail,
  82. });
  83. },
  84. /* 获取用户信息*/
  85. getUserInfo(){
  86. UTIL.httpRequest(API.URL_GET_GETINFO, {method:'GET'}, {
  87. success: (res) => {
  88. if (res.code == API.SUCCESS_CODE) {
  89. this.setData({item:res.user})
  90. // if(this.data.item.electronicSignature==null||this.data.item.electronicSignature==""){
  91. // this.setData({isShow:false})
  92. var ctx = wx.createCanvasContext('handWriting');
  93. const data = {
  94. devicePixelRatio: pix,
  95. };
  96. signaturePad = new SignaturePad(ctx, data);
  97. // }else{
  98. // this.setData({isShow:true})
  99. // }
  100. }
  101. }
  102. })
  103. },
  104. getBaseUrl:function(){
  105. let params={
  106. configKey: "system.attachment.url"}
  107. UTIL.httpRequest(API.URL_GET_SYSCONFIG,params,{
  108. success: (res) => {
  109. if (res.code == API.SUCCESS_CODE) {
  110. console.log(res.rows[0].configValue+this.data.item.electronicSignature)
  111. this.setData({url:res.rows[0].configValue+this.data.item.electronicSignature})
  112. }
  113. }
  114. })
  115. },
  116. uploadScaleStart(e) {
  117. const item = {
  118. penColor: penColor,
  119. lineWidth: lineWidth
  120. };
  121. signaturePad._handleTouchStart(e, item);
  122. },
  123. uploadScaleMove(e) {
  124. signaturePad._handleTouchMove(e);
  125. },
  126. uploadScaleEnd: function(e) {
  127. signaturePad._handleTouchEnd(e);
  128. const isEmpty = signaturePad.isEmpty();
  129. this.setData({
  130. isEmpty: isEmpty
  131. })
  132. },
  133. retDraw: function() {
  134. this.setData({isShow:false})
  135. var ctx = wx.createCanvasContext('handWriting');
  136. const data = {
  137. devicePixelRatio: pix,
  138. };
  139. signaturePad = new SignaturePad(ctx, data);
  140. signaturePad.clear();
  141. const isEmpty = signaturePad.isEmpty();
  142. this.setData({
  143. isEmpty: isEmpty
  144. })
  145. },
  146. getSysInfo: function() {
  147. var that = this
  148. wx.getSystemInfo({
  149. success: function(res) {
  150. pix = res.pixelRatio
  151. that.setData({
  152. width: res.windowWidth * pix,
  153. height: res.windowHeight * pix
  154. })
  155. }
  156. })
  157. },
  158. //保存canvas图像
  159. subCanvas: function() {
  160. let _this = this
  161. if (this.data.isEmpty) {
  162. wx.showToast({
  163. title: '请签字后提交',
  164. duration: 2000,
  165. icon:"none"
  166. })
  167. return false
  168. }
  169. wx.canvasToTempFilePath({
  170. canvasId: 'handWriting',
  171. success: function(res) {
  172. _this.data.form.voteId = _this.data.id;
  173. _this.data.form.file = res.tempFilePath;
  174. _this.data.form.voteBy = _this.data.item.userName;
  175. wx.uploadFile({
  176.       url: wx.getStorageSync('dressCode')+API.votedetailAdd, //服务器地址
  177.       filePath:res.tempFilePath,//本地照片地址
  178.       name: 'file',
  179. formData: _this.data.form,
  180. header: {
  181. 'Content-Type': 'multipart/form-data',
  182. 'Authorization':'Bearer '+getApp().globalData.userInfo.token, //如果需要token的话要传
  183. },
  184.       success (res){
  185. let dd = JSON.parse(res.data)
  186. if(dd.code==200){
  187. wx.showToast({
  188. title: dd.msg,
  189. duration: 2000,
  190. icon:"success"
  191. })
  192. setTimeout(() => {
  193. _this.back()
  194. }, 2000);
  195. }else{
  196. wx.showToast({
  197. title: dd.msg,
  198. duration: 2000,
  199. icon:"none"
  200. })
  201. }
  202.       }
  203.     })
  204. },
  205. fail: function(res) {
  206. console.log(res)
  207. }
  208. })
  209. },
  210. // 保存电子签名
  211. saveESign : function(item){
  212. UTIL.httpRequest(API.URL_POST_USEREDIT,item,{
  213. success: (res) => {
  214. if (res.code == API.SUCCESS_CODE) {
  215. wx.showToast({
  216. title: "保存成功!",
  217. duration: 2000,
  218. icon:"success"
  219. })
  220. }
  221. }
  222. })
  223. }
  224. })