signContract.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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 =JSON.parse(options.obj)
  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. // that.contractSrc = res.data
  156. // uni.downloadFile({
  157. // url: res.data,
  158. // success: function(res) {
  159. // var filePath = res.tempFilePath;
  160. // uni.openDocument({
  161. // filePath: filePath,
  162. // showMenu: true,
  163. // success: function(res) {
  164. // console.log('打开文档成功');
  165. // }
  166. // });
  167. // }
  168. // });
  169. // this.$refs.uToast.show({
  170. // type: 'success',
  171. // message: "提交成功",
  172. // complete() {
  173. // that.upCallback({
  174. // size: 10,
  175. // num: 1
  176. // })
  177. // }
  178. // })
  179. }
  180. })
  181. .catch(res => {
  182. uni.$u.toast(res.message);
  183. });
  184. }
  185. )
  186. }
  187. });
  188. },
  189. // change(e){
  190. // if(this.value){
  191. // this.$set(this.dataDetails,'advanceFreightService',1)
  192. // }else{
  193. // this.$set(this.dataDetails,'advanceFreightService',0)
  194. // }
  195. // },
  196. // 笔迹开始
  197. uploadScaleStart(e) {
  198. this.isScaleStart = true
  199. this.startX = e.changedTouches[0].x
  200. this.startY = e.changedTouches[0].y
  201. //设置画笔参数
  202. //画笔颜色
  203. this.ctx.setStrokeStyle(this.lineColor)
  204. //设置线条粗细
  205. this.ctx.setLineWidth(this.lineSize)
  206. //设置线条的结束端点样式
  207. this.ctx.setLineCap("round") //'butt'、'round'、'square'
  208. //开始画笔
  209. this.ctx.beginPath()
  210. },
  211. // 笔迹移动
  212. uploadScaleMove(e) {
  213. //取点
  214. let temX = e.changedTouches[0].x
  215. let temY = e.changedTouches[0].y
  216. //画线条
  217. this.ctx.moveTo(this.startX, this.startY)
  218. this.ctx.lineTo(temX, temY)
  219. this.ctx.stroke()
  220. this.startX = temX
  221. this.startY = temY
  222. this.ctx.draw(true)
  223. },
  224. /**
  225. * 重写
  226. */
  227. retDraw() {
  228. this.ctx.clearRect(0, 0, 700, 730);
  229. this.ctx.draw();
  230. //设置canvas背景
  231. this.setCanvasBg('#fff');
  232. },
  233. /**
  234. * @param {Object} str
  235. * @param {Object} color
  236. * 选择颜色
  237. */
  238. selectColorEvent(str, color) {
  239. this.selectColor = str;
  240. this.lineColor = color;
  241. },
  242. //完成
  243. subCanvas() {
  244. uni.canvasToTempFilePath({
  245. canvasId: 'handWriting',
  246. fileType: 'png',
  247. quality: 1, //图片质量
  248. success(res) {
  249. // console.log(res.tempFilePath, 'canvas生成图片地址');
  250. uni.showToast({
  251. title: '以保存'
  252. });
  253. //保存到系统相册
  254. uni.saveImageToPhotosAlbum({
  255. filePath: res.tempFilePath,
  256. success(res) {
  257. uni.showToast({
  258. title: '已成功保存到相册',
  259. duration: 2000
  260. });
  261. }
  262. });
  263. }
  264. });
  265. },
  266. //保存到相册
  267. saveCanvasAsImg() {
  268. uni.canvasToTempFilePath({
  269. canvasId: 'handWriting',
  270. fileType: 'png',
  271. quality: 1, //图片质量
  272. success(res) {
  273. console.log(res.tempFilePath, 'canvas生成图片地址');
  274. uni.saveImageToPhotosAlbum({
  275. filePath: res.tempFilePath,
  276. success(res) {
  277. uni.showToast({
  278. title: '已保存到相册',
  279. duration: 2000
  280. });
  281. }
  282. });
  283. }
  284. });
  285. },
  286. //预览
  287. previewCanvasImg() {
  288. uni.canvasToTempFilePath({
  289. canvasId: 'handWriting',
  290. fileType: 'jpg',
  291. quality: 1, //图片质量
  292. success(res) {
  293. uni.previewImage({
  294. urls: [res.tempFilePath] //预览图片 数组
  295. });
  296. }
  297. });
  298. },
  299. //设置canvas背景色 不设置 导出的canvas的背景为透明
  300. //@params:字符串 color
  301. setCanvasBg(color) {
  302. /* 将canvas背景设置为 白底,不设置 导出的canvas的背景为透明 */
  303. //rect() 参数说明 矩形路径左上角的横坐标,左上角的纵坐标, 矩形路径的宽度, 矩形路径的高度
  304. //这里是 canvasHeight - 4 是因为下边盖住边框了,所以手动减了写
  305. this.ctx.rect(0, 0, this.canvasWidth, this.canvasHeight - 4);
  306. // ctx.setFillStyle('red')
  307. this.ctx.setFillStyle(color);
  308. this.ctx.fill(); //设置填充
  309. this.ctx.draw(); //开画
  310. }
  311. }
  312. };
  313. </script>
  314. <style lang="scss" scoped>
  315. page {
  316. background: #fbfbfb;
  317. height: auto;
  318. }
  319. .content1 {
  320. background: white;
  321. border-radius: 20rpx;
  322. margin: 20rpx;
  323. padding: 30rpx 20rpx;
  324. display: flex;
  325. justify-content: space-between;
  326. .right {
  327. display: flex;
  328. }
  329. }
  330. .content2 {
  331. background: white;
  332. border-radius: 20rpx;
  333. margin: 20rpx;
  334. padding: 30rpx 20rpx;
  335. .title {
  336. font-size: 36rpx;
  337. font-weight: 700;
  338. margin-bottom: 20rpx;
  339. }
  340. .row-between {
  341. margin-bottom: 20rpx;
  342. }
  343. .left-text {
  344. margin-right: 20rpx;
  345. }
  346. .yf-input {
  347. padding-right: 10rpx;
  348. }
  349. }
  350. .content3 {
  351. background: white;
  352. border-radius: 20rpx;
  353. margin: 20rpx;
  354. padding: 30rpx 20rpx;
  355. }
  356. .place {
  357. width: 80%;
  358. text-align: right;
  359. }
  360. .handCenter {
  361. border: 4rpx dashed #e9e9e9;
  362. overflow: hidden;
  363. box-sizing: border-box;
  364. height: 500rpx;
  365. }
  366. .handWriting {
  367. background: #F9F9FB;
  368. width: 100%;
  369. height: 100%;
  370. }
  371. .handRight {
  372. display: inline-flex;
  373. align-items: center;
  374. }
  375. .handCenter {
  376. border: 4rpx dashed #e9e9e9;
  377. flex: 5;
  378. overflow: hidden;
  379. box-sizing: border-box;
  380. }
  381. .handTitle {
  382. font-size: 36rpx;
  383. color: #666;
  384. font-weight: 700;
  385. color: #333333;
  386. margin-bottom: 20rpx;
  387. }
  388. .retDraw-image {
  389. width: 50rpx;
  390. }
  391. .qm-row {
  392. display: flex;
  393. justify-content: space-between;
  394. }
  395. .saveBtn {
  396. width: 80%;
  397. background: #2772FB;
  398. color: white;
  399. text-align: center;
  400. border-radius: 50rpx;
  401. padding: 20rpx;
  402. }
  403. .handBtn {
  404. display: flex;
  405. justify-content: center;
  406. }
  407. /*
  408. .wrapper {
  409. width: 100%;
  410. height: 95vh;
  411. margin: 30rpx 0;
  412. overflow: hidden;
  413. display: flex;
  414. align-content: center;
  415. flex-direction: row;
  416. justify-content: center;
  417. font-size: 28rpx;
  418. }
  419. .handBtn button {
  420. font-size: 28rpx;
  421. }
  422. .handBtn {
  423. height: 95vh;
  424. display: inline-flex;
  425. flex-direction: column;
  426. justify-content: space-between;
  427. align-content: space-between;
  428. flex: 1;
  429. }
  430. .delBtn {
  431. position: absolute;
  432. top: 250rpx;
  433. left: 0rpx;
  434. transform: rotate(90deg);
  435. color: #666;
  436. }
  437. .delBtn image {
  438. position: absolute;
  439. top: 13rpx;
  440. left: 25rpx;
  441. }
  442. .subBtn {
  443. position: absolute;
  444. bottom: 52rpx;
  445. left: -3rpx;
  446. display: inline-flex;
  447. transform: rotate(90deg);
  448. background: #008ef6;
  449. color: #fff;
  450. margin-bottom: 30rpx;
  451. text-align: center;
  452. justify-content: center;
  453. }
  454. .saveBtn {
  455. position: absolute;
  456. top: 375rpx;
  457. left: 0rpx;
  458. transform: rotate(90deg);
  459. color: #666;
  460. }
  461. .previewBtn {
  462. position: absolute;
  463. top: 500rpx;
  464. left: 0rpx;
  465. transform: rotate(90deg);
  466. color: #666;
  467. }
  468. .uploadBtn {
  469. position: absolute;
  470. top: 625rpx;
  471. left: 0rpx;
  472. transform: rotate(90deg);
  473. color: #666;
  474. }
  475. .black-select {
  476. width: 60rpx;
  477. height: 60rpx;
  478. position: absolute;
  479. top: 30rpx;
  480. left: 25rpx;
  481. }
  482. .black-select.color_select {
  483. width: 90rpx;
  484. height: 90rpx;
  485. top: 100rpx;
  486. left: 10rpx;
  487. }
  488. .red-select {
  489. width: 60rpx;
  490. height: 60rpx;
  491. position: absolute;
  492. top: 140rpx;
  493. left: 25rpx;
  494. }
  495. .red-select.color_select {
  496. width: 90rpx;
  497. height: 90rpx;
  498. top: 120rpx;
  499. left: 10rpx;
  500. } */
  501. </style>