index.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import { appConfig } from '../../config/index';
  2. import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog'
  3. import { queryBankAccountSign } from '../../services/api/account/index';
  4. import { accountid, getAvatarUrl, getLoginCode, loginid, loginQuery, setLoginCode, taAccount, userid } from '../../services/utils';
  5. import { hideLoading, showLoading, showToast } from '../../utils/message/index';
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. /// 图片地址
  12. imgUrl: appConfig.imgUrl,
  13. // 功能菜单项
  14. menulists: [{id: 1, title: '我的库存', img: 'mine-wdkc', path: '/mMine/pages/myinventorys/list/index'},
  15. {id: 2, title: "我的订单", img: 'mine-wddd', path: '/mMine/pages/myorders/list/index'},
  16. {id: 3, title: '我的履约', img: 'mine-wdly', path: '/mMine/pages/myperformance/list/index'},
  17. {id: 4, title: '我的出境', img: 'mine-cjjc', path: '/mHome/pages/inspection/list/index'},
  18. {id: 5, title: '我的保税', img: 'mine-bsfw', path: '/mHome/pages/bond/list/index'}],
  19. // 列表菜单项
  20. tablelists: [{id: 1, title: '签约账户', iconfont: 'mine-qyzh', path: '/mMine/pages/bank/index'},
  21. {id: 2, title: '收货地址', iconfont: 'mine-shdz', path: '/mMine/pages/address/list/index?isMine=true'},
  22. {id: 3, title: '发票信息', iconfont: 'mine-fpxx', path: '/mMine/pages/invoice/list/index?isMine=true'},
  23. {id: 4, title: '账户安全', iconfont: 'mine-mmxg', path: '/mMine/pages/modifypwd/index'},
  24. {id: 5, title: '关于我们', iconfont: 'mine-gywm', path: '/mMine/pages/about/about/index'}],
  25. /// 微信头像
  26. avatarUrl: getAvatarUrl(),
  27. /// 微信昵称
  28. nickName: '',
  29. /// 资金账户信息
  30. ta: <GuangZuan.TaAccount>({}),
  31. /// 登录账号
  32. loginid: loginid(),
  33. /// 是否脱敏显示
  34. isOpenEye: false,
  35. /// 签约信息
  36. sign: <GuangZuan.BankAccountSign>({}),
  37. /// 状态栏高度
  38. statusBarHeight: getApp().globalData.statusBarHeight,
  39. /// 导航栏高度
  40. navHeight: getApp().globalData.navHeight,
  41. /// 余额
  42. balance: '0.00',
  43. /// 冻结
  44. freezemargin: '0.00',
  45. /// 可用
  46. currentbalance: '0.00',
  47. /// 脱敏
  48. secret: '********'
  49. },
  50. onEye() {
  51. this.setData({
  52. isOpenEye: !this.data.isOpenEye
  53. })
  54. },
  55. /**
  56. * 资金流水
  57. */
  58. goToFunds() {
  59. wx.navigateTo({
  60. url: '/mMine/pages/funds/list/index'
  61. })
  62. },
  63. /**
  64. * 按钮点击响应事件
  65. */
  66. onButtonPressed(e: any) {
  67. /// 出入金操作
  68. this.goToInOutGold(e.target.id)
  69. },
  70. /// 出入金操作
  71. goToInOutGold(id: string) {
  72. if (this.data.sign === undefined) {
  73. showToast('当前未查询到签约信息,请先签约!')
  74. return
  75. }
  76. switch (id) {
  77. case 'into-gold': /// 充值
  78. wx.navigateTo({ url: '/mMine/pages/inoutgold/index?id=0' })
  79. break;
  80. default: /// 提现
  81. wx.navigateTo({ url: '/mMine/pages/inoutgold/index?id=1' })
  82. break;
  83. }
  84. },
  85. /**
  86. * 进入系统设置
  87. */
  88. goToSettings() {
  89. wx.navigateTo({
  90. url: '/mMine/pages/settings/settings'
  91. })
  92. },
  93. /**
  94. * 生命周期函数--监听页面加载
  95. */
  96. onLoad() {
  97. this.setData({
  98. /// 设置账户信息
  99. ta: taAccount(accountid()),
  100. balance: taAccount(accountid()).balance.toFixed(2),
  101. nickName: loginQuery().userInfo.customername
  102. })
  103. /// 冻结金额
  104. const { orifreezecharge, oriotherfreezemargin, balance } = this.data.ta
  105. this.setData({
  106. freezemargin: (orifreezecharge+oriotherfreezemargin).toFixed(2),
  107. currentbalance: (balance-orifreezecharge-oriotherfreezemargin).toFixed(2)
  108. })
  109. /// 查询签约信息
  110. this.queryBankAccountSign()
  111. },
  112. /**
  113. * 获取用户信息
  114. */
  115. getUserInfo() {
  116. /// 如果不为空
  117. if (this.data.avatarUrl != '') {
  118. return
  119. }
  120. wx.getUserProfile({
  121. desc: '获取微信头像',
  122. success: (res) => {
  123. /// 存储头像
  124. wx.setStorageSync('avatarUrl', res.userInfo.avatarUrl)
  125. /// 显示信息
  126. this.setData({
  127. avatarUrl: res.userInfo.avatarUrl
  128. })
  129. }, fail: () => {
  130. showToast('获取用户头像失败!')
  131. }
  132. })
  133. },
  134. /**
  135. * 查询用户已签约信息
  136. */
  137. queryBankAccountSign() {
  138. /// loding.....
  139. showLoading(() => {
  140. /// 发送请求
  141. queryBankAccountSign({
  142. data: {
  143. userid: userid()
  144. },
  145. success: (res) => {
  146. /// 请求失败
  147. if (res.code != 200) {
  148. hideLoading(() => {}, '用户签约信息请求失败,原因:'+res.msg)
  149. return
  150. }
  151. hideLoading(() => {
  152. const sign = res.data.filter(obj => {
  153. return obj.signstatus === 2 || obj.signstatus === 3 || obj.signstatus === 4
  154. })[0]
  155. /// 数据赋值
  156. this.setData({ sign: sign })
  157. })
  158. },
  159. fail: (emsg) => {
  160. hideLoading(() => {}, emsg)
  161. }
  162. })
  163. })
  164. },
  165. /**
  166. * 系统登出响应
  167. */
  168. onLoginOut() {
  169. Dialog.confirm({
  170. title: '提示',
  171. message: '确定要退出系统吗?',
  172. }).then(() => {
  173. /// 获取上次登录账号
  174. const username = getLoginCode()
  175. /// 清楚所有的缓存数据
  176. wx.clearStorage()
  177. /// 设置登录账号
  178. setLoginCode(username)
  179. /// loding....
  180. showLoading(()=>{
  181. /// 登出
  182. setTimeout(function () {
  183. hideLoading(()=>{
  184. // on confirm
  185. wx.reLaunch({ url: '/pages/login/index' })
  186. }, '登出成功', 'success')
  187. }, 3000)
  188. }, '登出中....')
  189. }).catch(() => {
  190. // on cancel
  191. });
  192. },
  193. /**
  194. * 生命周期函数--监听页面初次渲染完成
  195. */
  196. onReady() {
  197. },
  198. /**
  199. * 生命周期函数--监听页面显示
  200. */
  201. onShow() {
  202. this.getTabBar().init()
  203. },
  204. /**
  205. * 生命周期函数--监听页面隐藏
  206. */
  207. onHide() {
  208. },
  209. /**
  210. * 生命周期函数--监听页面卸载
  211. */
  212. onUnload() {
  213. },
  214. /**
  215. * 页面相关事件处理函数--监听用户下拉动作
  216. */
  217. onPullDownRefresh() {
  218. },
  219. /**
  220. * 页面上拉触底事件的处理函数
  221. */
  222. onReachBottom() {
  223. },
  224. /**
  225. * 用户点击右上角分享
  226. */
  227. onShareAppMessage() {
  228. }
  229. })