signature.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view class="sign">
  3. <ujp-navbar title="签字"></ujp-navbar>
  4. <p>请在下方空白区域使用正楷字体进行电子签名</p>
  5. <view class="signature">
  6. <l-signature disableScroll ref="signatureRef" :penColor="penColor" :penSize="penSize"
  7. :openSmooth="openSmooth"></l-signature>
  8. </view>
  9. <view class="clean-save">
  10. <view class="clean" @click="onClick('clear')">
  11. <img src="../../../assets/img/riLine-eraser-line.svg" alt="">
  12. <view class="">
  13. 清除
  14. </view>
  15. </view>
  16. <view class="save" @click="onClick('save')">
  17. <img src="../../../assets/img/riLine-eraser-line.svg" alt="">
  18. <view class="">
  19. 保存
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import LSignature from '@/components/l-signature/l-signature.vue'
  27. import * as API from '@/apis/finance.js'
  28. import * as API_Common from '@/apis/common.js'
  29. import {
  30. parseUnixTime,
  31. } from '@/utils'
  32. export default {
  33. data() {
  34. return {
  35. info: null,
  36. detailList:null,
  37. penColor: '',
  38. penSize: 5,
  39. url: '',
  40. suburl: '',
  41. openSmooth: true,
  42. nowTime:"",
  43. serverUrl: "",
  44. token: "",
  45. uuid:"",
  46. }
  47. },onLoad(op){
  48. //this.userInfo=this.carhelp.getPersonInfo()
  49. this.uuid=op.uuid;
  50. this.id=op.id
  51. this.getInfo()
  52. // alert(this.carhelp.getToken({
  53. // jp_identity:
  54. // }))
  55. },
  56. methods: {
  57. //上传图片
  58. uploadpic() {
  59. uni.showLoading({
  60. title: "图片上传中",
  61. mask: true,
  62. })
  63. var formData = {
  64. "photoName":"signature.png",
  65. "photoBase64Data": this.url
  66. }
  67. // formData.append('photoName', '1.jpg');
  68. // formData.append('photoBase64Data', this.url);
  69. API_Common.uploadBase64Json(formData).then(response => {
  70. //this.suburl=response.data;
  71. this.info.status=0;
  72. this.info.signUrl=response.data;
  73. //this.$emit("signsubmit",0,this.suburl)
  74. this.submitFrom()
  75. }).catch(error => {
  76. uni.hideLoading()
  77. uni.showModal({
  78. title:"提示",
  79. content:error,
  80. showCancel:false
  81. })
  82. })
  83. },
  84. submitFrom(){
  85. uni.showLoading({
  86. title: "提交中...",
  87. mask: true,
  88. })
  89. //this.info.status=0;
  90. //var str=JSON.stringify();
  91. API.applyWithdrawByAccounting({
  92. record:this.info,
  93. detailList:this.detailList
  94. }).then((res) => {
  95. this.carhelp.set("withdrawRecord",{
  96. uuid:this.uuid,
  97. })
  98. this.id=res.data;
  99. uni.hideLoading()
  100. uni.redirectTo({
  101. url:"/pagesFinance/user/applyResult?value="+this.info.applicationAmount
  102. })
  103. }).catch(error => {
  104. uni.hideLoading()
  105. uni.showModal({
  106. title:"提示",
  107. content:error,
  108. showCancel:false
  109. })
  110. })
  111. },
  112. getInfo(){
  113. uni.showLoading({
  114. title: "加载中",
  115. mask: true,
  116. })
  117. API.getWithdrawInfoByAccounting(this.id).then((res) => {
  118. this.info=res.data.record
  119. this.detailList=res.data.detailList
  120. uni.hideLoading()
  121. }).catch(error => {
  122. uni.showToast({
  123. title: error
  124. })
  125. })
  126. },
  127. onClick(type) {
  128. this.url =""
  129. if(type == 'openSmooth') {
  130. this.openSmooth = !this.openSmooth
  131. return
  132. }
  133. if (type == 'save') {
  134. this.$refs.signatureRef.canvasToTempFilePath({
  135. success: (res) => {
  136. // 是否为空画板 无签名
  137. if(res.isEmpty){
  138. this.url ="";
  139. }else{
  140. this.url = res.tempFilePath
  141. console.log(this.url)
  142. // 生成图片的临时路径
  143. // app | H5 | 微信小程序 生成的是base64
  144. //this.uploadpic()
  145. uni.showLoading({
  146. title: '上传中'
  147. });
  148. this.token=this.carhelp.getToken();
  149. this.serverUrl=process.car.BASE_URL;
  150. var time= "";//parseUnixTime(new Date(), '{y}{m}{d}-{h}-{i}');
  151. uni.request({
  152. url: this.serverUrl + "/uploadBase64Json",
  153. method: "POST",
  154. header: {
  155. Authorization: this.token
  156. },
  157. data: {
  158. "photoName":"signature"+time+".png",
  159. "photoBase64Data": this.url
  160. },
  161. success: (res) => {
  162. uni.hideLoading();
  163. console.log(res)
  164. if(res.data.result){
  165. uni.showToast({
  166. title: '签名保存成功!',
  167. duration: 2000
  168. });
  169. this.info.status=0;
  170. this.info.signUrl=res.data.data;
  171. //this.$emit("signsubmit",0,this.suburl)
  172. this.submitFrom()
  173. }
  174. else{
  175. uni.showToast({
  176. title: '签名保存失败!'+ JSON.stringify(res),
  177. duration: 2000
  178. });
  179. }
  180. }
  181. })
  182. }
  183. }
  184. })
  185. return
  186. }
  187. if (this.$refs.signatureRef)
  188. this.$refs.signatureRef[type]()
  189. }
  190. }
  191. }
  192. </script>
  193. <style lang="scss" scoped>
  194. .sign{
  195. margin: 32rpx 16rpx ;
  196. font-weight: bold;
  197. line-height: 20px;
  198. p{
  199. color: rgba(16, 16, 16, 1);
  200. }
  201. .signature{
  202. background-color: #fff;
  203. margin-top: 8px;
  204. height: 160px;
  205. border: #c2c2c2 1px solid;
  206. }
  207. .clean-save{
  208. background-color: #fff;
  209. display: flex;
  210. .clean,.save{
  211. width: 50%;
  212. text-align: center;
  213. color: #252525;
  214. line-height: 40px;
  215. }
  216. .clean,.save{
  217. border:#c2c2c2 1px solid;
  218. display: flex;
  219. justify-content: center;
  220. img{
  221. margin-right: 4px;
  222. }
  223. }
  224. }
  225. }
  226. </style>