signContract.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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 class="left">
  11. 付款方式
  12. </view>
  13. <view class="right">
  14. <view class="left-text">平台垫付运费</view>
  15. <u-switch @change="change" v-model="value" inactiveColor='#ABB0BB' size="20" ></u-switch>
  16. </view> -->
  17. <!-- </view> -->
  18. <view class="content2">
  19. <view class="title">
  20. 合同摘要
  21. </view>
  22. <view class='row-between'>
  23. <view class="gray">发货单位</view>
  24. <view class="">{{dataDetails.cargoOwner?dataDetails.cargoOwner:'个人货主'}}</view>
  25. </view>
  26. <view class='row-between'>
  27. <view class="gray">发货地</view>
  28. <view class="place">
  29. {{dataDetails.sendPrivate}}{{dataDetails.sendCity}}{{dataDetails.sendArea}}{{dataDetails.sendDetailedAddress}}
  30. </view>
  31. </view>
  32. <view class='row-between'>
  33. <view class="gray">卸货地</view>
  34. <view class=" place">
  35. {{dataDetails.unloadPrivate}}{{dataDetails.unloadCity}}{{dataDetails.unloadArea}}{{dataDetails.unloadDetailedAddress}}
  36. </view>
  37. </view>
  38. <view class='row-between'>
  39. <view class="gray">货名</view>
  40. <view class="">{{dataDetails.goodsName}}</view>
  41. </view>
  42. <view class='row-between'>
  43. <view class="gray">距离</view>
  44. <view class="">约{{dataDetails.distance}}公里</view>
  45. </view>
  46. <!-- <view class='row-between'>
  47. <view class="gray">运费</view>
  48. <view class="">{{dataDetails.freightInfo.freight}}{{dataDetails.illingMethod==0?'元/吨':'元/车'}}</view>
  49. </view> -->
  50. <view class='row-between'>
  51. <!-- 后加 -->
  52. <view class="gray">收费比例(%)</view>
  53. <view class="">{{chargeProportion}}</view><!-- 暂时写死6% -->
  54. </view>
  55. <view style='color:#6A6A6A;margin-top:20px;font-size:30rpx;align-items: center;' class="flex">
  56. <u--image style='margin-right:3px;position:relative;top:1rpx;' @click='consent'
  57. :src="consentStatus==true?'../../static/images/mine/duihao@2x.png':'../../static/images/mine/wxz.png'"
  58. width="17px" height="17px"></u--image>
  59. 我已阅读并同意
  60. <view>
  61. <u--text type="primary" text="《货物运输委托协议》" @click="lookContract"></u--text>
  62. </view>
  63. 条款
  64. </view>
  65. </view>
  66. <view class="wrapper content3">
  67. <view class="qm-row">
  68. <view class="handTitle">手写签名</view>
  69. <image src="@/static/xiangpica@2x.png" mode="widthFix" @click="retDraw" class="retDraw-image"></image>
  70. <!-- <button @click="retDraw" class="delBtn">重写</button> -->
  71. </view>
  72. <view class="handCenter">
  73. <canvas class="handWriting" :disable-scroll="true" @touchstart="uploadScaleStart"
  74. @touchmove="uploadScaleMove" canvas-id="handWriting"></canvas>
  75. </view>
  76. <view class="handRight">
  77. </view>
  78. </view>
  79. <view class="handBtn">
  80. <!-- <image @click="selectColorEvent('black','#1A1A1A')"
  81. :src="selectColor === 'black' ? '/static/other/color_black_selected.png' : '/static/other/color_black.png'"
  82. :class="[selectColor === 'black' ? 'color_select' : '', 'black-select']"></image>
  83. <image @click="selectColorEvent('red','#ca262a')"
  84. :src="selectColor === 'red' ? '/static/other/color_red_selected.png' : '/static/other/color_red.png'"
  85. :class="[selectColor === 'red' ? 'color_select' : '', 'black-select']"></image> -->
  86. <!-- <button @click="saveCanvasAsImg" class="saveBtn">保存</button> -->
  87. <view @click="$u.throttle(submit, 1000)" class="saveBtn">提交</view>
  88. <!-- <button @click="previewCanvasImg" class="previewBtn">预览</button> -->
  89. <!-- <button @click="subCanvas" class="subBtn">完成</button> -->
  90. </view>
  91. <u-toast ref="uToast"></u-toast>
  92. </view>
  93. </template>
  94. <script>
  95. import {
  96. mapState
  97. } from 'vuex';
  98. var that;
  99. import uploadImage from '@/components/ossutil/uploadFile.js';
  100. export default {
  101. data() {
  102. return {
  103. isScaleStart: false,
  104. radioCustomStyle: {
  105. margin: '0 0 0 10rpx'
  106. },
  107. canvasName: 'handWriting',
  108. ctx: '',
  109. startX: null,
  110. startY: null,
  111. canvasWidth: 0,
  112. canvasHeight: 0,
  113. selectColor: 'black',
  114. lineColor: '#1A1A1A', // 颜色
  115. lineSize: 5, // 笔记倍数
  116. value: true,
  117. dataDetails: {
  118. carrierInfo: {},
  119. serviceCharge: '50'
  120. },
  121. radiolist1: [{
  122. name: '平台垫付运费',
  123. disabled: false
  124. },
  125. {
  126. name: '无需平台垫付运费',
  127. disabled: false
  128. },
  129. ],
  130. chargeProportion: "", //收费比例
  131. consentStatus: false,
  132. codestatus: false,
  133. addType: "",
  134. };
  135. },
  136. computed: {
  137. ...mapState(['hasLogin', 'userInfo', 'firstAuthentication'])
  138. },
  139. onLoad(options) {
  140. that = this
  141. // 如果登录之后没有切换到我的页面缓存不会存上,所以在这调用接口取收费比例
  142. this.$request.baseRequest('get', '/cargoOwnerInfo/firstAuthentication', {
  143. phone: this.userInfo.phone
  144. }).then(res => {
  145. uni.setStorageSync("firstAuthentication", res.data)
  146. //收费比例从缓存中取
  147. that.chargeProportion = uni.getStorageSync("firstAuthentication").chargeProportion * 100
  148. })
  149. this.dataDetails = JSON.parse(decodeURIComponent(options.obj))
  150. this.addType = JSON.parse(decodeURIComponent(options.type))
  151. // this.dataDetails.advanceFreightService = '平台垫付运费'
  152. this.ctx = uni.createCanvasContext("handWriting");
  153. this.$nextTick(() => {
  154. uni.createSelectorQuery().select('.handCenter').boundingClientRect(rect => {
  155. this.canvasWidth = rect.width;
  156. this.canvasHeight = rect.height;
  157. /* 将canvas背景设置为 白底,不设置 导出的canvas的背景为透明 */
  158. this.setCanvasBg('#fff');
  159. this.$request.baseRequest('get', '/commonUser/getSignatureAddress', {
  160. phone: this.userInfo.phone,
  161. identification: 2
  162. }).then(res => {
  163. if (res.data) {
  164. if (res.data.signImg) {
  165. // 获取远程图片,canvas无法直接绘制远程图片
  166. this.userInfo.signImg = res.data.signImg
  167. this.isScaleStart = res.data.signImg
  168. uni.getImageInfo({
  169. src: res.data.signImg,
  170. success(res) {
  171. var ctx = uni.createCanvasContext('handWriting')
  172. ctx.drawImage(res.path, 0, 0)
  173. // ctx.drawImage(res.path, 0, 0, 330, 244)
  174. ctx.save()
  175. ctx.draw()
  176. },
  177. fail(res) {
  178. uni.showToast({
  179. title: "图片下载异常",
  180. duration: 2000,
  181. icon: "none"
  182. })
  183. }
  184. })
  185. }
  186. }
  187. })
  188. })
  189. .exec();
  190. });
  191. },
  192. methods: {
  193. lookContract() {
  194. uni.downloadFile({
  195. url: "https://taohaoliang.oss-cn-beijing.aliyuncs.com/pcfiles/hzContract.pdf",
  196. success: function(res) {
  197. var filePath = res.tempFilePath;
  198. uni.openDocument({
  199. filePath: filePath,
  200. showMenu: true,
  201. success: function(res) {
  202. console.log('打开文档成功');
  203. }
  204. });
  205. }
  206. });
  207. },
  208. consent() {
  209. this.consentStatus = !this.consentStatus
  210. uni.setStorage({
  211. key: 'policyStorageKey',
  212. data: this.consentStatus
  213. });
  214. },
  215. submit() {
  216. if (!that.isScaleStart) {
  217. that.$refs.uToast.show({
  218. type: 'error',
  219. message: "手写签名不能为空!",
  220. })
  221. return
  222. }
  223. // if (uni.$u.test.isEmpty(that.dataDetails.freight)) {
  224. // that.$refs.uToast.show({
  225. // type: 'error',
  226. // message: "运费不能为空!",
  227. // })
  228. // return
  229. // }
  230. if (!that.consentStatus) {
  231. that.$refs.uToast.show({
  232. type: 'error',
  233. message: "请阅读并确认协议条款!",
  234. })
  235. return
  236. }
  237. uni.canvasToTempFilePath({
  238. canvasId: 'handWriting',
  239. fileType: 'png',
  240. quality: 1, //图片质量
  241. width: 330,
  242. height: 244,
  243. destWidth: 330,
  244. destHeight: 244,
  245. success(res) {
  246. uploadImage('image', res.tempFilePath, 'appData/',
  247. result => {
  248. // 上传成功
  249. console.log('图片地址', result)
  250. that.dataDetails.cargoOwnerAutograph = result
  251. uni.showLoading({
  252. title: '加载中',
  253. mask: true
  254. })
  255. if (that.addType == 1) { //新增
  256. that.$request.baseRequest('post', '/publishTaskInfo/api/addTask', that
  257. .dataDetails).then(res => {
  258. if (res.code == 200) {
  259. uni.removeStorage({
  260. key: 'storage_saddress'
  261. });
  262. uni.removeStorage({
  263. key: 'storage_faddress'
  264. });
  265. uni.removeStorage({
  266. key: 'releaseCargoOwner'
  267. });
  268. uni.removeStorage({
  269. key: 'releasecompId'
  270. });
  271. // uni.redirectTo({
  272. // url: "/pages/release/release"
  273. // })
  274. that.dataDetails.id = res.data
  275. let _obj = {}
  276. _obj.id = that.dataDetails.id
  277. _obj.cargoOwnerAutograph = that.dataDetails
  278. .cargoOwnerAutograph
  279. that.$request.baseRequest('get',
  280. '/publishTaskInfo/signContract', _obj).then(
  281. res => {
  282. uni.hideLoading()
  283. if (res.code == 200) {
  284. // that.contractSrc = res.data
  285. // uni.downloadFile({
  286. // url: res.data,
  287. // success: function(res) {
  288. // var filePath = res.tempFilePath;
  289. // uni.openDocument({
  290. // filePath: filePath,
  291. // showMenu: true,
  292. // success: function(res) {
  293. // console.log('打开文档成功');
  294. // }
  295. // });
  296. // }
  297. // });
  298. that.$refs.uToast.show({
  299. type: 'success',
  300. message: "发布成功",
  301. complete() {
  302. uni.switchTab({
  303. url: '/pages/order/index'
  304. });
  305. }
  306. })
  307. }
  308. })
  309. .catch(res => {
  310. uni.hideLoading()
  311. uni.$u.toast(res.message);
  312. });
  313. }
  314. })
  315. .catch(res => {
  316. uni.hideLoading()
  317. uni.showToast({
  318. title: res.message,
  319. icon: 'none',
  320. duration: 2000
  321. })
  322. });
  323. } else if (that.addType == 2) { //编辑
  324. that.$request.baseRequest('post', '/publishTaskInfo/api/editTask', that
  325. .dataDetails).then(res => {
  326. if (res.code == 200) {
  327. uni.removeStorage({
  328. key: 'storage_saddress'
  329. });
  330. uni.removeStorage({
  331. key: 'storage_faddress'
  332. });
  333. uni.removeStorage({
  334. key: 'releaseCargoOwner'
  335. });
  336. uni.removeStorage({
  337. key: 'releasecompId'
  338. });
  339. let _obj = {}
  340. _obj.id = that.dataDetails.id
  341. _obj.cargoOwnerAutograph = that.dataDetails
  342. .cargoOwnerAutograph
  343. that.$request.baseRequest('get',
  344. '/publishTaskInfo/signContract', _obj).then(
  345. res => {
  346. uni.hideLoading()
  347. if (res.code == 200) {
  348. // that.contractSrc = res.data
  349. // uni.downloadFile({
  350. // url: res.data,
  351. // success: function(res) {
  352. // var filePath = res.tempFilePath;
  353. // uni.openDocument({
  354. // filePath: filePath,
  355. // showMenu: true,
  356. // success: function(res) {
  357. // console.log('打开文档成功');
  358. // }
  359. // });
  360. // }
  361. // });
  362. that.$refs.uToast.show({
  363. type: 'success',
  364. message: "修改成功",
  365. complete() {
  366. uni.switchTab({
  367. url: '/pages/order/index'
  368. });
  369. }
  370. })
  371. }
  372. })
  373. .catch(res => {
  374. uni.hideLoading()
  375. uni.$u.toast(res.message);
  376. });
  377. }
  378. })
  379. .catch(res => {
  380. uni.hideLoading()
  381. uni.showToast({
  382. title: res.message,
  383. icon: 'none',
  384. duration: 2000
  385. })
  386. });
  387. }
  388. })
  389. }
  390. });
  391. },
  392. // change(e){
  393. // if(this.value){
  394. // this.$set(this.dataDetails,'advanceFreightService',1)
  395. // }else{
  396. // this.$set(this.dataDetails,'advanceFreightService',0)
  397. // }
  398. // },
  399. // 笔迹开始
  400. uploadScaleStart(e) {
  401. this.isScaleStart = true
  402. this.startX = e.changedTouches[0].x
  403. this.startY = e.changedTouches[0].y
  404. //设置画笔参数
  405. //画笔颜色
  406. this.ctx.setStrokeStyle(this.lineColor)
  407. //设置线条粗细
  408. this.ctx.setLineWidth(this.lineSize)
  409. //设置线条的结束端点样式
  410. this.ctx.setLineCap("round") //'butt'、'round'、'square'
  411. //开始画笔
  412. this.ctx.beginPath()
  413. },
  414. // 笔迹移动
  415. uploadScaleMove(e) {
  416. //取点
  417. let temX = e.changedTouches[0].x
  418. let temY = e.changedTouches[0].y
  419. //画线条
  420. this.ctx.moveTo(this.startX, this.startY)
  421. this.ctx.lineTo(temX, temY)
  422. this.ctx.stroke()
  423. this.startX = temX
  424. this.startY = temY
  425. this.ctx.draw(true)
  426. },
  427. /**
  428. * 重写
  429. */
  430. retDraw() {
  431. this.ctx.clearRect(0, 0, 700, 730);
  432. this.ctx.draw();
  433. //设置canvas背景
  434. this.setCanvasBg('#fff');
  435. },
  436. /**
  437. * @param {Object} str
  438. * @param {Object} color
  439. * 选择颜色
  440. */
  441. selectColorEvent(str, color) {
  442. this.selectColor = str;
  443. this.lineColor = color;
  444. },
  445. //完成
  446. subCanvas() {
  447. uni.canvasToTempFilePath({
  448. canvasId: 'handWriting',
  449. fileType: 'png',
  450. quality: 1, //图片质量
  451. success(res) {
  452. // console.log(res.tempFilePath, 'canvas生成图片地址');
  453. uni.showToast({
  454. title: '以保存'
  455. });
  456. //保存到系统相册
  457. uni.saveImageToPhotosAlbum({
  458. filePath: res.tempFilePath,
  459. success(res) {
  460. uni.showToast({
  461. title: '已成功保存到相册',
  462. duration: 2000
  463. });
  464. }
  465. });
  466. }
  467. });
  468. },
  469. //保存到相册
  470. saveCanvasAsImg() {
  471. uni.canvasToTempFilePath({
  472. canvasId: 'handWriting',
  473. fileType: 'png',
  474. quality: 1, //图片质量
  475. success(res) {
  476. console.log(res.tempFilePath, 'canvas生成图片地址');
  477. uni.saveImageToPhotosAlbum({
  478. filePath: res.tempFilePath,
  479. success(res) {
  480. uni.showToast({
  481. title: '已保存到相册',
  482. duration: 2000
  483. });
  484. }
  485. });
  486. }
  487. });
  488. },
  489. //预览
  490. previewCanvasImg() {
  491. uni.canvasToTempFilePath({
  492. canvasId: 'handWriting',
  493. fileType: 'jpg',
  494. quality: 1, //图片质量
  495. success(res) {
  496. uni.previewImage({
  497. urls: [res.tempFilePath] //预览图片 数组
  498. });
  499. }
  500. });
  501. },
  502. //设置canvas背景色 不设置 导出的canvas的背景为透明
  503. //@params:字符串 color
  504. setCanvasBg(color) {
  505. /* 将canvas背景设置为 白底,不设置 导出的canvas的背景为透明 */
  506. //rect() 参数说明 矩形路径左上角的横坐标,左上角的纵坐标, 矩形路径的宽度, 矩形路径的高度
  507. //这里是 canvasHeight - 4 是因为下边盖住边框了,所以手动减了写
  508. this.ctx.rect(0, 0, this.canvasWidth, this.canvasHeight - 4);
  509. // ctx.setFillStyle('red')
  510. this.ctx.setFillStyle(color);
  511. this.ctx.fill(); //设置填充
  512. this.ctx.draw(); //开画
  513. }
  514. }
  515. };
  516. </script>
  517. <style lang="scss" scoped>
  518. page {
  519. background: #fbfbfb;
  520. height: auto;
  521. }
  522. .content1 {
  523. background: white;
  524. border-radius: 20rpx;
  525. margin: 20rpx;
  526. padding: 30rpx 20rpx;
  527. display: flex;
  528. justify-content: space-between;
  529. .right {
  530. display: flex;
  531. }
  532. }
  533. .content2 {
  534. background: white;
  535. border-radius: 20rpx;
  536. margin: 20rpx;
  537. padding: 30rpx 20rpx;
  538. .title {
  539. font-size: 36rpx;
  540. font-weight: 700;
  541. margin-bottom: 20rpx;
  542. }
  543. .row-between {
  544. margin-bottom: 20rpx;
  545. }
  546. .left-text {
  547. margin-right: 20rpx;
  548. }
  549. .yf-input {
  550. padding-right: 10rpx;
  551. }
  552. }
  553. .content3 {
  554. background: white;
  555. border-radius: 20rpx;
  556. margin: 20rpx;
  557. padding: 30rpx 20rpx;
  558. }
  559. .place {
  560. width: 80%;
  561. text-align: right;
  562. }
  563. .handCenter {
  564. border: 4rpx dashed #e9e9e9;
  565. overflow: hidden;
  566. box-sizing: border-box;
  567. height: 500rpx;
  568. }
  569. .handWriting {
  570. background: #F9F9FB;
  571. width: 100%;
  572. height: 100%;
  573. }
  574. .handRight {
  575. display: inline-flex;
  576. align-items: center;
  577. }
  578. .handCenter {
  579. border: 4rpx dashed #e9e9e9;
  580. flex: 5;
  581. overflow: hidden;
  582. box-sizing: border-box;
  583. }
  584. .handTitle {
  585. font-size: 36rpx;
  586. color: #666;
  587. font-weight: 700;
  588. color: #333333;
  589. margin-bottom: 20rpx;
  590. }
  591. .retDraw-image {
  592. width: 50rpx;
  593. }
  594. .qm-row {
  595. display: flex;
  596. justify-content: space-between;
  597. }
  598. .saveBtn {
  599. width: 80%;
  600. background: #2772FB;
  601. color: white;
  602. text-align: center;
  603. border-radius: 50rpx;
  604. padding: 20rpx;
  605. height: 50rpx;
  606. }
  607. .handBtn {
  608. display: flex;
  609. height: 60px;
  610. bottom: 0px;
  611. padding-top: 20rpx;
  612. background-color: #FFFFFF;
  613. justify-content: center;
  614. }
  615. uni-navigator {
  616. //条款
  617. display: inline-block;
  618. color: #2772FB;
  619. }
  620. /*
  621. .wrapper {
  622. width: 100%;
  623. height: 95vh;
  624. margin: 30rpx 0;
  625. overflow: hidden;
  626. display: flex;
  627. align-content: center;
  628. flex-direction: row;
  629. justify-content: center;
  630. font-size: 28rpx;
  631. }
  632. .handBtn button {
  633. font-size: 28rpx;
  634. }
  635. .handBtn {
  636. height: 95vh;
  637. display: inline-flex;
  638. flex-direction: column;
  639. justify-content: space-between;
  640. align-content: space-between;
  641. flex: 1;
  642. }
  643. .delBtn {
  644. position: absolute;
  645. top: 250rpx;
  646. left: 0rpx;
  647. transform: rotate(90deg);
  648. color: #666;
  649. }
  650. .delBtn image {
  651. position: absolute;
  652. top: 13rpx;
  653. left: 25rpx;
  654. }
  655. .subBtn {
  656. position: absolute;
  657. bottom: 52rpx;
  658. left: -3rpx;
  659. display: inline-flex;
  660. transform: rotate(90deg);
  661. background: #008ef6;
  662. color: #fff;
  663. margin-bottom: 30rpx;
  664. text-align: center;
  665. justify-content: center;
  666. }
  667. .saveBtn {
  668. position: absolute;
  669. top: 375rpx;
  670. left: 0rpx;
  671. transform: rotate(90deg);
  672. color: #666;
  673. }
  674. .previewBtn {
  675. position: absolute;
  676. top: 500rpx;
  677. left: 0rpx;
  678. transform: rotate(90deg);
  679. color: #666;
  680. }
  681. .uploadBtn {
  682. position: absolute;
  683. top: 625rpx;
  684. left: 0rpx;
  685. transform: rotate(90deg);
  686. color: #666;
  687. }
  688. .black-select {
  689. width: 60rpx;
  690. height: 60rpx;
  691. position: absolute;
  692. top: 30rpx;
  693. left: 25rpx;
  694. }
  695. .black-select.color_select {
  696. width: 90rpx;
  697. height: 90rpx;
  698. top: 100rpx;
  699. left: 10rpx;
  700. }
  701. .red-select {
  702. width: 60rpx;
  703. height: 60rpx;
  704. position: absolute;
  705. top: 140rpx;
  706. left: 25rpx;
  707. }
  708. .red-select.color_select {
  709. width: 90rpx;
  710. height: 90rpx;
  711. top: 120rpx;
  712. left: 10rpx;
  713. } */
  714. </style>