riku
2025-06-24 4fbdf4c6b13d19b9be54900b5dcff29e2ca7ef01
src/views/fysp/check/components/ComChangeEdit.vue
@@ -46,32 +46,31 @@
        </el-col>
      </el-row>
      <div class="flex-div">
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <el-button type="primary" @click="onSubmit" :loading="loading"
          >保存</el-button
        >
        <el-button @click="onCancel">取消</el-button>
      </div>
      <el-image-viewer
          v-if="previewDialogVisible"
          :url-list="fileList.map((item) => item.url)"
          :initial-index="initialIndex"
          @close="previewDialogVisible = false"
          alt="预览"
          class="preview-pic"
        />
        v-if="previewDialogVisible"
        :url-list="fileList.map((item) => item.url)"
        :initial-index="initialIndex"
        @close="previewDialogVisible = false"
        alt="预览"
        class="preview-pic"
      />
    </template>
  </CompGenericWrapper>
</template>
<script>
import problemApi from '@/api/fysp/problemApi.js';
import CompGenericWrapper from './CompGenericWrapper.vue';
import { $fysp } from '@/api/index.js';
import fileUtil from '@/utils/fileUtils.js';
import { useCloned } from '@vueuse/core';
import { ElMessage } from 'element-plus';
export default {
  emits: ['submit', 'cancel'],
  components: {
    CompGenericWrapper
  },
  components: {},
  watch: {
    oldChangeFileList: {
      handler(nv, ov) {
@@ -119,13 +118,15 @@
      deleteImg: [],
      ledgerPicDialog: false,
      anyPhotoDialog: false
      anyPhotoDialog: false,
      loading: false
    };
  },
  mounted() {},
  methods: {
    pictureValidate() {
      if (this.changeType == 1 && this.fileList.length < 1) {
      if (this.fileList.length < 1) {
        ElMessage({
          message: '至少上传一张图片',
          type: 'error'
@@ -163,12 +164,14 @@
      this.oldFileList = useCloned(beforeEditImgList).cloned.value;
    },
    onCancel() {
      this.$emit("cancel")
      this.$emit('cancel');
      this.$emit('update:visible', false);
    },
    onSubmit() {
      if (!this.pictureValidate()) {
        return;
      }
      this.loading = true;
      // 数据准备
      let data = new FormData();
      var picUrls = [];
@@ -191,28 +194,35 @@
        }
      });
      const that = this;
      let deleteImgCopy = this.deleteImg;
      if (this.changeType == 1) {
        fileUtil.getImageFiles(picUrls, function (files) {
        fileUtil.getImageFiles(picUrls, (files) => {
          data.append('deleteImg', deleteImgCopy);
          data.append('problemId', that.problemId);
          data.append('problemId', this.problemId);
          files.forEach((image) => {
            data.append('images', image);
          });
          problemApi.updateChange(data).then((res) => {});
          problemApi
            .updateChange(data)
            .then((res) => {
              this.$emit('submit', true);
            })
            .finally(() => (this.loading = false));
        });
        that.$emit('submit', true);
      } else {
        fileUtil.getImageFiles(picUrls, function (files) {
          data.append('problemId', that.problemId);
        fileUtil.getImageFiles(picUrls, (files) => {
          data.append('problemId', this.problemId);
          files.forEach((image) => {
            data.append('images', image);
          });
          problemApi.changeProblem(data).then((res) => {});
          that.$emit('submit', true);
          problemApi
            .changeProblem(data)
            .then((res) => {
              this.$emit('submit', true);
            })
            .finally(() => (this.loading = false));
        });
      }
    },
@@ -223,7 +233,7 @@
      }
    },
    handlePictureCardPreview(uploadFile) {
      this.initialIndex = this.fileList.indexOf(uploadFile)
      this.initialIndex = this.fileList.indexOf(uploadFile);
      this.previewDialogVisible = true;
      this.previewDialogImageUrl = uploadFile.url;
    },