Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

551 řádky
13 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. id: "",
  11. organizationType: '',
  12. accountType: "",
  13. bankingList: [],
  14. bankBoj: null, //存放当前选中银行
  15. tempArr: [], //临时存放查询数据
  16. province: [], //省份数组
  17. provinceIndex: 0,
  18. city: [], //市
  19. cityIndex: 0,
  20. branch: [], //支行
  21. branchIndex: 0,
  22. accountList: [{
  23. id: 74,
  24. name: "对公银行账户"
  25. },
  26. {
  27. id: 75,
  28. name: "个人银行账户"
  29. },
  30. ],
  31. accountInfo: {
  32. bankAlias: "",
  33. bank_account_type: 74, //账户类型 74对公75对私
  34. accountIndex: 0,
  35. account_name: "", //开户名称
  36. account_bank: "", //开户银行
  37. need_bank_branch: "", //是否有支行
  38. bank_address_code: "", //开户银行省市编码
  39. bank_branch_id: "", //开户银行联行号
  40. bank_name: "", //开户银行全称(含支行)
  41. account_number: "", //银行账号
  42. },
  43. },
  44. setBranch(e) {
  45. console.log('setBranch')
  46. let value = e.detail.value
  47. console.log(value);
  48. let tempObj = this.data.accountInfo
  49. tempObj.bank_branch_id = this.data.branch[value].bankBranchId
  50. tempObj.bank_name = this.data.branch[value].bankBranchName
  51. this.setData({
  52. accountInfo: tempObj,
  53. branchIndex: value
  54. })
  55. },
  56. setAccount_name(e) {
  57. let value = e.detail.value
  58. let tempObj = this.data.accountInfo
  59. tempObj.account_name = value
  60. this.setData({
  61. accountInfo: tempObj,
  62. })
  63. },
  64. getBankBranches(e) {
  65. wx.showLoading({
  66. title: '加载中...',
  67. })
  68. console.log('getBankBranches')
  69. // if (!e.detail.ins) {
  70. // this.data.accountInfo.bankAlias = ''
  71. // this.data.accountInfo.bank_name = ''
  72. // }
  73. let value = e.detail.value
  74. let tempObj = this.data.accountInfo
  75. tempObj.bank_address_code = this.data.city[value].regionCode
  76. this.data.accountInfo.cityName = this.data.city[value].cityName
  77. this.setData({
  78. cityIndex: value,
  79. accountInfo: tempObj
  80. })
  81. if (this.data.bankBoj && this.data.bankBoj.needBankBranch) {
  82. Http.get({
  83. url: config.api.bankBranches,
  84. data: {
  85. bankAliasCode: this.data.bankBoj.bankAliasCode,
  86. cityCode: this.data.city[value].cityCode
  87. }
  88. }).then(res => {
  89. this.setData({
  90. branch: res.data
  91. })
  92. wx.hideLoading();
  93. this.setBranch({
  94. detail: {
  95. value: 0
  96. }
  97. })
  98. }).catch(err => {
  99. wx.hideLoading();
  100. wx.showToast({
  101. title: err.message,
  102. icon: "none",
  103. duration: 2000
  104. })
  105. })
  106. } else {
  107. wx.hideLoading();
  108. }
  109. },
  110. getAreasCities(e) {
  111. console.log('getAreasCities');
  112. wx.showLoading({
  113. title: '加载中...',
  114. })
  115. if (!e.detail.ins) {
  116. // this.data.accountInfo.bankAlias = ''
  117. // this.data.accountInfo.bank_name = ''
  118. }
  119. let value = e.detail.value
  120. console.log(e.detail, 'e.detail');
  121. this.setData({
  122. provinceIndex: value,
  123. })
  124. Http.get({
  125. url: config.api.areasCities,
  126. data: {
  127. provinceId: this.data.province[value].id
  128. }
  129. }).then(res => {
  130. this.setData({
  131. city: res.data
  132. })
  133. let tempObj = this.data.accountInfo
  134. tempObj.bank_address_code = this.data.city[0].regionCode
  135. tempObj.region_code = this.data.province[value].regionCode
  136. this.setData({
  137. cityIndex: 0,
  138. accountInfo: tempObj
  139. })
  140. wx.hideLoading();
  141. const index = this.data.accountInfo.cityIndex
  142. this.getBankBranches({
  143. detail: {
  144. value: index || 0,
  145. ins: 1
  146. }
  147. })
  148. }).catch(err => {
  149. wx.hideLoading();
  150. // wx.showToast({
  151. // title: err.message,
  152. // icon: "none",
  153. // duration: 2000
  154. // })
  155. })
  156. },
  157. getAreasProvinces() {
  158. console.log('getAreasProvinces');
  159. Http.get({
  160. url: config.api.areasProvinces,
  161. data: {}
  162. }).then(res => {
  163. this.setData({
  164. province: res.data
  165. })
  166. //选择市区
  167. console.log(this.data.province, 'province');
  168. if (this.data.accountInfo.region_code) {
  169. let tempArr = res.data.map((item, index) => {
  170. if (item.regionCode == this.data.accountInfo.region_code) {
  171. this.setData({
  172. provinceIndex: index
  173. })
  174. }
  175. })
  176. // console.log(this.data.provinceIndex,"tempArr888 provinceIndex")
  177. Http.get({
  178. url: config.api.areasCities,
  179. data: {
  180. provinceId: this.data.province[this.data.provinceIndex].id
  181. }
  182. }).then(res => {
  183. this.setData({
  184. city: res.data
  185. })
  186. // return
  187. let tempObj = this.data.accountInfo
  188. res.data.map((item, index) => {
  189. if (item.regionCode == this.data.accountInfo.bank_address_code) {
  190. this.setData({
  191. cityIndex: index
  192. })
  193. }
  194. })
  195. // tempObj.bank_address_code = this.data.city[0].regionCode
  196. // tempObj.region_code = this.data.province[value].regionCode
  197. // this.setData({
  198. // cityIndex: value,
  199. // accountInfo: tempObj
  200. // })
  201. // console.log(res.data)
  202. // wx.hideLoading();
  203. }).catch(err => {
  204. wx.hideLoading();
  205. wx.showToast({
  206. title: err.message,
  207. icon: "none",
  208. duration: 2000
  209. })
  210. })
  211. }
  212. }).catch(err => {
  213. wx.hideLoading();
  214. wx.showToast({
  215. title: err.message,
  216. icon: "none",
  217. duration: 2000
  218. })
  219. })
  220. },
  221. setBankObj(e) {
  222. let item = e.currentTarget.dataset.item
  223. let tempBoj = this.data.accountInfo
  224. tempBoj.bankAlias = item.bankAlias
  225. tempBoj.need_bank_branch = item.needBankBranch
  226. tempBoj.account_bank = item.accountBank
  227. this.setData({
  228. bankBoj: item,
  229. tempArr: [],
  230. branch: [],
  231. accountInfo: tempBoj,
  232. })
  233. Http.get({
  234. url: config.api.areasCities,
  235. data: {
  236. provinceId: this.data.province[0].id
  237. }
  238. }).then(res => {
  239. this.setData({
  240. // city: res.data,
  241. })
  242. let tempObj = this.data.accountInfo
  243. tempBoj.bank_address_code = this.data.city[0].regionCode
  244. tempObj.region_code = this.data.province[0].regionCode
  245. this.setData({
  246. accountInfo: tempBoj
  247. })
  248. console.log(res.data)
  249. wx.hideLoading();
  250. this.getBankBranches({
  251. detail: {
  252. value: 0,
  253. ins: 1
  254. }
  255. })
  256. }).catch(err => {
  257. wx.hideLoading();
  258. // wx.showToast({
  259. // title: err.message,
  260. // icon: "none",
  261. // duration: 2000
  262. // })
  263. })
  264. },
  265. inquireBank(e) {
  266. let mytext = e.detail.value;
  267. console.log(mytext)
  268. let arr = this.data.bankingList.filter((item) => {
  269. // indexOf()报告指定字符在此实例中的第一个匹配项的索引
  270. // 需要输入字符为首字母时候改'>-1'为'==0'
  271. return item.bankAlias.indexOf(mytext) > -1
  272. })
  273. if (arr.length > 0) {
  274. this.setData({
  275. tempArr: arr
  276. })
  277. } else {
  278. this.setData({
  279. tempArr: []
  280. })
  281. }
  282. },
  283. getBanking() {
  284. Http.get({
  285. url: config.api.banking,
  286. data: {
  287. bankAccountType: this.data.accountInfo.bank_account_type
  288. }
  289. }).then(res => {
  290. this.setData({
  291. bankingList: res.data
  292. })
  293. wx.hideLoading();
  294. }).catch(err => {
  295. wx.hideLoading();
  296. wx.showToast({
  297. title: err.message,
  298. icon: "none",
  299. duration: 2000
  300. })
  301. })
  302. },
  303. // setBank_address_code(e) {
  304. // let tempObj = this.data.accountInfo
  305. // tempObj.bank_address_code = e.detail.value
  306. // this.setData({
  307. // accountInfo: tempObj
  308. // })
  309. // },
  310. setAccount_number(e) {
  311. let tempObj = this.data.accountInfo
  312. tempObj.account_number = e.detail.value
  313. this.setData({
  314. accountInfo: tempObj
  315. })
  316. },
  317. getReceiverApply() {
  318. wx.showLoading({
  319. title: '加载中...',
  320. })
  321. Http.get({
  322. url: config.api.getReceiverApply,
  323. data: {
  324. merchantId: app.globalData.merchant.merchant_id
  325. }
  326. }).then(res => {
  327. if (res.data && res.data.organizationType) {
  328. this.setData({
  329. organizationType: res.data.organizationType
  330. })
  331. }
  332. if (res.data && res.data.id) {
  333. this.setData({
  334. id: res.data.id
  335. })
  336. }
  337. if (res.data && res.data.accountInfo) {
  338. let obj = JSON.parse(res.data.accountInfo)
  339. this.setData({
  340. accountInfo: {
  341. ...this.data.accountInfo,
  342. ...obj
  343. }
  344. })
  345. console.log(this.data.accountInfo, 'obj');
  346. }
  347. this.getBanking()
  348. this.getAreasProvinces()
  349. if (res.data && res.data.accountInfo) {
  350. setTimeout(() => {
  351. this.getAreasCities({
  352. detail: {
  353. value: this.data.accountInfo.provinceIndex,
  354. ins: 1
  355. }
  356. })
  357. }, 1000);
  358. }
  359. }).catch(err => {
  360. wx.hideLoading();
  361. // wx.showToast({
  362. // title: err.message,
  363. // icon: "none",
  364. // duration: 2000
  365. // })
  366. })
  367. },
  368. bindDateChange1: function (e) {
  369. let id = this.data.accountList[e.detail.value].id
  370. let tempObj = this.data.accountInfo
  371. tempObj.bank_account_type = id
  372. tempObj.accountIndex = e.detail.value
  373. this.setData({
  374. accountInfo: tempObj
  375. })
  376. console.log(id)
  377. },
  378. bindDateChange2: function (e) {
  379. let id = this.data.bankingList[e.detail.value].id
  380. let tempObj = this.data.accountInfo
  381. tempObj.bank_account_type = id
  382. tempObj.accountIndex = e.detail.value
  383. this.setData({
  384. accountInfo: tempObj
  385. })
  386. console.log(id)
  387. },
  388. save(e) {
  389. let flag = e.currentTarget.dataset.flag
  390. let errMeg = "";
  391. let errFlag = false;
  392. if (!this.data.accountInfo.account_name) {
  393. errMeg = "请输入开户名称"
  394. errFlag = true
  395. } else if (!this.data.accountInfo.bankAlias) {
  396. errMeg = "请输入开户行"
  397. errFlag = true
  398. } else if (!this.data.accountInfo.bank_address_code) {
  399. errMeg = "请选着开户行省市"
  400. errFlag = true
  401. } else if (!this.data.accountInfo.account_number) {
  402. errMeg = "请输入开户银行账号"
  403. errFlag = true
  404. }
  405. if (errFlag) {
  406. wx.showToast({
  407. title: errMeg,
  408. icon: "none",
  409. duration: 2000
  410. })
  411. return
  412. }
  413. let tempAccountInfo = {
  414. bank_account_type: this.data.accountInfo.bank_account_type, //账户类型 74对公75对私*
  415. accountIndex: this.data.accountInfo.accountIndex,
  416. account_name: this.data.accountInfo.account_name, //开户名称*
  417. account_bank: this.data.accountInfo.account_bank, //开户银行*
  418. need_bank_branch: this.data.accountInfo.need_bank_branch, //是否有支行
  419. bankAlias: this.data.accountInfo.bankAlias,
  420. bank_address_code: this.data.accountInfo.bank_address_code, //开户银行省市编码*
  421. // bank_branch_id: this.data.accountInfo.bank_branch_id, //开户银行联行号(支行)*
  422. // bank_name: this.data.accountInfo.bank_name, //开户银行全称(支行)*
  423. account_number: this.data.accountInfo.account_number, //银行账号*
  424. provinceIndex: this.data.provinceIndex,
  425. cityIndex: this.data.cityIndex
  426. // region_code: this.data.accountInfo.region_code,//选择省编码
  427. }
  428. if (this.data.accountInfo.need_bank_branch) {
  429. tempAccountInfo.bank_branch_id = this.data.accountInfo.bank_branch_id
  430. tempAccountInfo.bank_name = this.data.accountInfo.bank_name
  431. }
  432. console.log(tempAccountInfo)
  433. if (this.data.organizationType == 2) {
  434. tempAccountInfo.bank_account_type = 74
  435. }
  436. let parame = {
  437. id: this.data.id,
  438. organizationType: this.data.organizationType,
  439. accountInfo: JSON.stringify(tempAccountInfo)
  440. };
  441. console.log(parame, "parame")
  442. Http.post({
  443. url: config.api.receiverAdd,
  444. data: parame
  445. }).then(res => {
  446. console.log(res, "res")
  447. if (flag == "save") {
  448. wx.reLaunch({
  449. url: '/pages/warehouse/warehouse',
  450. })
  451. } else if (flag == "next") {
  452. wx.navigateTo({
  453. url: '/pages/warehouse/detail/adminFirm/adminFirm',
  454. })
  455. }
  456. }).catch(err => {
  457. wx.showToast({
  458. title: err.message,
  459. icon: "none",
  460. duration: 2000
  461. })
  462. })
  463. },
  464. /**
  465. * 生命周期函数--监听页面加载
  466. */
  467. onLoad: function (options) {
  468. this.getReceiverApply()
  469. },
  470. /**
  471. * 生命周期函数--监听页面初次渲染完成
  472. */
  473. onReady: function () {
  474. },
  475. /**
  476. * 生命周期函数--监听页面显示
  477. */
  478. onShow: function () {
  479. },
  480. /**
  481. * 生命周期函数--监听页面隐藏
  482. */
  483. onHide: function () {
  484. },
  485. /**
  486. * 生命周期函数--监听页面卸载
  487. */
  488. onUnload: function () {
  489. },
  490. /**
  491. * 页面相关事件处理函数--监听用户下拉动作
  492. */
  493. onPullDownRefresh: function () {
  494. },
  495. /**
  496. * 页面上拉触底事件的处理函数
  497. */
  498. onReachBottom: function () {
  499. },
  500. /**
  501. * 用户点击右上角分享
  502. */
  503. onShareAppMessage: function () {
  504. }
  505. })