notice.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <view class="container">
  3. <view class="safe-area-inset-bottom">
  4. <rider-curd
  5. v-model="form"
  6. :option="option"
  7. :data="list"
  8. :rules="rules"
  9. :readonly.sync="readonly"
  10. @search="onSearch"
  11. @action-click="onActionClick"
  12. @submit="onSubmit"
  13. @del="onRemove"
  14. ref="crud"
  15. >
  16. <view slot="form">
  17. <u-form-item label="通知标题" prop="title" :label-width="option.labelWidth || 160" required>
  18. <u-input v-model="form.title" :disabled="readonly" placeholder="通知标题" />
  19. </u-form-item>
  20. <u-form-item label="通知类型" prop="category" :label-width="option.labelWidth || 160" required>
  21. <u-input
  22. v-model="formLabel.category"
  23. :disabled="readonly"
  24. placeholder="通知类型"
  25. type="select"
  26. @click="
  27. () => {
  28. if (!readonly) categoryShow = true
  29. }
  30. "
  31. />
  32. </u-form-item>
  33. <u-form-item label="通知日期" prop="releaseTime" :label-width="option.labelWidth || 160" required>
  34. <u-input
  35. v-model="form.releaseTime"
  36. :disabled="readonly"
  37. placeholder="通知日期"
  38. type="select"
  39. @click="
  40. () => {
  41. if (!readonly) timeShow = true
  42. }
  43. "
  44. />
  45. </u-form-item>
  46. <u-form-item label="通知内容" :label-width="option.labelWidth || 160" :border-bottom="false">
  47. <template #right v-if="!readonly">
  48. <u-button
  49. @click="onRichEdit(form.content)"
  50. ripple
  51. :custom-style="{ background: '#FFF6E9', color: '#FAA646' }"
  52. size="mini"
  53. >
  54. 去编辑
  55. </u-button>
  56. </template>
  57. </u-form-item>
  58. <mp-html :content="form.content"></mp-html>
  59. </view>
  60. <template #loadmore>
  61. <u-loadmore :status="loadStatus" @loadmore="getList()" />
  62. </template>
  63. </rider-curd>
  64. </view>
  65. <!-- 通知类型 -->
  66. <u-select
  67. v-model="categoryShow"
  68. :list="categoryList"
  69. value-name="dictKey"
  70. label-name="dictValue"
  71. @confirm="e => onConfirm(e, 'category')"
  72. safe-area-inset-bottom
  73. ></u-select>
  74. <!-- 通知日期 -->
  75. <u-picker
  76. mode="time"
  77. v-model="timeShow"
  78. :params="timeParams"
  79. start-year="2000"
  80. end-year="2050"
  81. @confirm="e => onConfirm(e, 'releaseTime')"
  82. safe-area-inset-bottom
  83. ></u-picker>
  84. </view>
  85. </template>
  86. <script>
  87. import riderCurd from '@/components/rider-crud/index'
  88. import mpHtml from '@/components/rider-crud/components/mp-html/mp-html'
  89. import { getList, add, update, remove } from '@/api/notice.js'
  90. import { dictionary } from '@/api/system/dict.js'
  91. import { logo } from '../../common/setting'
  92. import { getDicLabel } from '@/components/rider-crud/util/tool.js'
  93. export default {
  94. components: { riderCurd, mpHtml },
  95. data() {
  96. return {
  97. loadStatus: 'loadmore', // 列表加载状态
  98. checkedSwitch: false, // 默认打开管理
  99. form: { content: '' }, // 表单
  100. formLabel: {}, // 表单label
  101. list: [], // 列表数据
  102. params: {
  103. // 分页
  104. current: 1,
  105. size: 10
  106. },
  107. readonly: false, // 查看时控制表单只读
  108. option: {
  109. // 组件选项
  110. navTitle: '通知公告', //标题
  111. manageBtn: true, // 右上角管理按钮,默认不显示
  112. searchShow: true, //是否显示搜索,默认不显示
  113. searchShow: true, //是否显示搜索,默认不显示
  114. labelWidth: 160, //form表单lable宽度, 默认160,单位rpx
  115. column: [
  116. {
  117. label: '通知标题',
  118. prop: 'title'
  119. },
  120. {
  121. label: '通知类型',
  122. prop: 'categoryName'
  123. },
  124. {
  125. label: '通知日期',
  126. prop: 'releaseTime'
  127. }
  128. ],
  129. actions: [
  130. // 左滑操作按钮
  131. {
  132. name: '编辑', // 操作名称
  133. icon: 'edit-pen', //操作图标,有图标文字不显示
  134. color: '#333', // 字体颜色
  135. fontsize: 30, //字体大小,单位rpx
  136. width: 40, // 宽度,单位px
  137. background: '#fff' // 菜单按钮背景色
  138. },
  139. {
  140. name: '删除',
  141. icon: 'trash',
  142. color: '#333',
  143. fontsize: 30,
  144. width: 40,
  145. background: '#fff'
  146. }
  147. ]
  148. },
  149. rules: {
  150. // 表单校验规则
  151. title: [{ required: true, message: '请输入通知标题', trigger: 'blur' }],
  152. category: [{ required: true, message: '请选择通知类型', trigger: 'change', type: 'number' }],
  153. releaseTime: [{ required: true, message: '请选择通知日期', trigger: 'change' }]
  154. },
  155. timeShow: false,
  156. timeParams: {
  157. year: true,
  158. month: true,
  159. day: true,
  160. hour: true,
  161. minute: true,
  162. second: true
  163. },
  164. categoryShow: false,
  165. categoryList: [] //类型
  166. }
  167. },
  168. onShow() {
  169. let that = this
  170. uni.$on('richBack', function(data) {
  171. that.$set(that.form, 'content', data)
  172. })
  173. },
  174. onReady() {
  175. this.getList(true)
  176. this.getCategoryList()
  177. },
  178. onPullDownRefresh() {
  179. this.getList(true)
  180. },
  181. onReachBottom() {
  182. if (this.loadStatus == 'nomore') return
  183. this.getList()
  184. },
  185. methods: {
  186. // 获取列表
  187. getList(override = false) {
  188. if (override) {
  189. this.params.current = 1
  190. }
  191. const { size } = this.params
  192. getList(this.params)
  193. .then(res => {
  194. const { records, current } = res.data
  195. if (records.length < size) this.loadStatus = 'nomore'
  196. else this.loadStatus = 'loadmore'
  197. if (override) {
  198. this.list = records
  199. } else {
  200. this.list = this.list.concat(records)
  201. }
  202. this.params.current++
  203. uni.stopPullDownRefresh()
  204. })
  205. .catch(err => {
  206. uni.stopPullDownRefresh()
  207. })
  208. },
  209. // 通知类型
  210. getCategoryList() {
  211. dictionary({ code: 'notice' }).then(res => {
  212. this.categoryList = res.data
  213. })
  214. },
  215. // 类型回调
  216. onConfirm(e, type) {
  217. if (type == 'category') {
  218. this.formLabel[type] = e[0].label
  219. this.form.category = Number(e[0].value)
  220. } else {
  221. this.$set(this.form, 'releaseTime', e.year + '-' + e.month + '-' + e.day + ' ' + e.hour + ':' + e.minute + ':' + e.second)
  222. }
  223. },
  224. // 编辑富文本
  225. onRichEdit(e) {
  226. uni.navigateTo({
  227. url: `/pages/rich/index?data=${e}`
  228. })
  229. },
  230. // 搜索 (自行配置搜索内容)
  231. onSearch(val) {
  232. this.params = {
  233. current: 1,
  234. size: 10,
  235. title: val
  236. }
  237. this.getList(true)
  238. },
  239. // 左滑按钮点击
  240. onActionClick({ index, data, action, done }) {
  241. const { name } = action
  242. switch (name) {
  243. case '新增':
  244. this.formLabel = {}
  245. this.form = { content: '' }
  246. done()
  247. break
  248. case '删除':
  249. this.onRemove(data.id)
  250. break
  251. case '查看':
  252. this.readonly = true
  253. case '编辑':
  254. this.formLabel.category = getDicLabel(data.category, this.categoryList)
  255. done()
  256. break
  257. }
  258. },
  259. // 删除
  260. onRemove(id) {
  261. uni.showModal({
  262. title: '确定要删除吗?',
  263. success: action => {
  264. if (action.confirm) {
  265. remove(id).then(() => {
  266. uni.showToast({
  267. title: '删除成功',
  268. icon: 'none'
  269. })
  270. setTimeout(() => {
  271. this.$refs['crud'].allCheckHide(false)
  272. }, 100)
  273. // #ifdef APP
  274. this.getList(true)
  275. // #endif
  276. // #ifndef APP
  277. uni.startPullDownRefresh({})
  278. // #endif
  279. })
  280. }
  281. }
  282. })
  283. },
  284. // 表单提交
  285. onSubmit(form, action, unloading, done) {
  286. if (action == '新增') {
  287. add(form)
  288. .then(res => {
  289. uni.showToast({
  290. title: '新增成功',
  291. icon: 'none'
  292. })
  293. this.formLabel = {}
  294. done()
  295. uni.startPullDownRefresh({})
  296. })
  297. .catch(() => {
  298. unloading()
  299. })
  300. } else if (action == '编辑') {
  301. update(form)
  302. .then(res => {
  303. uni.showToast({
  304. title: '编辑成功',
  305. icon: 'none'
  306. })
  307. this.formLabel = {}
  308. done()
  309. uni.startPullDownRefresh({})
  310. })
  311. .catch(() => {
  312. unloading()
  313. })
  314. }
  315. }
  316. }
  317. }
  318. </script>
  319. <style>
  320. page {
  321. background: #f6f6f6;
  322. }
  323. </style>