首页 > 其他分享 >编辑新增使用同一个表单

编辑新增使用同一个表单

时间:2023-09-14 19:32:25浏览次数:39  
标签:false 同一个 data fileList 表单 编辑 dataForm searchForm true

编辑新增使用一个表单

列表展示table

<template>
  <div class="mod-config ml10">
    <!--搜索-->
    <div class="search searchHead" v-show="showSearch">
      <el-form ref="searchForm" :model="searchForm" :inline="true" size="mini">
        <el-form-item label="版权名称" prop="name">
          <cl-input v-model="searchForm.name" prefix-icon="el-icon-search" placeholder="请输入版权名称" clearable size="small"
                    style="width: 240px"/>
        </el-form-item>
        <el-form-item label="版权类型" prop="type">
          <el-select v-model.trim="searchForm.type" clearable placeholder="请选择版权类型" style="width: 240px" size="small">
            <el-option v-for="(item) in typeList" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="primary" size="small" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-delete" size="small" @click="resetQuery">清空</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="tableContent">
      <!--搜索刷新-->
      <toolbar @refreshTable="getDataList" :showSearch.sync="showSearch">
        <el-button slot="add" type="primary" icon="el-icon-plus" size="small" @click="addOrUpdateHandle()">新增版权</el-button>
      </toolbar>

      <div class="avue-crud">
        <el-table
            :data="dataList"
            border
            :default-sort = "{prop: 'createTime', order: 'descending'}"
            v-loading="dataListLoading">
          <el-table-column label="序号" align="left" min-width="50px">
            <template slot-scope="scope">
              {{ helper.generateIndex(scope.$index, searchForm) }}
            </template>
          </el-table-column>
          <el-table-column
              prop="name"
              header-align="left"
              align="left"
              label="版权名称">
          </el-table-column>
          <el-table-column
            prop="files"
            header-align="left"
            align="left"
            width="120px"
            label="附件">
            <template slot-scope="scope">
              <div style="position: relative;">

                <div v-if="scope.row.files!==''&&scope.row.files!==null">

                  <el-image :src="$fileUrl+scope.row.files.split(',')[0]" v-if="
                scope.row.files.split(',')[0].indexOf('.png')!==-1||
               scope.row.files.split(',')[0].indexOf('.jpg')!==-1||
               scope.row.files.split(',')[0].indexOf('.jpeg')!==-1||
               scope.row.files.split(',')[0].indexOf('.gif')!==-1||
               scope.row.files.split(',')[0].indexOf('.bmp')!==-1
              || scope.row.files.split(',')[0].indexOf('.BMP') !== -1||
               scope.row.files.split(',')[0].indexOf('.GIF') !== -1||
               scope.row.files.split(',')[0].indexOf('.JPEG') !== -1||
               scope.row.files.split(',')[0].indexOf('.JPG') !== -1||
               scope.row.files.split(',')[0].indexOf('.PNG') !== -1"
                            style="width:100px;height:100px;"

                  >
                  </el-image>

                  <img src="public/images/file.png" fit="contain" style="width:100px;height:100px;" v-else></img>
                </div>

                <div class="div-mask-one">
                  <div class="mask-one-p"
                       v-if="
                scope.row.files.split(',')[0].indexOf('.png')!==-1||
               scope.row.files.split(',')[0].indexOf('.jpg')!==-1||
               scope.row.files.split(',')[0].indexOf('.jpeg')!==-1||
               scope.row.files.split(',')[0].indexOf('.gif')!==-1||
               scope.row.files.split(',')[0].indexOf('.bmp')!==-1
              || scope.row.files.split(',')[0].indexOf('.BMP') !== -1||
               scope.row.files.split(',')[0].indexOf('.GIF') !== -1||
               scope.row.files.split(',')[0].indexOf('.JPEG') !== -1||
               scope.row.files.split(',')[0].indexOf('.JPG') !== -1||
               scope.row.files.split(',')[0].indexOf('.PNG') !== -1">
                    <i class="el-icon-zoom-in"  @click="handleView(scope.row.files,1)" style="font-size:30px;"></i>
                  </div>
                  <div class="mask-one-p" v-else>
                    <i class="el-icon-zoom-in"  @click="handleView(scope.row.files,2)" style="font-size:30px;"></i>
                  </div>
                </div>
              </div>

            </template>
          </el-table-column>
          <el-table-column
              prop="region"
              header-align="left"
              align="left"
              label="版权类型">
            <template slot-scope="scope">
              <span v-if="scope.row.type===1">自有</span>
              <span v-else-if="scope.row.type===2">第三方</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="source"
            header-align="left"
            align="left"
            label="版权来源">
          </el-table-column>
          <el-table-column
              header-align="center"
              align="center"
              label="操作">
            <template slot-scope="scope">
              <!--<el-button v-if="permissions.onstudy_copyrighttemplate_view" type="text" size="small" icon="el-icon-view"
                         @click="addOrUpdateHandle(scope.row.copyrightTemplateId,1)">查看
              </el-button>-->
              <el-button v-if="permissions.onstudy_copyrighttemplate_edit" type="text" size="small" icon="el-icon-edit"
                         @click="addOrUpdateHandle(scope.row.copyrightTemplateId)">编辑
              </el-button>
              <el-button v-if="permissions.onstudy_copyrighttemplate_del" type="text" size="small" icon="el-icon-delete"
                         @click="deleteHandle(scope.row.copyrightTemplateId,scope.row.name)">删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="avue-crud__pagination">
        <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
                       :current-page="searchForm.current" :page-sizes="[10,20,50,100]"
                       :page-size="searchForm.size" :total="totalPage" background
                       layout="total,sizes,prev,pager,next,jumper"></el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
    </div>



    <tableJoinImg v-if="showImgVisible||showPdfVisible" @btnClickImg="btnClickImg"
                  :viewImgVisible="showImgVisible"
                  :viewFileVisible="showPdfVisible" :fileLists="fileListes"></tableJoinImg>

  </div>
</template>

<script>
import {fetchList, delObj} from '@/api/onstudy/copyrighttemplate'
import TableForm from './copyrighttemplate-form'
import Toolbar from "@/components/Toolbar"
import tableJoinImg from "@/components/images/tableJoinImg.vue"
import {mapGetters} from 'vuex'
import {getDicDataSource} from "@/util/common";
import {getStore} from "@/util/store";



export default {
  data() {
    return {
      searchForm: {
        current: 1,
        size: 10,
        name: '',
        type: '',
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      showSearch: true,
      dataListLoading: false,
      addOrUpdateVisible: false,
      load: false,
      userInfo: {},
      showImgVisible:false,
      showPdfVisible:false,
      fileListes:[],
      typeList: [{value: 1,label: '自有'},{value: 2,label: '第三方'},]
    }
  },
  components: {
    TableForm,
    Toolbar,tableJoinImg
  },
  created() {
    this.userInfo = getStore({name: 'userInfo'});
    console.log("this.userInfo:",this.userInfo);
    this.getDataList()
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    handleView(fileLists,num) {
      this.fileListes=[];

      this.fileListes=fileLists.split(',');
      if(num==1){
        this.showImgVisible = true;
        this.showPdfVisible = false;
      }
      else{
        this.showImgVisible = false;
        this.showPdfVisible = true;
      }

    },
    btnClickImg(){
      this.showImgVisible = false;
      this.showPdfVisible = false;
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      this.load = false;
      fetchList(this.searchForm).then(response => {
        this.dataList = response.data.data.records
        this.totalPage = response.data.data.total
        this.load = true;
      })
      this.dataListLoading = false
      console.log("list");
    },
    //每页数
    sizeChangeHandle(val) {
      this.searchForm.size = val;
      this.searchForm.current = 1;
      this.load = false;//重新加载
      this.getDataList();
    },
    //当前页
    currentChangeHandle(val) {
      console.log("page");
      this.searchForm.current = val;
      this.load = false;//重新加载
      this.getDataList();
    },
    // 新增 / 修改
    addOrUpdateHandle(id,views) {
      this.addOrUpdateVisible = true
      console.log(id, views);
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id,views);
      })
    },
    // 删除
    deleteHandle(id, name) {
      let that = this
      this.$confirm('是否确认删除:' + name, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        delObj(id).then(res => {
          if (res.data.data){
            that.$message.success('删除成功')
            that.getDataList()
          }else {
            that.$message.error('删除失败,当前文件有版权选用')
            that.getDataList()
          }
        })
      }).then(data => {

      })
    },
    //  导出excel
    exportExcel() {
      this.downBlobFile('/rs-training/subsidyfile/export', this.searchForm, 'subsidyfile.xlsx')
    },
    handleQuery() {
      this.searchForm.current = 1;
      this.load = false;//重新加载
      this.getDataList();
    },
    resetQuery() {
      this.searchForm.name = '';
      //this.searchForm.status = '';
      this.$refs['searchForm'].resetFields();
      this.handleQuery();
    },
  }
}
</script>
<style scoped lang="scss">
/deep/.cell {
  max-height: 110px;
  overflow-y: hidden;
}
/*查看截图水平居中*/
/*
/deep/.drag-inner {
  top: 50%!important;
  left: 50%;
  transform: translate(-50%,-50%);
}
*/

/deep/.el-icon-zoom-in {
  margin-right: 0!important;
}


.div-mask-one {
  position: absolute;
  bottom: 0px;
  left: 0px;
  width: 100px;
  cursor: pointer;
  height: 100px;
  background-color: rgba(0, 0, 0, 0.37);
  /* 垂直居中展示 注意点 如果使用绝对居中,其内容内容要用一个div包起来 */
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  font-size: 16px;
  color: #ffffff;
  transition: height 300ms;
  top: 1px;
}

.mask-one-p {
  width: 30px;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
}



</style>

查看和编辑form

<template>
  <el-dialog
    :title="!dataForm.copyrightTemplateId ? '新增版权' : views && dataForm.copyrightTemplateId ? '查看版权' : '修改版权'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    v-if="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="95px"
      label-position="left"
    >
      <el-form-item label="版权方名称" prop="name">
        <cl-input v-model="dataForm.name" placeholder="请输入版权方名称" :disabled="views"></cl-input>
      </el-form-item>
      <el-form-item label="版权类型" prop="type">
        <el-select v-model="dataForm.type" style="width: 100%" placeholder="请选择版权类型" :disabled="views">
          <el-option
            :label="item.label"
            :value="item.value"
            :key="index"
            v-for="(item, index) in typeOption"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="版权来源" prop="source" v-if="dataForm.type == 2">
        <cl-input v-model="dataForm.source" placeholder="请输入版权来源" :disabled="views"></cl-input>
      </el-form-item>

      <el-form-item label="添加附件" v-model="dataForm.files" prop="files" v-if="views">
        <div class="upload-content">
          <images :files="dataForm.files" :showPdfDownloadIcon="false" v-if="load"></images>
        </div>
      </el-form-item>
      <el-form-item label="添加附件" v-model="dataForm.files" prop="files" required :rules="{required: true,message: '附件文件不能为空',trigger: 'blur',}" v-else>

      <upload-file
          @uploadFileSuccess="uploadFileSuccess"
          @uploadDel="uploadDel"
          nameSpace="files"
          :limitSize="limitSize"
          table="copyrighttemplate"
          :files="fileList"
          :maximumNumber="true"
          :showPdfDownloadIcon="false"
      ></upload-file>

      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit"
        >确认{{ !dataForm.copyrightTemplateId ? '新增版权' : '修改版权'}}</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import { getObj, addObj, putObj } from "@/api/onstudy/copyrighttemplate";

import { getDicDataSource } from "@/util/common";
import uploadFile from "@/components/uploadFile";

export default {
  data() {
    return {
      visible: false,
      canSubmit: false,
      views: false,
      limitSize: 20,
      typeOption: [{value: 1,label: '自有'},{value: 2,label: '第三方'},],
      fileList: [],
      dataForm: {
        type: "",
        name: "",
        files: "",
        source: "",
      },
      dataRule: {
        type: [
          { required: true, message: "版权类型不能为空", trigger: "change" },
        ],
        name: [{ required: true, message: "版权方名称不能为空", trigger: "blur" }],
        source: [
          { required: true, message: "版权来源不能为空", trigger: "blur" },
          { pattern: /^[\u4e00-\u9fa5]+$/, message: "版权来源请输入文字",trigger: "blur" },
        ],
        // files: [{ required: true, message: "附件文件不能为空", trigger: "blur" }],
      },
      load:false
    };
  },
  created() {
  },
  components: { uploadFile },
  methods: {
    init(id,views) {
      console.log('views', id, views);
      if (views == 1) {
        this.views = true;
        this.canSubmit = false;
      } else {
        this.views = false;
        this.canSubmit = true;
      }
      this.fileList = []
      if (id) {
        this.dataForm.copyrightTemplateId = id;
      } else {
        delete this.dataForm.copyrightTemplateId;
      }
      this.dataForm.type = "";
      this.dataForm.name = "";
      this.dataForm.files = "";
      this.dataForm.source = "";
      this.visible = true;
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()

        this.load = false;

        if (this.dataForm.copyrightTemplateId) {
          getObj(this.dataForm.copyrightTemplateId).then((response) => {

            this.dataForm = response.data.data;
            this.fileList.push(response.data.data.files)
            if (this.fileList !== null) {
              this.fileList = this.fileList[0].split(",")
            }
            console.log(typeof this.fileList,this.fileList);
            this.load=true;
          });
        }
      });
    },
    //上传成功文件进行回显
    uploadFileSuccess(file, nameSpace) {
      console.log(file);
      this.fileList.push(file.relativelyPath);
    },
    //删除图片
    uploadDel(nameSpace, index) {
      this.fileList.splice(index, 1);
    },
    // 表单提交
    dataFormSubmit() {
      console.log(this.dataForm);
      this.dataForm.files = this.fileList.join(",");
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.canSubmit = false;
          if (this.dataForm.copyrightTemplateId) {
            putObj(this.dataForm)
              .then((data) => {
                this.$message({
                  message: "修改成功",
                  type: "success",
                });
                this.visible = false;
                this.$emit("refreshDataList");
              })
              .catch(() => {
                this.canSubmit = true;
              });
          } else {
            addObj(this.dataForm)
              .then((data) => {
                this.$message({
                  message: "添加成功",
                  type: "success",
                });
                this.visible = false;
                this.$emit("refreshDataList");
              })
              .catch(() => {
                this.canSubmit = true;
              });
          }
        }
      });
    },
  },
};
</script>
<style scoped lang="scss">
/deep/ #uploadContent {
  width: 440px;
}
</style>

标签:false,同一个,data,fileList,表单,编辑,dataForm,searchForm,true
From: https://blog.51cto.com/u_15694202/7473449

相关文章

  • 多个feign接口使用@FeignClient注解调用同一个名称的微服务时,启动会发生异常
    解决方案:方法1.将feign接口合并方法2.在application.yml文件中增加配置spring.main.allow-bean-definition-overriding=true方法3.在@FeignClient注解上增加contextId属性,确保每个feignclient的contextId唯一。如@FeignClient(name="服务名",contextId="唯一名称")......
  • 项目开发中难点-项目使用v-if控制表单/元素/组件显示隐藏,例如调用接口后赋值需重新加
    项目中使用v-if="show"  控制组件的显示或隐藏,当接口返回后this.show=false,进行赋值,后this.show=true显示 。但是页面没有正常显示,此时使用this.$nextTick。 一、$nextTick()概述1.$nextTick()原理$nextTick()是Vue.js框架中的一个方法,它主要用于DOM操作......
  • MySql数据库中,对于同一个表,如果直接把查询结果赋值给待更新字段,则会出现锁表的情况。
    MySql数据库中,对于同一个表,如果直接把查询结果赋值给待更新字段,则会出现锁表的情况。原因是:mysql在from子句中遇到子查询时,先执行子查询并将结果放到一个临时表中,我们通常称它为“派生表”;临时表是没有索引、无法加锁的。update时,会锁表,此时不能再select。所以会报错,此时如果将......
  • Nginx同一个端口代理前后端
    server{listen8080;server_namelocalhost;location/{proxy_passhttp://192.168.9.163:8899;}location/api/{rewrite^/api/(.*)$/$1break;proxy_pass......
  • iOS开发Swift-14-反向传值,右滑删除,语言本地化,编辑换序,DeBug,addTarget-待办事项Ap
    1.点击某一条待办事项,出现编辑界面,可对待办事项的文本进行修改.不重新设计界面,而是将新增页面进行修改复用.2.为新增页面取StoryboardID为TodoTableViewControllerID. 3.为列表最右边加一个小箭头.选中TodoCellID,将属性中的Selection修改为DisclosureIndicator. 4.......
  • 试试用Markdown来设计表单
    相信很多后端开发。对于前端知识是比较零碎的,所以很多时候写表单这样的工作,一般就是复制黏贴,然后改改字段。对于HTML格式,一直觉得比较杂乱,不够简洁。最近TJ发现了一个有趣的小工具:CreateHTMLForm。看看上面它的Slogan,是不是很有意思?居然可以通过Markdown来编写HTML的表单?下面......
  • "快速编辑模式"带来的命令行程序暂停问题
    在Windows下,"快速编辑模式"(QuickEditMode)允许用户通过点击和拖动来选择命令提示符窗口中的文本。但是,这可能会导致某些命令行程序暂停,直到用户按下Enter键。因此,某些用户可能希望禁用这个模式。要禁用"快速编辑模式",请按照以下步骤操作:打开命令提示符(cmd)。右......
  • 富文本编辑器 django-mdeditor如何复制粘贴图片
    1、找到文件\site-packages\mdeditor\templates\markdown.html文件2、找到<scripttype="text/javascript">这行3.这行及以下所有内容删除,也就是把js这块代码全删除了,把js替换<scripttype="text/javascript">$(function(){editormd("{{id}}-wmd-wrapp......
  • 福昕高级pdf编辑器器每次打开都弹出updater更新
    安装了福昕编辑器的特定版本:9.3.0.10826,每次打开pdf文件后(或者直接打开福昕pdf编辑器),都会弹出它的更新组件的UAC提示。无论是到编辑器的偏好设置中关闭更新还是到注册表相应条目去关闭更新都无法禁用该更新组件启动。解决办法:进入福昕编辑器的安装目录,通常是:'C:\Program......
  • EAS_客户端设置分录单元格背景色灰色不可编辑
    publicvoidonLoad()throwsException{if((!this.currentCompany.isIsBizUnit())&&(!"FINDVIEW".equalsIgnoreCase(getOprtState()))){thrownewNTException(NTException.CHANGE_TO_BIZUNIT);}super.onLoad();t......