edit.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="mobile-item-container">
  3. <Navbar :title="noticeId ? '修改公告' : '新增公告'" bgColor="#fff" :h5Show="false"></Navbar>
  4. <u--form ref="noticeForm" :model="notice" :rules="rules" labelPosition="left">
  5. <u-form-item label="标题" prop="noticeTitle" borderBottom>
  6. <u--textarea v-model="notice.noticeTitle" placeholder="请输入标题" :count="false" :maxlength="30" :autoHeight="true" confirmType="done"></u--textarea>
  7. </u-form-item>
  8. <u-form-item label="类型" prop="noticeType" borderBottom @click="actionShow = true;">
  9. <u--input v-model="noticeTypeName" disabled disabledColor="#ffffff" placeholder="请选择类型" border="none"></u--input>
  10. <u-icon slot="right" name="arrow-right"></u-icon>
  11. </u-form-item>
  12. <u-form-item label="状态" prop="status" borderBottom>
  13. <u-radio-group v-model="notice.status">
  14. <u-radio shape="circle" label="正常" name="0" checked></u-radio>
  15. <u-radio shape="circle" label="关闭" name="1"></u-radio>
  16. </u-radio-group>
  17. </u-form-item>
  18. <u-form-item label="正文" prop="noticeContent">
  19. <u--textarea v-model="notice.noticeContent" placeholder="请输入标题" :count="true" :maxlength="600" confirmType="done"></u--textarea>
  20. </u-form-item>
  21. </u--form>
  22. <u-action-sheet :actions="actions" :title="actionTitle" :show="actionShow" @close="actionShow = false" @select="actionSelect"></u-action-sheet>
  23. <u-row :gutter="16" style="margin-top: 36px;">
  24. <u-col :span="6">
  25. <u-button v-if="noticeId" type="error" text="删除" @click="del"></u-button>
  26. <u-button v-else icon="arrow-left" text="返回" plain @click="goBack()"></u-button>
  27. </u-col>
  28. <u-col :span="6">
  29. <u-button type="primary" text="提交" @click="submit"></u-button>
  30. </u-col>
  31. </u-row>
  32. </view>
  33. </template>
  34. <script>
  35. import * as NoticeApi from '@/api/work/notice'
  36. import Navbar from '@/components/navbar/Navbar'
  37. export default {
  38. components: {
  39. Navbar,
  40. },
  41. data () {
  42. return {
  43. noticeId: undefined,
  44. notice: {
  45. noticeTitle: '',
  46. status: '0',
  47. noticeContent: ''
  48. },
  49. actionShow: false,
  50. actions: [{
  51. name: '通知',
  52. value: '1'
  53. }, {
  54. name: '公告',
  55. value: '2'
  56. }],
  57. actionTitle: '',
  58. noticeTypeName: null,
  59. rules: {
  60. noticeTitle: [ { required: true, message: '请输入公告标题', trigger: ['blur', 'change'] } ],
  61. noticeType: [ { required: true, message: '请选择公告类型', trigger: ['blur', 'change'] } ],
  62. status: [ { required: true, message: '请选择公告状态', trigger: ['blur', 'change'] } ],
  63. noticeContent: [ { required: true, message: '请输入公告正文', trigger: ['blur', 'change'] } ],
  64. }
  65. }
  66. },
  67. onLoad (params) {
  68. this.noticeId = params.id
  69. this.loadData()
  70. },
  71. methods: {
  72. loadData () {
  73. if (this.noticeId) {
  74. const app = this
  75. NoticeApi.noticeById(this.noticeId).then(res => {
  76. app.notice = res.data
  77. })
  78. }
  79. },
  80. del () {
  81. NoticeApi.noticeDelete(this.noticeId).then(res => {
  82. uni.showToast({ title: '保存成功!' })
  83. })
  84. },
  85. submit () {
  86. this.$refs.noticeForm.validate().then(res => {
  87. if (this.noticeId) {
  88. NoticeApi.noticeModify(this.notice).then(res => {
  89. uni.showToast({ title: '提交成功!' })
  90. })
  91. } else {
  92. NoticeApi.noticeAdd(this.notice).then(res => {
  93. uni.showToast({ title: '提交成功!' })
  94. })
  95. }
  96. });
  97. },
  98. actionSelect (item) {
  99. this.noticeTypeName = item.name;
  100. this.notice.noticeType = item.value;
  101. this.$refs.noticeForm.validateField('noticeType');
  102. },
  103. goBack () {
  104. uni.navigateBack({ delta: 1});
  105. }
  106. }
  107. }
  108. </script>