userInfo.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. // pages/userInfo/userInfo.js
  2. const app = getApp()
  3. const utils = require('../../utils/util.js')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. globalUrl: app.globalData.globalUrl,
  10. userInfo: '', //缓存的用户信息
  11. user: '', //用户信息
  12. companyDefault: '', //默认用户企业(企业用户才有)
  13. sex: ['男', '女'], //性别列表
  14. sexIndex: '', //当前性别下标
  15. spreadFlag: false,
  16. entTypeDict:['一般纳税人','小规模纳税人','起征点以下纳税人'], //企业类型
  17. entTypeDictIndex:'', //企业类型下标
  18. deviceTypeDict:['软证书','税控盘','金税盘','税控ukey','税控服务器'], // 开票默认设备
  19. deviceTypeDictIndex:'',// 开票默认设备下标
  20. rateList: []
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. this.setData({
  27. userInfo: utils.getInfo()
  28. })
  29. //获取个人信息
  30. this.getUser()
  31. //如果是企业用户,获取默认公司信息
  32. if (this.data.userInfo.roles === 1) {
  33. this.getCompanyDefault()
  34. }
  35. },
  36. spreadBuyer() {
  37. this.setData({
  38. spreadFlag: !this.data.spreadFlag
  39. })
  40. },
  41. /* 公用函数—————————————————————————————————————————————————————————————— */
  42. //获取用户信息
  43. getUser() {
  44. utils.getUser({
  45. sendBefore: () => {
  46. wx.showLoading({
  47. title: '加载中...',
  48. mask: true
  49. })
  50. },
  51. complete: () => {
  52. wx.hideLoading()
  53. }
  54. }).then(res => {
  55. if (res.data) {
  56. if (res.data.sex === 'M') {
  57. this.setData({
  58. sexIndex: 0
  59. })
  60. } else if (res.data.sex === 'F') {
  61. this.setData({
  62. sexIndex: 1
  63. })
  64. }
  65. }
  66. this.setData({
  67. user: res.data
  68. })
  69. })
  70. },
  71. //修改或者上传头像
  72. uploadAvatar() {
  73. utils.chooseImage({
  74. sendBefore: () => {
  75. wx.showLoading({
  76. title: '上传中...'
  77. })
  78. }
  79. }).then(res => {
  80. utils.uploadFile({
  81. name: 'file',
  82. url: '/auth/comm/user/avatar/update',
  83. filePath: res.tempFilePaths[0],
  84. formData: {
  85. mobile: this.data.userInfo.mobile,
  86. reqChannel: 5
  87. },
  88. complete: () => {
  89. wx.hideLoading()
  90. }
  91. }).then(res => {
  92. this.updateSuccess()
  93. })
  94. })
  95. },
  96. //修改其他字段
  97. request(params) {
  98. utils.axios({
  99. method: 'post',
  100. url: '/auth/comm/user/personalInfo/save',
  101. data: params,
  102. success: res => {
  103. this.updateSuccess()
  104. }
  105. })
  106. },
  107. //信息修改成功执行的字段
  108. updateSuccess() {
  109. utils.toast('信息修改成功')
  110. this.selectComponent('#nickName').hideModal()
  111. this.selectComponent('#intro').hideModal()
  112. this.getUser()
  113. },
  114. //昵称
  115. showNickName() {
  116. this.selectComponent('#nickName').showModal()
  117. },
  118. getNickName(e) {
  119. let params = {
  120. mobile: this.data.userInfo.mobile,
  121. reqChannel: 5,
  122. nickName: e.detail
  123. }
  124. this.request(params)
  125. },
  126. //性别
  127. setSex(e) {
  128. let sexList = ['M', 'F']
  129. let params = {
  130. mobile: this.data.userInfo.mobile,
  131. reqChannel: 5,
  132. sex: sexList[e.detail.value]
  133. }
  134. this.request(params)
  135. },
  136. //个人简介
  137. showIntro() {
  138. this.selectComponent('#intro').showModal()
  139. },
  140. getIntro(e) {
  141. let params = {
  142. mobile: this.data.userInfo.mobile,
  143. reqChannel: 5,
  144. personalProfile: e.detail
  145. }
  146. this.request(params)
  147. },
  148. /* 企业用户—————————————————————————————————————————————————————————————— */
  149. //企业用户获取默认企业
  150. getCompanyDefault() {
  151. let entInfo=utils.getCurrEntInfo()
  152. this.setData({
  153. companyDefault: entInfo,
  154. entTypeDictIndex: entInfo.entType?entInfo.entType-1:'',
  155. deviceTypeDictIndex: entInfo.defaultInvoiceDevice?entInfo.defaultInvoiceDevice-1:'',
  156. })
  157. // utils.getCompany().then(res => {
  158. // this.setData({
  159. // companyDefault: res.data,
  160. // entTypeDictIndex: res.data.entType?res.data.entType-1:'',
  161. // deviceTypeDictIndex: res.data.defaultInvoiceDevice?res.data.defaultInvoiceDevice-1:'',
  162. // })
  163. // })
  164. },
  165. //企业类型
  166. setEntType(e) {
  167. let companyDefault = this.data.companyDefault
  168. companyDefault["entType"] = Number(e.detail.value)+1
  169. this.requestEntInfo(companyDefault)
  170. },
  171. //公司简称
  172. showEntShortName() {
  173. this.selectComponent('#entShortName').showModal()
  174. },
  175. getEntShortName(e) {
  176. let companyDefault = this.data.companyDefault
  177. companyDefault["entShortName"] = e.detail
  178. this.requestEntInfo(companyDefault)
  179. },
  180. //可用税率
  181. showAvailableTaxes() {
  182. utils.axios({
  183. method: 'get',
  184. url: '/auth/param/getRates',
  185. success: res => {
  186. this.setData({
  187. rateList:res.data
  188. })
  189. console.log(this.rateList)
  190. this.selectComponent('#availableTaxes').showModal()
  191. }
  192. })
  193. },
  194. getAvailableTaxes(e) {
  195. let companyDefault = this.data.companyDefault
  196. companyDefault["availableTaxes"] = e.detail
  197. this.requestEntInfo(companyDefault)
  198. },
  199. //默认开票设备
  200. setDefaultInvoiceDevice(e) {
  201. let companyDefault = this.data.companyDefault
  202. companyDefault["defaultInvoiceDevice"] = Number(e.detail.value)+1
  203. this.requestEntInfo(companyDefault)
  204. },
  205. //收款人
  206. showPayees() {
  207. this.selectComponent('#payees').showModal()
  208. },
  209. getPayees(e) {
  210. let companyDefault = this.data.companyDefault
  211. companyDefault["payees"] = e.detail
  212. this.requestEntInfo(companyDefault)
  213. },
  214. //审核人
  215. showReviewers() {
  216. this.selectComponent('#reviewers').showModal()
  217. },
  218. getReviewers(e) {
  219. let companyDefault = this.data.companyDefault
  220. companyDefault["reviewers"] = e.detail
  221. this.requestEntInfo(companyDefault)
  222. },
  223. //开户行
  224. showBankName() {
  225. this.selectComponent('#bankName').showModal()
  226. },
  227. getBankName(e) {
  228. let companyDefault = this.data.companyDefault
  229. companyDefault["bankName"] = e.detail
  230. this.requestEntInfo(companyDefault)
  231. },
  232. //联系人
  233. showEntContactPerson() {
  234. this.selectComponent('#entContactPerson').showModal()
  235. },
  236. getEntContactPerson(e) {
  237. let companyDefault = this.data.companyDefault
  238. companyDefault["entContactPerson"] = e.detail
  239. this.requestEntInfo(companyDefault)
  240. },
  241. //企业电话
  242. showEntPhone() {
  243. this.selectComponent('#entPhone').showModal()
  244. },
  245. getEntPhone(e) {
  246. let companyDefault = this.data.companyDefault
  247. companyDefault["entPhone"] = e.detail
  248. this.requestEntInfo(companyDefault)
  249. },
  250. //银行账号
  251. showBankAccountNumber() {
  252. this.selectComponent('#bankAccountNumber').showModal()
  253. },
  254. getbankAccountNumber(e) {
  255. let companyDefault = this.data.companyDefault
  256. companyDefault["bankAccountNumber"] = e.detail
  257. this.requestEntInfo(companyDefault)
  258. },
  259. //公司地址
  260. showEntAddress() {
  261. this.selectComponent('#entAddress').showModal()
  262. },
  263. getEntAddress(e) {
  264. let companyDefault =this.data.companyDefault
  265. companyDefault["entAddress"] = e.detail
  266. this.requestEntInfo(companyDefault)
  267. },
  268. //修改企业字段
  269. requestEntInfo(params) {
  270. params["userMobile"] = this.data.userInfo.mobile
  271. params["reqChannel"]=5
  272. utils.axios({
  273. method: 'post',
  274. url: '/sys/entInfo/updateBriefInfo',
  275. data: params,
  276. success: res => {
  277. this.setData({
  278. companyDefault: params
  279. })
  280. utils.toast('信息修改成功')
  281. this.selectComponent('#entShortName').hideModal()
  282. this.selectComponent('#availableTaxes').hideModal()
  283. this.selectComponent('#reviewers').hideModal()
  284. this.selectComponent('#bankName').hideModal()
  285. this.selectComponent('#bankAccountNumber').hideModal()
  286. this.selectComponent('#entContactPerson').hideModal()
  287. this.selectComponent('#entPhone').hideModal()
  288. this.selectComponent('#entAddress').hideModal()
  289. this.getCompanyDefault()
  290. }
  291. })
  292. },
  293. /**
  294. * 生命周期函数--监听页面初次渲染完成
  295. */
  296. onReady: function () {
  297. },
  298. /**
  299. * 生命周期函数--监听页面显示
  300. */
  301. onShow: function () {
  302. },
  303. /**
  304. * 生命周期函数--监听页面隐藏
  305. */
  306. onHide: function () {
  307. },
  308. /**
  309. * 生命周期函数--监听页面卸载
  310. */
  311. onUnload: function () {
  312. },
  313. /**
  314. * 页面相关事件处理函数--监听用户下拉动作
  315. */
  316. onPullDownRefresh: function () {
  317. },
  318. /**
  319. * 页面上拉触底事件的处理函数
  320. */
  321. onReachBottom: function () {
  322. },
  323. /**
  324. * 用户点击右上角分享
  325. */
  326. onShareAppMessage: function () {
  327. return {
  328. title: '诺信云',
  329. path: '/pages/index/index'
  330. }
  331. }
  332. })