No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

716 líneas
21 KiB

  1. var app = getApp();
  2. const config = require('../../../../config/config.js')
  3. const util = require('../../../../utils/util.js')
  4. const Http = require('../../../../utils/HttpBasics.js')
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. businessLicenseInfo: null,
  11. idCardInfo: null,
  12. idDocInfo: null,
  13. idDocType: null,
  14. id: "",
  15. organizationType: '',
  16. isSeal: "false",
  17. commonLsit: [{
  18. id: "true",
  19. name: "是",
  20. },
  21. {
  22. id: "false",
  23. name: "否",
  24. }],
  25. licenseEffectiveIdentityType: 1, ///身份证有效期类型
  26. figureLsit: [{
  27. id: 1,
  28. name: "法定代表人/经营者"
  29. },
  30. {
  31. id: 2,
  32. name: "经办人"
  33. },
  34. ],
  35. figureType: "",
  36. certificateType: null, //证件类型
  37. certificateLsit: [{
  38. id: 1,
  39. name: "中国大陆居民-身份证"
  40. },
  41. {
  42. id: 2,
  43. name: "其他国家或地区居民-护照"
  44. },
  45. {
  46. id: 3,
  47. name: "中国香港居民--来往内地通行证"
  48. },
  49. {
  50. id: 4,
  51. name: "中国澳门居民--来往内地通行证"
  52. },
  53. {
  54. id: 5,
  55. name: "中国台湾居民--来往内地通行证"
  56. },
  57. {
  58. id: 6,
  59. name: "外国人居留证"
  60. },
  61. {
  62. id: 7,
  63. name: "港澳居民证"
  64. },
  65. {
  66. id: 8,
  67. name: "台湾居民证"
  68. },
  69. ],
  70. identityZUrl: "",
  71. identityFUrl: "",
  72. licenseEffectiveIdentity: "", //身份证生效日期
  73. licenseLoseIdentity: "", //
  74. contactInfo: {
  75. is_index: "0",
  76. is_seal: "true",
  77. certificateIndex: 0, //证件下标
  78. contact_type: "1", //超级管理员类型 1经营者/法人2经办人
  79. figureIndex: 0, //超管身份下标
  80. contact_name: "", //超级管理员姓名
  81. mobile_phone: "", //联系手机
  82. contact_email: "", //邮箱
  83. contact_department: "", //超级管理员部门(当选择经办人时传)
  84. contact_job: "", //超级管理员职务(当选择经办人时传)
  85. contact_id_doc_type: 1, //超级管理员证件类型 身份证 等(当选择经办人时传)
  86. contact_id_number: "", //超级管理员证件号码 (当选择经办人时传)
  87. contact_id_doc_copy_info: { //超级管理员证件正面照片 (当选择经办人时传)
  88. url: "",
  89. media_id: ""
  90. },
  91. contact_id_doc_copy_back_info: { //超级管理员证件反面照片 护照不传 (当选择经办人时传)
  92. url: "",
  93. media_id: ""
  94. },
  95. contact_period_type: "1", //1=定期 2=长期 (当选择经办人时传)
  96. contact_period_begin: "", //超级管理员证件有效期开始时间 (当选择经办人时传)
  97. contact_period_end: "", //超级管理员证件有效期结束时间 (当选择经办人时传)
  98. business_authorization_letter_info: { //业务办理授权函(当选择经办人时传)
  99. url: "",
  100. media_id: ""
  101. }
  102. },
  103. active1: '',
  104. active2: '',
  105. active3: '',
  106. },
  107. save(e) {
  108. let flag = e.currentTarget.dataset.flag
  109. let parame = {};
  110. let tempContactInfo = {}
  111. let reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; //11位手机号码正则
  112. let reg_em = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/; //验证邮箱
  113. let errMeg = "";
  114. let errFlag = false;
  115. if (this.data.contactInfo.contact_type == 1) {
  116. if (!this.data.contactInfo.contact_name) {
  117. errMeg = "请输入超管姓名";
  118. errFlag = true;
  119. } else if (!this.data.contactInfo.mobile_phone || !reg_tel.test(this.data.contactInfo.mobile_phone)) {
  120. errMeg = "请输入正确手机号码";
  121. errFlag = true;
  122. } else if (!this.data.contactInfo.contact_email || !reg_em.test(this.data.contactInfo.contact_email)) {
  123. errMeg = "请输入正确电子邮箱";
  124. errFlag = true;
  125. }
  126. } else if (this.data.contactInfo.contact_type == 2) {
  127. if (!this.data.contactInfo.contact_name) {
  128. errMeg = "请输入超管姓名";
  129. errFlag = true;
  130. } else if (!this.data.contactInfo.mobile_phone || !reg_tel.test(this.data.contactInfo.mobile_phone)) {
  131. errMeg = "请输入正确手机号码";
  132. errFlag = true;
  133. } else if (!this.data.contactInfo.contact_email || !reg_em.test(this.data.contactInfo.contact_email)) {
  134. errMeg = "请输入正确电子邮箱";
  135. errFlag = true;
  136. } else if (!this.data.contactInfo.contact_id_doc_copy_info.url) {
  137. errMeg = "请上传证件正面照";
  138. errFlag = true;
  139. } else if (!this.data.contactInfo.contact_id_doc_copy_back_info.url) {
  140. errMeg = "请上传证件反面照";
  141. errFlag = true;
  142. } else if (!this.data.contactInfo.contact_id_number) {
  143. errMeg = "请输入证件号码";
  144. errFlag = true;
  145. } else if (!this.data.contactInfo.contact_department) {
  146. errMeg = "请输入职称部门";
  147. errFlag = true;
  148. } else if (!this.data.contactInfo.contact_job) {
  149. errMeg = "请输入职务";
  150. errFlag = true;
  151. }
  152. //else if (!this.data.contactInfo.business_authorization_letter_info.url) {
  153. // errMeg = "请输入上传业务办理授权函";
  154. // errFlag = true;
  155. // }
  156. }
  157. if (errFlag) {
  158. wx.showToast({
  159. title: errMeg,
  160. icon: "none",
  161. duration: 2000
  162. })
  163. return
  164. }
  165. if (this.data.contactInfo.contact_type == 1 && this.data.contactInfo.contact_period_type == 2) {
  166. let tempObj = this.data.contactInfo
  167. tempObj.contact_period_end = "长期"
  168. this.setData({
  169. contactInfo: tempObj
  170. })
  171. }
  172. if (this.data.contactInfo.contact_type == 1) { //1经营者/法人2经办人
  173. tempContactInfo.contact_type = this.data.contactInfo.contact_type
  174. tempContactInfo.contact_name = this.data.contactInfo.contact_name
  175. tempContactInfo.mobile_phone = this.data.contactInfo.mobile_phone
  176. tempContactInfo.contact_email = this.data.contactInfo.contact_email
  177. tempContactInfo.certificateIndex = this.data.contactInfo.certificateIndex
  178. } else if (this.data.contactInfo.contact_type == 2) {
  179. tempContactInfo.contact_type = this.data.contactInfo.contact_type
  180. tempContactInfo.contact_name = this.data.contactInfo.contact_name
  181. tempContactInfo.mobile_phone = this.data.contactInfo.mobile_phone
  182. tempContactInfo.contact_email = this.data.contactInfo.contact_email
  183. tempContactInfo.contact_department = this.data.contactInfo.contact_department
  184. tempContactInfo.contact_job = this.data.contactInfo.contact_job
  185. tempContactInfo.contact_id_doc_type = this.data.contactInfo.contact_id_doc_type
  186. tempContactInfo.contact_id_number = this.data.contactInfo.contact_id_number
  187. tempContactInfo.contact_id_doc_copy_info = this.data.contactInfo.contact_id_doc_copy_info
  188. if (this.data.contactInfo.contact_id_doc_type != 2) {
  189. tempContactInfo.contact_id_doc_copy_back_info = this.data.contactInfo.contact_id_doc_copy_back_info
  190. }
  191. tempContactInfo.contact_period_type = this.data.contactInfo.contact_period_type
  192. tempContactInfo.contact_period_begin = this.data.contactInfo.contact_period_begin
  193. tempContactInfo.contact_period_end = this.data.contactInfo.contact_period_end
  194. tempContactInfo.business_authorization_letter_info = this.data.contactInfo.business_authorization_letter_info
  195. tempContactInfo.figureIndex = this.data.contactInfo.figureIndex
  196. tempContactInfo.certificateIndex = this.data.contactInfo.certificateIndex
  197. tempContactInfo.is_index = this.data.contactInfo.is_index
  198. tempContactInfo.is_seal = this.data.contactInfo.is_seal
  199. }
  200. console.log(tempContactInfo)
  201. parame = {
  202. id: this.data.id,
  203. organizationType: this.data.organizationType,
  204. contactInfo: JSON.stringify(tempContactInfo)
  205. }
  206. console.log(parame, "parame")
  207. Http.post({
  208. url: config.api.receiverAdd,
  209. data: parame
  210. }).then(res => {
  211. console.log(res, "res")
  212. if (flag == "save") {
  213. wx.reLaunch({
  214. url: '/pages/warehouse/warehouse',
  215. })
  216. } else if (flag == "next") {
  217. wx.switchTab({
  218. url: '/pages/mine/mine',
  219. })
  220. }
  221. }).catch(err => {
  222. wx.showToast({
  223. title: err.message,
  224. icon: "none",
  225. duration: 2000
  226. })
  227. })
  228. },
  229. normalImage(e) {
  230. let type = e.currentTarget.dataset.type
  231. if (type == 1) {
  232. this.setData({
  233. active1: false
  234. })
  235. } else if (type == 2) {
  236. this.setData({
  237. active2: false
  238. })
  239. } else if (type == 3) {
  240. this.setData({
  241. active3: false
  242. })
  243. }
  244. console.log('normalImage');
  245. },
  246. previewImage(e) {
  247. let type = e.currentTarget.dataset.type
  248. if (type == 1) {
  249. this.setData({
  250. active1: true
  251. })
  252. } else if (type == 2) {
  253. this.setData({
  254. active2: true
  255. })
  256. } else if (type == 3) {
  257. this.setData({
  258. active3: true
  259. })
  260. }
  261. console.log('previewImage');
  262. },
  263. setValue(e) {
  264. let flag = e.currentTarget.dataset.flag
  265. let value = e.detail.value.trim()
  266. let tempObj = this.data.contactInfo
  267. tempObj[flag] = value
  268. console.log(value)
  269. this.setData({
  270. contactInfo: tempObj
  271. })
  272. },
  273. setlicenseEffectiveIdentityType(e) {
  274. let index = e.currentTarget.dataset.index
  275. let tempObj = this.data.contactInfo
  276. tempObj.contact_period_type = index
  277. this.setData({
  278. contactInfo: tempObj
  279. })
  280. },
  281. getReceiverApply() {
  282. wx.showLoading({
  283. title: '加载中...',
  284. })
  285. Http.get({
  286. url: config.api.getReceiverApply,
  287. data: {
  288. merchantId: app.globalData.merchant.merchant_id
  289. }
  290. }).then(res => {
  291. if (res.data && res.data.organizationType) {
  292. this.setData({
  293. organizationType: res.data.organizationType
  294. })
  295. }
  296. if (res.data && res.data.id) {
  297. this.setData({
  298. id: res.data.id
  299. })
  300. }
  301. if (res.data && res.data.contactInfo) {
  302. let obj = JSON.parse(res.data.contactInfo)
  303. this.setData({
  304. contactInfo: {
  305. ...this.data.contactInfo,
  306. ...obj
  307. }
  308. })
  309. }
  310. console.log(this.data.contactInfo, "this.data.contactInfo")
  311. if (this.data && res.data.businessLicenseInfo) {
  312. let obj = JSON.parse(res.data.businessLicenseInfo)
  313. this.setData({
  314. businessLicenseInfo: obj
  315. })
  316. }
  317. if (res.data.idCardInfo) {
  318. let obj = JSON.parse(res.data.idCardInfo)
  319. console.log(obj.id_card_number, 'id_card_number');
  320. this.setData({
  321. idCardInfo: obj
  322. })
  323. }
  324. if (res.data && res.data.idDocInfo) {
  325. let obj = JSON.parse(res.data.idDocInfo)
  326. this.setData({
  327. idDocInfo: obj
  328. })
  329. }
  330. if (res.data && res.data.idDocType) {
  331. this.setData({
  332. idDocType: res.data.idDocType
  333. })
  334. }
  335. console.log(this.data.contactInfo, "contactInfo")
  336. wx.hideLoading();
  337. }).catch(err => {
  338. wx.hideLoading();
  339. wx.showToast({
  340. title: err.message,
  341. icon: "none",
  342. duration: 2000
  343. })
  344. })
  345. },
  346. authorization() {
  347. let that = this;
  348. wx.chooseImage({
  349. success(res) {
  350. const tempFilePaths = res.tempFilePaths
  351. wx.uploadFile({
  352. url: config.api.merchantUpload, // 仅为示例,非真实的接口地址
  353. filePath: tempFilePaths[0],
  354. name: 'file',
  355. header: {
  356. 'token': app.globalData.token
  357. },
  358. success(res) {
  359. let tempObj = that.data.contactInfo
  360. tempObj.business_authorization_letter_info = JSON.parse(res.data).data
  361. that.setData({
  362. contactInfo: tempObj
  363. })
  364. // do something
  365. console.log(JSON.parse(res.data).data)
  366. }
  367. })
  368. }
  369. })
  370. },
  371. upIdentityZ() {
  372. let that = this;
  373. wx.chooseImage({
  374. success(res) {
  375. const tempFilePaths = res.tempFilePaths
  376. wx.uploadFile({
  377. url: config.api.merchantUpload, // 仅为示例,非真实的接口地址
  378. filePath: tempFilePaths[0],
  379. name: 'file',
  380. header: {
  381. 'token': app.globalData.token
  382. },
  383. success(res) {
  384. let tempObj = that.data.contactInfo
  385. tempObj.contact_id_doc_copy_info = JSON.parse(res.data).data
  386. that.setData({
  387. contactInfo: tempObj
  388. })
  389. // do something
  390. console.log(JSON.parse(res.data).data)
  391. }
  392. })
  393. }
  394. })
  395. },
  396. upIdentityF() {
  397. let that = this;
  398. wx.chooseImage({
  399. success(res) {
  400. const tempFilePaths = res.tempFilePaths
  401. wx.uploadFile({
  402. url: config.api.merchantUpload, // 仅为示例,非真实的接口地址
  403. filePath: tempFilePaths[0],
  404. name: 'file',
  405. header: {
  406. 'token': app.globalData.token
  407. },
  408. success(res) {
  409. let tempObj = that.data.contactInfo
  410. tempObj.contact_id_doc_copy_back_info = JSON.parse(res.data).data
  411. that.setData({
  412. contactInfo: tempObj
  413. })
  414. // do something
  415. }
  416. })
  417. }
  418. })
  419. },
  420. delIdentityFUrl() {
  421. let tempObj = this.data.contactInfo
  422. tempObj.contact_id_doc_copy_back_info = {}
  423. this.setData({
  424. contactInfo: tempObj,
  425. })
  426. },
  427. delIdentityZUrl() {
  428. let tempObj = this.data.contactInfo
  429. tempObj.contact_id_doc_copy_info = {}
  430. this.setData({
  431. contactInfo: tempObj,
  432. })
  433. },
  434. delAuthorization() {
  435. let tempObj = this.data.contactInfo
  436. tempObj.business_authorization_letter_info = {}
  437. this.setData({
  438. contactInfo: tempObj,
  439. })
  440. },
  441. setIsSealIndex(e) {
  442. let tempObj = this.data.contactInfo
  443. let id = this.data.commonLsit[e.detail.value].id
  444. tempObj.is_index = e.detail.value
  445. tempObj.is_seal = id
  446. this.setData({
  447. contactInfo: tempObj,
  448. })
  449. },
  450. bindDateChange1: function (e) {
  451. let id = this.data.figureLsit[e.detail.value].id
  452. let tempObj = this.data.contactInfo
  453. tempObj.contact_type = id
  454. tempObj.figureIndex = e.detail.value
  455. this.setData({
  456. contactInfo: tempObj
  457. })
  458. },
  459. bindDateChange2: function (e) {
  460. let id = this.data.certificateLsit[e.detail.value].id
  461. let tempObj = this.data.contactInfo
  462. tempObj.certificateIndex = e.detail.value
  463. tempObj.contact_id_doc_type = id
  464. this.setData({
  465. contactInfo: tempObj
  466. })
  467. console.log(id)
  468. },
  469. bindDateChange3: function (e) {
  470. let tempObj = this.data.contactInfo
  471. tempObj.contact_period_begin = e.detail.value
  472. this.setData({
  473. contactInfo: tempObj,
  474. })
  475. },
  476. bindDateChange4: function (e) {
  477. let tempObj = this.data.contactInfo
  478. tempObj.contact_period_end = e.detail.value
  479. this.setData({
  480. contactInfo: tempObj,
  481. })
  482. },
  483. downloadUrl() {
  484. let param = {
  485. contact_name: this.data.contactInfo.contact_name, //经办人姓名
  486. contact_id_number: this.data.contactInfo.contact_id_number, //经办人身份证
  487. contact_department: this.data.contactInfo.contact_department, //部门
  488. contact_job: this.data.contactInfo.contact_job, //职位
  489. id_card_number: this.data.idCardInfo.id_card_number,// 法人身份证号
  490. legal_person: this.data.businessLicenseInfo.legal_person, //法人姓名
  491. is_seal: this.data.contactInfo.is_seal, //是否有公章(字符串"true","false")
  492. merchant_name: this.data.businessLicenseInfo.merchant_name, //商户或企业名称
  493. card_period_begin: '',
  494. card_period_end: ''
  495. }
  496. if (this.data.idDocType == 1) {
  497. param.id_card_number = this.data.idCardInfo.id_card_number ? this.data.idCardInfo.id_card_number : ''; //法人身份证
  498. param.card_period_begin = this.data.idCardInfo.card_period_begin ? this.data.idCardInfo.card_period_begin : ''; //法人身份证有效期开始
  499. param.card_period_end = this.data.idCardInfo.card_period_end ? this.data.idCardInfo.card_period_end : ''; //法人身份证有效期结束
  500. } else {
  501. param.id_card_number = this.data.idDocInfo.id_card_number ? this.data.idDocInfo.id_card_number : ''; //法人身份证
  502. param.card_period_begin = this.data.idDocInfo.card_period_begin ? this.data.idDocInfo.card_period_begin : ''; //法人身份证有效期开始
  503. param.card_period_end = this.data.idDocInfo.card_period_end ? this.data.idDocInfo.card_period_end : ''; //法人身份证有效期结束
  504. }
  505. let errMeg = "";
  506. let errFlag = false;
  507. // 身份证号码正则校验——(中国大陆-兼容1代2代身份证号)
  508. const idReg = /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/
  509. if (!param.contact_name) {
  510. errMeg = "请输入证件姓名";
  511. errFlag = true;
  512. } else if (!param.contact_id_number) {
  513. errMeg = "请输入证件号码";
  514. errFlag = true;
  515. } else if (param.contact_id_number) {
  516. if (!idReg.test(param.contact_id_number)) {
  517. errMeg = "身份证号格式错误!";
  518. errFlag = true;
  519. }
  520. } else if (!param.contact_job) {
  521. errMeg = "请输入职务";
  522. errFlag = true;
  523. } else if (!param.contact_department) {
  524. errMeg = "请输入任职部门";
  525. errFlag = true;
  526. } else if (!param.legal_person) {
  527. errMeg = "请返回步骤一输入法人姓名";
  528. errFlag = true;
  529. } else if (!param.id_card_number) {
  530. errMeg = "请返回步骤一输入法人身份证号";
  531. errFlag = true;
  532. } else if (!param.card_period_begin || !param.card_period_end) {
  533. errMeg = "请返回步骤一输入法人身份证有效期";
  534. errFlag = true;
  535. } else if (!param.merchant_name) {
  536. errMeg = "请返回步骤一输入商户名称";
  537. errFlag = true;
  538. }
  539. // 当校验不通过时,阻止请求发送
  540. if (errFlag) {
  541. wx.showToast({
  542. title: errMeg,
  543. icon: "none",
  544. duration: 2000
  545. })
  546. return
  547. }
  548. wx.showLoading({
  549. title: '下载中...',
  550. })
  551. console.log(param, 'param');
  552. Http.post({
  553. url: config.api.getYwsqh,
  554. data: param
  555. }).then(res => {
  556. console.log(res, '获得的图片信息')
  557. const filepath = wx.env.USER_DATA_PATH + '/test.png';
  558. const imgTrans = wx.getFileSystemManager()
  559. imgTrans.writeFile({
  560. filePath: filepath,
  561. data: res.data,
  562. encoding: 'base64',
  563. success: res => {
  564. wx.saveImageToPhotosAlbum({
  565. filePath: filepath,
  566. success: function (res) {
  567. wx.hideLoading();
  568. wx.showToast({
  569. title: '保存成功',
  570. icon: "none"
  571. })
  572. },
  573. fail: function (err) {
  574. console.log(err, "errw")
  575. wx.showToast({
  576. title: "下载失败",
  577. icon: "none",
  578. duration: 3000
  579. })
  580. }
  581. })
  582. }
  583. })
  584. }).catch(err => {
  585. console.log(err)
  586. wx.hideLoading()
  587. wx.showToast({
  588. title: "下载失败",
  589. icon: "none",
  590. duration: 2000
  591. })
  592. })
  593. },
  594. /**
  595. * 生命周期函数--监听页面加载
  596. */
  597. onLoad: function (options) {
  598. this.getReceiverApply()
  599. let that = this;
  600. //获取完整的日期
  601. let date = new Date;
  602. let year = date.getFullYear();
  603. let month = date.getMonth() + 1;
  604. let day = date.getDate();
  605. let tempObj = this.data.contactInfo
  606. tempObj.contact_period_begin = year + '-' + month + '-' + day
  607. tempObj.contact_period_end = year + '-' + month + '-' + day
  608. if (month < 10) {
  609. month = "0" + month
  610. }
  611. if (day < 10) {
  612. day = "0" + day
  613. }
  614. that.setData({
  615. licenseEffectiveIdentity: year + '-' + month + '-' + day,
  616. licenseLoseIdentity: year + '-' + month + '-' + day,
  617. contactInfo: tempObj
  618. })
  619. },
  620. /**
  621. * 生命周期函数--监听页面初次渲染完成
  622. */
  623. onReady: function () {
  624. },
  625. /**
  626. * 生命周期函数--监听页面显示
  627. */
  628. onShow: function () {
  629. },
  630. /**
  631. * 生命周期函数--监听页面隐藏
  632. */
  633. onHide: function () {
  634. },
  635. /**
  636. * 生命周期函数--监听页面卸载
  637. */
  638. onUnload: function () {
  639. },
  640. /**
  641. * 页面相关事件处理函数--监听用户下拉动作
  642. */
  643. onPullDownRefresh: function () {
  644. },
  645. /**
  646. * 页面上拉触底事件的处理函数
  647. */
  648. onReachBottom: function () {
  649. },
  650. /**
  651. * 用户点击右上角分享
  652. */
  653. onShareAppMessage: function () {
  654. }
  655. })