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

273 lines
5.7 KiB

8 months ago
6 months ago
8 months ago
6 months ago
8 months ago
6 months ago
8 months ago
6 months ago
6 months ago
6 months ago
8 months ago
6 months ago
8 months ago
6 months ago
8 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 : Number(graph.y) + 0.062,
  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. if(res.code != 200){
  109. uni.showToast({
  110. title: res.result || '签署失败',
  111. icon:'none',
  112. })
  113. return
  114. }
  115. // uni.downloadFile({
  116. // url : res.result,
  117. // success : res => {
  118. // uni.openDocument({
  119. // filePath: res.tempFilePath,
  120. // })
  121. // }
  122. // })
  123. // return
  124. delete this.detail.createBy
  125. delete this.detail.createTime
  126. delete this.detail.updateBy
  127. delete this.detail.updateTime
  128. this.detail.contract = res.result
  129. this.$api('updateContract', this.detail)
  130. .then(res => {
  131. if(res.code == 200){
  132. uni.navigateBack(-1)
  133. }
  134. })
  135. },
  136. close() {
  137. let self = this
  138. uni.canvasToTempFilePath({
  139. canvasId: "mycanvas",
  140. success: (res) => {
  141. console.log(res.tempFilePath);
  142. const imagePath = res.tempFilePath;
  143. // uni.setStorageSync('electronicSignature', imagePath)
  144. // let o = this.options
  145. // uni.navigateBack(-1)
  146. self.$Oss.ossUpload(imagePath).then(url => {
  147. self.save(url)
  148. })
  149. },
  150. fail(error) {
  151. console.error("转化图片错误!", error)
  152. }
  153. });
  154. },
  155. initCanvas() {
  156. this.oc = uni.createCanvasContext("mycanvas");
  157. },
  158. ontouchstart(e) {
  159. this.points = []
  160. const startX = e.changedTouches[0].x;
  161. const startY = e.changedTouches[0].y;
  162. let startPoint = {
  163. X: startX,
  164. Y: startY,
  165. };
  166. this.points.push(startPoint);
  167. },
  168. touchmove(e) {
  169. let moveX = e.changedTouches[0].x;
  170. let moveY = e.changedTouches[0].y;
  171. let movePoint = {
  172. X: moveX,
  173. Y: moveY,
  174. };
  175. this.points.push(movePoint);
  176. let len = this.points.length;
  177. if (len >= 2) {
  178. this.draw(); //绘制路径
  179. }
  180. },
  181. draw() {
  182. if (this.points.length < 2) return;
  183. this.oc.beginPath();
  184. this.oc.moveTo(this.points[0].X, this.points[0].Y);
  185. // for (let i = 1; i < this.points.length; i++) {
  186. // let point = this.points[i];
  187. // this.oc.lineTo(point.X, point.Y);
  188. // }
  189. this.oc.lineTo(this.points[1].X, this.points[1].Y);
  190. this.points.shift()
  191. this.oc.setStrokeStyle('#000000');
  192. this.oc.setLineWidth(5);
  193. this.oc.setLineCap('round');
  194. this.oc.setLineJoin('round');
  195. this.oc.stroke();
  196. this.oc.draw(true);
  197. },
  198. //清空画布
  199. clear() {
  200. let that = this;
  201. uni.getSystemInfo({
  202. success: (res) => {
  203. let canvasw = res.windowWidth;
  204. let canvash = res.windowHeight;
  205. that.oc.clearRect(0, 0, canvasw, canvash);
  206. that.oc.draw(true);
  207. },
  208. });
  209. },
  210. }
  211. };
  212. </script>
  213. <style lang="scss" scoped>
  214. .contain {
  215. position: relative;
  216. .mycanvas {
  217. background-color: #fff;
  218. border-radius: 20rpx;
  219. }
  220. .electronic-contract{
  221. display: flex;
  222. justify-content: center;
  223. align-items: center;
  224. margin: 25rpx;
  225. }
  226. .crosswise{
  227. .title{
  228. writing-mode: vertical-lr; /* 垂直从上到下 */
  229. transform: skewY(180deg); /* 颠倒文本 */
  230. display: inline-block; /* 需要设置为内联块 */
  231. }
  232. }
  233. .btn-list {
  234. display: flex;
  235. padding: 20rpx;
  236. justify-content: space-around;
  237. .uni-color-btn {
  238. border-radius: 10rpx;
  239. margin: 0;
  240. padding: 20rpx 40rpx;
  241. }
  242. }
  243. }
  244. </style>