You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

361 lines
10 KiB

  1. -- 下载界面
  2. local MainSettingView = class("MainSettingView", cc.UIView)
  3. local PluginConfig = require("preload.PluginConfig")
  4. local LoginConfig = require("luaScript.Views.Login.LoginConfig")
  5. function MainSettingView:ctor()
  6. MainSettingView.super.ctor(self);
  7. end
  8. function MainSettingView:onEnter()
  9. MainSettingView.super.onEnter(self)
  10. local ui = loadUI("res/ui/ui_dating/ui_shezhi.ui")
  11. self.ui = ui
  12. self:addChild(ui)
  13. self:registerButton()
  14. self:setPlayerInfo()
  15. self:initBindEvents()
  16. if app.config.ModuleConfig.IsSupportUnion then
  17. app.club_php:requestClubBelong()
  18. end
  19. self.lastSendLogin = 0;
  20. end
  21. function MainSettingView:initBindEvents()
  22. self:bindEvent(app, "onCheckForbidClubInvite", handler(self, self.onCheckForbidClubInvite))
  23. self:bindEvent(app.user, "onBindResponse", handler(self, self.onBindResponse))
  24. self:bindEvent(app.user, "onChangePlayerInfo", handler(self, self.onChangePlayerInfoResponse))
  25. self:bindEvent(app.club_php, GAME_EVENT.CLUB_UNION_CLUB_BELONG, handler(self, self.onClubBelongEvent))
  26. end
  27. function MainSettingView:registerButton()
  28. -- 关闭
  29. self.ui.Items.Button_close:registerClick(handler(self , self.onClickClose))
  30. -- 游戏管理
  31. self.ui.Items.Button_game_manage:registerClick(handler(self , self.onClickGameManage))
  32. -- 注销登陆
  33. self.ui.Items.Button_change_account:registerClick(handler(self , self.onClickLogout))
  34. -- 音乐
  35. self.ui.Items.Button_music:registerClick(handler(self , self.onClickYinYue))
  36. if app.systemSetting.info.musicVolume == 0 then
  37. self.ui.Items.Button_music:setBright(true)
  38. else
  39. self.ui.Items.Button_music:setBright(false)
  40. end
  41. -- 音效
  42. self.ui.Items.Button_effect:registerClick(handler(self , self.onClickYinXiao))
  43. if app.systemSetting.info.soundVolume == 0 then
  44. self.ui.Items.Button_effect:setBright(true)
  45. else
  46. self.ui.Items.Button_effect:setBright(false)
  47. end
  48. --手机绑定
  49. self.ui.Items.Text_bindPhone:registerClick(handler(self, self.onClickBindPhone))
  50. --微信绑定
  51. self.ui.Items.Text_bindWetChat:registerClick(handler(self, self.onClickBindWetChat))
  52. --设置密码
  53. self.ui.Items.Text_setPassword:registerClick(handler(self, self.onClickSetPassword))
  54. --我的装扮
  55. self.ui.Items.Button_zhuangban:registerClick(handler(self, self.onClickChaKan))
  56. self.ui.Items.Layout_zhuangban:setVisible(false)
  57. --亲友圈归属设置
  58. self.ui.Items.Layout_clubbelong:setVisible(app.config.ModuleConfig.IsSupportUnion)
  59. self.ui.Items.Button_clubbelong:registerClick(handler(self, self.onClickClubBelong))
  60. self.ui.Items.Text_zhuangban_1:setText((app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_CEST_NAME2).."归属设置")
  61. --屏蔽茶馆邀请
  62. self.checkBoxForbid = import("luaScript.Tools.CheckBoxManager"):new();
  63. self.checkBoxForbid:setColorSwitch(false)
  64. self.checkBoxForbid:addItem(self.ui.Items.CheckBox_select,"forbidClubInvite",1,0)
  65. -- 设置默认状态
  66. local ttSelected = {}
  67. self.checkBoxForbid:setDefault(ttSelected);
  68. -- 设置回调
  69. self.checkBoxForbid:setCallback(handler(self,self.onClickForbidInviteClub))
  70. --用户协议
  71. self.ui.Items.Text_agreement:registerClick(handler(self, self.onClickAgreement))
  72. --隐私政策
  73. self.ui.Items.Text_private:registerClick(handler(self, self.onClickPrivate))
  74. --账号注销
  75. self.ui.Items.Text_logout:registerClick(handler(self, self.onClickAccountLogOut))
  76. --请求屏蔽茶馆邀请配置
  77. app.php:requestCheckForbidClubInvite()
  78. end
  79. function MainSettingView:onClickForbidInviteClub()
  80. local result = self.checkBoxForbid:getResult2()
  81. local isallowgroup = result["forbidClubInvite"]
  82. --请求屏蔽茶馆邀请配置
  83. app.php:requestSetForbidClubInvite(isallowgroup)
  84. end
  85. --设置玩家信息
  86. function MainSettingView:setPlayerInfo()
  87. -- 头像
  88. local headurl = app.user.headimgurl
  89. setPlayerHeadImage(app.user.loginInfo.uid, headurl or "", self.ui.Items.ImageView_head)
  90. -- 昵称
  91. local nickname = getShortName(app.user.nickname)
  92. self.ui.Items.Text_nickname:setText(tostring(nickname))
  93. -- ID
  94. self.ui.Items.Text_ID:setText(tostring(app.user.loginInfo.uid))
  95. local stUserInfo = json.decode(app.user.userInfo);
  96. logD("MainSettingView:setPlayerInfo() stUserInfo = ", table.tostring(stUserInfo))
  97. self:updatePhone()
  98. end
  99. function MainSettingView:updatePhone()
  100. -- 手机号
  101. local phonenum = app.user.phonenum
  102. local bindPhone = not phonenum or phonenum == ""
  103. if bindPhone then
  104. self.ui.Items.Text_phone:setText("未绑定")
  105. self.ui.Items.Text_bindPhone:setText("绑定手机")
  106. else
  107. self.ui.Items.Text_phone:setText(tostring(phonenum))
  108. self.ui.Items.Text_bindPhone:setText("修改手机")
  109. end
  110. --微信绑定
  111. local visible = app.user.unionid == "?"
  112. if visible then
  113. self.ui.Items.Text_wetChat:setText("未绑定")
  114. else
  115. --微信号
  116. local nickname = getShortName(app.user.nickname)
  117. self.ui.Items.Text_wetChat:setText(tostring(nickname))
  118. end
  119. self.ui.Items.Text_bindWetChat:setVisible(visible)
  120. end
  121. function MainSettingView:onClickUpload()
  122. local url = string.format("http://cnagent.dingdingqipai.com/client/user/loginpost?token=%s&app=%s",app.user.loginInfo.token,getAppId())
  123. app.plugin:callUrl(url)
  124. end
  125. function MainSettingView:onClickChaKan()
  126. playBtnEffect()
  127. app.serverConfigs:requestClientConfig(function()
  128. local url = string.format(app.serverConfigs.clientConfig.myHead.."&token=%s&app=%s",app.user.loginInfo.token,getAppId())
  129. app.plugin:callUrl(url)
  130. end)
  131. end
  132. function MainSettingView:onClickClubBelong()
  133. playBtnEffect()
  134. local view = import("luaScript.Views.Main.MainUnionBelong"):new()
  135. view:setAnchorPoint(cc.p(0.5,0.5))
  136. app:showWaitDialog(view)
  137. end
  138. -- 注销
  139. function MainSettingView:onClickLogout()
  140. playBtnEffect()
  141. app.plugin:logout()
  142. end
  143. -- 关闭设置界面
  144. function MainSettingView:onClickClose()
  145. playBtnCloseEffect()
  146. self:removeFromParent()
  147. end
  148. -- 音乐
  149. function MainSettingView:onClickYinYue()
  150. playBtnEffect()
  151. local curValue = 0
  152. if self.ui.Items.Button_music:isBright() then
  153. curValue = 1
  154. else
  155. curValue = 0
  156. end
  157. self.ui.Items.Button_music:setBright(not self.ui.Items.Button_music:isBright())
  158. app.systemSetting.info.musicVolume = curValue;
  159. app.systemSetting:save()
  160. end
  161. -- 音效
  162. function MainSettingView:onClickYinXiao()
  163. playBtnEffect()
  164. local curValue = 0
  165. if self.ui.Items.Button_effect:isBright() then
  166. curValue = 1
  167. else
  168. curValue = 0
  169. end
  170. self.ui.Items.Button_effect:setBright(not self.ui.Items.Button_effect:isBright())
  171. app.systemSetting.info.soundVolume = curValue;
  172. app.systemSetting:save()
  173. end
  174. --游戏管理
  175. function MainSettingView:onClickGameManage()
  176. playBtnEffect()
  177. local view = import("luaScript.Views.Main.GameManagerView"):new()
  178. view:setAnchorPoint(cc.p(0.5, 0.5))
  179. app:showWaitDialog(view)
  180. end
  181. function MainSettingView:onClickSetPassword()
  182. playBtnEffect()
  183. local view = import("luaScript.Views.Main.SetPasswordView"):new(endCallback)
  184. view:setAnchorPoint(cc.p(0.5, 0.5))
  185. app:showWaitDialog(view)
  186. end
  187. --手机绑定
  188. function MainSettingView:onClickBindPhone()
  189. playBtnEffect()
  190. local phonenum = app.user.phonenum
  191. local bindPhone = not phonenum or phonenum == ""
  192. if bindPhone then
  193. local view = import("luaScript.Views.Main.PhoneBindView"):new()
  194. view:setAnchorPoint(cc.p(0.5, 0.5))
  195. app:showWaitDialog(view)
  196. else
  197. local view = import("luaScript.Views.Main.PhoneChangeView"):new()
  198. view:setAnchorPoint(cc.p(0.5, 0.5))
  199. app:showWaitDialog(view)
  200. end
  201. end
  202. --weixin绑定
  203. function MainSettingView:onClickBindWetChat()
  204. playBtnEffect()
  205. if isWin32Platform() then
  206. showTooltip("请在手机操作")
  207. return
  208. end
  209. local timeNow = os.time();
  210. if timeNow - self.lastSendLogin <= 2 then
  211. showTooltip("点击太过频繁,请稍后再试")
  212. return
  213. end
  214. if not app.plugin:isSupportWeiXin() then
  215. local text = "未安装【微信】,是否前往下载【微信】?"
  216. local okBtnImage = "res/ui/zy_tongyong/zy_button/btn_like_xiazai.png"
  217. local okCallBack = function()
  218. app.plugin:callUrl("http://weixin.qq.com/");
  219. end
  220. local cancelCallBack = function()
  221. end
  222. showConfirmDialog(text, okCallBack, cancelCallBack, 26, okBtnImage)
  223. return;
  224. end
  225. self.lastSendLogin = timeNow;
  226. --到时候二次授权可以用这段代码
  227. --绑定标志
  228. app.user.bindWeiXinIng = true
  229. --PluginConfig.WeiXin = PluginConfig.WeiXinNew
  230. --启动登录微信
  231. app.plugin:loginWeiXin()
  232. end
  233. function MainSettingView:onBindResponse(event)
  234. logD("MainSettingView:onBindResponse()")
  235. local response = event.response
  236. local errCode = response.ret
  237. if errCode == BIND_TYPE_RESULT.PHONE or errCode == BIND_TYPE_RESULT.WEIXIN then
  238. self:setPlayerInfo()
  239. end
  240. end
  241. function MainSettingView:onChangePlayerInfoResponse(event)
  242. logD("MainSettingView:onChangePlayerInfoResponse()")
  243. local response = event.response
  244. local errCode = response.ret
  245. local requestType = response.requestType
  246. if errCode == 0 then
  247. if requestType == ChangePlayerInfo.REPLCACE_PHONE then
  248. self:setPlayerInfo()
  249. end
  250. end
  251. end
  252. function MainSettingView:onClubBelongEvent(data)
  253. if not data then
  254. return
  255. end
  256. local result = data.result
  257. local bindInfo = result.bindInfo
  258. if bindInfo then
  259. self.ui.Items.Layout_clubbelong:setVisible(true)
  260. else
  261. self.ui.Items.Layout_clubbelong:setVisible(false)
  262. end
  263. self.ui.Items.Layout_btns:requestDoLayout()
  264. self.ui.Items.Layout_btns:doLayout()
  265. end
  266. function MainSettingView:onCheckForbidClubInvite(data)
  267. if not data then
  268. return
  269. end
  270. local response = data.response
  271. if response and response.isallowgroup then
  272. -- 设置默认状态
  273. local isallowgroup = tonumber(response.isallowgroup)
  274. local ttSelected = {}
  275. if isallowgroup > 0 then
  276. table.insert(ttSelected,"forbidClubInvite")
  277. end
  278. self.checkBoxForbid:setDefault(ttSelected);
  279. end
  280. end
  281. function MainSettingView:onClickAgreement()
  282. app.plugin:callUrl(LoginConfig.AgreementUrl)
  283. end
  284. function MainSettingView:onClickPrivate()
  285. --app.plugin:callUrl(LoginConfig.PrivateUrl)
  286. local view = import("luaScript.Views.Main.LogOut.LogOutPrivateTips"):new()
  287. view:setAnchorPoint(cc.p(0.5,0.5))
  288. app:showWaitDialog(view,nil,false)
  289. end
  290. function MainSettingView:onClickAccountLogOut()
  291. local logOut = app.user.logOut
  292. if logOut.status == 0 then
  293. local text = "注销账号将会清除您的账号及账号内的资产,且无法恢复"
  294. local notice = "是否确认注销账号?"
  295. local okCallBack = function()
  296. local view = import("luaScript.Views.Main.LogOut.LogOutView"):new()
  297. view:setAnchorPoint(cc.p(0.5,0.5))
  298. app:showWaitDialog(view,nil,false)
  299. end
  300. local cancelCallBack = function()
  301. end
  302. showConfirmDialog(text, okCallBack, cancelCallBack, 26, nil, notice, false);
  303. else
  304. local view = import("luaScript.Views.Main.LogOut.LogOutRevoke"):new()
  305. view:setAnchorPoint(cc.p(0.5,0.5))
  306. app:showWaitDialog(view,nil,false)
  307. end
  308. end
  309. return MainSettingView;