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

195 lines
3.9 KiB

5 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>
  38. </template>
  39. <script>
  40. import canvasDrag from "@/components/canvas-drag/index";
  41. import setData from "@/components/canvas-drag/setData.js";
  42. export default {
  43. components: {
  44. canvasDrag
  45. },
  46. mixins : [setData],
  47. data() {
  48. return {
  49. id : 0,
  50. detail : {},
  51. height: 750,
  52. width: 700,
  53. ctx : null,
  54. imagePath : 0,
  55. }
  56. },
  57. onLoad({id}) {
  58. this.id = id
  59. this.getDetail()
  60. },
  61. onShow() {
  62. this.initCanvas()
  63. this.syntheticSignature()
  64. },
  65. methods: {
  66. // 获取合同内容
  67. getDetail(){
  68. let data = {
  69. contractId: this.id
  70. }
  71. if (uni.getStorageSync('token')) {
  72. // data.token = uni.getStorageSync('token')
  73. }
  74. this.$api('queryContracById', data, res => {
  75. if (res.code == 200) {
  76. this.detail = res.result
  77. }
  78. })
  79. },
  80. initCanvas() {
  81. this.ctx = uni.createCanvasContext("mycanvas")
  82. },
  83. // 去签名
  84. toSignature(){
  85. uni.navigateTo({
  86. url: `/pages_order/contract/electronicSignature?id=${this.id}&signature=1`
  87. })
  88. },
  89. // 导出合同
  90. onExportJSON() {
  91. uni.showLoading({
  92. title: '保存中...'
  93. })
  94. this.$refs.canvasRef.exportFun().then(image => {
  95. console.log(image);
  96. uni.hideLoading()
  97. // this.imagePath = image
  98. uni.previewImage({
  99. urls: [image],
  100. current: 0,
  101. })
  102. }).catch(e => {
  103. uni.hideLoading()
  104. console.error(e);
  105. });
  106. },
  107. /**
  108. * 导入合同
  109. */
  110. onChangeBgImage() {
  111. let self = this
  112. wx.chooseImage({
  113. success: res => {
  114. uni.getImageInfo({
  115. src: res.tempFilePaths[0],
  116. success: image => {
  117. let allwh = image.height + image.width
  118. let imgw = (image.width / allwh).toFixed(2)
  119. let imgh = (image.height / allwh).toFixed(2)
  120. self.height = imgh * Math.ceil(this.width / imgw)
  121. // this.width = image.width
  122. // this.height = image.height
  123. self.$nextTick(() => {
  124. this.$refs.canvasRef.changeBgImage(image.path)
  125. // this.ctx.drawImage(image.path, 0, 0, this.ctx.width, this.ctx.height)
  126. // this.ctx.stroke();
  127. // this.ctx.draw(false, () => {
  128. // wx.canvasToTempFilePath({
  129. // canvasId: 'mycanvas',
  130. // success: res => {
  131. // // this.imagePath = res.tempFilePath
  132. // uni.previewImage({
  133. // urls: [res.tempFilePath],
  134. // current: 0,
  135. // })
  136. // },
  137. // fail: e => {
  138. // }
  139. // }, this);
  140. // });
  141. })
  142. }
  143. })
  144. }
  145. });
  146. },
  147. // 合成签名
  148. syntheticSignature(){
  149. let url = uni.getStorageSync('electronicSignature')
  150. if(!url) return
  151. uni.removeStorageSync('electronicSignature')
  152. this.setData({
  153. graph: {
  154. w: 100,
  155. h: 50,
  156. x : 0,
  157. y : 0,
  158. type: 'image',
  159. url,
  160. permitSelected : true,
  161. }
  162. });
  163. // this.$nextTick(() => {
  164. // this.onExportJSON()
  165. // })
  166. },
  167. }
  168. }
  169. </script>
  170. <style scoped lang="scss">
  171. .page{
  172. .mycanvas{
  173. background-color: #fff;
  174. }
  175. }
  176. </style>