index.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view class="page_container">
  3. <custom-nav-bar title="消息通知设置" />
  4. <view class="info_wrap">
  5. <setting-item
  6. :loading="loadingState.beep"
  7. @switch="changeBeep"
  8. :switchValue="selfInfo.allowBeep === 1"
  9. title="声音"
  10. :is_switch="true"
  11. />
  12. <setting-item
  13. :loading="loadingState.vibration"
  14. @switch="changeVibration"
  15. :switchValue="selfInfo.allowVibration === 1"
  16. title="震动"
  17. :is_switch="true"
  18. />
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  24. import SettingItem from "../../../components/SettingItem/index.vue";
  25. import { businessInfoUpdate } from "../../../api/login";
  26. export default {
  27. components: {
  28. CustomNavBar,
  29. SettingItem,
  30. },
  31. data() {
  32. return {
  33. loadingState: {
  34. beep: false,
  35. vibration: false,
  36. },
  37. };
  38. },
  39. computed: {
  40. selfInfo() {
  41. return this.$store.getters.storeSelfInfo;
  42. },
  43. },
  44. onLoad() {
  45. console.log(this.$store.getters.storeSelfInfo);
  46. },
  47. methods: {
  48. changeBeep(flag) {
  49. this.loadingState.beep = true;
  50. this.updateSelfInfo(
  51. {
  52. allowBeep: flag ? 1 : 2,
  53. },
  54. "beep",
  55. );
  56. },
  57. changeVibration(flag) {
  58. this.loadingState.vibration = true;
  59. this.updateSelfInfo(
  60. {
  61. allowVibration: flag ? 1 : 2,
  62. },
  63. "vibration",
  64. );
  65. },
  66. async updateSelfInfo(data, key) {
  67. try {
  68. await businessInfoUpdate({
  69. userID: this.selfInfo.userID,
  70. ...data,
  71. });
  72. await this.$store.dispatch("user/updateBusinessInfo");
  73. uni.$u.toast("修改成功");
  74. } catch (e) {
  75. uni.$u.toast("修改失败");
  76. }
  77. this.loadingState[key] = false;
  78. },
  79. },
  80. };
  81. </script>
  82. <style lang="scss" scoped>
  83. .page_container {
  84. background-color: #f8f8f8;
  85. .info_wrap {
  86. background-color: #fff;
  87. margin-top: 24rpx;
  88. }
  89. }
  90. </style>