update.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div>
  3. <el-dialog :title="dialogtitle" width="800px" class="icon-dialog" :visible.sync="show" @open="open"
  4. :before-close="closeForm" append-to-body>
  5. <el-form :size="size" ref="form" :model="form" :rules="rules"
  6. :label-width="$store.getters.device !== 'mobile'?'16%':'90px'">
  7. <el-row>
  8. <el-col :span="24">
  9. <el-form-item label="内容" prop="content">
  10. <el-input v-model="form.content" type="textarea" autoComplete="off" clearable placeholder="请输入内容">
  11. </el-input>
  12. </el-form-item>
  13. </el-col>
  14. </el-row>
  15. <el-row>
  16. <el-col :span="24">
  17. <el-form-item label="状态" prop="status">
  18. <el-switch :active-value="1" :inactive-value="0" v-model="form.status"></el-switch>
  19. </el-form-item>
  20. </el-col>
  21. </el-row>
  22. <el-row>
  23. <el-col :span="24">
  24. <el-form-item label="排序" prop="px">
  25. <el-input-number controls-position="right" style="width:200px;" autoComplete="off"
  26. v-model="form.px" clearable :min="0" placeholder="排序" />
  27. </el-form-item>
  28. </el-col>
  29. </el-row>
  30. </el-form>
  31. <div slot="footer" class="dialog-footer">
  32. <el-button :loading="loading" type="primary" @click="submit">
  33. <span v-if="!loading">确 定</span>
  34. <span v-else>提 交 中...</span>
  35. </el-button>
  36. <el-button @click="closeForm">取 消</el-button>
  37. </div>
  38. </el-dialog>
  39. </div>
  40. </template>
  41. <script>
  42. import ImagesUpload from '@/components/common/ImagesUpload.vue'
  43. export default {
  44. name: 'update',
  45. components: {
  46. ImagesUpload
  47. },
  48. props: {
  49. show: {
  50. type: Boolean,
  51. default: false
  52. },
  53. opentype:{
  54. type: String,
  55. default: 'add'
  56. },
  57. size: {
  58. type: String,
  59. default: 'small'
  60. },
  61. info: {
  62. type: Object,
  63. },
  64. },
  65. data() {
  66. return {
  67. dialogtitle:'',
  68. form: {
  69. content: '',
  70. status: 1,
  71. },
  72. loading: false,
  73. rules: {
  74. content: [{
  75. required: true,
  76. message: '内容不能为空',
  77. trigger: 'blur'
  78. }, ],
  79. }
  80. }
  81. },
  82. watch: {
  83. show(val) {
  84. }
  85. },
  86. methods: {
  87. open() {
  88. if(this.opentype=='update'){
  89. this.dialogtitle = "修改";
  90. this.form = this.info
  91. if (this.info.pid == '0') {
  92. this.$delete(this.info, 'pid')
  93. }
  94. }else{
  95. this.dialogtitle = "添加";
  96. this.form = {
  97. type: 1,
  98. status: 1,
  99. };
  100. //console.log(this.form);
  101. }
  102. },
  103. submit() {
  104. this.$refs['form'].validate(valid => {
  105. if (valid) {
  106. this.loading = true
  107. this.$api.post('/kefu.commonly/update', this.form).then(res => {
  108. this.$message({
  109. message: res.msg,
  110. type: 'success'
  111. })
  112. this.$emit('refesh_list')
  113. this.closeForm()
  114. }).catch(() => {
  115. this.loading = false
  116. })
  117. }
  118. })
  119. },
  120. closeForm() {
  121. this.$emit('update:show', false)
  122. this.loading = false
  123. if (this.$refs['form'] !== undefined) {
  124. this.$refs['form'].resetFields()
  125. }
  126. },
  127. }
  128. }
  129. </script>