zhanghua
2025-04-14 829f5116884f98643ffc5b2a548a600d40c0cedb
src/views/operate/images/updateUser/index.vue
@@ -1,17 +1,17 @@
<template>
  <div class="updateUser">
    <main>
      <div class="mainContent">
        <el-form
          label-position="right"
          label-width="150px"
          :model="imagedata"
          :rules="rules"
          :disabled="isDisabled"
          ref="user"
          style="width: 100%"
        >
          <!-- <el-form-item prop="belongToId" label="所属事件编号" v-if="true">
    <div class="updateUser">
        <main>
            <div class="mainContent">
                <el-form
                    label-position="right"
                    label-width="150px"
                    :model="imagedata"
                    :rules="rules"
                    :disabled="isDisabled"
                    ref="user"
                    style="width: 100%"
                >
                    <!-- <el-form-item prop="belongToId" label="所属事件编号" v-if="true">
            <el-input v-model="imagedata.code"></el-input>
          </el-form-item>
          <el-form-item prop="eventSource" label="事件来源">
@@ -31,7 +31,7 @@
          <el-form-item prop="id" label="图片Id">
            <el-input v-model="imagedata.id"></el-input>
          </el-form-item> -->
          <!-- <el-form-item prop="type" label="类型" v-show="false">
                    <!-- <el-form-item prop="type" label="类型" v-show="false">
            <el-select v-model="imagedata.type">
              <el-option
                v-for="item in getResourceType()"
@@ -41,308 +41,315 @@
              />
            </el-select>
          </el-form-item> -->
          <el-form-item prop="url" label="图片:" min-width="8">
            <my-upload
              :picture-list="imageList"
              :is-show-upload="dialogType !== 'view'"
              @setPictureUrl="setPictureUrl"
              @delPictureUrl="delPictureUrl"
            ></my-upload>
          </el-form-item>
          <div v-if="!isDisabled" class="optionBtn">
            <el-button
              type="primary"
              class="btn submit"
              @click.native.prevent="onSubmit"
              >提交</el-button>
          </div>
        </el-form>
      </div>
    </main>
  </div>
                    <el-form-item prop="url" label="图片:" min-width="8">
                        <my-upload
                            :picture-list="imageList"
                            :is-show-upload="dialogType !== 'view'"
                            @setPictureUrl="setPictureUrl"
                            @delPictureUrl="delPictureUrl"
                        ></my-upload>
                    </el-form-item>
                    <div v-if="!isDisabled" class="optionBtn">
                        <el-button
                            type="primary"
                            class="btn submit"
                            @click.native.prevent="onSubmit"
                            >提交</el-button
                        >
                    </div>
                </el-form>
            </div>
        </main>
    </div>
</template>
<script>
import {
  deepClone,
  RESOURCE_TYPE,
  CATEGOTY,
  EVENT_SOURCE,
    deepClone,
    RESOURCE_TYPE,
    CATEGOTY,
    EVENT_SOURCE,
} from "@/utils/helper";
import imageManagement from "@/api/operate/imageManagement";
import { FILE_ORIGINAL_URL } from "@/utils";
import { FILE_ORIGINAL_PATH } from "@/utils";
import MyUpload from "@/components/myUpload";
export default {
  components: { MyUpload },
  data() {
    const validateImageUrl = (rule, value, callback) => {
      if (this.imagedata.url) {
        callback();
      } else {
        callback(new Error("请上传图片"));
      }
    };
    return {
      imagedata: {
        belongToId: "",
        eventSource: 1,
        regionName: "",
        category: 1,
        id: "",
        url: "",
        type: "",
      },
      rules: {
        // belongToId: [
        //   { required: true, trigger: "blur", message: "请输入所属事件编号" },
        // ],
        // eventSource: [
        //   { required: true, trigger: "blur", message: "请输入事件来源" },
        // ],
        // regionName: [
        //   { required: true, trigger: "blur", message: "请输入社区名称" },
        // ],
        // id: [{ required: true, trigger: "blur", message: "请输入图片Id" }],
        // category: [
        //   { required: true, trigger: "blue", message: "请输入问题类型" },
        // ],
        url: [{ required: true, validator: validateImageUrl }],
        // type: [
        //   {
        //     required: true,
        //     trigger: ["blur", "change"],
        //     message: "请选择类型",
        //   },
        // ],
      },
      isDisabled: false,
      imageList: [],
    };
  },
    components: { MyUpload },
    data() {
        const validateImageUrl = (rule, value, callback) => {
            if (this.imagedata.url) {
                callback();
            } else {
                callback(new Error("请上传图片"));
            }
        };
        return {
            imagedata: {
                belongToId: "",
                eventSource: 1,
                regionName: "",
                category: 1,
                id: "",
                url: "",
                type: "",
            },
            rules: {
                // belongToId: [
                //   { required: true, trigger: "blur", message: "请输入所属事件编号" },
                // ],
                // eventSource: [
                //   { required: true, trigger: "blur", message: "请输入事件来源" },
                // ],
                // regionName: [
                //   { required: true, trigger: "blur", message: "请输入社区名称" },
                // ],
                // id: [{ required: true, trigger: "blur", message: "请输入图片Id" }],
                // category: [
                //   { required: true, trigger: "blue", message: "请输入问题类型" },
                // ],
                url: [{ required: true, validator: validateImageUrl }],
                // type: [
                //   {
                //     required: true,
                //     trigger: ["blur", "change"],
                //     message: "请选择类型",
                //   },
                // ],
            },
            isDisabled: false,
            imageList: [],
        };
    },
  created() {
    if (this.originalData) {
      this.imagedata = deepClone(this.originalData);
    }
    if (this.dialogType !== "create") {
      this.imageList = this.imagedata.url.split(",");
    }
    this.isDisabled = this.dialogType === "view";
  },
  methods: {
    onSubmit() {
      this.$refs.user.validate((valid) => {
        if (valid) {
          this.imagedata.type="03";
          const params = Object.assign({}, this.imagedata);
          delete params.regionName;
          delete params.category;
          delete params.eventSource;
          delete params.id;
          params.belongToId = +params.belongToId;
          if (this.dialogType === "create") {
            imageManagement
              .addImageResource(params)
              .then(() => {
                this.$message.success("操作成功");
                this.$emit("closeDialog");
              })
              .catch((err) => this.$message.error(`${err}`));
          } else {
            imageManagement
              .updateImageResource(params)
              .then(() => {
                this.$message.success("操作成功");
                this.$emit("closeDialog");
              })
              .catch((err) => this.$message.error(`${err}`));
          }
        } else {
          this.$message.warning("请检查必填项");
    created() {
        if (this.originalData) {
            this.imagedata = deepClone(this.originalData);
        }
      });
        if (this.dialogType !== "create") {
            let _imageList = [];
            let imageData = this.imagedata.url.split(",");
            imageData.forEach((url) => {
                _imageList.push(FILE_ORIGINAL_PATH + url);
            });
            this.imageList = _imageList;
        }
        this.isDisabled = this.dialogType === "view";
    },
    setPictureUrl({ url }) {
      this.imageList.push(`${FILE_ORIGINAL_URL}sccg/API/img?fileUrl=${url}`);
      this.imagedata.url = this.imageList.join(",");
    },
    delPictureUrl({ url }) {
      this.imageList = this.imageList.filter((item) => item !== url);
      this.imagedata.url = this.imageList.join(",");
    },
    getCategory(value) {
      return CATEGOTY.find((item) => item.value === value);
    },
    methods: {
        onSubmit() {
            this.$refs.user.validate((valid) => {
                if (valid) {
                    this.imagedata.type = "03";
                    const params = Object.assign({}, this.imagedata);
                    delete params.regionName;
                    delete params.category;
                    delete params.eventSource;
                    delete params.id;
                    params.belongToId = +params.belongToId;
                    if (this.dialogType === "create") {
                        imageManagement
                            .addImageResource(params)
                            .then(() => {
                                this.$message.success("操作成功");
                                this.$emit("closeDialog");
                            })
                            .catch((err) => this.$message.error(`${err}`));
                    } else {
                        imageManagement
                            .updateImageResource(params)
                            .then(() => {
                                this.$message.success("操作成功");
                                this.$emit("closeDialog");
                            })
                            .catch((err) => this.$message.error(`${err}`));
                    }
                } else {
                    this.$message.warning("请检查必填项");
                }
            });
        },
        setPictureUrl({ url }) {
    getEventSource(value) {
      return EVENT_SOURCE.find((item) => item.value === value);
            this.imageList.push(FILE_ORIGINAL_PATH + url);
            this.imagedata.url = this.imageList.join(",");
        },
        delPictureUrl({ url }) {
            this.imageList = this.imageList.filter((item) => item !== url);
            this.imagedata.url = this.imageList.join(",");
        },
        getCategory(value) {
            return CATEGOTY.find((item) => item.value === value);
        },
        getEventSource(value) {
            return EVENT_SOURCE.find((item) => item.value === value);
        },
        getResourceType(value) {
            return value
                ? RESOURCE_TYPE.find((item) => item.value === value)
                : RESOURCE_TYPE;
        },
    },
    getResourceType(value) {
      return value
        ? RESOURCE_TYPE.find((item) => item.value === value)
        : RESOURCE_TYPE;
    props: {
        originalData: {
            type: Object,
            default: () => null,
        },
        dialogType: {
            type: String,
            default: () => "create",
        },
    },
  },
  props: {
    originalData: {
      type: Object,
      default: () => null,
    },
    dialogType: {
      type: String,
      default: () => "create",
    },
  },
};
</script>
<style lang="scss" scoped>
.updateUser {
  border-radius: 1px;
  // background-color: #09152f;
  main {
    // border: 1px solid #fff;
    text-align: left;
    padding: 0 55px;
    border-radius: 1px;
    // background-color: #09152f;
    padding-bottom: 50px;
    .mainContent {
      display: flex;
      justify-content: center;
      padding-top: 50px;
    main {
        // border: 1px solid #fff;
        text-align: left;
        padding: 0 55px;
        // background-color: #09152f;
        padding-bottom: 50px;
      .el-form-item__content {
        width: 400px;
        .mainContent {
            display: flex;
            justify-content: center;
            padding-top: 50px;
        .el-select {
          width: 100%;
            .el-form-item__content {
                width: 400px;
                .el-select {
                    width: 100%;
                }
            }
            .optionHandleSp {
                display: flex;
                .areaNumber,
                .moreNumber {
                    flex: 1;
                }
                .telNumber {
                    flex: 2;
                }
            }
            .optionBtn {
                display: flex;
                margin-top: 20px;
                justify-content: center;
                .btn {
                    padding: 12px 50px;
                }
            }
        }
      }
      .optionHandleSp {
        display: flex;
        .areaNumber,
        .moreNumber {
          flex: 1;
        }
        .telNumber {
          flex: 2;
        }
      }
      .optionBtn {
        display: flex;
        margin-top: 20px;
        justify-content: center;
        .btn {
          padding: 12px 50px;
        }
      }
    }
  }
}
.updateUser::v-deep .el-form-item__label {
  color: #4b9bb7;
    color: #4b9bb7;
}
.updateUser::v-deep .el-input__inner {
  // background-color: #09152f;
  border: 1px solid #17324c;
    // background-color: #09152f;
    border: 1px solid #17324c;
}
.addPerson {
  display: flex;
  list-style: none;
  padding: 0;
  flex-wrap: wrap;
  max-width: 280px;
    display: flex;
    list-style: none;
    padding: 0;
    flex-wrap: wrap;
    max-width: 280px;
  li {
    color: #fff;
    text-align: center;
    font-size: 30px;
    margin-left: 10px;
  }
    li {
        color: #fff;
        text-align: center;
        font-size: 30px;
        margin-left: 10px;
    }
}
.li-icon {
  background-color: #cccccc;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  margin: 0 auto;
    background-color: #cccccc;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin: 0 auto;
}
.li-btn {
  background-color: #cccccc;
  width: 36px;
  height: 36px;
  border-radius: 50%;
    background-color: #cccccc;
    width: 36px;
    height: 36px;
    border-radius: 50%;
}
.card {
  position: absolute;
  z-index: 2000;
  right: 0;
    position: absolute;
    z-index: 2000;
    right: 0;
  .box-card {
    min-height: 240px;
    max-height: 260px;
    overflow: hidden;
    // background-color: #09152f;
    position: relative;
    max-width: 220px;
    .box-card {
        min-height: 240px;
        max-height: 260px;
        overflow: hidden;
        // background-color: #09152f;
        position: relative;
        max-width: 220px;
    .scrollWrap {
      overflow: scroll;
      height: 180px;
      position: relative;
      color: #4b9bb7;
        .scrollWrap {
            overflow: scroll;
            height: 180px;
            position: relative;
            color: #4b9bb7;
      .el-checkbox-group {
        display: flex;
        flex-direction: column;
            .el-checkbox-group {
                display: flex;
                flex-direction: column;
        .el-checkbox {
          line-height: 20px;
                .el-checkbox {
                    line-height: 20px;
                }
            }
        }
      }
    }
    .myclear {
      width: 100%;
      line-height: 20px;
      color: #4b9bb7;
      display: flex;
      justify-content: space-between;
    }
        .myclear {
            width: 100%;
            line-height: 20px;
            color: #4b9bb7;
            display: flex;
            justify-content: space-between;
        }
    .hidebar {
      position: absolute;
      top: 77px;
      right: 20px;
      width: 20px;
      height: 180px;
      // background-color: #09152f;
    }
        .hidebar {
            position: absolute;
            top: 77px;
            right: 20px;
            width: 20px;
            height: 180px;
            // background-color: #09152f;
        }
    .item {
      line-height: 40px;
        .item {
            line-height: 40px;
        }
    }
  }
}
.leader {
  color: red;
    color: red;
}
.el-input,
.el-select {
  width: 280px !important;
    width: 280px !important;
}
</style>