edit-customer.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. var sysT = require('../../../tool/sys-tool.js')
  2. var verify = require('../../../tool/verify.js')
  3. var businessT = require('../../../tool/business-tool.js')
  4. var publicData = require('../../../constant/data.js')
  5. var url = require('../../../constant/url.js')
  6. import Net from '../../../tool/net.js'
  7. var net = new Net()
  8. var app = getApp()
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. adapter: {
  15. isIos: false,
  16. bgHeight: '',
  17. suffix: ''
  18. },
  19. scroll: true,
  20. inputHide: false,
  21. requireView: {
  22. animation: {},
  23. hidden: true
  24. },
  25. data: {},
  26. customer: {},//自动同步(引用)
  27. inputValue: '',
  28. textareaValue: '',
  29. textareaPlaceholderHide: false,
  30. idCard: {
  31. currentChose: '1',
  32. first_image: '',
  33. second_image: ''
  34. },
  35. userPhone: '',
  36. verify: {
  37. code: '',
  38. buttonT: '获取验证码',
  39. buttonC: 'verify-button-n',//verify-button-g
  40. hidden: true
  41. },
  42. // bankInfoHidden: true,
  43. bankCard: '',
  44. editBankCard: false
  45. },
  46. hiddenRequireView: businessT.action(function (sender) {
  47. var animation = wx.createAnimation({
  48. duration: 300,
  49. timingFunction: 'ease',
  50. })
  51. animation.bottom('-800rpx').step()
  52. this.setData({
  53. requireView: {
  54. animation: animation.export(),
  55. hidden: false
  56. }
  57. })
  58. setTimeout(function () {
  59. this.data.requireView.hidden = true
  60. this.setData({
  61. requireView: this.data.requireView,
  62. inputHide: false,
  63. scroll: true
  64. })
  65. }.bind(this), 300)
  66. }),
  67. requireAction: businessT.action(function (sender) {
  68. if (!this.data.requireView.hidden) {
  69. return
  70. }
  71. this.data.requireView.hidden = false
  72. this.setData({
  73. requireView: this.data.requireView,
  74. scroll: false,
  75. inputHide: true,
  76. })
  77. var animation = wx.createAnimation({
  78. duration: 300,
  79. timingFunction: 'ease',
  80. })
  81. animation.bottom('0rpx').step()
  82. this.setData({
  83. requireView: {
  84. animation: animation.export(),
  85. hidden: false
  86. }
  87. })
  88. }),
  89. saveAction: businessT.action(function (sender) {
  90. // businessT.debugLog(this.data.textareaValue.trim())
  91. var newData = false
  92. var phone = this.data.customer.phone
  93. var address = this.data.customer.hk_address
  94. if (this.data.inputValue != phone) {
  95. if (!verify.isPhoneNum(this.data.inputValue)) {
  96. wx.showToast({
  97. title: '请输入正确的手机号码',
  98. icon: 'none'
  99. })
  100. return
  101. }
  102. newData = true
  103. phone = this.data.inputValue
  104. }
  105. if (this.data.textareaValue != address) {
  106. var temp = this.data.textareaValue.trim()
  107. if (temp.length == 0) {
  108. wx.showToast({
  109. title: '请输入户籍地址',
  110. icon: 'none'
  111. })
  112. return
  113. }
  114. newData = true
  115. address = this.data.textareaValue
  116. } else {
  117. if (address.length == 0) {
  118. wx.showToast({
  119. title: '请输入户籍地址',
  120. icon: 'none'
  121. })
  122. return
  123. }
  124. }
  125. if (newData) {
  126. wx.showLoading({
  127. title: '正在保存',
  128. mask: true
  129. })
  130. net.connectNeedLogin({
  131. url: url.app_host + url.modifyCustomer,
  132. data: {
  133. id: this.data.customer.id,
  134. id_card: this.data.customer.id_card,
  135. hk_address: address,
  136. user_name: this.data.customer.user_name,
  137. nation: this.data.customer.nation,
  138. gender: this.data.customer.gender,
  139. phone: phone
  140. },
  141. success: (err, res) => {
  142. this.data.customer.phone = phone
  143. this.data.customer.hk_address = address
  144. wx.hideLoading()
  145. wx.showToast({
  146. title: '保存成功',
  147. icon: 'none'
  148. })
  149. },
  150. fail: (err, res) => {
  151. businessT.showFailTips(err, '保存失败')
  152. }
  153. })
  154. }
  155. if (this.data.idCard.first_image != '') {
  156. net.uploadImage({
  157. url: url.www_host + url.uploadIdcardById,
  158. imgPath: this.data.idCard.first_image,
  159. imgName: 'file1',
  160. data: { sbuId: this.data.customer.id, pos: 0 },
  161. success: (err, res) => {
  162. },
  163. fail: (err, res) => {
  164. }
  165. })
  166. this.data.idCard.first_image = ''
  167. }
  168. if (this.data.idCard.second_image != '') {
  169. net.uploadImage({
  170. url: url.www_host + url.uploadIdcardById,
  171. imgPath: this.data.idCard.second_image,
  172. imgName: 'file2',
  173. data: { sbuId: this.data.customer.id, pos: 1 },
  174. success: (err, res) => {
  175. },
  176. fail: (err, res) => {
  177. }
  178. })
  179. this.data.idCard.second_image = ''
  180. }
  181. if (!newData) {
  182. wx.showToast({
  183. title: '保存成功',
  184. icon: 'none'
  185. })
  186. }
  187. }),
  188. takePhoto: businessT.action(function (sender) {
  189. this.data.idCard.currentChose = sender.currentTarget.id
  190. wx.navigateTo({
  191. url: '../../../public/pages/take-photo/take-photo',
  192. })
  193. }),
  194. finishTakePhoto: function (path) {
  195. if (this.data.idCard.currentChose == '1') {
  196. this.data.idCard.first_image = path
  197. this.data.data.first_image = path
  198. this.setData({
  199. data: this.data.data
  200. })
  201. } else if (this.data.idCard.currentChose == '2') {
  202. this.data.idCard.second_image = path
  203. this.data.data.second_image = path
  204. this.setData({
  205. data: this.data.data
  206. })
  207. }
  208. },
  209. checkImage: businessT.action(function (sender) {
  210. if (sender.currentTarget.id == '1' && this.data.idCard.first_image != '') {
  211. wx.previewImage({
  212. urls: [this.data.idCard.first_image],
  213. })
  214. } else if (sender.currentTarget.id == '2' && this.data.idCard.second_image != '') {
  215. wx.previewImage({
  216. urls: [this.data.idCard.second_image],
  217. })
  218. }
  219. }),
  220. inputAction: function (sender) {
  221. businessT.debugLog(sender)
  222. this.data.inputValue = sender.detail.value
  223. this.setData({
  224. inputValue: this.data.inputValue
  225. })
  226. },
  227. textareaInput: function (sender) {
  228. businessT.debugLog(sender)
  229. this.data.textareaValue = sender.detail.value
  230. this.setData({
  231. textareaValue: this.data.textareaValue
  232. })
  233. },
  234. textareaFocus: function (sender) {
  235. if (!this.data.textareaPlaceholderHide) {
  236. this.data.textareaPlaceholderHide = true;
  237. this.setData({
  238. textareaPlaceholderHide: this.data.textareaPlaceholderHide
  239. })
  240. }
  241. },
  242. textareaBlur: function (sender) {
  243. if (this.data.textareaValue.length == 0 && this.data.textareaPlaceholderHide) {
  244. this.data.textareaPlaceholderHide = false;
  245. this.setData({
  246. textareaPlaceholderHide: this.data.textareaPlaceholderHide
  247. })
  248. }
  249. },
  250. verifyInputAction: function (sender) {
  251. businessT.debugLog(sender)
  252. this.data.verify.code = sender.detail.value
  253. this.setData({
  254. verify: this.data.verify
  255. })
  256. },
  257. getVerify: businessT.action(function (sender) {
  258. if (this.data.verify.buttonC == 'verify-button-g') {
  259. return
  260. }
  261. this.data.verify.buttonC = 'verify-button-g'
  262. this.data.verify.buttonT = '正在获取'
  263. this.setData({
  264. verify: this.data.verify
  265. })
  266. net.connect({
  267. url: url.app_host + url.getVerifyCode,
  268. data: {
  269. phone: app.globalData.userInfo.phone,
  270. },
  271. method: 'POST',
  272. success: (err, res) => {
  273. this.setVerifyButtonReciprocal(60)
  274. },
  275. fail: (err, res) => {
  276. this.setVerifyButtonReciprocal(0)
  277. businessT.showFailTips(err, '获取验证码失败')
  278. }
  279. })
  280. }),
  281. setVerifyButtonReciprocal: function (i) {
  282. if (this.data.verify.hidden) {
  283. return
  284. }
  285. if (i == 0) {
  286. this.data.verify.buttonC = 'verify-button-n'
  287. this.data.verify.buttonT = '获取验证码'
  288. this.setData({
  289. verify: this.data.verify
  290. })
  291. } else {
  292. this.data.verify.buttonC = 'verify-button-g'
  293. this.data.verify.buttonT = '还剩' + i + '秒'
  294. this.setData({
  295. verify: this.data.verify
  296. })
  297. setTimeout(function () {
  298. i--
  299. this.setVerifyButtonReciprocal(i)
  300. }.bind(this), 1000)
  301. }
  302. },
  303. getIdCard: businessT.action(function (sender) {
  304. if (this.data.verify.code.length != publicData.verifyCodeLength) {
  305. wx.showToast({
  306. title: '请输入四位验证码',
  307. icon: 'none'
  308. })
  309. return
  310. }
  311. wx.showLoading({
  312. title: '加载中',
  313. mask: true
  314. })
  315. net.connectNeedLogin({
  316. url: url.app_host + url.getCustomer,
  317. data: {
  318. id: this.data.customer.id,
  319. verifyCode: this.data.verify.code
  320. },
  321. success: (err, res) => {
  322. this.data.data.getIdCard = true
  323. this.hiddenVerifyView()
  324. this.data.data.id_card = res.data.id_card
  325. this.setData({
  326. data: this.data.data
  327. })
  328. wx.hideLoading()
  329. },
  330. fail: (err, res) => {
  331. wx.hideLoading()
  332. businessT.showFailTips(err, '加载失败')
  333. }
  334. }, true)
  335. }),
  336. hiddenVerifyView: function () {
  337. this.data.verify.hidden = true
  338. this.setData({
  339. verify: this.data.verify,
  340. inputHide: false,
  341. scroll: true
  342. })
  343. },
  344. hiddenIdCard: businessT.action(function (sender) {
  345. this.hiddenVerifyView()
  346. }),
  347. showIdCard: businessT.action(function (sender) {
  348. if (!this.data.verify.hidden || this.data.data.getIdCard) {
  349. return
  350. }
  351. this.data.verify = {
  352. code: '',
  353. buttonT: '获取验证码',
  354. buttonC: 'verify-button-n',
  355. hidden: false
  356. }
  357. this.setData({
  358. verify: this.data.verify,
  359. scroll: false,
  360. inputHide: true,
  361. })
  362. }),
  363. // bankInfo: businessT.action(function (sender) {
  364. // if (!this.data.bankInfoHidden) {
  365. // return
  366. // }
  367. // this.data.bankInfoHidden = false
  368. // this.setData({
  369. // bankInfoHidden: this.data.bankInfoHidden,
  370. // scroll: false,
  371. // inputHide: true,
  372. // })
  373. // }),
  374. // dismissBankInfo: businessT.action(function (sender) {
  375. // this.data.bankInfoHidden = true
  376. // this.setData({
  377. // bankInfoHidden: this.data.bankInfoHidden,
  378. // scroll: false,
  379. // inputHide: false,
  380. // })
  381. // }),
  382. editBankCard: businessT.action(function (sender) {
  383. this.data.editBankCard = true
  384. wx.navigateTo({
  385. url: '../edit-bank/edit-bank?i=' + this.data.customerIndex,
  386. })
  387. }),
  388. getBankCode: function () {
  389. var bankCode = String(this.data.customer.bank_code)
  390. if (bankCode.length == 0) {
  391. this.data.bankCard = '未添加'
  392. } else {
  393. this.data.bankCard = '**** **** **** ' + bankCode.substring(bankCode.length - 4)
  394. }
  395. },
  396. /**
  397. * 生命周期函数--监听页面加载
  398. */
  399. onLoad: function (options) {
  400. sysT.adaptor()
  401. businessT.debugLog(sysT.usableHeight(112))
  402. this.data.customer = app.globalData.customerList[options.i]
  403. this.data.customerIndex = options.i
  404. this.data.data = {
  405. id_card: this.data.customer.id_card,
  406. user_name: this.data.customer.user_name,
  407. nation: this.data.customer.nation,
  408. phone: this.data.customer.phone,
  409. shebao_card: this.data.customer.shebao_card,
  410. fund_card: this.data.customer.fund_card,
  411. first_image: '../../../icon/public/customer_idcard_front.png',
  412. second_image: '../../../icon/public/customer_idcard_verso.png',
  413. getIdCard: false,
  414. hk_address: this.data.customer.hk_address,
  415. }
  416. businessT.debugLog(this.data.data)
  417. wx.setNavigationBarTitle({
  418. title: this.data.data.user_name,
  419. })
  420. var isIos = sysT.sysInfo().system.indexOf("iOS") == 0
  421. this.data.adapter = {
  422. isIos: isIos,
  423. bgHeight: sysT.usableHeight(112),
  424. suffix: sysT.suffixOfClass(),
  425. }
  426. this.data.userPhone = String(app.globalData.userInfo.phone).slice(0, 3) + '****' + String(app.globalData.userInfo.phone).slice(7, 11)
  427. this.data.textareaPlaceholderHide = this.data.data.hk_address.length > 0
  428. this.getBankCode()
  429. this.setData({
  430. adapter: this.data.adapter,
  431. data: this.data.data,
  432. textareaValue: this.data.data.hk_address,
  433. textareaPlaceholderHide: this.data.textareaPlaceholderHide,
  434. inputValue: this.data.data.phone,
  435. userPhone: this.data.userPhone,
  436. bankCard: this.data.bankCard
  437. })
  438. },
  439. wxvoid: function () {
  440. },
  441. /**
  442. * 生命周期函数--监听页面初次渲染完成
  443. */
  444. onReady: function () {
  445. },
  446. /**
  447. * 生命周期函数--监听页面显示
  448. */
  449. onShow: function () {
  450. if (this.data.editBankCard) {
  451. this.data.editBankCard = false
  452. this.getBankCode()
  453. this.setData({
  454. bankCard: this.data.bankCard
  455. })
  456. }
  457. },
  458. /**
  459. * 生命周期函数--监听页面隐藏
  460. */
  461. onHide: function () {
  462. },
  463. /**
  464. * 生命周期函数--监听页面卸载
  465. */
  466. onUnload: function () {
  467. },
  468. /**
  469. * 页面相关事件处理函数--监听用户下拉动作
  470. */
  471. onPullDownRefresh: function () {
  472. },
  473. /**
  474. * 页面上拉触底事件的处理函数
  475. */
  476. onReachBottom: function () {
  477. },
  478. /**
  479. * 用户点击右上角分享
  480. */
  481. // onShareAppMessage: function () {
  482. // }
  483. })