index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="reminder-config-page">
  3. <scroll-view class="content" scroll-y>
  4. <!-- 鍚敤寮€鍏?-->
  5. <view class="cfg-card">
  6. <view class="cfg-card-header">
  7. <text class="cfg-card-title">鎻愰啋寮€鍏?/text>
  8. <text class="cfg-switch" :class="{ 'cfg-switch-on': enabled === 1 }" @tap="toggleEnabled">
  9. <text class="cfg-switch-text">{{ enabled === 1 ? '宸插紑鍚? : '宸插叧闂? }}</text>
  10. </text>
  11. </view>
  12. <text class="cfg-card-desc">寮€鍚悗锛屼换鍔℃墦鍗℃湭瀹屾垚鏃朵細鎸変互涓嬭缃彂閫佹彁閱?/text>
  13. </view>
  14. <!-- 鎻愰啋娓犻亾 -->
  15. <view class="cfg-card">
  16. <text class="cfg-card-title">鎻愰啋娓犻亾</text>
  17. <view class="channel-list">
  18. <view class="channel-item" v-for="(ch, index) in channels" :key="ch.type + '_' + index"
  19. :class="{
  20. 'channel-selected': isSelected(ch.type),
  21. 'channel-disabled': !ch.available
  22. }"
  23. @tap="toggleChannel(ch)">
  24. <view class="channel-check" v-if="isSelected(ch.type) && ch.available">鉁?/view>
  25. <view class="channel-info">
  26. <text class="channel-name">{{ ch.label }}</text>
  27. <text class="channel-reason" v-if="!ch.available">{{ ch.reason || '鏈紑閫? }}</text>
  28. </view>
  29. </view>
  30. <view class="channel-tip" v-if="channelTip">
  31. <text class="channel-tip-text">{{ channelTip }}</text>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 鎻愰啋鏃舵満 -->
  36. <view class="cfg-card">
  37. <text class="cfg-card-title">鎻愰啋鏃舵満</text>
  38. <view class="timing-list">
  39. <view class="timing-item" :class="{ 'timing-active': timingMode === 'before_deadline' }" @tap="switchTiming('before_deadline')">
  40. <text class="timing-name">浠诲姟鎴鍓?/text>
  41. <text class="timing-desc">鎴鏃堕棿涔嬪墠鎻愰啋</text>
  42. </view>
  43. <view class="timing-item" :class="{ 'timing-active': timingMode === 'after_timeout' }" @tap="switchTiming('after_timeout')">
  44. <text class="timing-name">浠诲姟瓒呮椂鍚?/text>
  45. <text class="timing-desc">鎴鏃堕棿涔嬪悗鎻愰啋</text>
  46. </view>
  47. </view>
  48. <!-- 鍋忕Щ鍒嗛挓 -->
  49. <view class="offset-row">
  50. <text class="offset-label">{{ offsetLabel }}</text>
  51. <input class="offset-input" type="number" :value="String(offsetMinutes)" @input="onOffsetInput" placeholder="鍒嗛挓鏁? />
  52. <text class="offset-unit">鍒嗛挓</text>
  53. </view>
  54. <text class="offset-hint" v-if="offsetHint">{{ offsetHint }}</text>
  55. </view>
  56. <!-- 瀹屾垚琛ㄦ壃寮€鍏?-->
  57. <view class="cfg-card">
  58. <view class="cfg-card-header">
  59. <text class="cfg-card-title">浠诲姟瀹屾垚榧撳姳</text>
  60. <text class="cfg-switch" :class="{ 'cfg-switch-on': completionPraiseEnabled === 1 }" @tap="togglePraiseEnabled">
  61. <text class="cfg-switch-text">{{ completionPraiseEnabled === 1 ? '宸插紑鍚? : '宸插叧闂? }}</text>
  62. </text>
  63. </view>
  64. <text class="cfg-card-desc">浠诲姟姝e父瀹屾垚鏃讹紝鍙戦€佽〃鎵紦鍔辨秷鎭?/text>
  65. <view class="channel-list" v-if="completionPraiseEnabled === 1" style="margin-top:20rpx">
  66. <view class="channel-item" v-for="(ch, pIndex) in channels" :key="'p-' + pIndex"
  67. :class="{
  68. 'channel-selected': isPraiseSelected(ch.type),
  69. 'channel-disabled': !ch.available
  70. }"
  71. @tap="togglePraiseChannel(ch)">
  72. <view class="channel-check" v-if="isPraiseSelected(ch.type) && ch.available">鉁?/view>
  73. <view class="channel-info">
  74. <text class="channel-name">{{ ch.label }}</text>
  75. <text class="channel-reason" v-if="!ch.available">{{ ch.reason || '鏈紑閫? }}</text>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. <!-- 绔欏唴娑堟伅鍏滃簳璇存槑 -->
  81. <view class="tip-card">
  82. <text class="tip-text">馃挕 绔欏唴娑堟伅鎻愰啋濮嬬粓寮€鍚紝浣滀负鍏滃簳閫氶亾涓嶉殢浠ヤ笂璁剧疆鍏抽棴</text>
  83. </view>
  84. <!-- 淇濆瓨鎸夐挳 -->
  85. <view class="save-area">
  86. <view class="save-btn" @tap="saveConfig">
  87. <text>{{ saving ? '淇濆瓨涓?..' : '淇濆瓨閰嶇疆' }}</text>
  88. </view>
  89. </view>
  90. </scroll-view>
  91. </view>
  92. </template>
  93. <script>
  94. import { getReminderConfig, saveReminderConfig } from '@/utils/api.js'
  95. export default {
  96. data() {
  97. return {
  98. loading: true,
  99. saving: false,
  100. enabled: 1,
  101. channels: [],
  102. selectedChannels: [],
  103. timingMode: 'after_timeout',
  104. offsetMinutes: 60,
  105. completionPraiseEnabled: 0,
  106. selectedPraiseChannels: ['wechat', 'in_app'],
  107. _loaded: false
  108. }
  109. },
  110. computed: {
  111. offsetLabel: function() {
  112. return this.timingMode === 'before_deadline' ? '鎻愬墠' : '瓒呮椂鍚?
  113. },
  114. offsetHint: function() {
  115. if (!this.offsetMinutes || this.offsetMinutes < 1 || this.offsetMinutes > 1440) {
  116. return '璇疯緭鍏?1-1440 涔嬮棿鐨勫垎閽熸暟'
  117. }
  118. if (this.timingMode === 'before_deadline') {
  119. return '灏嗗湪浠诲姟鎴鍓?' + this.offsetMinutes + ' 鍒嗛挓鎻愰啋'
  120. }
  121. return '灏嗗湪浠诲姟瓒呮椂鍚?' + this.offsetMinutes + ' 鍒嗛挓鎻愰啋'
  122. },
  123. channelTip: function() {
  124. var selected = this.selectedChannels || []
  125. if (selected.length === 0) {
  126. return '璇疯嚦灏戦€夋嫨涓€涓彁閱掓笭閬?
  127. }
  128. return '宸查€夋嫨 ' + selected.length + ' 涓彁閱掓笭閬?
  129. }
  130. },
  131. onLoad: function() {
  132. var self = this
  133. this.loading = true
  134. getReminderConfig().then(function(res) {
  135. self.loading = false
  136. self._loaded = true
  137. if (res && res.code === 200 && res.data) {
  138. var d = res.data
  139. self.enabled = d.enabled === 0 ? 0 : 1
  140. self.timingMode = d.timingMode || 'after_timeout'
  141. self.offsetMinutes = d.offsetMinutes || 60
  142. self.selectedChannels = Array.isArray(d.channels) ? d.channels.slice() : []
  143. self.channels = Array.isArray(d.availableChannels) ? d.availableChannels.filter(function(c) {
  144. return c && c.type !== 'in_app'
  145. }) : []
  146. self.completionPraiseEnabled = d.completionPraiseEnabled === 1 ? 1 : 0
  147. self.selectedPraiseChannels = Array.isArray(d.completionPraiseChannels) ? d.completionPraiseChannels.slice() : ['wechat', 'in_app']
  148. }
  149. }).catch(function() {
  150. self.loading = false
  151. uni.showToast({ title: '鍔犺浇澶辫触锛岃閲嶈瘯', icon: 'none' })
  152. })
  153. },
  154. methods: {
  155. toggleEnabled: function() {
  156. this.enabled = this.enabled === 1 ? 0 : 1
  157. },
  158. togglePraiseEnabled: function() {
  159. this.completionPraiseEnabled = this.completionPraiseEnabled === 1 ? 0 : 1
  160. },
  161. isSelected: function(type) {
  162. return (this.selectedChannels || []).indexOf(type) >= 0
  163. },
  164. isPraiseSelected: function(type) {
  165. return (this.selectedPraiseChannels || []).indexOf(type) >= 0
  166. },
  167. toggleChannel: function(ch) {
  168. if (!ch.available) return
  169. var idx = this.selectedChannels.indexOf(ch.type)
  170. if (idx >= 0) {
  171. this.selectedChannels.splice(idx, 1)
  172. } else {
  173. this.selectedChannels.push(ch.type)
  174. }
  175. },
  176. togglePraiseChannel: function(ch) {
  177. if (!ch.available) return
  178. var idx = this.selectedPraiseChannels.indexOf(ch.type)
  179. if (idx >= 0) {
  180. this.selectedPraiseChannels.splice(idx, 1)
  181. } else {
  182. this.selectedPraiseChannels.push(ch.type)
  183. }
  184. },
  185. switchTiming: function(mode) {
  186. this.timingMode = mode
  187. },
  188. onOffsetInput: function(e) {
  189. var v = e && e.detail && e.detail.value
  190. var n = parseInt(v, 10)
  191. this.offsetMinutes = isNaN(n) ? 0 : n
  192. },
  193. saveConfig: function() {
  194. var self = this
  195. if (!this.selectedChannels || this.selectedChannels.length === 0) {
  196. uni.showToast({ title: '璇疯嚦灏戦€夋嫨涓€涓彁閱掓笭閬?, icon: 'none' })
  197. return
  198. }
  199. var offset = this.offsetMinutes || 0
  200. if (offset < 1 || offset > 1440) {
  201. uni.showToast({ title: '鍋忕Щ鍒嗛挓闇€鍦?1-1440 涔嬮棿', icon: 'none' })
  202. return
  203. }
  204. if (this.saving) return
  205. this.saving = true
  206. saveReminderConfig({
  207. channels: this.selectedChannels.slice(),
  208. timingMode: this.timingMode,
  209. offsetMinutes: offset,
  210. enabled: this.enabled === 1 ? 1 : 0,
  211. completionPraiseEnabled: this.completionPraiseEnabled === 1 ? 1 : 0,
  212. completionPraiseChannels: this.selectedPraiseChannels.slice()
  213. }).then(function(res) {
  214. self.saving = false
  215. if (res && res.code === 200) {
  216. uni.showToast({ title: '淇濆瓨鎴愬姛', icon: 'success' })
  217. setTimeout(function() {
  218. uni.navigateBack()
  219. }, 1000)
  220. } else {
  221. uni.showToast({ title: (res && res.message) || '淇濆瓨澶辫触', icon: 'none' })
  222. }
  223. }).catch(function(err) {
  224. self.saving = false
  225. uni.showToast({ title: (err && err.message) || '淇濆瓨澶辫触', icon: 'none' })
  226. })
  227. }
  228. }
  229. }
  230. </script>