|
@@ -0,0 +1,98 @@
|
|
|
+<template>
|
|
|
+ <div id="templates">
|
|
|
+ <detail-frame :title="pageTitle">
|
|
|
+ <data-form :data="info" :fields="fields" :rules="rules" @save="handleSave" :isNew="isNew" labelWidth="165px" :reset="false">
|
|
|
+ <template #custom="{item}">
|
|
|
+ <template v-if="item.model == 'color'">
|
|
|
+ <el-color-picker v-model="color" :predefine="info.color" @change="toChange" color-format="hex"></el-color-picker>
|
|
|
+ <el-button type="primary" @click="toClear" size="mini">清空</el-button>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </data-form>
|
|
|
+ </detail-frame>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import _ from 'lodash';
|
|
|
+import detailFrame from '@frame/layout/admin/detail-frame';
|
|
|
+import dataForm from '@frame/components/form';
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: trainTemplate } = createNamespacedHelpers('trainTemplate');
|
|
|
+export default {
|
|
|
+ name: 'templates',
|
|
|
+ props: {},
|
|
|
+ components: { detailFrame, dataForm },
|
|
|
+ data: () => {
|
|
|
+ return {
|
|
|
+ info: { color: [] },
|
|
|
+ color: '',
|
|
|
+ isNew: true,
|
|
|
+ fields: [
|
|
|
+ { label: '总人数', required: true, model: 'total', type: 'number' },
|
|
|
+ { label: '每批所需天数', required: true, model: 'day', type: 'number' },
|
|
|
+ { label: '默认每期中的批次数', required: true, model: 'batchnum', type: 'number' },
|
|
|
+ { label: '默认每批次中的班级数', required: true, model: 'classnum', type: 'number' },
|
|
|
+ { label: '默认颜色', model: 'color', custom: true },
|
|
|
+ ],
|
|
|
+ rules: {
|
|
|
+ total: [{ required: true, message: '请输入总人数' }],
|
|
|
+ day: [{ required: true, message: '请输入每批所需天数' }],
|
|
|
+ batchnum: [{ required: true, message: '请输入默认每期中的批次数' }],
|
|
|
+ classnum: [{ required: true, message: '请输入默认每批次中的班级数' }],
|
|
|
+ },
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.search();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...trainTemplate(['query', 'create', 'update']),
|
|
|
+ async search() {
|
|
|
+ let res = await this.query();
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ if (res.data.length > 0) {
|
|
|
+ this.$set(this, `info`, res.data[0]);
|
|
|
+ this.$set(this, `isNew`, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async handleSave({ isNew, data }) {
|
|
|
+ let res;
|
|
|
+ if (isNew) {
|
|
|
+ res = await this.create(data);
|
|
|
+ } else {
|
|
|
+ res = await this.update(data);
|
|
|
+ }
|
|
|
+ this.$checkRes(res, '保存成功', res.errmsg || '保存失败');
|
|
|
+ },
|
|
|
+ toChange(data) {
|
|
|
+ let colors = _.get(this.info, 'color');
|
|
|
+ if (colors && colors.length >= 8) {
|
|
|
+ this.$message.error('只能选择8个预存颜色');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let res = this.info.color.find(f => f == data);
|
|
|
+ if (res) {
|
|
|
+ this.$message.error('已选择当前颜色');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.info.color.push(data);
|
|
|
+ },
|
|
|
+ toClear() {
|
|
|
+ this.info.color = [];
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['user']),
|
|
|
+ pageTitle() {
|
|
|
+ return `${this.$route.meta.title}`;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ metaInfo() {
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped></style>
|