index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <<<<<<< HEAD
  3. <view class="signBox column-me">
  4. <!-- 这个是自定义的title-可根据自己封装的title的作为调整 -->
  5. <status-bar title="电子签名" :bgColor="null"></status-bar>
  6. <view class="topHint">请绘制清晰可辨的签名并保存</view>
  7. <canvas class="canvas flex1" :canvas-id="cid" :id="cid" @touchstart="touchstart" @touchmove="touchmove"
  8. @touchend="touchend" :disable-scroll="true"></canvas>
  9. <view class="btn margin-top10 margin-bottom10">
  10. <view class="cancelBtn" @click="reWrite">重写</view>
  11. <view class="saveBtn margin-left30" @click="save">保存</view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. export default {
  17. components: {},
  18. data() {
  19. return {
  20. line: [],
  21. radius: 0,
  22. taskId: '',
  23. //以下与签名有关参数
  24. dom: null,
  25. cid: 'canvas', //画布id
  26. Strokes: [],
  27. showCanvasDialog: false,
  28. canvasImg: '', //签名图片
  29. }
  30. },
  31. onLoad(e) {
  32. this.taskId = e.taskId
  33. },
  34. computed: {},
  35. mounted: function() {
  36. let that = this
  37. this.initCanvas()
  38. },
  39. methods: {
  40. initCanvas() {
  41. let that = this
  42. this.$nextTick(function() {
  43. this.dom = uni.createCanvasContext(this.cid, this);
  44. var query = wx.createSelectorQuery();
  45. query.select('#canvas').boundingClientRect();
  46. query.exec(function(res) {
  47. let widths = res[0].width
  48. let heights = res[0].height
  49. that.dom.rect(0, 0, widths, heights)
  50. that.dom.setFillStyle('#FFFFFF')
  51. that.dom.fill()
  52. that.dom.draw()
  53. })
  54. });
  55. },
  56. touchstart(e) {
  57. this.Strokes.push({
  58. imageData: null,
  59. style: {
  60. color: '#000000',
  61. lineWidth: '3',
  62. },
  63. points: [{
  64. x: e.touches[0].x,
  65. y: e.touches[0].y,
  66. type: e.type,
  67. }]
  68. })
  69. this.drawLine(this.Strokes[this.Strokes.length - 1], e.type);
  70. },
  71. touchmove(e) {
  72. this.Strokes[this.Strokes.length - 1].points.push({
  73. x: e.touches[0].x,
  74. y: e.touches[0].y,
  75. type: e.type,
  76. })
  77. this.drawLine(this.Strokes[this.Strokes.length - 1], e.type);
  78. },
  79. touchend(e) {
  80. if (this.Strokes[this.Strokes.length - 1].points.length < 2) { //当此路径只有一个点的时候
  81. this.Strokes.pop();
  82. }
  83. },
  84. drawLine(StrokesItem, type) {
  85. if (StrokesItem.points.length > 1) {
  86. this.dom.setLineCap('round')
  87. this.dom.setStrokeStyle(StrokesItem.style.color);
  88. this.dom.setLineWidth(StrokesItem.style.lineWidth);
  89. this.dom.moveTo(StrokesItem.points[StrokesItem.points.length - 2].x, StrokesItem.points[StrokesItem
  90. .points.length -
  91. 2].y);
  92. this.dom.lineTo(StrokesItem.points[StrokesItem.points.length - 1].x, StrokesItem.points[StrokesItem
  93. .points.length -
  94. 1].y);
  95. this.dom.stroke();
  96. this.dom.draw(true);
  97. }
  98. },
  99. //重写签名
  100. reWrite() {
  101. this.Strokes = [];
  102. this.dom.draw();
  103. this.initCanvas()
  104. },
  105. // 保存图片
  106. save() {
  107. let that = this
  108. uni.canvasToTempFilePath({
  109. canvasId: 'canvas',
  110. fileType: 'png',
  111. quality: 1, //图片质量
  112. success: function(res) {
  113. let imgs = [res.tempFilePath]
  114. that.$.upload_img(imgs, 0, res => {
  115. let imgUrl = res.data //签名图片
  116. let mediaUrl = that.$.get_data('mediaUrl') //采集图片
  117. if (that.$.isEmpty(mediaUrl)) {
  118. mediaUrl = ''
  119. }
  120. that.$.ajax("POST", "/customer/user/checkTask", {
  121. taskId: that.taskId,
  122. status: 1, //状态:1同意2拒绝
  123. signImage: imgUrl,
  124. userVideo: mediaUrl,
  125. }, (res) => {
  126. if (res.code === 1000) {
  127. that.$.ti_shi(res.message)
  128. setTimeout(() => {
  129. uni.$emit('signOk')
  130. that.$.back()
  131. }, 1000)
  132. } else {
  133. that.$.ti_shi(res.message)
  134. }
  135. });
  136. })
  137. },
  138. fail(e) {
  139. console.log(e)
  140. }
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style scoped lang="less">
  147. .signBox {
  148. position: relative;
  149. overflow: hidden;
  150. background-color: #F6F6F6;
  151. height: 100vh;
  152. width: 100vw;
  153. .canvas {
  154. width: 100%;
  155. background: #FFFFFF;
  156. }
  157. .topHint {
  158. width: 100%;
  159. height: 60rpx;
  160. line-height: 60rpx;
  161. font-size: 28rpx;
  162. color: #6D7984;
  163. text-align: center;
  164. background: ;
  165. }
  166. .btn {
  167. width: 100%;
  168. height: 132rpx;
  169. display: flex;
  170. align-items: center;
  171. justify-content: center;
  172. .saveBtn {
  173. width: 300rpx;
  174. height: 88rpx;
  175. line-height: 88rpx;
  176. background: #215AA0;
  177. border-radius: 20rpx;
  178. text-align: center;
  179. font-size: 32rpx;
  180. color: #FFFFFF;
  181. }
  182. .cancelBtn {
  183. width: 298rpx;
  184. height: 86rpx;
  185. line-height: 86rpx;
  186. background: #FFFFFF;
  187. border-radius: 20rpx;
  188. text-align: center;
  189. font-size: 32rpx;
  190. color: #202233;
  191. border: 1px solid #BBC4CC;
  192. }
  193. }
  194. }
  195. </style>
  196. =======
  197. <view>
  198. <signature :salaryId="salaryId" :showCanvas="showCanvas" @closeCanvas="closeCanvas"></signature>
  199. <uni-popup ref="popup" type="dialog">
  200. <uni-popup-dialog mode="input" message="成功消息" :duration="2000" :before-close="true" @close="close" @confirm="confirm"></uni-popup-dialog>
  201. </uni-popup>
  202. </view>
  203. </template>
  204. <script>
  205. import signature from './signMode/signMode.vue';
  206. export default {
  207. components: {
  208. signature
  209. },
  210. data() {
  211. return {
  212. //打开canvas绘制签名
  213. showCanvas: true,
  214. salaryId:'',
  215. //是否展示操作菜单
  216. completionSignPath: '' //签名
  217. }
  218. },
  219. onLoad: function(options) {
  220. this.salaryId=Number(options.id)
  221. console.log(options, 'options')
  222. },
  223. methods: {
  224. //隐藏canvas签名组件
  225. closeCanvas(e) {
  226. uni.navigateBack({ delta: 1 })
  227. // this.showCanvas = false;
  228. console.log(e,'eeee')
  229. if (e) {
  230. this.completionSignPath = e
  231. }
  232. },
  233. sign() {
  234. this.showCanvas = true;
  235. }
  236. }
  237. }
  238. </script>
  239. >>>>>>> d5d543f6014ac2bbe7c450bec75cf372ae8284be