1
0

add.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="main">
  3. <view class="bgm">
  4. <view class="form_group">
  5. <view class="lable">标题</view>
  6. <input v-model="item.title" placeholder="请输入标题" />
  7. </view>
  8. <view class="form_group">
  9. <view class="lable">分类</view>
  10. <picker :range="type" range-key="dictLabel" @change="picker($event, 'type')">
  11. <input placeholder="请选择" v-model="item.type" :disabled="true" />
  12. <view class="icon more">&#xe62b;</view>
  13. </picker>
  14. </view>
  15. <leditor ref="editor" v-model="item.content"></leditor>
  16. <view class="form_group">
  17. <view class="lable">状态</view>
  18. <picker :range="state" @change="picker($event, 'state')">
  19. <input placeholder="请选择" :value="item.state == 0 ? '启用' : '停用'" :disabled="true" />
  20. <view class="icon more">&#xe62b;</view>
  21. </picker>
  22. </view>
  23. </view>
  24. <button class="btn" @click="add()">确认</button>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. item: { state: 0 },
  32. type: [],
  33. state: ['启用', '停用']
  34. };
  35. },
  36. onLoad(e) {
  37. this.getType();
  38. if (e.id) {
  39. this.http.request({
  40. url: '/work/knowledge/detail/' + e.id,
  41. success: (res) => {
  42. this.item = res.data.data;
  43. this.$refs.editor.setContents();
  44. uni.setNavigationBarTitle({ title: '编辑知识库' });
  45. }
  46. });
  47. }
  48. },
  49. methods: {
  50. picker(e, tag) {
  51. if (tag == 'type') {
  52. this.item.type = this.type[e.detail.value].dictLabel;
  53. } else {
  54. this.item[tag] = e.detail.value;
  55. }
  56. this.$forceUpdate();
  57. },
  58. getType() {
  59. this.http.request({
  60. url: '/app/common/type/knowledge_type',
  61. loading: 'false',
  62. success: (res) => {
  63. this.type = res.data.data;
  64. }
  65. });
  66. },
  67. add() {
  68. let rule = [
  69. { name: 'title', checkType: 'notnull', errorMsg: '请输入标题' },
  70. { name: 'type', checkType: 'notnull', errorMsg: '请选择分类' },
  71. { name: 'content', checkType: 'notnull', errorMsg: '请输入内容' }
  72. ];
  73. if (!this.verify.check(this.item, rule)) {
  74. uni.showModal({ content: this.verify.error, showCancel: false });
  75. return false;
  76. }
  77. this.http.request({
  78. url: this.item.id ? '/work/knowledge/edit' : '/work/knowledge/add',
  79. method: 'POST',
  80. data: this.item,
  81. success: (res) => {
  82. uni.showModal({
  83. title: '提示',
  84. content: '操作成功',
  85. showCancel: false,
  86. success: (res) => {
  87. uni.$emit('knowledge');
  88. uni.navigateBack();
  89. }
  90. });
  91. }
  92. });
  93. }
  94. }
  95. };
  96. </script>
  97. <style lang="scss">
  98. .bgm {
  99. border-radius: 5px;
  100. overflow: hidden;
  101. }
  102. .btn {
  103. margin-top: 35px;
  104. }
  105. </style>