特易招,招聘小程序
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.

264 lines
5.5 KiB

5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
  1. <template>
  2. <div class="contain">
  3. <navbar
  4. title="电子签名"
  5. v-if="!crosswise"
  6. leftClick
  7. @leftClick="$utils.navigateBack"/>
  8. <view
  9. class="electronic-contract"
  10. :class="{crosswise}">
  11. <canvas
  12. canvas-id="mycanvas"
  13. class="mycanvas"
  14. :style="{height, width}"
  15. disable-scroll="true"
  16. @touchstart="ontouchstart"
  17. @touchmove="touchmove"></canvas>
  18. <view class="title"
  19. v-if="crosswise">
  20. 请旋转屏幕按文字方向开始签名
  21. </view>
  22. </view>
  23. <view class="btn-list">
  24. <view class="uni-color-btn" @click="clear">
  25. 清除
  26. </view>
  27. <view class="uni-color-btn" @click="close">
  28. 完成
  29. </view>
  30. </view>
  31. </div>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. oc: null,
  38. points: [], //路径点集合
  39. show: true,
  40. height : '350rpx',
  41. width : '700rpx',
  42. crosswise : false,
  43. options : {},
  44. detail : {},
  45. }
  46. },
  47. onReady() {
  48. this.open()
  49. },
  50. onLoad(options) {
  51. this.options = options
  52. },
  53. onShow() {
  54. this.initPM()
  55. this.getDetail()
  56. },
  57. methods: {
  58. // 获取合同内容
  59. getDetail(){
  60. let data = {
  61. contractId: this.options.id
  62. }
  63. if (uni.getStorageSync('token')) {
  64. // data.token = uni.getStorageSync('token')
  65. }
  66. this.$api('queryContracById', data, res => {
  67. if (res.code == 200) {
  68. this.detail = res.result
  69. }
  70. })
  71. },
  72. initPM(){
  73. if(!this.crosswise) return
  74. let info = uni.getSystemInfoSync();
  75. console.log(info.windowWidth);
  76. console.log(info.windowHeight);
  77. },
  78. open() {
  79. this.initCanvas();
  80. },
  81. async save(imagePath){
  82. let graph = {}, pageNo = 1;
  83. if(this.role){
  84. graph = JSON.parse(this.detail.bossPosition)
  85. this.detail.bossImage = imagePath
  86. this.detail.bossStatus = 1
  87. pageNo = this.detail.bossPage
  88. }else{
  89. graph = JSON.parse(this.detail.employeePosition)
  90. this.detail.employeeImage = imagePath
  91. this.detail.employeeStatus = 1
  92. pageNo = this.detail.employeePage
  93. }
  94. for(let k in graph){
  95. graph[k] = (parseFloat(graph[k]) / 700.0).toFixed(2)
  96. }
  97. let res = await this.$api('signPdf', {
  98. imageHeight : graph.h,
  99. imageWidth : graph.w,
  100. positionX : graph.x,
  101. positonY : graph.y,
  102. // pdfPath : this.detail.contract,
  103. // imagePath,
  104. pdfPath : 'https://augcl.oss-cn-guangzhou.aliyuncs.com/test/mytest.pdf',
  105. imagePath : 'https://augcl.oss-cn-guangzhou.aliyuncs.com/test/image.png',
  106. pageNo : parseInt(pageNo) + 1,
  107. })
  108. // uni.downloadFile({
  109. // url : res.result,
  110. // success : res => {
  111. // uni.openDocument({
  112. // filePath: res.tempFilePath,
  113. // })
  114. // }
  115. // })
  116. // return
  117. delete this.detail.createBy
  118. delete this.detail.createTime
  119. delete this.detail.updateBy
  120. delete this.detail.updateTime
  121. this.detail.contract = res.result
  122. this.$api('updateContract', this.detail)
  123. .then(res => {
  124. if(res.code == 200){
  125. uni.navigateBack(-1)
  126. }
  127. })
  128. },
  129. close() {
  130. let self = this
  131. uni.canvasToTempFilePath({
  132. canvasId: "mycanvas",
  133. success: (res) => {
  134. console.log(res.tempFilePath);
  135. const imagePath = res.tempFilePath;
  136. // uni.setStorageSync('electronicSignature', imagePath)
  137. // let o = this.options
  138. // uni.navigateBack(-1)
  139. self.$Oss.ossUpload(imagePath).then(url => {
  140. self.save(url)
  141. })
  142. },
  143. fail(error) {
  144. console.error("转化图片错误!", error)
  145. }
  146. });
  147. },
  148. initCanvas() {
  149. this.oc = uni.createCanvasContext("mycanvas");
  150. },
  151. ontouchstart(e) {
  152. this.points = []
  153. const startX = e.changedTouches[0].x;
  154. const startY = e.changedTouches[0].y;
  155. let startPoint = {
  156. X: startX,
  157. Y: startY,
  158. };
  159. this.points.push(startPoint);
  160. },
  161. touchmove(e) {
  162. let moveX = e.changedTouches[0].x;
  163. let moveY = e.changedTouches[0].y;
  164. let movePoint = {
  165. X: moveX,
  166. Y: moveY,
  167. };
  168. this.points.push(movePoint);
  169. let len = this.points.length;
  170. if (len >= 2) {
  171. this.draw(); //绘制路径
  172. }
  173. },
  174. draw() {
  175. if (this.points.length < 2) return;
  176. this.oc.beginPath();
  177. this.oc.moveTo(this.points[0].X, this.points[0].Y);
  178. // for (let i = 1; i < this.points.length; i++) {
  179. // let point = this.points[i];
  180. // this.oc.lineTo(point.X, point.Y);
  181. // }
  182. this.oc.lineTo(this.points[1].X, this.points[1].Y);
  183. this.points.shift()
  184. this.oc.setStrokeStyle('#000000');
  185. this.oc.setLineWidth(5);
  186. this.oc.setLineCap('round');
  187. this.oc.setLineJoin('round');
  188. this.oc.stroke();
  189. this.oc.draw(true);
  190. },
  191. //清空画布
  192. clear() {
  193. let that = this;
  194. uni.getSystemInfo({
  195. success: (res) => {
  196. let canvasw = res.windowWidth;
  197. let canvash = res.windowHeight;
  198. that.oc.clearRect(0, 0, canvasw, canvash);
  199. that.oc.draw(true);
  200. },
  201. });
  202. },
  203. }
  204. };
  205. </script>
  206. <style lang="scss" scoped>
  207. .contain {
  208. position: relative;
  209. .mycanvas {
  210. background-color: #fff;
  211. border-radius: 20rpx;
  212. }
  213. .electronic-contract{
  214. display: flex;
  215. justify-content: center;
  216. align-items: center;
  217. margin: 25rpx;
  218. }
  219. .crosswise{
  220. .title{
  221. writing-mode: vertical-lr; /* 垂直从上到下 */
  222. transform: skewY(180deg); /* 颠倒文本 */
  223. display: inline-block; /* 需要设置为内联块 */
  224. }
  225. }
  226. .btn-list {
  227. display: flex;
  228. padding: 20rpx;
  229. justify-content: space-around;
  230. .uni-color-btn {
  231. border-radius: 10rpx;
  232. margin: 0;
  233. padding: 20rpx 40rpx;
  234. }
  235. }
  236. }
  237. </style>