receiver.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. const util = require('../../utils/util.js');
  2. const app = getApp()
  3. Page({
  4. data: {
  5. userInfo: wx.getStorageSync("userInfo"),
  6. cloudCardOrder: {},
  7. validTime: 0,
  8. imageList: [],
  9. fileList: [],
  10. sec: 1,
  11. countdown: "",
  12. name: "",//姓名
  13. phone: "",//手机号
  14. code: '',//验证码
  15. iscode: null,//用于存放验证码接口里获取到的code
  16. codename: '获取验证码',
  17. disabled: false, //按钮是否禁用
  18. click: true,
  19. canShow: false
  20. },
  21. onLoad: function (option) {
  22. var that = this;
  23. wx.login({
  24. success: res => {
  25. wx.request({
  26. url: app.globalData.serverUrl + '/user/weiXinLogin',
  27. data: {
  28. code: res.code
  29. },
  30. header: {
  31. 'content-type': 'application/json'
  32. },
  33. success: function (res) {
  34. if(res.data.statusCode != null){
  35. wx.showToast({
  36. title: '获取用户信息失败',
  37. icon: 'none',
  38. duration: 2000
  39. })
  40. } else {
  41. app.globalData.userInfo = res.data.data;
  42. wx.setStorageSync('userInfo', res.data.data);
  43. wx.setStorageSync('openId', res.data.data.openid);
  44. that.getDetail(option.id);
  45. }
  46. },
  47. fail: function (res) {
  48. wx.showToast({
  49. title: '获取用户信息失败',
  50. icon: 'none',
  51. duration: 2000
  52. })
  53. }
  54. })
  55. }
  56. })
  57. wx.showShareMenu({
  58. withShareTicket: true
  59. })
  60. },
  61. //获取详情
  62. getDetail: function(id){
  63. var that = this;
  64. wx.request({
  65. url: app.globalData.serverUrl + '/cloudcard/detail',
  66. data: {
  67. openId : wx.getStorageSync("openId"),
  68. id : id,
  69. type: 1
  70. },
  71. success(res) {
  72. if (res.data.data != null) {
  73. var cloudCardOrder = res.data.data.cloudCardOrder, imageList = [], fileList = [];
  74. var strId = cloudCardOrder.initiatorId + "," + cloudCardOrder.receiverId + ",";
  75. var lawyeIds = "";
  76. for (var i in cloudCardOrder.lawyes) {
  77. strId += cloudCardOrder.lawyes[i].id + ",";
  78. lawyeIds += cloudCardOrder.lawyes[i].id + ",";
  79. }
  80. for (var i in cloudCardOrder.uploadFileModels) {
  81. var str = app.globalData.fileUrl + cloudCardOrder.uploadFileModels[i].fileUrl;
  82. imageList.push(str);
  83. }
  84. if (cloudCardOrder.receiverId != null) {
  85. if(strId.indexOf(wx.getStorageSync("userInfo").id) == -1) {
  86. wx.showToast({
  87. title: '您没有权限预览!',
  88. icon: 'none',
  89. duration: 2000
  90. })
  91. setTimeout(function () {
  92. wx.reLaunch({
  93. url: '../index/index'
  94. })
  95. }, 100)
  96. return false
  97. }
  98. }
  99. if(res.data.data.cloudCardOrder.isOpen == 1
  100. && res.data.data.cloudCardOrder.initiatorId != that.data.userInfo.id){
  101. wx.request({
  102. url: app.globalData.serverUrl + '/cloudcard/orderChecking',
  103. data: {
  104. id : res.data.data.cloudCardOrder.id
  105. },
  106. method:"GET",
  107. success(res) {
  108. setTimeout(function() {
  109. wx.reLaunch({
  110. url: '../detail/detail?id=' + res.data.data.cloudCardOrder.id + '&fromReceiver=1'
  111. })
  112. }, 200)
  113. },
  114. fail: function (res) {
  115. setTimeout(function() {
  116. wx.reLaunch({
  117. url: '../detail/detail?id=' + res.data.data.cloudCardOrder.id + '&fromReceiver=1'
  118. })
  119. }, 200)
  120. }
  121. })
  122. setTimeout(function() {
  123. wx.reLaunch({
  124. url: '../detail/detail?id=' + res.data.data.cloudCardOrder.id + '&fromReceiver=1'
  125. })
  126. }, 200)
  127. }
  128. if(res.data.data.cloudCardOrder.orderStatus != "NOT_SIGN"){
  129. setTimeout(function() {
  130. wx.reLaunch({
  131. url: '../detail/detail?id=' + res.data.data.cloudCardOrder.id + '&fromReceiver=1'
  132. })
  133. }, 200)
  134. }
  135. for (var i in cloudCardOrder.textFile) {
  136. var str = app.globalData.fileUrl + cloudCardOrder.textFile[i].fileUrl;
  137. fileList.push({
  138. url: str,
  139. name: cloudCardOrder.textFile[i].fileName
  140. });
  141. }
  142. for (var i in cloudCardOrder.lawyes) {
  143. var str = app.globalData.fileUrl + cloudCardOrder.lawyes[i].headPortrait;
  144. cloudCardOrder.lawyes[i].headPortrait = str;
  145. }
  146. that.setData({
  147. cloudCardOrder: cloudCardOrder,
  148. validTime: res.data.data.minute,
  149. sec: res.data.data.second,
  150. imageList: imageList,
  151. fileList: fileList
  152. })
  153. that.countTime();
  154. if (cloudCardOrder.initiatorId == that.data.userInfo.id) {
  155. that.setData({
  156. // countdown: cloudCardOrder.validTime + "分 00 秒",
  157. canShow: false
  158. })
  159. } else {
  160. that.setData({
  161. canShow: true
  162. })
  163. wx.request({
  164. url: app.globalData.serverUrl + "/cloudcard/checkIsOpen",
  165. method: "GET",
  166. data: {
  167. id: that.data.cloudCardOrder.id,
  168. isOpen: 1
  169. },
  170. success(res) {
  171. },
  172. fail: function (res) {
  173. }
  174. })
  175. }
  176. } else {
  177. wx.showToast({
  178. title: '获取失败!',
  179. icon: 'none',
  180. duration: 2000
  181. })
  182. }
  183. },
  184. fail: function (res) {
  185. wx.showToast({
  186. title: '获取失败!',
  187. icon: 'none',
  188. duration: 2000
  189. })
  190. }
  191. })
  192. },
  193. //倒计时
  194. countTime: function(){
  195. var m = this.data.validTime , s = this.data.sec;
  196. if (m >= 0) {
  197. m = m < 10 ? "0" + m : m;
  198. s = s < 10 ? "0" + s : s;
  199. this.setData({
  200. countdown: m + "分 " + s + " 秒",
  201. })
  202. this.data.sec--;
  203. if(this.data.sec < 0){
  204. this.data.sec = 59;
  205. this.data.validTime--;
  206. }
  207. this.setData({
  208. validTime: this.data.validTime,
  209. sec: this.data.sec
  210. })
  211. //递归每秒调用countTime方法,显示动态时间效果
  212. setTimeout(this.countTime, 1000);
  213. } else {
  214. this.setData({
  215. countdown: '已过期'
  216. })
  217. setTimeout(function() {
  218. wx.reLaunch({
  219. url: '../detail/detail?id=' + that.data.cloudCardOrder.id + '&fromReceiver=1'
  220. })
  221. }, 200)
  222. }
  223. },
  224. //图片预览
  225. handleImagePreview: function(e){
  226. const i = e.target.dataset.index;
  227. const images = this.data.imageList;
  228. wx.previewImage({
  229. current: images[i],
  230. urls: images,
  231. })
  232. },
  233. //文件预览
  234. showFile: function(e){
  235. const i = e.target.dataset.index;
  236. var that = this , url = this.data.fileList[i].url;
  237. // wx.getSystemInfo({
  238. // success: function (res) {
  239. // if(res.system.indexOf("iOS") > -1){
  240. // wx.navigateTo({
  241. // url: '../book/pdf?url=' + url + '&type=1'
  242. // })
  243. // } else {
  244. wx.showLoading({
  245. title: '正在打开请稍候...',
  246. })
  247. wx.downloadFile({
  248. url: url,
  249. success: function (res) {
  250. wx.hideLoading()
  251. var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
  252. wx.openDocument({
  253. filePath: Path,
  254. success: function (res) {
  255. console.log('打开成功');
  256. }
  257. })
  258. },
  259. fail: function (res) {
  260. wx.hideLoading()
  261. wx.showToast({
  262. title: '文件打开失败!',
  263. icon: 'none',
  264. duration: 1000
  265. })
  266. }
  267. })
  268. // }
  269. // }
  270. // })
  271. },
  272. getNameValue: function (e) {
  273. this.setData({
  274. name: e.detail.value
  275. })
  276. },
  277. getPhoneValue: function (e) {
  278. this.setData({
  279. phone: e.detail.value
  280. })
  281. },
  282. getCodeValue: function (e) {
  283. this.setData({
  284. code: e.detail.value
  285. })
  286. },
  287. //判断手机号
  288. getCode: function () {
  289. var phoneNum = this.data.phone;
  290. var that = this;
  291. var myreg = /^1[0-9]{10,11}$/;
  292. if (this.data.phone == "") {
  293. wx.showToast({
  294. title: '手机号不能为空',
  295. icon: 'none',
  296. duration: 1000
  297. })
  298. return false;
  299. } else if (!myreg.test(this.data.phone)) {
  300. wx.showToast({
  301. title: '请输入正确的手机号',
  302. icon: 'none',
  303. duration: 1000
  304. })
  305. return false;
  306. } else {
  307. wx.showLoading({
  308. title: '请稍候...',
  309. mask: true
  310. })
  311. wx.request({
  312. url: app.globalData.serverUrl + "/cloudcard/getVcode",
  313. data: {
  314. mobile: phoneNum
  315. },
  316. success(res) {
  317. wx.hideLoading();
  318. // that.setData({
  319. // iscode: res.data.data
  320. // })
  321. var num = 61;
  322. var timer = setInterval(function () {
  323. num--;
  324. if (num <= 0) {
  325. clearInterval(timer);
  326. that.setData({
  327. codename: '重新发送',
  328. disabled: false
  329. })
  330. } else {
  331. that.setData({
  332. codename: num + "s"
  333. })
  334. }
  335. }, 1000)
  336. },
  337. fail: function (res) {
  338. wx.hideLoading();
  339. }
  340. })
  341. }
  342. },
  343. //获取验证码
  344. getVerificationCode() {
  345. this.getCode();
  346. var that = this
  347. that.setData({
  348. disabled: true
  349. })
  350. },
  351. //查看确认书
  352. book: function(){
  353. wx.navigateTo({
  354. url: '../book/book'
  355. })
  356. },
  357. //同意
  358. agree: function(e){
  359. var myreg = /^1[0-9]{10,11}$/;
  360. if (this.data.name == "") {
  361. wx.showToast({
  362. title: '姓名不能为空',
  363. icon: 'none',
  364. duration: 1000
  365. })
  366. return false;
  367. } else if (this.data.phone == "") {
  368. wx.showToast({
  369. title: '手机号不能为空',
  370. icon: 'none',
  371. duration: 1000
  372. })
  373. return false;
  374. } else if (!myreg.test(this.data.phone)) {
  375. wx.showToast({
  376. title: '请输入正确的手机号',
  377. icon: 'none',
  378. duration: 1000
  379. })
  380. return false;
  381. } else if (this.data.code == "") {
  382. wx.showToast({
  383. title: '请输入验证码',
  384. icon: 'none',
  385. duration: 1000
  386. })
  387. return false;
  388. } else {
  389. if(this.data.click){
  390. var that = this;
  391. that.setData({
  392. click: false
  393. })
  394. wx.request({
  395. url: app.globalData.serverUrl + "/cloudcard/orderAgree",
  396. method: "GET",
  397. data: {
  398. orderId: that.data.cloudCardOrder.id,
  399. openid: wx.getStorageSync("openId"),
  400. userName: that.data.name,
  401. mobile: that.data.phone,
  402. VCode: that.data.code,
  403. formId: e.detail.formId
  404. },
  405. success(res) {
  406. wx.request({
  407. url: app.globalData.fileUrl + "/index/copy",
  408. method: "GET",
  409. data: {
  410. id: that.data.cloudCardOrder.id
  411. },
  412. success(res) {
  413. },
  414. fail: function (res) {
  415. }
  416. })
  417. that.setData({
  418. click: true
  419. })
  420. if(res.data.code == "ok"){
  421. wx.showToast({
  422. title: "操作成功",
  423. icon: 'success',
  424. duration: 2000
  425. })
  426. } else {
  427. wx.showToast({
  428. title: res.data.msg,
  429. icon: 'none',
  430. duration: 2000
  431. })
  432. }
  433. setTimeout(function() {
  434. wx.reLaunch({
  435. url: '../detail/detail?id=' + that.data.cloudCardOrder.id + '&fromReceiver=1'
  436. })
  437. }, 200)
  438. },
  439. fail: function (res) {
  440. that.setData({
  441. click: true
  442. })
  443. wx.showToast({
  444. title: "操作失败",
  445. icon: 'none',
  446. duration: 2000
  447. })
  448. }
  449. })
  450. } else {
  451. wx.showToast({
  452. title: '保存中,请勿重复提交',
  453. icon: 'none',
  454. duration: 1000
  455. })
  456. }
  457. }
  458. },
  459. //拒绝
  460. refuse: function(e){
  461. if(this.data.click){
  462. var that = this;
  463. that.setData({
  464. click: false
  465. })
  466. wx.request({
  467. url: app.globalData.serverUrl + "/cloudcard/orderReject",
  468. method: "GET",
  469. data: {
  470. orderId: that.data.cloudCardOrder.id,
  471. openid: wx.getStorageSync("openId"),
  472. formId: e.detail.formId
  473. },
  474. success(res) {
  475. if(res.data.code == "ok"){
  476. wx.showToast({
  477. title: "操作成功",
  478. icon: 'success',
  479. duration: 2000
  480. })
  481. } else {
  482. wx.showToast({
  483. title: "操作失败",
  484. icon: 'none',
  485. duration: 2000
  486. })
  487. }
  488. setTimeout(function() {
  489. wx.reLaunch({
  490. url: '../detail/detail?id=' + that.data.cloudCardOrder.id + '&fromReceiver=1'
  491. })
  492. }, 200)
  493. },
  494. fail: function (res) {
  495. wx.showToast({
  496. title: "操作失败",
  497. icon: 'none',
  498. duration: 2000
  499. })
  500. }
  501. })
  502. } else {
  503. wx.showToast({
  504. title: '保存中,请勿重复提交',
  505. icon: 'none',
  506. duration: 1000
  507. })
  508. }
  509. }
  510. })