initCloud.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. const util = require('../../utils/util.js');
  2. const app = getApp()
  3. Page({
  4. data: {
  5. index: 0,
  6. userList: [],
  7. userNum: 0,
  8. name: "",
  9. phone: "",
  10. content: "",
  11. showImg: [],
  12. images: [],
  13. fileList: [],
  14. files: [],
  15. timeArray: [ "请选择有效时间" , "5分钟" , "10分钟" , "15分钟" ],
  16. totalFee: "",
  17. isCheck: false,
  18. click: true
  19. },
  20. onLoad: function () {
  21. var that = this , userInfo = wx.getStorageSync("userInfo");
  22. that.setData({
  23. name: userInfo.userName,
  24. phone: userInfo.mobile
  25. })
  26. //第一次进来加载律师
  27. wx.request({
  28. url: app.globalData.serverUrl + '/cloudcard/addLawyer',
  29. method: "GET",
  30. data: {
  31. id : userInfo.id
  32. },
  33. success(res) {
  34. var lawyerList = res.data.data.lawyerList;
  35. for(var i in lawyerList){
  36. var str = app.globalData.fileUrl + lawyerList[i].headPortrait;
  37. lawyerList[i].headPortrait = str;
  38. }
  39. that.setData({
  40. userList: lawyerList,
  41. userNum: res.data.data.lawyerCount,
  42. totalFee: res.data.data.totalFee
  43. })
  44. },
  45. fail: function (res) {
  46. wx.showToast({
  47. title: '获取失败!',
  48. icon: 'none',
  49. duration: 2000
  50. })
  51. }
  52. })
  53. },
  54. //添加律师
  55. addLawyer: function(){
  56. if(this.data.userNum <= this.data.userList.length){
  57. wx.showToast({
  58. title: '已达到律师添加上限!',
  59. icon: 'none',
  60. duration: 2000
  61. })
  62. } else {
  63. var that = this;
  64. var str = "" , list = that.data.userList;
  65. for(var i in list){
  66. str += list[i].id + ","
  67. }
  68. str = str.substring( 0 , str.length -1);
  69. wx.request({
  70. url: app.globalData.serverUrl + '/cloudcard/addLawyer',
  71. method: "GET",
  72. data: {
  73. lawyerIds: str
  74. },
  75. success(res) {
  76. that.data.userList.push(res.data.data);
  77. that.setData({
  78. userList: that.data.userList
  79. })
  80. },
  81. fail: function (res) {
  82. wx.showToast({
  83. title: '获取失败!',
  84. icon: 'none',
  85. duration: 2000
  86. })
  87. }
  88. })
  89. }
  90. },
  91. //移除律师
  92. removeUser: function(e){
  93. const userList = this.data.userList , i = e.target.dataset.index;
  94. userList.splice(i,1);
  95. this.setData({
  96. userList: userList
  97. })
  98. },
  99. //获取接收人
  100. getNameValue: function(e){
  101. this.setData({
  102. name: e.detail.value
  103. })
  104. },
  105. //获取手机号
  106. getPhoneValue: function(e){
  107. this.setData({
  108. phone: e.detail.value
  109. })
  110. },
  111. //获取合意内容
  112. getContentValue: function(e){
  113. this.setData({
  114. content: e.detail.value
  115. })
  116. },
  117. //图片上传
  118. chooseImage: function(e){
  119. var that = this;
  120. wx.chooseImage({
  121. count: 9,
  122. sizeType: ['original', 'compressed'],
  123. sourceType: ['album', 'camera'],
  124. success: res => {
  125. var list = res.tempFilePaths;
  126. wx.showLoading({
  127. title: '上传中...',
  128. })
  129. var num = 0;
  130. for(var i in list){
  131. if(that.data.images.length + (parseInt(i)+1) > 9){
  132. wx.hideLoading();
  133. wx.showToast({
  134. title: '上传图片不能超过9张!',
  135. icon: 'none',
  136. duration: 1000
  137. })
  138. return false;
  139. } else {
  140. var showArray = that.data.showImg;
  141. showArray.push(res.tempFilePaths[i]);
  142. var array = that.data.images;
  143. wx.uploadFile({
  144. url: app.globalData.serverUrl + '/cloudcard/upload',
  145. filePath: res.tempFilePaths[i],
  146. name: 'file',
  147. formData: {
  148. 'flag': 0
  149. },
  150. success: function (res) {
  151. num ++;
  152. var data = JSON.parse(res.data);
  153. var msg = {
  154. fileUrl: data.data.fileUrl,
  155. fileSize: data.data.fileSize,
  156. fileName: data.data.fileName,
  157. fileType: 0
  158. }
  159. array.push(msg);
  160. that.setData({
  161. showImg: showArray,
  162. images: array
  163. })
  164. if(i == list.length-1){
  165. wx.showToast({
  166. title: '上传成功!',
  167. icon: 'success',
  168. duration: 1000
  169. })
  170. }
  171. },
  172. fail: function(res){
  173. num ++;
  174. wx.showToast({
  175. title: '上传失败!',
  176. icon: 'none',
  177. duration: 1000
  178. })
  179. }
  180. });
  181. }
  182. }
  183. if(num == list.length-1){
  184. wx.hideLoading();
  185. }
  186. }
  187. })
  188. },
  189. //图片预览
  190. handleImagePreview: function(e){
  191. const i = e.target.dataset.index;
  192. const images = this.data.showImg;
  193. wx.previewImage({
  194. current: images[i],
  195. urls: images,
  196. })
  197. },
  198. //移除图片
  199. removeImage: function(e){
  200. const showImg = this.data.showImg , images = this.data.images , i = e.target.dataset.index;
  201. showImg.splice(i,1);
  202. images.splice(i,1);
  203. this.setData({
  204. showImg: showImg,
  205. images: images
  206. })
  207. },
  208. //文件上传
  209. chooseFile: function(e){
  210. var that = this;
  211. wx.chooseMessageFile({
  212. count: 10,
  213. type: 'file',
  214. success: function(res) {
  215. var list = res.tempFiles;
  216. wx.showLoading({
  217. title: '上传中...',
  218. })
  219. var num = 0;
  220. for(var i in list){
  221. if(list[i].size < (1024*1024*50)){
  222. var fileList = that.data.fileList;
  223. fileList.push(list[i]);
  224. var array = that.data.images;
  225. wx.uploadFile({
  226. url: app.globalData.serverUrl + '/cloudcard/upload',
  227. filePath: list[i].path,
  228. name: 'file',
  229. formData: {
  230. "originalFileName": list[i].name,
  231. 'flag': 1
  232. },
  233. success: function(res){
  234. num ++;
  235. var data = JSON.parse(res.data);
  236. var msg = {
  237. fileUrl: data.data.fileUrl,
  238. fileSize: data.data.fileSize,
  239. fileName: data.data.fileName,
  240. fileOld: list[i].path,
  241. fileType: 1
  242. }
  243. array.push(msg);
  244. fileList[i].url = data.data.fileUrl,
  245. that.setData({
  246. fileList: fileList,
  247. images: that.data.images
  248. })
  249. if(i == list.length-1){
  250. wx.showToast({
  251. title: '上传成功!',
  252. icon: 'success',
  253. duration: 1000
  254. })
  255. }
  256. },
  257. fail: function(res){
  258. num++;
  259. wx.showToast({
  260. title: '上传失败!',
  261. icon: 'none',
  262. duration: 1000
  263. })
  264. }
  265. })
  266. } else {
  267. wx.showToast({
  268. title: '上传文件不得超过50M!',
  269. icon: 'none',
  270. duration: 1000
  271. })
  272. }
  273. }
  274. if(num == list.length-1){
  275. wx.hideLoading();
  276. }
  277. }
  278. })
  279. },
  280. //文件预览
  281. showFile: function(e){
  282. const i = e.target.dataset.index;
  283. var that = this , url = that.data.fileList[i].url;
  284. // wx.getSystemInfo({
  285. // success: function (res) {
  286. // if(res.system.indexOf("iOS") > -1){
  287. // wx.navigateTo({
  288. // url: '../book/pdf?url=' + url
  289. // })
  290. // } else {
  291. wx.showLoading({
  292. title: '正在打开请稍候...',
  293. })
  294. wx.downloadFile({
  295. url: app.globalData.fileUrl + url,
  296. success: function (res) {
  297. wx.hideLoading()
  298. var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
  299. wx.openDocument({
  300. filePath: Path,
  301. success: function (res) {
  302. console.log('打开成功');
  303. }
  304. })
  305. },
  306. fail: function (res) {
  307. wx.hideLoading()
  308. wx.showToast({
  309. title: '文件打开失败!',
  310. icon: 'none',
  311. duration: 1000
  312. })
  313. }
  314. })
  315. // }
  316. // }
  317. // })
  318. },
  319. //移除文件
  320. removeFile: function(e){
  321. const fileList = this.data.fileList , i = e.currentTarget.dataset.index;
  322. var images = this.data.images;
  323. for(var j in images){
  324. if(images[j].fileOld == fileList[i].path){
  325. images.splice(j,1);
  326. break;
  327. }
  328. }
  329. fileList.splice(i,1);
  330. this.setData({
  331. fileList: fileList,
  332. images: images
  333. })
  334. },
  335. //时间选择
  336. bindPickerChange: function(e){
  337. this.setData({
  338. index: e.detail.value
  339. })
  340. },
  341. //查看确认书
  342. book: function(){
  343. wx.navigateTo({
  344. url: '../book/book'
  345. })
  346. },
  347. //阅读确认书
  348. checkboxChange: function(e){
  349. var ischeck;
  350. if(e.detail.value.length == 0){
  351. ischeck = false;
  352. } else {
  353. ischeck = true;
  354. }
  355. this.setData({
  356. isCheck: ischeck
  357. })
  358. },
  359. //保存并支付
  360. // toPay
  361. formSubmit: function(e){
  362. var myreg = /^1[0-9]{10,11}$/ , openId = wx.getStorageSync("openId");
  363. var users = "",time = 0;
  364. if(this.data.userList.length == 0){
  365. wx.showToast({
  366. title: '云证律师不能为空',
  367. icon: 'none',
  368. duration: 1000
  369. })
  370. return false;
  371. } else {
  372. for(var i in this.data.userList){
  373. users += this.data.userList[i].id + ","
  374. }
  375. users = users.substring( 0 , users.length -1);
  376. }
  377. if(this.data.index == 0){
  378. time = 0;
  379. } else if(this.data.index == 1){
  380. time = 5;
  381. } else if(this.data.index == 2){
  382. time = 10;
  383. } else if(this.data.index == 3){
  384. time = 15;
  385. }
  386. if (this.data.name == "") {
  387. wx.showToast({
  388. title: '姓名不能为空',
  389. icon: 'none',
  390. duration: 1000
  391. })
  392. return false;
  393. } else if (this.data.phone == "") {
  394. wx.showToast({
  395. title: '手机号不能为空',
  396. icon: 'none',
  397. duration: 1000
  398. })
  399. return false;
  400. } else if (!myreg.test(this.data.phone)) {
  401. wx.showToast({
  402. title: '请输入正确的手机号',
  403. icon: 'none',
  404. duration: 1000
  405. })
  406. return false;
  407. } else if(time == 0){
  408. wx.showToast({
  409. title: '请选择有效时间',
  410. icon: 'none',
  411. duration: 1000
  412. })
  413. return false;
  414. } else if(!this.data.isCheck){
  415. wx.showToast({
  416. title: '请阅读《网律云证用户确认书》',
  417. icon: 'none',
  418. duration: 1000
  419. })
  420. return false;
  421. } else {
  422. var that = this;
  423. if(that.data.click){
  424. that.setData({
  425. click: false
  426. })
  427. wx.request({
  428. url: app.globalData.serverUrl + "/cloudcard/create",
  429. method: "POST",
  430. data: {
  431. openId: openId,
  432. lawyerIds: users,
  433. initiatorName: this.data.name,
  434. initiatorMobile: this.data.phone,
  435. content: this.data.content,
  436. validTime: time,
  437. fileUploads: JSON.stringify(this.data.images),
  438. formId: e.detail.formId
  439. },
  440. header: {
  441. "Content-Type": "application/x-www-form-urlencoded"
  442. },
  443. success: function (res) {
  444. if(res.data.code == "ok"){
  445. wx.showToast({
  446. title: '创建成功!',
  447. icon: 'success',
  448. duration: 2000
  449. })
  450. var item = res.data.data;
  451. wx.requestPayment({
  452. timeStamp: item.timeStamp,
  453. nonceStr: item.nonceStr,
  454. package: item.package,
  455. signType: item.signType,
  456. paySign: item.paySign,
  457. success (res) {
  458. console.log("成功")
  459. that.setData({
  460. click: true
  461. })
  462. console.log(item)
  463. setTimeout(function() {
  464. wx.reLaunch({
  465. url: '../share/share?id=' + item.cloudCardOrder.id
  466. })
  467. }, 200)
  468. },
  469. fail (res) {
  470. console.log("失败")
  471. that.setData({
  472. click: true
  473. })
  474. wx.showToast({
  475. title: "支付失败",
  476. icon: 'none',
  477. duration: 2000
  478. })
  479. setTimeout(function() {
  480. wx.reLaunch({
  481. url: '../cloud/cloud'
  482. })
  483. }, 200)
  484. }
  485. })
  486. } else {
  487. that.setData({
  488. click: true
  489. })
  490. wx.showToast({
  491. title: res.data.msg,
  492. icon: 'none',
  493. duration: 2000
  494. })
  495. }
  496. },
  497. fail: function (res) {
  498. that.setData({
  499. click: true
  500. })
  501. wx.showToast({
  502. title: '提交失败!',
  503. icon: 'none',
  504. duration: 2000
  505. })
  506. }
  507. })
  508. } else {
  509. wx.showToast({
  510. title: '保存中,请勿重复提交',
  511. icon: 'none',
  512. duration: 1000
  513. })
  514. }
  515. }
  516. }
  517. })