index.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. //index.js
  2. const utils = require('../../utils/util.js')
  3. Page({
  4. data: {
  5. isLogin: false, //是否登陆
  6. roles: 1, //登录角色(默认企业用户)
  7. userInfo: '', //缓存的用户信息
  8. statistics: '', //统计信息
  9. noticeList: [], //公告消息
  10. bannerList: ['../../images/example-02.png', '../../images/example-02.png', '../../images/example-02.png'], //轮播图
  11. tabIndex: 0,
  12. companyDefault: '', //企业用户默认
  13. remain: '', //获取剩余发票数量
  14. iconList: [{ //企业列表
  15. icon: '../../images/ico_stay-open@3x.png',
  16. text: '待开单据',
  17. path: '/pages/ticketWaiting/ticketWaiting'
  18. },
  19. {
  20. icon: '../../images/ico_query@3x.png',
  21. text: '发票查询',
  22. path: '/pages/ticketQuery/ticketQuery'
  23. },
  24. {
  25. icon: '../../images/ico_red-rush@3x.png',
  26. text: '空白作废',
  27. path: '/pages/blankInvoice/blankInvoice'
  28. },
  29. {
  30. icon: '../../images/ico_invoice-purchase@3x.png',
  31. text: '发票领购',
  32. path: '/pages/ticketGet/ticketGet'
  33. },
  34. {
  35. icon: '../../images/ico_clear-card@3x.png',
  36. text: '发票库存',
  37. path: '/pages/invoiceStock/invoiceStock'
  38. },
  39. {
  40. icon: '../../images/ico_network-copy@3x.png',
  41. text: '发票汇总',
  42. path: '/pages/invoiceSummary/invoiceSummary'
  43. },
  44. {
  45. icon: '../../images/ico_deploy@3x.png',
  46. text: '配置管理',
  47. path: '/pages/ticketConfig/ticketConfig'
  48. }
  49. // {
  50. // icon: '../../images/ico_audit@3x.png',
  51. // text: '操作审计',
  52. // path: '/pages/audit/audit'
  53. // },
  54. ],
  55. ispName: '', //服务商名称
  56. ispList: [{ //服务商列表
  57. icon: '../../images/ico_enterprise-shelves@3x.png',
  58. text: '企业上架',
  59. path: '/pages/ispPutaway/ispPutaway'
  60. },
  61. // {
  62. // icon: '../../images/ico_invoice-purchase@3x.png',
  63. // text: '人员管理',
  64. // path: '/pages/ispPeople/ispPeople'
  65. // },
  66. // {
  67. // icon: '../../images/ico_audit@3x.png',
  68. // text: '操作审计',
  69. // path: '/pages/audit/audit'
  70. // }
  71. ],
  72. operName: '', //运营商名称
  73. operList: [ //运营商列表
  74. {
  75. icon: '../../images/ico_facilitator@3x.png',
  76. text: '服务商列表',
  77. path: '/pages/operIsp/operIsp'
  78. },
  79. // {
  80. // icon: '../../images/ico_invoice-purchase@3x.png',
  81. // text: '人员管理',
  82. // path: '/pages/operPeople/operPeople'
  83. // },
  84. // {
  85. // icon: '../../images/ico_audit@3x.png',
  86. // text: '操作审计',
  87. // path: '/pages/audit/audit'
  88. // }
  89. ],
  90. },
  91. onLoad: function () { },
  92. /* 以下是三端公用函数=================================================== */
  93. //公告(公用)
  94. getNotice() {
  95. let params = {
  96. mobile: this.data.userInfo.mobile,
  97. pageNum: 1,
  98. pageSize: 10
  99. }
  100. utils.axios({
  101. method: 'get',
  102. url: '/auth/user/msg/findGlobalNotice',
  103. data: params,
  104. noLogin: () => { },
  105. complete: () => { },
  106. success: res => {
  107. this.setData({
  108. noticeList: res.data.records
  109. })
  110. }
  111. })
  112. },
  113. //统计信息(公用)
  114. getStatis() {
  115. let params = {
  116. mobile: this.data.userInfo.mobile
  117. }
  118. if (this.data.userInfo.roles === 1) {
  119. params.entTaxId = this.data.companyDefault.entTaxId
  120. }
  121. utils.axios({
  122. method: 'get',
  123. url: '/sys/stat/home',
  124. data: params,
  125. complete: () => { },
  126. success: res => {
  127. this.setData({
  128. statistics: res.data
  129. })
  130. }
  131. })
  132. },
  133. //菜单跳转
  134. toSkip(e) {
  135. let path = e.currentTarget.dataset.path
  136. // if(path==='/pages/ticketGet/ticketGet'){
  137. // utils.toast('功能完善中')
  138. // return
  139. // }
  140. if (path) {
  141. wx.navigateTo({
  142. url: path
  143. })
  144. }
  145. },
  146. //点击公告列表
  147. toNotice() {
  148. if (this.data.isLogin) {
  149. wx.navigateTo({
  150. url: '/pages/notice/notice'
  151. })
  152. } else {
  153. utils.toLogin()
  154. }
  155. },
  156. //点击公告详情
  157. toDetail(e) {
  158. if (this.data.isLogin) {
  159. let msgId = e.currentTarget.dataset.id
  160. wx.navigateTo({
  161. url: '/pages/notice/noticeDetail?msgId=' + msgId
  162. })
  163. } else {
  164. utils.toLogin()
  165. }
  166. },
  167. /* 以下是企业端=================================================== */
  168. //登录用户获取默认企业(企业端)
  169. getCompanyDefault() {
  170. let params = {
  171. mobile: this.data.userInfo.mobile
  172. }
  173. utils.axios({
  174. method: 'get',
  175. url: '/auth/comm/user/findDefaultChoose',
  176. data: params,
  177. success: res => {
  178. this.setData({
  179. companyDefault: res.data
  180. })
  181. wx.setStorageSync('company', res.data)
  182. wx.setStorageSync('entTaxId', this.data.companyDefault.entTaxId)
  183. this.getStatis()
  184. },
  185. sendBefore: () => {
  186. if (params.sendBefore) {
  187. params.sendBefore()
  188. }
  189. },
  190. error: res => {
  191. if (params.error) {
  192. params.error(res)
  193. }
  194. },
  195. complete: () => {
  196. if (params.complete) {
  197. params.complete()
  198. }
  199. },
  200. noLogin: res => {
  201. if (params.noLogin) {
  202. params.noLogin()
  203. } else {
  204. toLogin()
  205. }
  206. }
  207. })
  208. },
  209. //获取剩余发票数量(企业端)
  210. getRemain() {
  211. let params = {
  212. reqChannel: 5,
  213. entTaxId: this.data.companyDefault.entTaxId
  214. }
  215. utils.axios({
  216. method: 'post',
  217. url: '/sys/invoiceInfo/remain',
  218. data: params,
  219. complete: () => { },
  220. success: res => {
  221. this.setData({
  222. remain: res.data
  223. })
  224. }
  225. })
  226. },
  227. //手工开票
  228. toHand() {
  229. if (this.data.isLogin) {
  230. wx.navigateTo({
  231. url: '/pages/ticketHand/ticketHand'
  232. })
  233. } else {
  234. utils.toLogin()
  235. }
  236. },
  237. //扫码开票
  238. toScan() {
  239. if (this.data.isLogin) {
  240. wx.navigateTo({
  241. url: '/pages/ticketScan/ticketScan'
  242. })
  243. } else {
  244. utils.toLogin()
  245. }
  246. },
  247. //购方开票
  248. toBuy() {
  249. if (this.data.isLogin) {
  250. wx.navigateTo({
  251. url: '/pages/ticketBuy/ticketBuy'
  252. })
  253. } else {
  254. utils.toLogin()
  255. }
  256. },
  257. //待开抬头
  258. toWait() {
  259. if (this.data.isLogin) {
  260. wx.navigateTo({
  261. url: '/pages/ticketWait/ticketWait'
  262. })
  263. } else {
  264. utils.toLogin()
  265. }
  266. },
  267. //切换企业
  268. toSwitch() {
  269. if (this.data.isLogin) {
  270. wx.navigateTo({
  271. url: '/pages/switchAccount/switchAccount?entTaxId=' + this.data.companyDefault.entTaxId
  272. })
  273. } else {
  274. utils.toLogin()
  275. }
  276. },
  277. //切换(总计/本月)
  278. switchTab(e) {
  279. let tabIndex = e.currentTarget.dataset.index
  280. this.setData({
  281. tabIndex
  282. })
  283. },
  284. /* 以下是服务端=================================================== */
  285. //企业列表(服务商)
  286. toBusiness() {
  287. wx.navigateTo({
  288. url: '/pages/ispBusiness/ispBusiness'
  289. })
  290. },
  291. //服务器列表(服务商)
  292. toServers() {
  293. wx.navigateTo({
  294. url: '/pages/ispServers/ispServers'
  295. })
  296. },
  297. //开票列表(服务商)
  298. toTicket() {
  299. wx.navigateTo({
  300. url: '/pages/ispTicket/ispTicket'
  301. })
  302. },
  303. /**
  304. * 生命周期函数--监听页面初次渲染完成
  305. */
  306. onReady: function () {
  307. },
  308. /**
  309. * 生命周期函数--监听页面显示
  310. */
  311. onShow: function () {
  312. if (typeof this.getTabBar === 'function' &&
  313. this.getTabBar()) {
  314. this.getTabBar().setData({
  315. selected: 0
  316. })
  317. }
  318. //验证是否登陆
  319. utils.getUser({
  320. noLogin: () => {
  321. this.setData({
  322. isLogin: false
  323. })
  324. }
  325. }).then(res => {
  326. this.setData({
  327. isLogin: true,
  328. roles: utils.getInfo().roles,
  329. userInfo: utils.getInfo()
  330. })
  331. // this.getNotice()
  332. //角色为企业时发送
  333. if (this.data.userInfo.roles === 1) {
  334. this.getCompanyDefault()
  335. }
  336. //角色为服务商时发送
  337. if (this.data.userInfo.roles === 2) {
  338. utils.getIsp({
  339. noLogin: () => { }
  340. }).then(res => {
  341. this.setData({
  342. ispName: res.data.name
  343. })
  344. })
  345. this.getStatis()
  346. }
  347. //角色为运营商时发送
  348. if (this.data.userInfo.roles === 3) {
  349. this.setData({
  350. operName: this.data.userInfo.userName
  351. })
  352. this.getStatis()
  353. }
  354. })
  355. },
  356. /**
  357. * 生命周期函数--监听页面隐藏
  358. */
  359. onHide: function () {
  360. },
  361. /**
  362. * 生命周期函数--监听页面卸载
  363. */
  364. onUnload: function () {
  365. },
  366. /**
  367. * 页面相关事件处理函数--监听用户下拉动作
  368. */
  369. onPullDownRefresh: function () {
  370. },
  371. /**
  372. * 页面上拉触底事件的处理函数
  373. */
  374. onReachBottom: function () {
  375. },
  376. /**
  377. * 用户点击右上角分享
  378. */
  379. onShareAppMessage: function () {
  380. return {
  381. title: '诺信云',
  382. path: '/pages/index/index'
  383. }
  384. }
  385. })