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

240 lines
4.9 KiB

11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
  1. <template>
  2. <view class="page">
  3. <navbar title="电子合同"
  4. leftClick
  5. @leftClick="$utils.navigateBack"/>
  6. <view style="padding: 25rpx;">
  7. <canvas-drag ref="canvasRef"
  8. id="canvas-drag"
  9. :graph="graph"
  10. :width="width"
  11. :height="height"
  12. bgColor="#fff"
  13. enableUndo="true"></canvas-drag>
  14. <!-- <canvas
  15. canvas-id="mycanvas"
  16. class="mycanvas"
  17. v-if="!imagePath"
  18. :style="{height : height + 'rpx', width : width + 'rpx'}"
  19. disable-scroll="true"></canvas> -->
  20. <image :src="imagePath"
  21. v-if="imagePath"
  22. style="width: 700rpx;"
  23. mode="widthFix"></image>
  24. </view>
  25. <!-- <view class="uni-color-btn"
  26. @click.stop="onChangeBgImage">
  27. 导入合同
  28. </view> -->
  29. <view class="uni-color-btn"
  30. @click.stop="toSignature">
  31. 签名
  32. </view>
  33. <!-- <view class="uni-color-btn"
  34. @click.stop="onExportJSON">
  35. 保存合同
  36. </view> -->
  37. <view class="uni-color-btn"
  38. @click.stop="showPDF">
  39. 查看完整内容
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import canvasDrag from "../components/canvas-drag/index";
  45. import setData from "../components/canvas-drag/setData.js";
  46. export default {
  47. components: {
  48. canvasDrag
  49. },
  50. mixins : [setData],
  51. data() {
  52. return {
  53. id : 0,
  54. detail : {},
  55. height: 750,
  56. width: 700,
  57. ctx : null,
  58. imagePath : 0,
  59. }
  60. },
  61. onLoad({id}) {
  62. this.id = id
  63. this.getDetail()
  64. },
  65. onShow() {
  66. this.initCanvas()
  67. this.syntheticSignature()
  68. },
  69. methods: {
  70. // 获取合同内容
  71. getDetail(){
  72. let data = {
  73. contractId: this.id
  74. }
  75. if (uni.getStorageSync('token')) {
  76. // data.token = uni.getStorageSync('token')
  77. }
  78. this.$api('queryContracById', data, res => {
  79. if (res.code == 200) {
  80. this.detail = res.result
  81. }
  82. })
  83. },
  84. showPDF(){
  85. uni.downloadFile({
  86. url : this.detail.contract,
  87. success : res => {
  88. uni.openDocument({
  89. filePath: res.tempFilePath,
  90. })
  91. }
  92. })
  93. },
  94. initCanvas() {
  95. this.ctx = uni.createCanvasContext("mycanvas")
  96. },
  97. // 去签名
  98. toSignature(){
  99. console.log('toSignature');
  100. uni.showModal({
  101. title: '签署前请熟知合同完整内容!',
  102. cancelText: '已知晓',
  103. confirmText: '查看完整内容',
  104. success : e => {
  105. if(e.confirm){
  106. this.showPDF()
  107. }else{
  108. uni.navigateTo({
  109. url: `/pages_order/contract/electronicSignature?id=${this.id}&signature=1`
  110. })
  111. }
  112. }
  113. })
  114. },
  115. // 导出合同
  116. onExportJSON() {
  117. uni.showLoading({
  118. title: '保存中...'
  119. })
  120. this.$refs.canvasRef.exportFun().then(image => {
  121. console.log(image);
  122. uni.hideLoading()
  123. // this.imagePath = image
  124. uni.previewImage({
  125. urls: [image],
  126. current: 0,
  127. })
  128. }).catch(e => {
  129. uni.hideLoading()
  130. console.error(e);
  131. });
  132. },
  133. /**
  134. * 导入合同
  135. */
  136. onChangeBgImage() {
  137. let self = this
  138. wx.chooseImage({
  139. success: res => {
  140. uni.getImageInfo({
  141. src: res.tempFilePaths[0],
  142. success: image => {
  143. let allwh = image.height + image.width
  144. let imgw = (image.width / allwh).toFixed(2)
  145. let imgh = (image.height / allwh).toFixed(2)
  146. self.height = imgh * Math.ceil(this.width / imgw)
  147. // this.width = image.width
  148. // this.height = image.height
  149. self.$nextTick(() => {
  150. this.$refs.canvasRef.changeBgImage(image.path)
  151. // this.ctx.drawImage(image.path, 0, 0, this.ctx.width, this.ctx.height)
  152. // this.ctx.stroke();
  153. // this.ctx.draw(false, () => {
  154. // wx.canvasToTempFilePath({
  155. // canvasId: 'mycanvas',
  156. // success: res => {
  157. // // this.imagePath = res.tempFilePath
  158. // uni.previewImage({
  159. // urls: [res.tempFilePath],
  160. // current: 0,
  161. // })
  162. // },
  163. // fail: e => {
  164. // }
  165. // }, this);
  166. // });
  167. })
  168. }
  169. })
  170. }
  171. });
  172. },
  173. // 合成签名
  174. syntheticSignature(){
  175. let url = uni.getStorageSync('electronicSignature')
  176. if(!url) return
  177. uni.removeStorageSync('electronicSignature')
  178. let graph = {}
  179. if(this.role){
  180. graph = JSON.parse(this.form.bossPosition)
  181. this.detail.bossImage = url
  182. this.detail.bossStatus = 1
  183. }else{
  184. graph = JSON.parse(this.form.employeePosition)
  185. this.detail.employeeImage = url
  186. this.detail.employeeStatus = 1
  187. }
  188. for(let k in graph){
  189. graph[k] = this.$utils.screenSystemInfoInt(graph[k]) - 0
  190. }
  191. this.setData({
  192. graph: {
  193. w: graph.w,
  194. h: graph.h,
  195. x : graph.x,
  196. y : graph.y,
  197. type: 'image',
  198. url,
  199. permitSelected : true,
  200. }
  201. });
  202. this.$nextTick(() => {
  203. this.onExportJSON()
  204. })
  205. },
  206. }
  207. }
  208. </script>
  209. <style scoped lang="scss">
  210. .page{
  211. .mycanvas{
  212. background-color: #fff;
  213. }
  214. }
  215. </style>