setting.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="page">
  3. <!-- 菜单 -->
  4. <view class="menu-list-wrap box-shadow">
  5. <!-- #ifdef MP-WEIXIN -->
  6. <view class="menu-item" @click="bindWeixin">
  7. <view class="menu-title-wrap">
  8. <view class="title">
  9. <u-icon class="u-m-r-10" name="weixin-fill" color="#07c160" size="40"></u-icon>
  10. 绑定微信
  11. </view>
  12. </view>
  13. <u-icon name="arrow-right" size="24" :label="vk.vuex.get('$user.userInfo.wx_openid') ? '已绑定' : ''" labelPos="left"></u-icon>
  14. </view>
  15. <!-- #endif -->
  16. <view class="menu-item" @click="vk.navigateTo('/pages/user/setting/profile')">
  17. <view class="menu-title-wrap">
  18. <view class="title">
  19. <u-icon class="u-m-r-10" name="/static/icon/notebook.png" size="36"></u-icon>
  20. 补全个人信息
  21. </view>
  22. </view>
  23. <u-icon name="arrow-right" size="24" :label="vk.vuex.get('$user.agentInfo.verify_status') == 0 ? '审核中' : '已认证'" labelPos="left"></u-icon>
  24. </view>
  25. <view class="menu-item" @click="vk.navigateTo('/pages/user/setting/bank')">
  26. <view class="menu-title-wrap">
  27. <view class="title">
  28. <u-icon class="u-m-r-10" name="/static/icon/bank-card.png" size="36"></u-icon>
  29. 补全银行卡信息
  30. </view>
  31. </view>
  32. <u-icon name="arrow-right" size="24" :label="vk.vuex.get('$user.agentInfo.verify_status') == 0 ? '审核中' : '已认证'" labelPos="left"></u-icon>
  33. </view>
  34. <!-- <view class="menu-item">
  35. <view class="menu-title-wrap">
  36. <view class="title">
  37. <u-icon class="u-m-r-10" name="/static/icon/bell.png" size="36"></u-icon>
  38. 接收推送
  39. </view>
  40. </view>
  41. <button class="u-reset-button" open-type="openSetting" size="mini" style="margin: 0;padding: 0;color: #424242;">
  42. <u-icon name="arrow-right" size="24"></u-icon>
  43. </button>
  44. </view> -->
  45. <!-- #ifdef MP-WEIXIN -->
  46. <view class="menu-item" @click="checkUpdate()">
  47. <view class="menu-title-wrap">
  48. <view class="title">
  49. <u-icon class="u-m-r-10" name="/static/icon/balloon.png" size="36"></u-icon>
  50. 检查最新版本
  51. </view>
  52. </view>
  53. <u-icon name="arrow-right" size="24"></u-icon>
  54. </view>
  55. <!-- #endif -->
  56. </view>
  57. <view class="menu-list-wrap box-shadow">
  58. <view class="menu-item" @click="vk.navigateTo('/pages/user/help/help')">
  59. <view class="menu-title-wrap">
  60. <view class="title">
  61. <u-icon class="u-m-r-10 u-m-t-6" name="/static/icon/handshake.png" size="36"></u-icon>
  62. 帮助中心
  63. </view>
  64. </view>
  65. <u-icon name="arrow-right" size="24"></u-icon>
  66. </view>
  67. <view class="menu-item" @click="vk.navigateTo('/pages/user/help/suggest')">
  68. <view class="menu-title-wrap">
  69. <view class="title">
  70. <u-icon class="u-m-r-10" name="/static/icon/mail-box.png" size="36"></u-icon>
  71. 意见建议
  72. </view>
  73. </view>
  74. <u-icon name="arrow-right" size="24"></u-icon>
  75. </view>
  76. <view class="menu-item" @click="vk.navigateTo('/pages/agreement/agreement?type=user_agreement')">
  77. <view class="menu-title-wrap">
  78. <view class="title">
  79. <u-icon class="u-m-r-10" name="/static/icon/agreement.png" size="36"></u-icon>
  80. 用户协议
  81. </view>
  82. </view>
  83. <u-icon name="arrow-right" size="24"></u-icon>
  84. </view>
  85. <view class="menu-item" @click="vk.navigateTo('/pages/agreement/agreement?type=privacy_agreement')">
  86. <view class="menu-title-wrap">
  87. <view class="title">
  88. <u-icon class="u-m-r-10" name="/static/icon/agreement.png" size="36"></u-icon>
  89. 隐私协议
  90. </view>
  91. </view>
  92. <u-icon name="arrow-right" size="24"></u-icon>
  93. </view>
  94. <view class="menu-item" @click="logoffModalShow = true">
  95. <view class="menu-title-wrap">
  96. <view class="title">
  97. <u-icon class="u-m-r-10" name="/static/icon/lock.png" size="36"></u-icon>
  98. 注销账号
  99. </view>
  100. </view>
  101. <u-icon name="arrow-right" size="24"></u-icon>
  102. </view>
  103. </view>
  104. <u-button type="primary" v-show="vk.checkToken()" @click="logout">注销登录</u-button>
  105. <!-- 授权微信资料弹窗 -->
  106. <!-- 平台佣金政策弹窗 -->
  107. <u-popup v-model="editWeixinUserInfoPopupShow" mode="center" width="80%" height="440rpx" border-radius="20">
  108. <view class="bwin-popup">
  109. <view class="popup-header">同步微信资料</view>
  110. <view class="popup-body">
  111. <view class="choose-avatar u-m-b-20">
  112. <u-avatar :src="form.avatarUrl" size="128" showLevel levelIcon="edit-pen" levelBgColor="#2979ff"></u-avatar>
  113. <button
  114. class="u-reset-button"
  115. style="width: 128rpx;height: 128rpx;position: absolute;left: 0;top: 0;"
  116. open-type="chooseAvatar"
  117. @chooseavatar="bindWeixinAvatar"
  118. ></button>
  119. </view>
  120. <u-input border placeholder="点击可使用微信昵称填充" v-model="form.nickname" style="width: 100%;" type="nickname"></u-input>
  121. </view>
  122. <view class="popup-footer" style="position: absolute;">
  123. <u-button size="medium" @click="editWeixinUserInfoPopupShow = false">取消</u-button>
  124. <u-button size="medium" type="primary" @click="updateUserInfoByWeixin()">保存</u-button>
  125. </view>
  126. </view>
  127. </u-popup>
  128. <!-- 注销账号modal -->
  129. <u-modal
  130. v-model="logoffModalShow"
  131. title="重要提示"
  132. content="提交后,您的账号将被彻底删除,包括但不限于您的推荐记录、佣金结算记录等均将被同步删除。请确认是否仍要注销您的账号?"
  133. showCancelButton
  134. @cancel="logoffModalShow = false"
  135. @confirm="vk.toast('已提交注销申请')"
  136. ></u-modal>
  137. </view>
  138. </template>
  139. <script>
  140. var that;
  141. var vk;
  142. export default {
  143. data() {
  144. return {
  145. logoffModalShow: false, // 注销提示
  146. editWeixinUserInfoPopupShow: false, // 补全微信资料
  147. form: {
  148. avatarUrl: null,
  149. nickname: ''
  150. }
  151. };
  152. },
  153. onLoad() {
  154. that = this;
  155. vk = that.vk;
  156. that.form.avatarUrl = vk.vuex.get('$user.userInfo.avatar');
  157. },
  158. onReady() {},
  159. methods: {
  160. // 绑定微信号
  161. bindWeixin() {
  162. if (vk.vuex.get('$user.userInfo.wx_openid')) {
  163. let currentTime = Date.parse(new Date()) / 1000; // 秒级
  164. if (currentTime - vk.vuex.get('$user.history.lastEditUserInfoTime') <= 86400) {
  165. vk.alert('已绑定微信,用户资料在每7天内仅允许修改一次', '提示', '确定');
  166. } else {
  167. that.editWeixinUserInfoPopupShow = true;
  168. }
  169. return;
  170. }
  171. vk.userCenter.bindWeixin({
  172. success: data => {
  173. // 成功后的逻辑
  174. vk.alert('绑定成功,请继续设置头像、昵称', '提示', '确定', function() {
  175. that.editWeixinUserInfoPopupShow = true;
  176. });
  177. console.log(data);
  178. }
  179. });
  180. },
  181. // 获取用户微信头像
  182. bindWeixinAvatar(e) {
  183. let { avatarUrl } = e.detail;
  184. that.form.avatarUrl = avatarUrl; // 临时渲染
  185. },
  186. // 通过微信资料修改个人资料
  187. updateUserInfoByWeixin() {
  188. // 上传头像
  189. vk.callFunctionUtil.uploadFile({
  190. title: '上传头像中...',
  191. filePath: that.form.avatarUrl,
  192. suffix: 'png', // 不传suffix会自动获取,但H5环境下获取不到后缀,但可以通过file.name 获取
  193. provider: 'unicloud',
  194. success(res) {
  195. // 上传成功
  196. vk.userCenter.updateUser({
  197. data: {
  198. avatar: res.url,
  199. nickname: that.form.nickname
  200. },
  201. success: data => {
  202. // 成功后的逻辑
  203. that.editWeixinUserInfoPopupShow = false;
  204. // 写入本次修改时间
  205. let currentTime = Date.parse(new Date()) / 1000; // 秒级
  206. vk.vuex.set('$user.history.lastEditUserInfoTime', currentTime);
  207. vk.alert('保存成功');
  208. }
  209. });
  210. }
  211. });
  212. },
  213. // 检测版本更新
  214. checkUpdate() {
  215. const updateManager = uni.getUpdateManager();
  216. updateManager.onCheckForUpdate(function(res) {
  217. // 请求完新版本信息的回调
  218. console.log(res.hasUpdate);
  219. if (!res.hasUpdate) {
  220. vk.toast('当前已是最新版本');
  221. }
  222. });
  223. updateManager.onUpdateReady(function(res) {
  224. uni.showModal({
  225. title: '更新提示',
  226. content: '新版本已经准备好,是否重启应用?',
  227. success(res) {
  228. if (res.confirm) {
  229. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  230. updateManager.applyUpdate();
  231. }
  232. }
  233. });
  234. });
  235. updateManager.onUpdateFailed(function(res) {
  236. // 新的版本下载失败
  237. });
  238. },
  239. // 退出登录
  240. logout() {
  241. vk.userCenter.logout({
  242. success: function(data) {
  243. vk.vuex.set('$user.agentInfo', {});
  244. vk.vuex.set('$user.dataInfo', {
  245. recommendNum: 0,
  246. visitedNum: 0,
  247. buyNum: 0,
  248. totalCommission: 0,
  249. unreadMsgNum: 0
  250. });
  251. vk.toast('注销登录成功', 'success', 1500, true, function() {
  252. vk.navigateToHome();
  253. });
  254. }
  255. });
  256. }
  257. }
  258. };
  259. </script>
  260. <style lang="scss">
  261. .page {
  262. min-height: calc(100vh - 45px);
  263. }
  264. .popup-body {
  265. display: flex;
  266. flex-direction: column;
  267. align-items: center;
  268. .choose-avatar {
  269. position: relative;
  270. }
  271. }
  272. // 菜单列表
  273. .menu-list-wrap {
  274. display: flex;
  275. flex-direction: column;
  276. align-items: flex-start;
  277. background-color: #fff;
  278. padding: 32rpx;
  279. width: 100%;
  280. margin-bottom: 20rpx;
  281. border-radius: 10rpx;
  282. position: relative;
  283. .menu-item {
  284. width: 100%;
  285. display: flex;
  286. align-items: center;
  287. justify-content: space-between;
  288. padding: 20rpx 0;
  289. .menu-title-wrap {
  290. display: flex;
  291. align-items: center;
  292. .title {
  293. display: flex;
  294. align-items: center;
  295. font-size: $u-p;
  296. }
  297. }
  298. }
  299. }
  300. </style>