signContract.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <view class="content">
  3. <!-- <view class="content1">
  4. <view style='width:70px'>付款方式</view>
  5. <u-radio-group v-model="dataDetails.advanceFreightService" placement="row">
  6. <u-radio :customStyle="radioCustomStyle" v-for="(item, index) in radiolist1" :key="index"
  7. :label="item.name" :name="item.name" @change="radioChange">
  8. </u-radio>
  9. </u-radio-group>
  10. </view> -->
  11. <view class="content2">
  12. <view class="title">
  13. 合同摘要
  14. </view>
  15. <view class='row-between'>
  16. <view class="gray">发货单位</view>
  17. <view class="">{{dataDetails.compName?dataDetails.compName:'个人货主'}}</view>
  18. </view>
  19. <view class='row-between'>
  20. <view class="gray">发货地</view>
  21. <view class="place">
  22. {{dataDetails.sendPrivate}}{{dataDetails.sendCity}}{{dataDetails.sendArea}}{{dataDetails.sendDetailedAddress}}
  23. </view>
  24. </view>
  25. <view class='row-between'>
  26. <view class="gray">卸货地</view>
  27. <view class=" place">
  28. {{dataDetails.unloadPrivate}}{{dataDetails.unloadCity}}{{dataDetails.unloadArea}}{{dataDetails.unloadDetailedAddress}}
  29. </view>
  30. </view>
  31. <view class='row-between'>
  32. <view class="gray">货名</view>
  33. <view class="">{{dataDetails.goodsName}}</view>
  34. </view>
  35. <view class='row-between'>
  36. <view class="gray">距离</view>
  37. <view class="">约{{dataDetails.distance}}公里</view>
  38. </view>
  39. <view class='row-between'>
  40. <view class="gray">运费</view>
  41. <view class="">{{dataDetails.freight}}{{dataDetails.illingMethod==0?'元/吨':'元/车'}}</view>
  42. <!-- <view class="flex"><input type="text" placeholder="请输入运费" v-model="dataDetails.freight"
  43. class="text-align-right yf-input">{{dataDetails.freight}}元/车</view> -->
  44. </view>
  45. </view>
  46. <view class="wrapper content3">
  47. <view class="qm-row">
  48. <view class="handTitle">手写签名</view>
  49. <image src="@/static/xiangpica@2x.png" mode="widthFix" @click="retDraw" class="retDraw-image"></image>
  50. <!-- <button @click="retDraw" class="delBtn">重写</button> -->
  51. </view>
  52. <view class="handCenter">
  53. <canvas class="handWriting" :disable-scroll="true" @touchstart="uploadScaleStart"
  54. @touchmove="uploadScaleMove" canvas-id="handWriting"></canvas>
  55. </view>
  56. <view class="handRight">
  57. </view>
  58. <view class="handBtn">
  59. <!-- <image @click="selectColorEvent('black','#1A1A1A')"
  60. :src="selectColor === 'black' ? '/static/other/color_black_selected.png' : '/static/other/color_black.png'"
  61. :class="[selectColor === 'black' ? 'color_select' : '', 'black-select']"></image>
  62. <image @click="selectColorEvent('red','#ca262a')"
  63. :src="selectColor === 'red' ? '/static/other/color_red_selected.png' : '/static/other/color_red.png'"
  64. :class="[selectColor === 'red' ? 'color_select' : '', 'black-select']"></image> -->
  65. <!-- <button @click="saveCanvasAsImg" class="saveBtn">保存</button> -->
  66. <view @click="submit" class="saveBtn">提交</view>
  67. <!-- <button @click="previewCanvasImg" class="previewBtn">预览</button> -->
  68. <!-- <button @click="subCanvas" class="subBtn">完成</button> -->
  69. </view>
  70. </view>
  71. <u-toast ref="uToast"></u-toast>
  72. </view>
  73. </template>
  74. <script>
  75. var that;
  76. import uploadImage from '@/components/ossutil/uploadFile.js';
  77. export default {
  78. data() {
  79. return {
  80. isScaleStart: false,
  81. radioCustomStyle: {
  82. margin: '0 0 0 10rpx'
  83. },
  84. canvasName: 'handWriting',
  85. ctx: '',
  86. startX: null,
  87. startY: null,
  88. canvasWidth: 0,
  89. canvasHeight: 0,
  90. selectColor: 'black',
  91. lineColor: '#1A1A1A', // 颜色
  92. lineSize: 5, // 笔记倍数
  93. value: true,
  94. dataDetails: {},
  95. radiolist1: [{
  96. name: '平台垫付运费',
  97. disabled: false
  98. },
  99. {
  100. name: '无需平台垫付运费',
  101. disabled: false
  102. },
  103. ],
  104. };
  105. },
  106. onLoad(options) {
  107. that = this
  108. console.log(options)
  109. this.dataDetails = options
  110. this.dataDetails.advanceFreightService = '平台垫付运费'
  111. this.ctx = uni.createCanvasContext("handWriting");
  112. this.$nextTick(() => {
  113. uni.createSelectorQuery().select('.handCenter').boundingClientRect(rect => {
  114. this.canvasWidth = rect.width;
  115. this.canvasHeight = rect.height;
  116. /* 将canvas背景设置为 白底,不设置 导出的canvas的背景为透明 */
  117. this.setCanvasBg('#fff');
  118. })
  119. .exec();
  120. });
  121. },
  122. methods: {
  123. submit() {
  124. if (!that.isScaleStart) {
  125. that.$refs.uToast.show({
  126. type: 'error',
  127. message: "手写签名不能为空!",
  128. })
  129. return
  130. }
  131. // if (uni.$u.test.isEmpty(that.dataDetails.freight)) {
  132. // that.$refs.uToast.show({
  133. // type: 'error',
  134. // message: "运费不能为空!",
  135. // })
  136. // return
  137. // }
  138. uni.canvasToTempFilePath({
  139. canvasId: 'handWriting',
  140. fileType: 'png',
  141. quality: 1, //图片质量
  142. success(res) {
  143. console.log(res.tempFilePath, 'canvas生成图片地址');
  144. uploadImage('image', res.tempFilePath, 'appData/',
  145. result => {
  146. // 上传成功
  147. console.log('图片地址', result)
  148. that.dataDetails.cargoOwnerAutograph = result
  149. uni.showLoading({
  150. title: '加载中',
  151. mask: true
  152. })
  153. that.$request.baseRequest('get', '/orderInfo/setPdf', that.dataDetails).then(res => {
  154. if (res.code == 200) {
  155. debugger
  156. // that.contractSrc = res.data
  157. // uni.downloadFile({
  158. // url: res.data,
  159. // success: function(res) {
  160. // var filePath = res.tempFilePath;
  161. // uni.openDocument({
  162. // filePath: filePath,
  163. // showMenu: true,
  164. // success: function(res) {
  165. // console.log('打开文档成功');
  166. // }
  167. // });
  168. // }
  169. // });
  170. // this.$refs.uToast.show({
  171. // type: 'success',
  172. // message: "提交成功",
  173. // complete() {
  174. // that.upCallback({
  175. // size: 10,
  176. // num: 1
  177. // })
  178. // }
  179. // })
  180. }
  181. })
  182. .catch(res => {
  183. uni.$u.toast(res.message);
  184. });
  185. }
  186. )
  187. }
  188. });
  189. },
  190. // change(e){
  191. // if(this.value){
  192. // this.$set(this.dataDetails,'advanceFreightService',1)
  193. // }else{
  194. // this.$set(this.dataDetails,'advanceFreightService',0)
  195. // }
  196. // },
  197. // 笔迹开始
  198. uploadScaleStart(e) {
  199. this.isScaleStart = true
  200. this.startX = e.changedTouches[0].x
  201. this.startY = e.changedTouches[0].y
  202. //设置画笔参数
  203. //画笔颜色
  204. this.ctx.setStrokeStyle(this.lineColor)
  205. //设置线条粗细
  206. this.ctx.setLineWidth(this.lineSize)
  207. //设置线条的结束端点样式
  208. this.ctx.setLineCap("round") //'butt'、'round'、'square'
  209. //开始画笔
  210. this.ctx.beginPath()
  211. },
  212. // 笔迹移动
  213. uploadScaleMove(e) {
  214. //取点
  215. let temX = e.changedTouches[0].x
  216. let temY = e.changedTouches[0].y
  217. //画线条
  218. this.ctx.moveTo(this.startX, this.startY)
  219. this.ctx.lineTo(temX, temY)
  220. this.ctx.stroke()
  221. this.startX = temX
  222. this.startY = temY
  223. this.ctx.draw(true)
  224. },
  225. /**
  226. * 重写
  227. */
  228. retDraw() {
  229. this.ctx.clearRect(0, 0, 700, 730);
  230. this.ctx.draw();
  231. //设置canvas背景
  232. this.setCanvasBg('#fff');
  233. },
  234. /**
  235. * @param {Object} str
  236. * @param {Object} color
  237. * 选择颜色
  238. */
  239. selectColorEvent(str, color) {
  240. this.selectColor = str;
  241. this.lineColor = color;
  242. },
  243. //完成
  244. subCanvas() {
  245. uni.canvasToTempFilePath({
  246. canvasId: 'handWriting',
  247. fileType: 'png',
  248. quality: 1, //图片质量
  249. success(res) {
  250. // console.log(res.tempFilePath, 'canvas生成图片地址');
  251. uni.showToast({
  252. title: '以保存'
  253. });
  254. //保存到系统相册
  255. uni.saveImageToPhotosAlbum({
  256. filePath: res.tempFilePath,
  257. success(res) {
  258. uni.showToast({
  259. title: '已成功保存到相册',
  260. duration: 2000
  261. });
  262. }
  263. });
  264. }
  265. });
  266. },
  267. //保存到相册
  268. saveCanvasAsImg() {
  269. uni.canvasToTempFilePath({
  270. canvasId: 'handWriting',
  271. fileType: 'png',
  272. quality: 1, //图片质量
  273. success(res) {
  274. console.log(res.tempFilePath, 'canvas生成图片地址');
  275. uni.saveImageToPhotosAlbum({
  276. filePath: res.tempFilePath,
  277. success(res) {
  278. uni.showToast({
  279. title: '已保存到相册',
  280. duration: 2000
  281. });
  282. }
  283. });
  284. }
  285. });
  286. },
  287. //预览
  288. previewCanvasImg() {
  289. uni.canvasToTempFilePath({
  290. canvasId: 'handWriting',
  291. fileType: 'jpg',
  292. quality: 1, //图片质量
  293. success(res) {
  294. uni.previewImage({
  295. urls: [res.tempFilePath] //预览图片 数组
  296. });
  297. }
  298. });
  299. },
  300. //设置canvas背景色 不设置 导出的canvas的背景为透明
  301. //@params:字符串 color
  302. setCanvasBg(color) {
  303. /* 将canvas背景设置为 白底,不设置 导出的canvas的背景为透明 */
  304. //rect() 参数说明 矩形路径左上角的横坐标,左上角的纵坐标, 矩形路径的宽度, 矩形路径的高度
  305. //这里是 canvasHeight - 4 是因为下边盖住边框了,所以手动减了写
  306. this.ctx.rect(0, 0, this.canvasWidth, this.canvasHeight - 4);
  307. // ctx.setFillStyle('red')
  308. this.ctx.setFillStyle(color);
  309. this.ctx.fill(); //设置填充
  310. this.ctx.draw(); //开画
  311. }
  312. }
  313. };
  314. </script>
  315. <style lang="scss" scoped>
  316. page {
  317. background: #fbfbfb;
  318. height: auto;
  319. }
  320. .content1 {
  321. background: white;
  322. border-radius: 20rpx;
  323. margin: 20rpx;
  324. padding: 30rpx 20rpx;
  325. display: flex;
  326. justify-content: space-between;
  327. .right {
  328. display: flex;
  329. }
  330. }
  331. .content2 {
  332. background: white;
  333. border-radius: 20rpx;
  334. margin: 20rpx;
  335. padding: 30rpx 20rpx;
  336. .title {
  337. font-size: 36rpx;
  338. font-weight: 700;
  339. margin-bottom: 20rpx;
  340. }
  341. .row-between {
  342. margin-bottom: 20rpx;
  343. }
  344. .left-text {
  345. margin-right: 20rpx;
  346. }
  347. .yf-input {
  348. padding-right: 10rpx;
  349. }
  350. }
  351. .content3 {
  352. background: white;
  353. border-radius: 20rpx;
  354. margin: 20rpx;
  355. padding: 30rpx 20rpx;
  356. }
  357. .place {
  358. width: 80%;
  359. text-align: right;
  360. }
  361. .handCenter {
  362. border: 4rpx dashed #e9e9e9;
  363. overflow: hidden;
  364. box-sizing: border-box;
  365. height: 500rpx;
  366. }
  367. .handWriting {
  368. background: #F9F9FB;
  369. width: 100%;
  370. height: 100%;
  371. }
  372. .handRight {
  373. display: inline-flex;
  374. align-items: center;
  375. }
  376. .handCenter {
  377. border: 4rpx dashed #e9e9e9;
  378. flex: 5;
  379. overflow: hidden;
  380. box-sizing: border-box;
  381. }
  382. .handTitle {
  383. font-size: 36rpx;
  384. color: #666;
  385. font-weight: 700;
  386. color: #333333;
  387. margin-bottom: 20rpx;
  388. }
  389. .retDraw-image {
  390. width: 50rpx;
  391. }
  392. .qm-row {
  393. display: flex;
  394. justify-content: space-between;
  395. }
  396. .saveBtn {
  397. width: 80%;
  398. background: #2772FB;
  399. color: white;
  400. text-align: center;
  401. border-radius: 50rpx;
  402. padding: 20rpx;
  403. }
  404. .handBtn {
  405. display: flex;
  406. justify-content: center;
  407. }
  408. /*
  409. .wrapper {
  410. width: 100%;
  411. height: 95vh;
  412. margin: 30rpx 0;
  413. overflow: hidden;
  414. display: flex;
  415. align-content: center;
  416. flex-direction: row;
  417. justify-content: center;
  418. font-size: 28rpx;
  419. }
  420. .handBtn button {
  421. font-size: 28rpx;
  422. }
  423. .handBtn {
  424. height: 95vh;
  425. display: inline-flex;
  426. flex-direction: column;
  427. justify-content: space-between;
  428. align-content: space-between;
  429. flex: 1;
  430. }
  431. .delBtn {
  432. position: absolute;
  433. top: 250rpx;
  434. left: 0rpx;
  435. transform: rotate(90deg);
  436. color: #666;
  437. }
  438. .delBtn image {
  439. position: absolute;
  440. top: 13rpx;
  441. left: 25rpx;
  442. }
  443. .subBtn {
  444. position: absolute;
  445. bottom: 52rpx;
  446. left: -3rpx;
  447. display: inline-flex;
  448. transform: rotate(90deg);
  449. background: #008ef6;
  450. color: #fff;
  451. margin-bottom: 30rpx;
  452. text-align: center;
  453. justify-content: center;
  454. }
  455. .saveBtn {
  456. position: absolute;
  457. top: 375rpx;
  458. left: 0rpx;
  459. transform: rotate(90deg);
  460. color: #666;
  461. }
  462. .previewBtn {
  463. position: absolute;
  464. top: 500rpx;
  465. left: 0rpx;
  466. transform: rotate(90deg);
  467. color: #666;
  468. }
  469. .uploadBtn {
  470. position: absolute;
  471. top: 625rpx;
  472. left: 0rpx;
  473. transform: rotate(90deg);
  474. color: #666;
  475. }
  476. .black-select {
  477. width: 60rpx;
  478. height: 60rpx;
  479. position: absolute;
  480. top: 30rpx;
  481. left: 25rpx;
  482. }
  483. .black-select.color_select {
  484. width: 90rpx;
  485. height: 90rpx;
  486. top: 100rpx;
  487. left: 10rpx;
  488. }
  489. .red-select {
  490. width: 60rpx;
  491. height: 60rpx;
  492. position: absolute;
  493. top: 140rpx;
  494. left: 25rpx;
  495. }
  496. .red-select.color_select {
  497. width: 90rpx;
  498. height: 90rpx;
  499. top: 120rpx;
  500. left: 10rpx;
  501. } */
  502. </style>