|
@@ -0,0 +1,121 @@
|
|
|
+<template>
|
|
|
+ <div id="form-1">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24" class="main animate__animated animate__backInRight">
|
|
|
+ <el-col class="top-btn">
|
|
|
+ <el-button type="primary" size="mini" @click="toBack()">返回</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12" class="one">
|
|
|
+ <data-form :fields="fields" v-model="form" :rules="rules" @save="onSubmit">
|
|
|
+ <template #options="{ item }">
|
|
|
+ <template v-if="item.model == 'type'">
|
|
|
+ <el-option v-for="i in typeList" :key="i.label" :label="i.label" :value="i.value"></el-option>
|
|
|
+ </template>
|
|
|
+ <template v-else-if="item.model == 'status'">
|
|
|
+ <el-option v-for="i in statusList" :key="i.label" :label="i.label" :value="i.value"></el-option>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </data-form>
|
|
|
+ </el-col>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+const _ = require('lodash');
|
|
|
+const moment = require('moment');
|
|
|
+import { mapState, mapGetters, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions } = createNamespacedHelpers('banner');
|
|
|
+const { mapActions: dictData } = createNamespacedHelpers('dictData');
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'form-1',
|
|
|
+ props: {},
|
|
|
+ components: {},
|
|
|
+ data: function () {
|
|
|
+ return {
|
|
|
+ form: {},
|
|
|
+ rules: {
|
|
|
+ name: [{ required: false, message: '请输入名称', trigger: 'blur' }],
|
|
|
+ type: [{ required: false, message: '请选择类型', trigger: 'change' }],
|
|
|
+ to: [{ required: false, message: '请输入跳转至', trigger: 'blur' }],
|
|
|
+ is_use: [{ required: false, message: '请选择是否正在使用', trigger: 'change' }],
|
|
|
+ url: [{ required: false, message: '请选择路径', trigger: 'change' }],
|
|
|
+ },
|
|
|
+ fields: [
|
|
|
+ { label: '名称', model: 'name' },
|
|
|
+ { label: '类型', model: 'type', type: 'select' },
|
|
|
+ { label: '跳转至', model: 'to' },
|
|
|
+ { label: '是否正在使用', model: 'status', type: 'select' },
|
|
|
+ { label: '路径', model: 'url', type: 'upload', url: '/files/point/goods/upload' },
|
|
|
+ ],
|
|
|
+ typeList: [],
|
|
|
+ statusList: [],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ async created() {
|
|
|
+ await this.searchOther();
|
|
|
+ await this.search();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...dictData({ dictQuery: 'query' }),
|
|
|
+ ...mapActions(['fetch', 'create', 'update']),
|
|
|
+ // 查询
|
|
|
+ async search() {
|
|
|
+ if (this.id) {
|
|
|
+ let res = await this.fetch(this.id);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `form`, res.data);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$set(this, `form`, {});
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 提交
|
|
|
+ async onSubmit(data) {
|
|
|
+ console.log(data);
|
|
|
+ let res;
|
|
|
+ if (data.id) res = await this.update(data);
|
|
|
+ else res = await this.create(data);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ console.log(res);
|
|
|
+ this.$message({ type: `success`, message: `维护信息成功` });
|
|
|
+ this.toBack();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 查询其他信息
|
|
|
+ async searchOther() {
|
|
|
+ let res;
|
|
|
+ // 类型
|
|
|
+ res = await this.dictQuery({ code: 'banner_type' });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ console.log(res.data);
|
|
|
+ this.$set(this, `typeList`, res.data);
|
|
|
+ }
|
|
|
+ res = await this.dictQuery({ code: 'status' });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ console.log(res.data);
|
|
|
+ this.$set(this, `statusList`, res.data);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 返回
|
|
|
+ toBack() {
|
|
|
+ window.history.go('-1');
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {},
|
|
|
+ metaInfo() {
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ test: {
|
|
|
+ deep: true,
|
|
|
+ immediate: true,
|
|
|
+ handler(val) {},
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped></style>
|