index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. // pages/tabber/my/index.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. btnInfo: null,
  9. menuList: [
  10. {
  11. icon: '/image/my/youhuiquan.png',
  12. text: '优惠券',
  13. url: '/pages/my/coupon/coupon'
  14. },
  15. // {
  16. // icon: '/image/my/fenxianghaoyou.png',
  17. // text: '分享好友'
  18. // },
  19. {
  20. icon: '/image/my/dizhiguanli.png',
  21. text: '地址管理',
  22. url: '/pages/my/address/address'
  23. },
  24. // {
  25. // icon: '/image/my/fuwuliucheng.png',
  26. // text: '服务流程'
  27. // }, {
  28. // icon: '/image/my/yonghuxieyi.png',
  29. // text: '用户协议'
  30. // },
  31. // {
  32. // icon: '/image/my/lipeixize.png',
  33. // text: '理赔细则'
  34. // },
  35. {
  36. icon: '/image/my/kefurexian.png',
  37. text: '客服热线',
  38. url:""
  39. }
  40. ],
  41. active: true,
  42. userInfo: "",
  43. hasUserInfo: false,
  44. code: "",
  45. yue:0,
  46. one:'',
  47. two:'',
  48. three:'',
  49. four:'',
  50. five:'',
  51. six:'',
  52. inputValue:'',
  53. show:false,
  54. focus:false,
  55. nid: 0
  56. },
  57. /**
  58. * 生命周期函数--监听页面加载
  59. */
  60. onLoad: function (options) {
  61. this.getUser();
  62. if (this.data.active == true) {
  63. this.data.menuList.shift()
  64. this.setData({
  65. code: wx.getStorageSync('phone'),
  66. menuList: this.data.menuList
  67. })
  68. }
  69. // this.getwallet();
  70. },
  71. onShow(){
  72. this.getBtnInfo()
  73. this.getwallet();
  74. },
  75. goqjm(){
  76. let that = this
  77. that.setData({
  78. nid: 0,
  79. inputValue:'',
  80. one:'',
  81. two:'',
  82. three:'',
  83. four:'',
  84. five:'',
  85. six:''
  86. })
  87. console.log(that.data.nid)
  88. wx.scanCode({
  89. onlyFromCamera: true,
  90. success (res) {
  91. console.log( res.result.substr(1));
  92. var regstr = new RegExp('(^|&|/?)orde_num=([^&|/?]*)', 'i');
  93. var exp = res.result.match(regstr);
  94. console.log(exp[2]);
  95. that.setData({nid: exp[2]})
  96. that.onClose()
  97. }
  98. })
  99. },
  100. finish:function(e){
  101. var that=this
  102. var val=e.detail.value;
  103. this.setData({
  104. one:val.split('')[0]?val.split('')[0]:'',
  105. two:val.split('')[1]?val.split('')[1]:'',
  106. three:val.split('')[2]?val.split('')[2]:'',
  107. four:val.split('')[3]?val.split('')[3]:'',
  108. five:val.split('')[4]?val.split('')[4]:'',
  109. six:val.split('')[5]?val.split('')[5]:''
  110. })
  111. if(val.length>=6){
  112. that.submitValue()
  113. }
  114. },
  115. submitValue:function(){
  116. var that=this
  117. if(that.data.inputValue=='')
  118. return wx.showToast({title: '存衣码不能为空',icon:'none'})
  119. console.log(that.data.inputValue)
  120. wx.showLoading()
  121. app.api.useApi(app.globalData.baseAppUrl + "api/open_temporary", {
  122. temporary_code: that.data.inputValue,
  123. device_id:this.data.nid
  124. }, "post").then(function (res) {
  125. wx.hideLoading();
  126. wx.showToast({title: res.message.msg,icon:'none'})
  127. if (res.code== 200) {
  128. that.setData({
  129. show:!that.data.show,
  130. inputValue:'',
  131. one:'',
  132. two:'',
  133. three:'',
  134. four:'',
  135. five:'',
  136. six:''
  137. })
  138. wx.showModal({
  139. title: res.message.data.external_cabinet+'号柜门',
  140. content: '请尽快取走衣物',
  141. showCancel: false,
  142. success (ress) {
  143. if (ress.confirm) {
  144. // console.log('用户点击确定')
  145. }
  146. }
  147. })
  148. }
  149. }).catch(function (err) {
  150. console.log(222);
  151. })
  152. },
  153. onClose(){
  154. this.setData({
  155. show:!this.data.show
  156. })
  157. },
  158. getBtnInfo() {
  159. this.setData({
  160. btnInfo: app.globalData.btnInfo
  161. })
  162. },
  163. toUrl(e) {
  164. let url = e.currentTarget.dataset.url
  165. wx.navigateTo({
  166. url,
  167. })
  168. },
  169. getUserProfile(e) {
  170. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
  171. // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  172. wx.getUserProfile({
  173. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  174. success: (res) => {
  175. // this.setData({
  176. // userInfo: res.userInfo,
  177. // hasUserInfo: true
  178. // })
  179. this.updateUser(res.userInfo);
  180. }
  181. })
  182. },
  183. getPhoneNumber(e) {
  184. let that = this
  185. console.log(e)
  186. that.setData({
  187. code: e.detail.code,
  188. })
  189. var data = {
  190. 'mds': wx.getStorageSync('seisson_key'),
  191. 'encryptedData': e.detail.encryptedData,
  192. 'errMsg': e.detail.errMsg,
  193. 'iv': e.detail.iv,
  194. 'appid': wx.getAppBaseInfo().host.appId,
  195. }
  196. app.api.useApi(app.globalData.baseAppUrl+"api/user/getPhoneNumber",data,"post").then((res)=>{
  197. if (res.code == 200) {
  198. var phone = res.message.data.phone
  199. console.log(phone);
  200. if (phone) {
  201. that.setData({
  202. code: phone,
  203. })
  204. }
  205. that.getUser()
  206. }
  207. }).catch((err)=>{
  208. console.log(err)
  209. })
  210. },
  211. getwallet() {
  212. var that = this;
  213. app.api.useApi(app.globalData.baseAppUrl + "api/wallet", {
  214. }, "get").then(function (res) {
  215. if (res.code != 200) {
  216. wx.showLoading({
  217. title: res.message.msg,
  218. })
  219. setTimeout(function () {
  220. wx.hideLoading({
  221. success: (res) => { },
  222. })
  223. }, 2000);
  224. } else {
  225. console.log(res.message.data);
  226. that.setData({
  227. yue: res.message.data.balance,
  228. })
  229. }
  230. }).catch(function (err) {
  231. console.log(222);
  232. })
  233. },
  234. updateUser(userinfo){
  235. wx.showLoading({
  236. title: '更新用户信息中',
  237. })
  238. var that=this;
  239. var userinfo=userinfo;
  240. app.api.useApi(app.globalData.baseAppUrl+"api/user",userinfo,"post").then((res)=>{
  241. if(res.code==200){
  242. wx.hideLoading();
  243. that.getUser()
  244. }else{
  245. that.updateUser(userinfo)
  246. }
  247. }).catch((err)=>{
  248. that.updateUser(userinfo)
  249. })
  250. },
  251. /**
  252. * 获取用户信息
  253. */
  254. getUser(){
  255. var that=this;
  256. app.api.useApi(app.globalData.baseAppUrl+"api/user/getUser","","get").then((res)=>{
  257. if(res.code==200){
  258. wx.hideLoading();
  259. that.setData({
  260. userInfo:res.message.data,
  261. hasUserInfo:res.message.data.avatar!=""?true:false
  262. })
  263. }else{
  264. that.getUser()
  265. }
  266. }).catch((err)=>{
  267. that.getUser()
  268. })
  269. }
  270. })