signature.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <view class="sign">
  3. <ujp-navbar title="签字"></ujp-navbar>
  4. <p>请在下方空白区域使用正楷字体进行电子签名</p>
  5. <view class="signature">
  6. <l-signature
  7. disableScroll ref="signatureRef" :penColor="penColor" :penSize="penSize"
  8. :openSmooth="openSmooth"></l-signature>
  9. </view>
  10. <view class="clean-save">
  11. <view class="clean" @click="onClick('clear')">
  12. <img src="../../../assets/img/riLine-eraser-line.svg" alt="">
  13. <view class="">
  14. 清除
  15. </view>
  16. </view>
  17. <view class="save" @click="onClick('save')">
  18. <img src="../../../assets/img/riLine-eraser-line.svg" alt="">
  19. <view class="">
  20. 保存并提交
  21. </view>
  22. </view>
  23. </view>
  24. <view v-if="info&&info.signUrl" style="margin-top: 20px;">使用上一次签字</view>
  25. <img :src="info.signUrl" v-if="info&&info.signUrl" style="width: 100%;border: 1px solid;">
  26. <button v-if="info" :class="{
  27. submit:info.signUrl,
  28. submitNo:!info.signUrl
  29. }" @click="submit()">提交确认单</button>
  30. </view>
  31. </template>
  32. <script>
  33. import LSignature from '@/components/l-signature/l-signature.vue'
  34. import * as API from '@/apis/finance.js'
  35. import * as API_Common from '@/apis/common.js'
  36. import {
  37. parseUnixTime,
  38. } from '@/utils'
  39. export default {
  40. data() {
  41. return {
  42. init:true,
  43. info: null,
  44. detailList:null,
  45. penColor: '',
  46. penSize: 5,
  47. url: '',
  48. suburl: '',
  49. openSmooth: true,
  50. nowTime:"",
  51. serverUrl: "",
  52. token: "",
  53. uuid:"",
  54. }
  55. },onLoad(op){
  56. //this.userInfo=this.carhelp.getPersonInfo()
  57. this.uuid=op.uuid;
  58. this.id=op.id
  59. // alert(this.carhelp.getToken({
  60. // jp_identity:
  61. // }))
  62. },
  63. onReady() {
  64. this.getInfo()
  65. },
  66. methods: {
  67. //上传图片
  68. uploadpic() {
  69. uni.showLoading({
  70. title: "图片上传中",
  71. mask: true,
  72. })
  73. var formData = {
  74. "photoName":"signature.png",
  75. "photoBase64Data": this.url
  76. }
  77. // formData.append('photoName', '1.jpg');
  78. // formData.append('photoBase64Data', this.url);
  79. API_Common.uploadBase64Json(formData).then(response => {
  80. //this.suburl=response.data;
  81. this.info.status=0;
  82. this.info.signUrl=response.data;
  83. //this.$emit("signsubmit",0,this.suburl)
  84. this.submitFrom()
  85. }).catch(error => {
  86. uni.hideLoading()
  87. uni.showModal({
  88. title:"提示",
  89. content:error,
  90. showCancel:false
  91. })
  92. })
  93. },
  94. submit(){
  95. if(this.info.signUrl){
  96. this.submitFrom()
  97. }else{
  98. uni.showToast({
  99. title: "请签字后提交"
  100. })
  101. }
  102. },
  103. submitFrom(){
  104. uni.showLoading({
  105. title: "提交中...",
  106. mask: true,
  107. })
  108. //this.info.status=5;
  109. //var str=JSON.stringify();
  110. API.applyWithdrawByAccounting({
  111. record:this.info,
  112. detailList:this.detailList
  113. }).then((res) => {
  114. this.carhelp.set("withdrawRecord",{
  115. uuid:this.uuid,
  116. })
  117. this.id=res.data;
  118. uni.hideLoading()
  119. uni.redirectTo({
  120. url:"/pagesFinance/user/applyResult?value="+this.info.applicationAmount
  121. })
  122. }).catch(error => {
  123. uni.hideLoading()
  124. uni.showModal({
  125. title:"提示",
  126. content:error,
  127. showCancel:false
  128. })
  129. })
  130. },
  131. getBase64(url,callback){
  132. //通过构造函数来创建的 img 实例,在赋予 src 值后就会立刻下载图片,相比 createElement() 创建 <img> 省去了 append(),也就避免了文档冗余和污染
  133. var Img = new Image(),
  134. dataURL='';
  135. Img.src=url;
  136. Img.onload=function(){ //要先确保图片完整获取到,这是个异步事件
  137. var canvas = document.createElement("canvas"), //创建canvas元素
  138. width=Img.width, //确保canvas的尺寸和图片一样
  139. height=Img.height;
  140. canvas.width=width;
  141. canvas.height=height;
  142. canvas.getContext("2d").drawImage(Img,0,0,width,height); //将图片绘制到canvas中
  143. dataURL=canvas.toDataURL('image/jpeg'); //转换图片为dataURL
  144. callback?callback(dataURL):null; //调用回调函数
  145. };
  146. },
  147. getInfo(){
  148. uni.showLoading({
  149. title: "加载中",
  150. mask: true,
  151. })
  152. API.getWithdrawInfoByAccounting(this.id).then((res) => {
  153. this.info=res.data.record
  154. this.detailList=res.data.detailList
  155. uni.hideLoading()
  156. }).catch(error => {
  157. uni.showToast({
  158. title: error
  159. })
  160. })
  161. },
  162. onClick(type) {
  163. this.url =""
  164. if(type == 'openSmooth') {
  165. this.openSmooth = !this.openSmooth
  166. return
  167. }
  168. if (type == 'save') {
  169. this.$refs.signatureRef.canvasToTempFilePath({
  170. success: (res) => {
  171. // 是否为空画板 无签名
  172. if(res.isEmpty){
  173. this.url ="";
  174. }else{
  175. this.url = res.tempFilePath
  176. console.log(this.url)
  177. // 生成图片的临时路径
  178. // app | H5 | 微信小程序 生成的是base64
  179. //this.uploadpic()
  180. uni.showLoading({
  181. title: '上传中'
  182. });
  183. this.token=this.carhelp.getToken();
  184. this.serverUrl=process.car.BASE_URL;
  185. var time= "";//parseUnixTime(new Date(), '{y}{m}{d}-{h}-{i}');
  186. uni.request({
  187. url: this.serverUrl + "/uploadBase64Json",
  188. method: "POST",
  189. header: {
  190. Authorization: this.token
  191. },
  192. data: {
  193. "photoName":"signature"+time+".png",
  194. "photoBase64Data": this.url
  195. },
  196. success: (res) => {
  197. uni.hideLoading();
  198. console.log(res)
  199. if(res.data.result){
  200. uni.showToast({
  201. title: '签名保存成功!',
  202. duration: 2000
  203. });
  204. this.info.status=0;
  205. this.info.signUrl=res.data.data;
  206. //this.$emit("signsubmit",0,this.suburl)
  207. this.submitFrom()
  208. }
  209. else{
  210. uni.showToast({
  211. title: '签名保存失败!'+ JSON.stringify(res),
  212. duration: 2000
  213. });
  214. }
  215. }
  216. })
  217. }
  218. }
  219. })
  220. return
  221. }
  222. if (this.$refs.signatureRef)
  223. this.$refs.signatureRef[type]()
  224. }
  225. }
  226. }
  227. </script>
  228. <style lang="scss" scoped>
  229. .sign{
  230. margin: 32rpx 16rpx ;
  231. font-weight: bold;
  232. line-height: 20px;
  233. p{
  234. color: rgba(16, 16, 16, 1);
  235. }
  236. .signature{
  237. background-color: #fff;
  238. margin-top: 8px;
  239. height: 160px;
  240. border: #c2c2c2 1px solid;
  241. }
  242. .clean-save{
  243. background-color: #fff;
  244. display: flex;
  245. .clean,.save{
  246. width: 50%;
  247. text-align: center;
  248. color: #252525;
  249. line-height: 40px;
  250. }
  251. .clean,.save{
  252. border:#c2c2c2 1px solid;
  253. display: flex;
  254. justify-content: center;
  255. img{
  256. margin-right: 4px;
  257. }
  258. }
  259. }
  260. }
  261. .submit{
  262. border-radius: 8px;
  263. background-color: rgba(24, 90, 198, 1);
  264. color: rgba(255, 255, 255, 1);
  265. font-size: 16px;
  266. line-height: 44px;
  267. margin: 0 16px;
  268. position: fixed;
  269. bottom: 12px;
  270. left: 0;
  271. right: 0;
  272. }
  273. .submitNo{
  274. border-radius: 8px;
  275. background-color: #185ac6a8;
  276. color: rgba(255, 255, 255, 1);
  277. font-size: 16px;
  278. line-height: 44px;
  279. margin: 0 16px;
  280. position: fixed;
  281. bottom: 12px;
  282. left: 0;
  283. right: 0;
  284. }
  285. </style>