|
@@ -3,27 +3,16 @@
|
|
|
<el-row>
|
|
|
<el-col :span="24" class="formMain">
|
|
|
<el-col :span="24" class="one">
|
|
|
- <el-button
|
|
|
- type="primary"
|
|
|
- plain
|
|
|
- icon="el-icon-back"
|
|
|
- size="mini"
|
|
|
- @click="toBack"
|
|
|
- >返回</el-button
|
|
|
- ></el-col
|
|
|
- >
|
|
|
+ <el-button type="primary" plain icon="el-icon-back" size="mini" @click="toBack">返回</el-button>
|
|
|
+ </el-col>
|
|
|
<el-col :span="24" class="two">
|
|
|
- <el-form :model="form" :rules="rules" ref="form" label-width="100px">
|
|
|
+ <el-form ref="form" :model="form" :rules="rules" label-width="100px">
|
|
|
<el-form-item label="申请年度" prop="apply_year">
|
|
|
- <el-input
|
|
|
- v-model="form.apply_year"
|
|
|
- placeholder="请输入申请年度"
|
|
|
- ></el-input>
|
|
|
+ <el-input v-model="form.apply_year" placeholder="请输入申请年度" />
|
|
|
</el-form-item>
|
|
|
- <el-col :span="24" class="btn">
|
|
|
- <el-button type="primary" @click="onSubmit('form')"
|
|
|
- >提交保存</el-button
|
|
|
- >
|
|
|
+ <excel-view v-if="!excelLoading" ref="excelView" v-model="form.excel" :read="true" :view="viewStyle" />
|
|
|
+ <el-col v-if="!view" :span="24" class="btn">
|
|
|
+ <el-button type="primary" @click="onSubmit('form')">提交保存</el-button>
|
|
|
<el-button type="warning" @click="onDraft()">保存草稿</el-button>
|
|
|
<el-button @click="onReset('form')">重置信息</el-button>
|
|
|
</el-col>
|
|
@@ -35,97 +24,126 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { mapState, mapGetters, createNamespacedHelpers } from "vuex";
|
|
|
-const { mapActions: merits_apply } = createNamespacedHelpers("merits_apply");
|
|
|
+import excelView from '@/components/free/excel-view.vue'
|
|
|
+import { mapState, mapGetters, createNamespacedHelpers } from 'vuex'
|
|
|
+const { mapActions: merits_apply } = createNamespacedHelpers('merits_apply')
|
|
|
+const { mapActions: template } = createNamespacedHelpers('template')
|
|
|
export default {
|
|
|
- name: "form-frame",
|
|
|
+ name: 'FormFrame',
|
|
|
+ components: { excelView },
|
|
|
props: {
|
|
|
id: { type: String },
|
|
|
+ view: { type: Boolean, default: false }
|
|
|
},
|
|
|
- components: {},
|
|
|
- data: function () {
|
|
|
+ data: function() {
|
|
|
return {
|
|
|
- form: {},
|
|
|
+ form: { excel: {}},
|
|
|
+ viewStyle: {
|
|
|
+ height: () => document.documentElement.clientHeight - 250,
|
|
|
+ width: () => 800
|
|
|
+ },
|
|
|
rules: {
|
|
|
apply_year: [
|
|
|
- { required: true, message: "请输入申请年度", trigger: "blur" },
|
|
|
- ],
|
|
|
+ { required: true, message: '请输入申请年度', trigger: 'blur' }
|
|
|
+ ]
|
|
|
},
|
|
|
- };
|
|
|
+ excel: {},
|
|
|
+ excelLoading: true
|
|
|
+ }
|
|
|
},
|
|
|
- created() {
|
|
|
- this.$set(this, `form`, { user_id: this.user_id, user_name: this.name });
|
|
|
+ async created() {
|
|
|
+ await this.getTemplate()
|
|
|
+ if (this.id) {
|
|
|
+ this.searchInfo(this.id)
|
|
|
+ } else { this.init() }
|
|
|
},
|
|
|
methods: {
|
|
|
- ...merits_apply(["fetch", "create", "update"]),
|
|
|
+ ...merits_apply(['fetch', 'create', 'update']),
|
|
|
+ ...template(['query']),
|
|
|
+ async init() {
|
|
|
+ this.$set(this, `form`, { user_id: this.user_id, user_name: this.name, excel: this.excel })
|
|
|
+ this.excelLoading = false
|
|
|
+ },
|
|
|
+ async getTemplate() {
|
|
|
+ if (this.id) return
|
|
|
+ const res = await this.query()
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ const template = res.data.find(f => f.is_use)
|
|
|
+ if (template) {
|
|
|
+ const { excel = {}} = template
|
|
|
+ this.$set(this, 'excel', excel)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
// 返回
|
|
|
toBack() {
|
|
|
- this.$emit("toBack");
|
|
|
+ this.$emit('toBack')
|
|
|
},
|
|
|
// 提交保存
|
|
|
onSubmit(formName) {
|
|
|
- this.$refs[formName].validate(async (valid) => {
|
|
|
+ this.$refs[formName].validate(async(valid) => {
|
|
|
if (valid) {
|
|
|
- let data = this.form;
|
|
|
- data.status = "1";
|
|
|
- let res;
|
|
|
- if (data.id) res = await this.update(data);
|
|
|
- else res = await this.create(data);
|
|
|
+ const data = this.form
|
|
|
+ data.status = '1'
|
|
|
+ let res
|
|
|
+ if (data.id) res = await this.update(data)
|
|
|
+ else res = await this.create(data)
|
|
|
if (res.code === 200) {
|
|
|
- this.$message({ type: `success`, message: res.msg });
|
|
|
- this.toBack();
|
|
|
+ this.$message({ type: `success`, message: res.msg })
|
|
|
+ this.toBack()
|
|
|
} else {
|
|
|
- this.$message({ type: `error`, message: res.msg });
|
|
|
+ this.$message({ type: `error`, message: res.msg })
|
|
|
}
|
|
|
} else {
|
|
|
- console.log("error submit!!");
|
|
|
- return false;
|
|
|
+ console.log('error submit!!')
|
|
|
+ return false
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
},
|
|
|
// 保存草稿
|
|
|
async onDraft() {
|
|
|
- let data = this.form;
|
|
|
- let res;
|
|
|
- if (data.id) res = await this.update(data);
|
|
|
- else res = await this.create(data);
|
|
|
+ const data = this.form
|
|
|
+ let res
|
|
|
+ if (data.id) res = await this.update(data)
|
|
|
+ else res = await this.create(data)
|
|
|
if (res.code === 200) {
|
|
|
- this.$message({ type: `success`, message: res.msg });
|
|
|
- this.toBack();
|
|
|
+ this.$message({ type: `success`, message: res.msg })
|
|
|
+ this.toBack()
|
|
|
} else {
|
|
|
- this.$message({ type: `error`, message: res.msg });
|
|
|
+ this.$message({ type: `error`, message: res.msg })
|
|
|
}
|
|
|
},
|
|
|
// 查看详情
|
|
|
async searchInfo(id) {
|
|
|
- let res = await this.fetch(id);
|
|
|
+ const res = await this.fetch(id)
|
|
|
if (res.code === 200) {
|
|
|
- this.$set(this, `form`, res.data);
|
|
|
+ this.$set(this, `form`, res.data)
|
|
|
+ this.excelLoading = false
|
|
|
} else {
|
|
|
- this.$message({ type: `error`, message: res.msg });
|
|
|
+ this.$message({ type: `error`, message: res.msg })
|
|
|
}
|
|
|
},
|
|
|
// 重置信息
|
|
|
onReset(formName) {
|
|
|
- this.$refs[formName].resetFields();
|
|
|
- },
|
|
|
+ this.$refs[formName].resetFields()
|
|
|
+ }
|
|
|
},
|
|
|
computed: {
|
|
|
- ...mapGetters(["user_id", "name"]),
|
|
|
+ ...mapGetters(['user_id', 'name'])
|
|
|
},
|
|
|
metaInfo() {
|
|
|
- return { title: this.$route.meta.title };
|
|
|
- },
|
|
|
- watch: {
|
|
|
- id: {
|
|
|
- deep: true,
|
|
|
- immediate: true,
|
|
|
- handler(val) {
|
|
|
- if (val) this.searchInfo(val);
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
-};
|
|
|
+ return { title: this.$route.meta.title }
|
|
|
+ }
|
|
|
+ // watch: {
|
|
|
+ // id: {
|
|
|
+ // deep: true,
|
|
|
+ // immediate: true,
|
|
|
+ // handler(val) {
|
|
|
+ // if (val) this.searchInfo(val)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<style lang="less" scoped>
|