add.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 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() {
  37. this.getType();
  38. },
  39. methods: {
  40. picker(e, tag) {
  41. if (tag == 'type') {
  42. this.item.type = this.type[e.detail.value].dictLabel;
  43. } else {
  44. this.item[tag] = e.detail.value;
  45. }
  46. this.$forceUpdate();
  47. },
  48. getType() {
  49. this.http.request({
  50. url: '/app/common/type/knowledge_type',
  51. loading: 'false',
  52. success: (res) => {
  53. this.type = res.data.data;
  54. }
  55. });
  56. },
  57. add() {
  58. let rule = [
  59. { name: 'title', checkType: 'notnull', errorMsg: '请输入标题' },
  60. { name: 'type', checkType: 'notnull', errorMsg: '请选择分类' },
  61. { name: 'content', checkType: 'notnull', errorMsg: '请输入内容' }
  62. ];
  63. if (!this.verify.check(this.item, rule)) {
  64. uni.showModal({ content: this.verify.error, showCancel: false });
  65. return false;
  66. }
  67. this.http.request({
  68. url: '/work/knowledge/add',
  69. method: 'POST',
  70. data: this.item,
  71. success: (res) => {
  72. uni.showModal({
  73. title: '提示',
  74. content: '新增成功',
  75. showCancel: false,
  76. success: (res) => {
  77. uni.$emit('knowledge');
  78. uni.navigateBack();
  79. }
  80. });
  81. }
  82. });
  83. }
  84. }
  85. };
  86. </script>
  87. <style lang="scss">
  88. .bgm {
  89. border-radius: 5px;
  90. overflow: hidden;
  91. }
  92. .btn {
  93. margin-top: 35px;
  94. }
  95. </style>