write.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. const api = require('../../../utils/api.js');
  2. const login = require('../../../utils/index.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. img:[],
  9. index: 0,
  10. tabindex: 0,
  11. codeType: ['身份证', '士官证', '港澳台居住证'],
  12. sbCodeIndex:0,
  13. lxCodeIndex:0,
  14. mask: false,
  15. imgList:[],
  16. image:[],
  17. dis: false,
  18. disabled:true,
  19. items: [
  20. { name: 'pickUp', value: '自取',checked: 'true' },
  21. { name: 'post', value: '邮寄' },
  22. ],
  23. textaddress:true
  24. },
  25. blur:function(e){
  26. this.setData({
  27. youjiaddress: e.detail.value,
  28. textaddress: true
  29. })
  30. },
  31. addresstext:function(e){
  32. this.setData({
  33. textaddress:false
  34. })
  35. },
  36. scroll:function(e){
  37. console.log(e)
  38. },
  39. kindToggle: function (e) {
  40. let that = this
  41. if (that.data.expand ===e.currentTarget.dataset.value){
  42. that.setData({
  43. dis: false,
  44. expand: e.currentTarget.dataset.value,
  45. })
  46. that.data.expand=''
  47. }else{
  48. that.setData({
  49. dis: true,
  50. expand: e.currentTarget.dataset.value,
  51. })
  52. }
  53. },
  54. /**
  55. * 生命周期函数--监听页面加载
  56. */
  57. onLoad: function (options) {
  58. var that=this
  59. that.data.flag=options.flag
  60. if(options.search){
  61. that.data.search = options.search
  62. }
  63. wx.request({
  64. url: api.guide,
  65. data: { unid:options.unid,userId:wx.getStorageSync('userId')},
  66. success(res){
  67. let levelList=[]
  68. for (var i = 0; i < res.data.data.preService.preServiceMaterialList.length;i++){
  69. if (res.data.data.preService.preServiceMaterialList[i].importLevel=='2'){
  70. that.data.image.push('')
  71. levelList.push(res.data.data.preService.preServiceMaterialList[i])
  72. }
  73. }
  74. res.data.data.preService.preServiceMaterialList=levelList
  75. that.setData({
  76. server:res.data.data,
  77. search: options.search == 1 ? true:false
  78. })
  79. }
  80. })
  81. var query = wx.createSelectorQuery();
  82. query.select('.tab').boundingClientRect();
  83. query.select('.flxed-bottom').boundingClientRect();
  84. query.exec(function (res) {
  85. that.data.topHeight = res[0].height
  86. that.data.flexHeight = res[1].height
  87. wx.getSystemInfo({
  88. success: function (res) {
  89. that.data.oldHeight = res.windowHeight - that.data.topHeight - that.data.flexHeight
  90. that.setData({
  91. clientHeight: res.windowHeight - that.data.topHeight - that.data.flexHeight
  92. });
  93. }
  94. })
  95. })
  96. },
  97. //提交表单
  98. formData:function(e){
  99. let that=this
  100. if (!that.setInput()){
  101. wx.showToast({
  102. title: '请完善表单信息',
  103. icon:'none'
  104. })
  105. return false;
  106. }
  107. for(let i=0;i<that.data.server.preService.preServiceMaterialList.length;i++){
  108. if (that.data.server.preService.preServiceMaterialList[i].importLevel==2){
  109. if (that.data.server.preService.preServiceMaterialList[i].isSet!=1){
  110. wx.showToast({
  111. title: '请上传必要材料信息',
  112. icon: 'none'
  113. })
  114. return false
  115. }
  116. }
  117. }
  118. if (that.data.mode =='post'){
  119. if (!e.detail.value.applyCardtype){
  120. wx.showToast({
  121. title: '请填写邮寄地址',
  122. icon: 'none'
  123. })
  124. return false
  125. }
  126. }
  127. wx.showLoading({
  128. title: '正在提交',
  129. })
  130. // for (var i = 0; i < that.data.server.preService.preServiceMaterialList.length;i++){
  131. // if (!that.data.server.preService.preServiceMaterialList[i].isSet && that.data.server.preService.preServiceMaterialList[i].importLevel!=2){}
  132. // }
  133. if (that.data.user.identity == '0'){
  134. if (!e.detail.value.applyCardtype) {
  135. e.detail.value.applyCardtype = that.data.user.pDocumentType
  136. } else {
  137. e.detail.value.applyCardtype = that.data.contactmanCardtype[parseInt(e.detail.value.applyCardtype)].dictValueCode
  138. }
  139. }else{
  140. if (!e.detail.value.applyCardtype) {
  141. e.detail.value.applyCardtype = that.data.user.lInstitutionType
  142. } else {
  143. e.detail.value.applyCardtype = that.data.contactmanCardtype[parseInt(e.detail.value.applyCardtype)].dictValueCode
  144. }
  145. }
  146. if (!e.detail.value.contactmanCardtype) {
  147. e.detail.value.contactmanCardtype = that.data.contactmanCardtype[0].dictValueCode
  148. }else{
  149. e.detail.value.contactmanCardtype = that.data.contactmanCardtype[parseInt(e.detail.value.contactmanCardtype)].dictValueCode
  150. }
  151. e.detail.value.servicecode = that.data.server.preService.serviceCode
  152. e.detail.value.receiveUseid=wx.getStorageSync('userId')
  153. if(wx.getStorageSync('flag')==1){
  154. e.detail.value.applyType='个人申请'
  155. }else{
  156. e.detail.value.applyType = '法人申请'
  157. }
  158. e.detail.value.applyerTypeCode=wx.getStorageSync('flag')
  159. e.detail.value.applyCardtypeCode = e.detail.value.applyCardtype//申请者证件类型代码
  160. e.detail.value.contactmanCardtypeCode = e.detail.value.contactmanCardtype//代理人证件类型
  161. // 处理图片
  162. var imgList=[]
  163. for (var i = 0; i < that.data.server.preService.preServiceMaterialList.length;i++){
  164. var imgObj = {}
  165. imgObj.attrname = that.data.server.preService.preServiceMaterialList[i].name
  166. imgObj.amount = that.data.server.preService.preServiceMaterialList[i].copyNum + that.data.server.preService.preServiceMaterialList[i].srcNum
  167. imgObj.fileUrl=''
  168. imgObj.filename=''
  169. imgList.push(imgObj)
  170. }
  171. if(!that.data.image){
  172. that.data.image=[]
  173. }
  174. for (var j = 0; j < that.data.image.length; j++) {
  175. if (that.data.image[j]!=''){
  176. imgList[parseInt(that.data.image[j].index)].fileUrl += that.data.image[j].url + '^'
  177. }
  178. }
  179. e.detail.value.preAttrFile=imgList
  180. that.setData({
  181. disabled: false
  182. })
  183. if (that.data.mode =='post'){
  184. e.detail.value.resultAccess='02'
  185. }else{
  186. e.detail.value.resultAccess = '01'
  187. }
  188. wx.request({
  189. url: api.apasinfo,
  190. data: e.detail.value,
  191. success(res){
  192. wx.hideLoading();
  193. if(res.data.errno==0){
  194. wx.navigateTo({
  195. url: '/pages/success/index?type=handle&code='+res.data.data,
  196. })
  197. }else{
  198. wx.showToast({
  199. title: '网络繁忙,请稍候再试',
  200. icon:'none'
  201. })
  202. }
  203. }
  204. })
  205. },
  206. /**
  207. * 生命周期函数--监听页面初次渲染完成
  208. */
  209. onReady: function () {
  210. let that=this
  211. wx.showLoading({
  212. title: '正在加载',
  213. mask:true
  214. })
  215. wx.request({
  216. url: api.server,
  217. data: { code: 'CARDTYPE' },
  218. success(res){
  219. that.data.contactmanCardtype=res.data.data
  220. wx.request({
  221. url: api.getUser,
  222. data: { userId: wx.getStorageSync('userId') },
  223. success(r) {
  224. wx.hideLoading()
  225. var codeType = ''
  226. if (r.data.data.user.identity=='0'){
  227. if (r.data.data.user.pDocumentType) {
  228. for (var i = 0; i < res.data.data.length; i++) {
  229. if (res.data.data[i].dictValueCode == r.data.data.user.pDocumentType) {
  230. codeType = i
  231. }
  232. }
  233. }
  234. } else if (r.data.data.user.identity == '1'){
  235. if (r.data.data.user.lInstitutionType) {
  236. for (var i = 0; i < res.data.data.length; i++) {
  237. if (res.data.data[i].dictValueCode == r.data.data.user.lInstitutionType) {
  238. codeType = i
  239. }
  240. }
  241. }
  242. }
  243. console.log(r.data.data.user)
  244. that.setData({
  245. user: r.data.data.user,
  246. code: res.data.data,
  247. codeIndex: codeType ? codeType : 0,
  248. flag:that.data.flag,
  249. identity: r.data.data.user.identity,
  250. })
  251. }
  252. })
  253. }
  254. })
  255. },
  256. /**
  257. * 生命周期函数--监听页面显示
  258. */
  259. onShow: function () {
  260. let that=this
  261. if (wx.getStorageSync('setImageIndex')){
  262. var setImageIndex = wx.getStorageSync('setImageIndex')
  263. wx.removeStorageSync('setImageIndex')
  264. var httpUrl = wx.getStorageSync('httpUrl');
  265. wx.removeStorageSync('httpUrl')
  266. // obj = { "url": '', "index": '', "time": '' }
  267. var imgUrl = wx.getStorageSync('imgUrl')
  268. if (!that.data.image) {
  269. that.data.image = []
  270. }
  271. for (var i = 0; i < imgUrl.length;i++){
  272. var obj = {}
  273. obj.url = imgUrl[i]
  274. obj.index = setImageIndex
  275. obj.time = i + '' + Math.random()
  276. obj.http = httpUrl
  277. that.data.image.push(obj)
  278. }
  279. that.data.server.preService.preServiceMaterialList[obj.index].isSet = 1
  280. that.data.img = that.data.image
  281. console.log(that.data.image)
  282. that.setData({
  283. image: that.data.image,
  284. ['server.preService.preServiceMaterialList']: that.data.server.preService.preServiceMaterialList
  285. })
  286. wx.removeStorageSync('imgUrl')
  287. }
  288. var obj = { "url": '', "index": 0, "time": 0}
  289. if (!that.data.img){
  290. obj = { "url": '', "index": wx.getStorageSync('setImageIndex'), "time": Math.random(), 'http': httpUrl}
  291. }
  292. for(var i=0;i<wx.getStorageSync('key').length;i++){
  293. }
  294. },
  295. image:function(e){
  296. let that=this
  297. that.data.imgIndex = e.target.dataset.index
  298. wx.showActionSheet({
  299. itemList: ['拍照', '选择图库', '我的材料'],
  300. success(res) {
  301. if (res.tapIndex==0){
  302. that.uploadImg('camera');
  303. } else if (res.tapIndex == 1){
  304. that.uploadImg('album');
  305. } else if (res.tapIndex == 2){
  306. wx.setStorageSync('setImageIndex', that.data.imgIndex.toString())
  307. wx.navigateTo({
  308. url: 'setData/setData',
  309. })
  310. }
  311. },
  312. fail(res) {
  313. }
  314. })
  315. return false
  316. },
  317. //跳转到基本表单
  318. basicForm:function(){
  319. this.setData({
  320. index:1
  321. })
  322. },
  323. dataName:function(e){
  324. this.data.dataName=e.detail.value
  325. },
  326. uploadImg:function(type){
  327. var that = this
  328. wx.chooseImage({
  329. count: 1,
  330. sizeType: ['original', 'compressed'],
  331. sourceType: [type],
  332. success(res) {
  333. wx.showLoading({
  334. title: '正在上传',
  335. })
  336. wx.hideLoading();
  337. wx.uploadFile({
  338. url: api.uploadImg,
  339. filePath: res.tempFilePaths[0],
  340. header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', },
  341. name: 'filePath',
  342. formData: {
  343. 'fileType': 'image'
  344. },
  345. success(res1) {
  346. var obj = {}
  347. wx.hideLoading()
  348. that.data.uploadImage = JSON.parse(res1.data)
  349. that.data.img = that.data.image ? that.data.image : []
  350. for (var i = 0; i < res.tempFilePaths.length; i++) {
  351. obj = { "url": that.data.uploadImage.data.filePath, "index": that.data.imgIndex, "time": i + '' + Math.random(), 'http': that.data.uploadImage.data.filePathPrefix }
  352. that.data.img.push(obj)
  353. }
  354. if (that.data.uploadImage.errno==0) {
  355. that.data.server.preService.preServiceMaterialList[that.data.imgIndex].isSet=1
  356. that.setData({
  357. image: that.data.img,
  358. mask: true,
  359. imageIndex: that.data.imgIndex,
  360. ['server.preService.preServiceMaterialList']: that.data.server.preService.preServiceMaterialList
  361. })
  362. }
  363. }
  364. })
  365. }
  366. })
  367. },
  368. // 编辑材料名称
  369. maskSubmit:function(){
  370. let that=this
  371. if (!that.data.dataName){
  372. wx.showToast({
  373. title: '名称不能为空',
  374. icon:'none'
  375. })
  376. return false;
  377. }
  378. wx.request({
  379. url: api.addMaterial,
  380. data: {
  381. userId: wx.getStorageSync('userId'),
  382. materialName: that.data.dataName,
  383. materialUrl: that.data.uploadImage.data.filePath
  384. },
  385. method:'POST',
  386. success(res) {
  387. wx.showToast({
  388. title: '添加成功',
  389. icon: 'none'
  390. })
  391. that.setData({
  392. mask: false
  393. })
  394. }
  395. })
  396. },
  397. //预览图片
  398. preview:function(e){
  399. var url=[]
  400. for (var i = 0; i < e.target.dataset.url.length;i++){
  401. if(e.target.dataset.url[i]!=''){
  402. url.push(e.target.dataset.url[i].http + e.target.dataset.url[i].url)
  403. }
  404. }
  405. wx.previewImage({
  406. current: e.target.dataset.url[e.target.dataset.i].http+e.target.dataset.url[e.target.dataset.i].url, // 当前显示图片的http链接
  407. urls: url // 需要预览的图片http链接列表
  408. })
  409. },
  410. // 删除已选图片
  411. deleteImg:function(e){
  412. var that=this;
  413. for(var i=0;i<that.data.img.length;i++){
  414. if (that.data.img[i].time == e.target.dataset.id){
  415. that.data.img.splice(i,1);
  416. }
  417. }
  418. var number=0
  419. for (var i = 0; i < that.data.img.length; i++){
  420. if (that.data.img[i].index == e.target.dataset.index){
  421. number++
  422. }
  423. }
  424. if(number>0){
  425. that.data.server.preService.preServiceMaterialList[e.target.dataset.index].isSet = 1
  426. }else{
  427. that.data.server.preService.preServiceMaterialList[e.target.dataset.index].isSet = 0
  428. }
  429. that.setData({
  430. image: that.data.img,
  431. ['server.preService.preServiceMaterialList']: that.data.server.preService.preServiceMaterialList
  432. })
  433. },
  434. applyname: function (e) {
  435. e.detail.value ? this.data.applyname = true : false
  436. this.setData({
  437. applyname: e.detail.value
  438. })
  439. },
  440. applyCardnumber: function (e) {
  441. e.detail.value ? this.data.applyCardnumber = true : false
  442. this.setData({
  443. applyCardnumber: e.detail.value
  444. })
  445. },
  446. contactman:function(e){
  447. e.detail.value?this.data.contactman=true:false
  448. this.setData({
  449. contactman: e.detail.value
  450. })
  451. },
  452. contactmanCardnumber:function(e){
  453. e.detail.value ? this.data.contactmanCardnumber = true : false
  454. this.setData({
  455. contactmanCardnumber: e.detail.value
  456. })
  457. },
  458. telphone:function(e){
  459. e.detail.value ? this.data.telphone = true : false
  460. this.setData({
  461. telphone: e.detail.value
  462. })
  463. },
  464. postcode:function(e){
  465. this.setData({
  466. postcode: e.detail.value
  467. })
  468. },
  469. address:function(e){
  470. this.setData({
  471. address: e.detail.value
  472. })
  473. },
  474. remark: function (e) {
  475. this.setData({
  476. remark: e.detail.value
  477. })
  478. },
  479. setInput(){
  480. if (this.data.contactman && this.data.contactmanCardnumber && this.data.telphone){
  481. return true
  482. }else{
  483. return false
  484. }
  485. },
  486. //切换自取、邮寄
  487. radioChange: function (e) {
  488. this.data.mode=e.detail.value
  489. if (e.detail.value=='pickUp'){
  490. this.setData({
  491. modeInput: false,
  492. ['items[0].checked']: true
  493. })
  494. } else if (e.detail.value =='post'){
  495. this.setData({
  496. modeInput: true,
  497. ['items[1].checked']:true
  498. })
  499. }
  500. },
  501. // 打开遮罩层
  502. mask: function () {
  503. let that = this;
  504. that.setData({
  505. mask: true
  506. })
  507. },
  508. // 关闭遮罩层
  509. clear: function () {
  510. let that = this;
  511. that.setData({
  512. mask: false
  513. })
  514. },
  515. // 确认申报
  516. submit: function () {
  517. wx.navigateTo({
  518. url: '../success/success',
  519. })
  520. },
  521. // 申报人证件类型
  522. bindSbCodeChange: function (e) {
  523. this.setData({
  524. codeIndex: e.detail.value
  525. })
  526. },
  527. // 联系人证件类型
  528. bindLxCodeChange: function (e) {
  529. this.setData({
  530. lxCodeIndex: e.detail.value
  531. })
  532. },
  533. // tab切换
  534. tab: function (e) {
  535. let that = this
  536. if (that.setInput()) {
  537. that.setData({
  538. index: e.currentTarget.dataset.index,
  539. current_index: e.currentTarget.dataset.index,
  540. setInput: true
  541. })
  542. } else {
  543. that.setData({
  544. index: e.currentTarget.dataset.index,
  545. current_index: e.currentTarget.dataset.index,
  546. setInput: false
  547. })
  548. }
  549. if(e.currentTarget.dataset.index==3){
  550. var query = wx.createSelectorQuery();
  551. query.select('.tab').boundingClientRect();
  552. query.select('.flxed-bottom1').boundingClientRect();
  553. query.exec(function (res) {
  554. that.data.topHeight = res[0].height
  555. that.data.flexHeight = res[1].height
  556. wx.getSystemInfo({
  557. success: function (res) {
  558. that.setData({
  559. clientHeight: res.windowHeight - that.data.topHeight - that.data.flexHeight
  560. });
  561. }
  562. })
  563. })
  564. }else{
  565. that.setData({
  566. clientHeight:that.data.oldHeight
  567. })
  568. }
  569. },
  570. change: function (e) {
  571. var that=this
  572. if (that.setInput()) {
  573. that.setData({
  574. index: e.detail.current,
  575. setInput: true
  576. })
  577. } else {
  578. that.setData({
  579. index: e.detail.current,
  580. setInput: false
  581. })
  582. }
  583. },
  584. // 下一步
  585. next: function () {
  586. let that = this
  587. that.setData({
  588. index: that.data.index + 1,
  589. current_index: that.data.index + 1
  590. })
  591. },
  592. // 上一步
  593. up: function () {
  594. let that = this
  595. that.setData({
  596. index: that.data.index - 1,
  597. current_index: that.data.index - 1
  598. })
  599. },
  600. /**
  601. * 生命周期函数--监听页面隐藏
  602. */
  603. onHide: function () {
  604. },
  605. /**
  606. * 生命周期函数--监听页面卸载
  607. */
  608. onUnload: function () {
  609. },
  610. /**
  611. * 页面相关事件处理函数--监听用户下拉动作
  612. */
  613. onPullDownRefresh: function () {
  614. },
  615. /**
  616. * 页面上拉触底事件的处理函数
  617. */
  618. onReachBottom: function () {
  619. },
  620. /**
  621. * 用户点击右上角分享
  622. */
  623. onShareAppMessage: function () {
  624. }
  625. })