123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <template>
- <div>
- <el-dialog
- :title="exData.id ? '编辑': '新增'"
- :visible.sync="dialog"
- width="900px"
- :close-on-click-modal="false"
- top="50px">
- <el-form
- ref="form"
- :model="form"
- :rules="formRules"
- label-width="120px">
- <el-form-item
- prop="lunbo_name"
- :rules="formRules.required"
- label="标题:">
- <el-input
- v-model="form.lunbo_name"
- placeholder="请输入标题"
- clearable></el-input>
- </el-form-item>
- <el-form-item
- :rules="formRules.required"
- label="内容:">
- <tinymce
- :height="300"
- v-model="form.content"
- id='tinymce'></tinymce>
- </el-form-item>
- <el-form-item
- prop="lunbo_status"
- :rules="formRules.select"
- label="状态:">
- <el-select
- style="width: 100%;"
- v-model="form.lunbo_status"
- filterable
- clearable
- placeholder="请选择是否显示">
- <el-option
- :label="item.name"
- :value="item.value"
- v-for="item in arrLunboStatus"
- :key="item.value"></el-option>
- </el-select>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer text-center">
- <el-button @click="dialog = false">取 消</el-button>
- <el-button type="primary" :disabled="booLock" @click="handleSubmit">确 定</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import tinymce from '@/components/Tinymce'
- export default {
- props: {
- value: {
- type: Boolean,
- default: true
- },
- exData: {
- type: Object,
- default: function () {
- return {}
- }
- }
- },
- components: {
- tinymce
- },
- data() {
- return {
- dialog: !!this.value,
- form: {
- 'lunbo_name': '',
- 'content': '',
- 'lunbo_status': ''
- },
- booLock: false
- }
- },
- computed: {
- arrLunboStatus() {
- return this.$store.state.common.arrLunboStatus
- }
- },
- methods: {
- handleSubmit() {
- const url = this.exData.id ? '/api/admin/tlunbo/modify' : '/api/admin/tlunbo/add'
- this.$refs.form.validate(async valid => {
- if (valid) {
- const formData = JSON.parse(JSON.stringify(this.form))
- const postData = {
- ...formData
- }
- this.booLock = true
- const data = await this.$fetch(url, postData)
- this.booLock = false
- if (data.code === 200) {
- this.$message.success('提交成功')
- this.$emit('success')
- this.dialog = false
- }
- }
- })
- }
- },
- mounted() {
- if (this.exData.id) {
- this.$set(this.form, 'id', this.exData.id)
- for (const key in this.exData) {
- if (this.form.hasOwnProperty(key)) {
- let value = this.exData[key]
- if ((Array.isArray(value) && value.length >= 1) || (Object.prototype.toString.call(value) === '[object Object]') || (typeof value === 'string' && value) || typeof value === 'number') {
- this.$set(this.form, key, value)
- }
- }
- }
- }
- },
- watch: {
- dialog(val) {
- if (!val) this.$emit('input', val)
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .top-tip {
- margin-top: -20px;
- margin-bottom: 20px;
- }
- .af-put-line-radio {
- display: flex;
- align-items: center;
- p.lalel {
- padding: 0 10px;
- }
- p {
- padding: 0;
- margin: 0;
- }
- }
- </style>
|