index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="page_container">
  3. <custom-nav-bar title="设置禁言">
  4. <view class="top_right_action" slot="more">
  5. <u-button
  6. v-show="canCancelMute || choosed || customValue"
  7. @click="confirmMute"
  8. :loading="loading"
  9. type="primary"
  10. text="完成"
  11. size="mini"
  12. ></u-button>
  13. </view>
  14. </custom-nav-bar>
  15. <view class="choose_area">
  16. <view
  17. @click="chooseItem(item)"
  18. v-for="item in chooseList.slice(canCancelMute ? 0 : 1, chooseList.length)"
  19. :key="item.title"
  20. class="choose_item"
  21. >
  22. <view>{{ item.title }}</view>
  23. <u-icon
  24. v-show="choosed === item.value && customValue === ''"
  25. name="checkbox-mark"
  26. color="#1D6BED"
  27. >
  28. </u-icon>
  29. </view>
  30. <view class="choose_item">
  31. <view>自定义</view>
  32. <view style="width: 70px">
  33. <u-input
  34. placeholder="请输入"
  35. border="none"
  36. type="number"
  37. v-model="customValue"
  38. >
  39. <template slot="suffix">
  40. <text>天</text>
  41. </template>
  42. </u-input>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import IMSDK from "openim-uniapp-polyfill";
  50. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  51. export default {
  52. components: {
  53. CustomNavBar,
  54. },
  55. data() {
  56. return {
  57. choosed: 0,
  58. loading: false,
  59. customValue: "",
  60. fromList: 0,
  61. sourceList: [],
  62. chooseList: [
  63. {
  64. title: "取消禁言",
  65. value: 0,
  66. },
  67. {
  68. title: "10分钟",
  69. value: 600,
  70. },
  71. {
  72. title: "1小时",
  73. value: 3600,
  74. },
  75. {
  76. title: "12小时",
  77. value: 43200,
  78. },
  79. {
  80. title: "1天",
  81. value: 86400,
  82. },
  83. ],
  84. canCancelMute: false
  85. };
  86. },
  87. onLoad(options) {
  88. const { sourceInfo, fromList } = options;
  89. this.sourceList = JSON.parse(sourceInfo);
  90. this.fromList = fromList ?? 0
  91. this.canCancelMute = this.sourceList.find(item => item.muteEndTime ?? 0 > Date.now())
  92. },
  93. methods: {
  94. confirmMute() {
  95. this.loading = true;
  96. let seconds = this.choosed;
  97. if (this.customValue !== "") {
  98. seconds = this.customValue * 86400;
  99. }
  100. const promiseArray = this.sourceList.map(async ({ userID, groupID }) => {
  101. await IMSDK.asyncApi(IMSDK.IMMethods.ChangeGroupMemberMute, IMSDK.uuid(), {
  102. groupID,
  103. userID,
  104. mutedSeconds: seconds,
  105. })
  106. })
  107. Promise.all(promiseArray)
  108. .then(() => {
  109. uni.$u.toast("设置成功");
  110. if(this.fromList){
  111. setTimeout(() => uni.navigateBack({ delta:2 }), 1000);
  112. }else{
  113. setTimeout(() => uni.navigateBack(), 1000);
  114. }
  115. })
  116. .catch(() => uni.$u.toast("设置失败"))
  117. .finally(() => (this.loading = false));
  118. },
  119. chooseItem({ value }) {
  120. this.choosed = value;
  121. this.customValue = "";
  122. },
  123. },
  124. };
  125. </script>
  126. <style lang="scss">
  127. .page_container {
  128. background-color: #f2f2f2;
  129. .top_right_action {
  130. margin-right: 44rpx;
  131. }
  132. .choose_area {
  133. background-color: #fff;
  134. .choose_item {
  135. display: flex;
  136. justify-content: space-between;
  137. align-items: center;
  138. padding: 24rpx 44rpx;
  139. border-bottom: 1px solid #f0f0f0;
  140. }
  141. }
  142. }
  143. </style>