| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- <template>
- <el-dialog
- title="政策信息"
- :visible.sync="dialogVisible"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- @close="handleClose"
- width="1200px"
- height="800px"
- >
- <el-form
- ref="baseForm"
- class="base-form"
- label-position="right"
- label-width="130px"
- :model="baseForm"
- :rules="rules"
- size="small"
- >
- <el-row>
- <el-form-item label="标题:" prop="subsidypolicyTitle">
- <el-input
- placeholder="请输入"
- maxlength="50"
- v-model="baseForm.subsidypolicyTitle">
- </el-input>
- </el-form-item>
- </el-row>
- <el-row>
- <el-form-item label="图片:" prop="src">
- <el-upload
- ref="uploader"
- class="avatar-uploader"
- :action="uploadUrl"
- :show-file-list="false"
- :on-success="handleAvatarSuccess"
- :on-error="handleUploadError"
- name="file"
- :headers="headers"
- :before-upload="beforeAvatarUpload">
- <img v-if="baseForm.src" :src="baseForm.src" class="avatar">
- <i v-else class="el-icon-plus avatar-uploader-icon"></i>
- </el-upload>
- </el-form-item>
- </el-row>
- <el-row style="height: 200px;">
- <el-form-item label="内容:" prop="subsidypolicyContent">
- <Editor
- style="height: 150px"
- v-model="baseForm.subsidypolicyContent"
- :mode="mode"
- @onCreated="onCreated"
- />
- </el-form-item>
- </el-row>
- </el-form>
- <div style="text-align: right;margin-top:20px;" class="button-container">
- <el-button type="info" plain @click="resetForm('baseForm')"
- >取消</el-button
- >
- <el-button
- type="primary"
- style="margin-left:16px;"
- @click="submitForm('baseForm')"
- :disabled="dialogSubmitLoading"
- :loading="dialogSubmitLoading"
- >确定</el-button
- >
- </div>
- </el-dialog>
- </template>
- <script>
- import { addSubsidyPolicy, editSubsidyPolicy } from '@/api/subsidypolicy/index.js'
- import { getToken } from "@/utils/auth";
- import { Message } from 'element-ui'
- import { assign } from 'lodash-es';
- export default {
- name:'newPolicy',
- props: {
- data: {
- default() {
- return {};
- }
- },
- visible: {
- type: Boolean,
- default: false
- },
- editRow: {
- type: Object,
- default: () => { }
- },
- areaId: {
- type: String
- },
- policyType: {
- type: String
- }
- },
- data() {
- return {
- uploadUrl: process.env.VUE_APP_BASE_API + "/wpr/subsidypolicy/preview/upload", // 上传的图片服务器地址
- headers: {
- Authorization: "Bearer " + getToken()
- },
- textarea: '',
- editor: null,
- decisionContent:"",
- mode: 'default',
- dialogSubmitLoading: false,
- dialogVisible: false,
- src: '',
- baseForm: {
- subsidypolicyTitle: '',
- src: '',
- subsidypolicyContent: ''
- },
- resId: '',
- hasFetched: false,
- rules: {
- subsidypolicyTitle: [
- { required: true, message: '请输入您的标题', trigger: 'blur' }
- ],
- src: [
- { required: true, message: '请选择您的图片', trigger: 'change' }
- ],
- subsidypolicyContent: [
- { required: true, message: '请输入内容', trigger: 'change' }
- ]
- }
- };
- },
- watch: {
- visible(val) {
- if (val !== this.dialogVisible) {
- this.dialogVisible = val;
- if (val) {
- assign(this.baseForm, this.data);
- }
- }
- },
- data: {
- deep: true,
- handler(val) {
- assign(this.baseForm, val);
- }
- },
- editRow: {
- handler(val) {
- this.baseForm = { ...this.editRow }
- },
- deep: true
- },
- baseForm: {
- handler(val) {
- const { src, subsidypolicyContent } = val
- const uploader = this.$refs.uploader
- const errorUploadText = uploader
- console.log(errorUploadText,'uploaderuploaderuploader')
- },
- deep: true
- }
- },
- methods: {
- onCreated(editor) {
- this.editor = Object.seal(editor)
- },
- handleAvatarSuccess(res, file) {
- this.resId = res?.data?.resId
- this.baseForm.src = URL.createObjectURL(file.raw);
- },
- handleUploadError() {
- Message.error("图片插入失败");
- },
- beforeAvatarUpload(file) {
- const isJPG = file.type === 'image/jpeg';
- const isLt2M = file.size / 1024 / 1024 < 2;
- if (!isLt2M) {
- Message({
- type: 'error',
- message: '上传头像图片大小不能超过 2MB!'
- })
- }
- return isJPG && isLt2M;
- },
- resetForm() {
- this.dialogVisible = false;
- this.resetFormData()
- },
-
- resetFormData() {
- this.baseForm = {
- subsidypolicyTitle: '',
- src: '',
- subsidypolicyContent: ''
- };
- },
- async addSubsidyPolicyHandler() {
- if (this.policyType == 'add') {
- const params = {
- areaIds: this.areaId,
- resIds: this.resId,
- subsidypolicyContent: this.baseForm.subsidypolicyContent,
- subsidypolicyTitle: this.baseForm.subsidypolicyTitle
- }
- await addSubsidyPolicy(params)
- } else {
- const params = {
- areaIds: this.areaId,
- resIds: this.resId,
- subsidypolicyContent: this.baseForm.subsidypolicyContent,
- subsidypolicyTitle: this.baseForm.subsidypolicyTitle,
- subsidypolicyId: this.baseForm.subsidypolicyId
- }
- await editSubsidyPolicy(params)
- }
- this.handleClose()
- this.$emit('addSuccess')
- },
- submitForm(formName) {
- this.$refs[formName].validate((valid) => {
- valid && this.addSubsidyPolicyHandler()
- })
- },
- handleClose() {
- this.$emit('update:visible', false);
- this.resetForm('baseForm');
- },
- }
- };
- </script>
- <style lang="scss" scoped>
- ::v-deep.avatar-uploader .el-upload {
- border: 1px dashed #d9d9d9;
- border-radius: 6px;
- cursor: pointer;
- position: relative;
- overflow: hidden;
- }
- ::v-deep.avatar-uploader .el-upload:hover {
- border-color: #409EFF;
- }
- ::v-deep.avatar-uploader-icon {
- font-size: 28px;
- color: #8c939d;
- width: 100px;
- height: 100px;
- line-height: 100px;
- text-align: center;
- }
- ::v-deep.avatar {
- width: 100px;
- height: 100px;
- display: block;
- }
- .input-number {
- width: 100%;
- }
- .base-form {
- max-height: 70vh;
- overflow-y: auto;
- overflow-x: hidden;
- padding: 0 20px;
- }
- </style>
- <style lang="css" scoped>
- ::v-deep .el-dialog__header {
- border-bottom: 1px solid #ebeef5;
- }
- </style>
|