details.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="exData.id ? '编辑': '新增'"
  5. :visible.sync="dialog"
  6. width="900px"
  7. :close-on-click-modal="false"
  8. top="50px">
  9. <el-form
  10. ref="form"
  11. :model="form"
  12. :rules="formRules"
  13. label-width="120px">
  14. <el-form-item
  15. prop="lunbo_name"
  16. :rules="formRules.required"
  17. label="标题:">
  18. <el-input
  19. v-model="form.lunbo_name"
  20. placeholder="请输入标题"
  21. clearable></el-input>
  22. </el-form-item>
  23. <el-form-item
  24. :rules="formRules.required"
  25. label="内容:">
  26. <tinymce
  27. :height="300"
  28. v-model="form.content"
  29. id='tinymce'></tinymce>
  30. </el-form-item>
  31. <el-form-item
  32. prop="lunbo_status"
  33. :rules="formRules.select"
  34. label="状态:">
  35. <el-select
  36. style="width: 100%;"
  37. v-model="form.lunbo_status"
  38. filterable
  39. clearable
  40. placeholder="请选择是否显示">
  41. <el-option
  42. :label="item.name"
  43. :value="item.value"
  44. v-for="item in arrLunboStatus"
  45. :key="item.value"></el-option>
  46. </el-select>
  47. </el-form-item>
  48. </el-form>
  49. <div slot="footer" class="dialog-footer text-center">
  50. <el-button @click="dialog = false">取 消</el-button>
  51. <el-button type="primary" :disabled="booLock" @click="handleSubmit">确 定</el-button>
  52. </div>
  53. </el-dialog>
  54. </div>
  55. </template>
  56. <script>
  57. import tinymce from '@/components/Tinymce'
  58. export default {
  59. props: {
  60. value: {
  61. type: Boolean,
  62. default: true
  63. },
  64. exData: {
  65. type: Object,
  66. default: function () {
  67. return {}
  68. }
  69. }
  70. },
  71. components: {
  72. tinymce
  73. },
  74. data() {
  75. return {
  76. dialog: !!this.value,
  77. form: {
  78. 'lunbo_name': '', // 轮播图名称
  79. 'content': '',
  80. 'lunbo_status': '' // 状态(0下架1上架)
  81. },
  82. booLock: false
  83. }
  84. },
  85. computed: {
  86. arrLunboStatus() {
  87. return this.$store.state.common.arrLunboStatus
  88. }
  89. },
  90. methods: {
  91. handleSubmit() {
  92. const url = this.exData.id ? '/api/admin/tlunbo/modify' : '/api/admin/tlunbo/add'
  93. this.$refs.form.validate(async valid => {
  94. if (valid) {
  95. const formData = JSON.parse(JSON.stringify(this.form))
  96. const postData = {
  97. ...formData
  98. }
  99. this.booLock = true
  100. const data = await this.$fetch(url, postData)
  101. this.booLock = false
  102. if (data.code === 200) {
  103. this.$message.success('提交成功')
  104. this.$emit('success')
  105. this.dialog = false
  106. }
  107. }
  108. })
  109. }
  110. },
  111. mounted() {
  112. if (this.exData.id) {
  113. this.$set(this.form, 'id', this.exData.id)
  114. for (const key in this.exData) {
  115. if (this.form.hasOwnProperty(key)) {
  116. let value = this.exData[key]
  117. if ((Array.isArray(value) && value.length >= 1) || (Object.prototype.toString.call(value) === '[object Object]') || (typeof value === 'string' && value) || typeof value === 'number') {
  118. this.$set(this.form, key, value)
  119. }
  120. }
  121. }
  122. }
  123. },
  124. watch: {
  125. dialog(val) {
  126. if (!val) this.$emit('input', val)
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .top-tip {
  133. margin-top: -20px;
  134. margin-bottom: 20px;
  135. }
  136. .af-put-line-radio {
  137. display: flex;
  138. align-items: center;
  139. p.lalel {
  140. padding: 0 10px;
  141. }
  142. p {
  143. padding: 0;
  144. margin: 0;
  145. }
  146. }
  147. </style>