调解系统PC端服务

editTemplate.vue 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div>
  3. <el-dialog title="修改模板" :visible="editVisable" v-if="editVisable" @close="cancel" width="600px" center>
  4. <el-form :model="ruleForm" label-position="left" :rules="rules" ref="ruleForm" label-width="90px"
  5. class="demo-ruleForm">
  6. <el-form-item label="模板名称" prop="temName">
  7. <el-input v-model="ruleForm.temName"></el-input>
  8. </el-form-item>
  9. <el-form-item label="模板类型" prop="temType">
  10. <el-select v-model="ruleForm.temType" placeholder="请选择">
  11. <el-option v-for="dict in dict.type.template_type" :key="dict.value" :label="dict.label"
  12. :value="dict.value"></el-option>
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="当前模板">
  16. <span style="color: #0e5ce3;cursor:pointer" @click="openUrl(editData.temOrigPath)">{{ editData.fileName
  17. }}</span>
  18. </el-form-item>
  19. </el-form>
  20. <el-upload class="avatar-uploader" :before-upload="beforeUpload" :on-success="handleSuccess" ref="upload"
  21. :action="UploadUrl()" :headers="headers" :data="filedata" :on-remove="handleRemove"
  22. :on-change="handleChange" accept=".doc,.docx" :file-list="fileList" :auto-upload="false">
  23. <el-button size="small" type="primary">选择模板文件</el-button>
  24. </el-upload>
  25. <div slot="footer" class="dialog-footer">
  26. <el-button @click="cancel" class="endbutton"><span>取 消</span></el-button>
  27. <el-button type="primary" @click="submitUpload" class="endbutton"><span>确认</span></el-button>
  28. </div>
  29. </el-dialog>
  30. </div>
  31. </template>
  32. <script>
  33. import { getToken } from "@/utils/auth";
  34. import { updateTemplate } from "@/api/officialSeal/officialSeal"
  35. export default {
  36. props: ["editVisable", "editData", "queryParams"],
  37. dicts: ["template_type"],
  38. data() {
  39. return {
  40. fileList: [],
  41. data: [],
  42. headers: {
  43. Authorization: "Bearer " + getToken(),
  44. },
  45. isImg: true,
  46. filedata: {},
  47. flagBtn: false,
  48. ruleForm: {},
  49. rules: {
  50. temName: [
  51. { required: true, message: '请输入模板名称', trigger: 'blur' },
  52. ],
  53. temType: [
  54. { required: true, message: '请输入模板名称', trigger: 'blur' },
  55. ],
  56. }
  57. };
  58. },
  59. watch: {
  60. editData(val) {
  61. if (val) {
  62. this.ruleForm = val;
  63. this.fileList = [];
  64. this.ruleForm.temType = this.ruleForm.temType + '';
  65. }
  66. }
  67. },
  68. created() {
  69. },
  70. methods: {
  71. // 打开链接
  72. openUrl(urlTemp) {
  73. let headPath = window.location.origin + "/API/";
  74. window.open(headPath + urlTemp);
  75. },
  76. cancel() {
  77. this.$emit("cancelEdit");
  78. },
  79. handleChange(file, fileList) {
  80. this.isImg = file.type === '.doc' || '.docx';
  81. this.fileList = fileList;
  82. },
  83. UploadUrl() {
  84. return window.location.origin + "/API/deptIdentify/updateTemplate";
  85. },
  86. submitUpload() {
  87. let that = this;
  88. this.$refs['ruleForm'].validate((valid) => {
  89. if (valid) {
  90. if (that.fileList.length > 0) {
  91. that.filedata.id = that.editData.id;
  92. that.filedata.temName = that.ruleForm.temName;
  93. if (that.isImg) {
  94. that.$refs.upload.submit();
  95. } else {
  96. that.$message.error('只能上传doc,docx格式的文件')
  97. }
  98. } else {
  99. updateTemplate({
  100. id: that.editData.id,
  101. temName: that.ruleForm.temName
  102. }).then(res => {
  103. that.$message.success('修改成功');
  104. that.$emit("cancelEdit");
  105. that.$emit('getList', that.queryParams);
  106. })
  107. }
  108. }
  109. });
  110. },
  111. handleRemove(file, fileList) {
  112. console.log(file, fileList);
  113. },
  114. beforeUpload(file) {
  115. // this.isImg = file.type === '.doc' || '.docx'
  116. },
  117. handleSuccess() {
  118. this.$message.success('修改成功');
  119. this.$emit("cancelEdit");
  120. this.$emit('getList', this.queryParams);
  121. }
  122. },
  123. };
  124. </script>
  125. <style lang="scss" scoped></style>