signature.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <scroll-view scroll-y="false">
  3. <cu-custom bgColor="bg-blue" :isBack="true">
  4. <block slot="backText">电子签名</block>
  5. <block slot="content"></block>
  6. <block slot="right">
  7. <view class="flex justify-center">
  8. <button @click="paint" class="margin-top-ssm cu-btn round line-blue text-white ">手写签名</button>
  9. </view>
  10. </block>
  11. </cu-custom>
  12. <form class="cu-list menu margin-bottom-xl shadow-lg">
  13. <!-- <view class="cu-form-group">
  14. <view class="action text-black">
  15. 手写签名
  16. </view>
  17. <view class="grid col-4 grid-square flex-sub cont">
  18. <button class='cu-btn bg-green shadow' @click="paint">手写签名</button>
  19. </view>
  20. </view> -->
  21. <view class="cu-form-group">
  22. <view class="action" style="color: #101010;">
  23. 签名上传
  24. </view>
  25. <view class="grid col-4 grid-square flex-sub cont margin-top">
  26. <view class="bg-img" v-for="(item,index) in qmimgList" :key="index" @tap="ChooseImage(2)" :data-url="qmimgList[index]">
  27. <image :src="qmimgList[index]" mode="aspectFill"></image>
  28. <!-- <view class="cu-tag bg-red" @tap.stop="qmDelImg" :data-index="index">
  29. <text class='cuIcon-close'></text>
  30. </view> -->
  31. </view>
  32. <view class="solids margin-top" @tap="ChooseImage(2)" v-if="qmimgList.length<1">
  33. <text class='cuIcon-cameraadd'></text>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="cu-form-group">
  38. <view class="action " style="color: #101010;">
  39. 签章上传
  40. </view>
  41. <view class="grid col-4 grid-square flex-sub cont margin-top">
  42. <view class="bg-img" v-for="(item,index) in qzimgList" :key="index" @tap="ChooseImage(3)" :data-url="qzimgList[index]">
  43. <image :src="qzimgList[index]" mode="aspectFill"></image>
  44. <!-- <view class="cu-tag bg-red" @tap.stop="qzDelImg" :data-index="index">
  45. <text class='cuIcon-close'></text>
  46. </view> -->
  47. </view>
  48. <view class="solids margin-top" @tap="ChooseImage(3)" v-if="qzimgList.length<1">
  49. <text class='cuIcon-cameraadd'></text>
  50. </view>
  51. </view>
  52. </view>
  53. </form>
  54. <!-- <view class="cu-modal" :class="modalName=='Image'?'show':''">
  55. <view class="cu-dialog">
  56. <view class="cu-bar bg-white justify-end">
  57. <view class="content">请在绿色区域手写签名</view>
  58. <view class="action" @tap="modalName=''">
  59. <text class="cuIcon-close text-red"></text>
  60. </view>
  61. </view>
  62. <view class="padding-xl" style="height: 600rpx;">
  63. <canvas style="border: 1px solid #39B54A;height: 100%;width: 100%;" canvas-id="mycanvas" @touchmove='move' @touchstart='start($event)' @touchend='end'
  64. @touchcancel='cancel' @longtap='tap' disable-scroll='true' @error='error'>
  65. </canvas>
  66. </view>
  67. <view class="cu-bar bg-white justify-end">
  68. <view class="action">
  69. <button class="cu-btn line-green text-green" @click="clearClick">清空</button>
  70. <button class="cu-btn bg-green margin-left" @click="finish">确定</button>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. -->
  76. </scroll-view>
  77. </template>
  78. <script>
  79. import config from "../../../core/api.js"
  80. export default {
  81. data() {
  82. return {
  83. qmimgList:[],
  84. qzimgList:[],
  85. userInfo:"",
  86. modalName:"",
  87. baseOrPath:true
  88. };
  89. },
  90. onLoad() {
  91. },
  92. onShow() {
  93. var userInfo = uni.getStorageSync("userInfo")
  94. if(userInfo!=null){
  95. this.userInfo=userInfo;
  96. if(userInfo.signature!='null' && userInfo.signature!=null){
  97. this.qmimgList=[];
  98. this.qmimgList.push(userInfo.signature)
  99. }
  100. if(userInfo.signaturepreview!='null' && userInfo.signaturepreview!=null){
  101. this.qzimgList=[];
  102. this.qzimgList.push(userInfo.signaturepreview);
  103. }
  104. }
  105. },
  106. methods: {
  107. changeqz(){
  108. var that=this;
  109. var token =uni.getStorageSync("token");
  110. var url = config.api;
  111. uni.uploadFile({
  112. url:url+ '/app/updateSignaturepreview',
  113. filePath: that.qzimgList[0],
  114. name: 'file',
  115. header:{"Authorization": token},
  116. formData:{
  117. "userId":this.userInfo.id,
  118. },
  119. success: function (uploadFileRes) {
  120. var data = JSON.parse(uploadFileRes.data);
  121. if(data.result=="1"){
  122. uni.setStorageSync("userInfo",data.data);
  123. that.qzimgList=[];
  124. that.qzimgList.push(data.data.signaturepreview);
  125. that.userInfo.signaturepreview = data.data.signaturepreview
  126. that.$prompt.none("更新成功");
  127. }
  128. }
  129. });
  130. },
  131. paint(){
  132. uni.navigateTo({
  133. url:"paint/paint"
  134. })
  135. },
  136. ChooseImage(e) {
  137. var that=this;
  138. uni.chooseImage({
  139. count: 1, //默认9
  140. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  141. sourceType: ['album'], //从相册选择
  142. success: (res) => {
  143. if(e==2){
  144. that.baseOrPath=true;
  145. that.qmimgList=[];
  146. that.qmimgList = res.tempFilePaths;
  147. that.saveSignature();
  148. }else if(e==3){
  149. that.qzimgList=[];
  150. that.qzimgList = res.tempFilePaths;
  151. that.changeqz();
  152. }
  153. }
  154. });
  155. },
  156. qmViewImage(e) {
  157. uni.previewImage({
  158. urls: this.qmimgList,
  159. current: e.currentTarget.dataset.url,
  160. });
  161. },
  162. qmDelImg(e) {
  163. uni.showModal({
  164. title: '提示',
  165. content: '确定要删除吗',
  166. cancelText: '取消',
  167. confirmText: '确定',
  168. success: res => {
  169. if (res.confirm) {
  170. this.qmimgList.splice(e.currentTarget.dataset.index, 1)
  171. }
  172. }
  173. })
  174. },
  175. qzViewImage(e) {
  176. uni.previewImage({
  177. urls: this.qzimgList,
  178. current: e.currentTarget.dataset.url
  179. });
  180. },
  181. qzDelImg(e) {
  182. uni.showModal({
  183. title: '提示',
  184. content: '确定要删除吗',
  185. cancelText: '取消',
  186. confirmText: '确定',
  187. success: res => {
  188. if (res.confirm) {
  189. this.qzimgList.splice(e.currentTarget.dataset.index, 1)
  190. }
  191. }
  192. })
  193. },
  194. saveSignature(){
  195. var that =this;
  196. var url = config.api;
  197. var token =uni.getStorageSync("token");
  198. uni.uploadFile({
  199. url: url+'/app/updateSignature',
  200. filePath: that.qmimgList[0],
  201. name: 'file',
  202. header:{"Authorization": token},
  203. formData:{
  204. "userId":this.userInfo.id,
  205. },
  206. success: function (uploadFileRes) {
  207. var data = JSON.parse(uploadFileRes.data);
  208. if(data.result=="1"){
  209. uni.setStorageSync("userInfo",data.data);
  210. that.qmimgList=[];
  211. that.qmimgList.push(data.data.signature);
  212. that.userInfo.signature =data.data.signature ;
  213. that.$prompt.none("更新成功");
  214. }
  215. }
  216. });
  217. }
  218. }
  219. }
  220. </script>
  221. <style>
  222. .cu-form-group .title {
  223. min-width: calc(4em + 15px);
  224. }
  225. .cont{
  226. display: flex;
  227. flex-direction: row;
  228. align-items: center;
  229. justify-content: flex-end;
  230. }
  231. </style>