odc.xiaohui
2023-02-09 085fa2fb257e9f11f8f6d34bf12e2dc281c36b4d
src/views/operate/message/myIndex/update/index.vue
@@ -9,12 +9,13 @@
          :model="role"
          :rules="createRoleRules"
          label-position="right"
          :disabled="type === 'view'"
        >
          <!-- 提醒方式 -->
          <el-form-item class="optionItem" label="提醒方式:" prop="channelCode">
          <el-form-item class="optionItem" label="提醒方式:" prop="channelCode" >
            <el-radio-group v-model="role.channelCode">
              <el-radio label="01">站内信</el-radio>
              <el-radio label="02">邮件</el-radio>
              <el-radio label="03">邮件</el-radio>
            </el-radio-group>
            <span class="message-tip">(短信可用数: 1000条)</span>
          </el-form-item>
@@ -66,6 +67,7 @@
                    show-checkbox
                    @check="handleCheck"
                    default-expand-all
                    :default-checked-keys="checkedList"
                    node-key="id"
                  >
                  </el-tree>
@@ -75,7 +77,7 @@
          </el-form-item>
          <!-- 消息内容 -->
          <el-form-item class="optionItem" label="消息内容:" prop="body">
            <MyEditor ref="edit" @getMyBody="getMyBody"></MyEditor>
            <MyEditor ref="edit"></MyEditor>
          </el-form-item>
          <el-form-item>
            <div class="optionBtn">
@@ -83,21 +85,24 @@
                type="primary"
                @click.native.prevent="handleSubmit(0)"
                class="btn save"
                v-if="type !== 'view'"
                >保存
              </el-button>
              <el-button
                type="primary"
                @click.native.prevent="handleSubmit(1)"
                class="btn submit"
                v-if="type !== 'view'"
                >发布
              </el-button>
              <el-button
                type="primary"
                @click.native.prevent="handleView"
                class="btn submit"
                v-if="type !== 'view'"
                >预览
              </el-button>
              <el-button class="btn cancel" @click.native.prevent="handleReset"
              <el-button class="btn cancel" @click.native.prevent="handleReset" v-if="type !== 'view'"
                >重置</el-button
              >
            </div>
@@ -133,20 +138,26 @@
import MyEditor from "@/components/edit";
import MyColumnAdd from "@/views/operate/message/mycontrol/createUser";
import MyColView from "../messageView";
import { sendMessage, updateMessage } from "@/api/operate/messageManagement";
import { sendMessage, updateMessage, getMessageById,saveMessage } from "@/api/operate/messageManagement";
export default {
  components: { MyEditor, MyColumnAdd, MyColView },
  props: ["type", "myDataRow"],
  data() {
    const validateEditor = (rule, value, callback) => {
      if (value) {
        callback();
      } else {
        callback(new Error('请输入'));
      }
    };
    return {
      role: {
        messageType: "",
        messageType: null,
        head: "",
        targetTo: "",
        targetFrom: null,
        body: "",
        channelCode: "01",
        channelCode: null,
      },
      createRoleRules: {
        messageType: [
@@ -163,8 +174,7 @@
        body: [
          {
            required: true,
            trigger: ["blue", "change"],
            message: "请输入消息内容",
            validator: validateEditor
          },
        ],
      },
@@ -187,9 +197,23 @@
    this.getColumnList();
    this.getDepartList();
    this.getLoginUserInfo();
    if (this.type === "update" && this.myDataRow) {
      this.role = this.myDataRow;
    if (this.type !== "create" && this.myDataRow) {
      getMessageById(this.myDataRow.id)
          .then(res => {
            this.role = res;
            if (res.targetTo) {
              this.checkedList = res.targetTo.split(',');
              this.role.targetTo = `${this.checkedList.length}人`;
            }
          })
          .catch(err => this.$message.error(`${err}`))
    }
  },
  mounted() {
    if (this.type !== 'create') {
      this.$refs.edit.editor.txt.append(this.myDataRow.body);
    }
  },
  methods: {
    // 关闭弹窗
@@ -203,7 +227,7 @@
    async getColumnList() {
      await this.$axios({
        method: "get",
        url: "sccg/message_column/getAllColumn",
        url: "sccg/message_column/show ",
      }).then((res) => {
        this.colList = res.data;
      });
@@ -216,7 +240,9 @@
        this.getColumnList();
      }
    },
    getType(){
      return this.type;
    },
    // 获取部门树
    async getDepartList() {
      await this.$axios({
@@ -250,21 +276,19 @@
    // 选中id
    handleCheck(data, node) {
      node.checkedNodes.forEach((item) => {
        if (!item.hasOwnProperty("departType")) {
          this.checkedList.push(item.id);
          this.tempNameArr.push(item.departName);
        }
      });
      this.role.targetTo = this.checkedList.length + "人";
      const checkedNodes = node.checkedNodes.filter(item => !item.children);
      this.checkedList = checkedNodes.map(item => item.id);
      this.tempNameArr = checkedNodes.map(item => item.departName);
      this.role.targetTo = this.checkedList.length ? this.checkedList.length + "人" : null;
    },
    // 新建/保存消息(1:新建,0保存消息)
    handleSubmit(mystatus) {
      this.role.body = this.$refs.edit.editor.txt.html();
      this.$refs.user.validate((valid) => {
        if (valid) {
          const { body, head, messageType, targetFrom, channelCode } =
            this.role;
          if(mystatus==1){
            const { body, head, messageType, channelCode } = this.role;
          const params = {
            body,
            head,
@@ -272,9 +296,11 @@
            channelCode: `${channelCode}`,
            sendTime: new Date(),
            targetTo: this.checkedList.join(","),
            targetFrom: `${targetFrom}`,
            status: mystatus,
          };
          if (this.role.channelCode === '03') {
            delete params.messageType;
          }
          if (this.type === "create") {
            sendMessage(params)
              .then(() => {
@@ -288,7 +314,7 @@
                })
              );
          } else {
            updateMessage(params)
            updateMessage({ id: this.myDataRow.id, ...params })
              .then(() => {
                this.$emit("closeMyDialog");
                this.$message({ type: "success", message: "操作成功" });
@@ -300,21 +326,57 @@
                })
              );
          }
          }
          if(mystatus==0){
            const { body, head, messageType, channelCode } = this.role;
          const params = {
            body,
            head,
            messageType,
            channelCode: `${channelCode}`,
            sendTime: new Date(),
            targetTo: this.checkedList.join(","),
            status: mystatus,
          };
          if (this.role.channelCode === '03') {
            delete params.messageType;
          }
          if (this.type === "create") {
            saveMessage(params)
              .then(() => {
                this.$emit("closeMyDialog");
                this.$message({ type: "success", message: "操作成功" });
              })
              .catch((err) =>
                this.$message({
                  type: "error",
                  message: err.data || err.message,
                })
              );
          } else {
            updateMessage({ id: this.myDataRow.id, ...params })
              .then(() => {
                this.$emit("closeMyDialog");
                this.$message({ type: "success", message: "操作成功" });
              })
              .catch((err) =>
                this.$message({
                  type: "error",
                  message: err.data || err.message,
                })
              );
          }
          }
        } else {
          this.$message.error({ type: "warning", message: "请检查必填项" });
        }
      });
    },
    // 获得消息体
    getMyBody(obj) {
      this.role.body = obj;
    },
    // 重置表单
    handleReset() {
      this.$refs.edit.editor.txt.clear();
      this.setDepartList();
      this.$refs.user.resetFields();
    },
@@ -332,6 +394,7 @@
    // 消息预览
    handleView() {
      this.role.body = this.$refs.edit.editor.txt.html();
      this.$refs.user.validate((valid) => {
        if (valid) {
          const { body, head, channelCode } = this.role;
@@ -342,55 +405,46 @@
            channelCode:
              channelCode === "01"
                ? "站内信"
                : channelCode === "02"
                : channelCode === "03"
                ? "邮件"
                : "短信",
            messageType: this.getColText(this.role.messageType),
            messageType: this.role.messageType,
            targetTo: this.tempNameArr,
            targetFrom: this.sendUser,
            targetFrom: this.sendUser
          };
        } else {
          this.$message({ type: "warning", message: "请检查必填项" });
        }
      });
    },
    // 获得栏目消息
    getColText(id) {
      let str = "";
      this.colList.forEach((item) => {
        item.id === id ? (str = item.columnName) : "";
      });
      return str;
    },
    }
  },
};
</script>
<style lang="scss" scoped>
.createUser {
  border-radius: 1px;
  background-color: #09152f;
  background-color: white;
  main {
    text-align: left;
    padding: 0 55px;
    background-color: #09152f;
    background-color: white;
    .mainContent {
      display: flex;
      justify-content: center;
      padding-top: 50px;
      &:deep(.el-dialog__title) {
        color: #4b9bb7;
        //color: #4b9bb7;
      }
      &::v-deep .el-form-item__label {
        color: #4b9bb7;
        //color: #4b9bb7;
      }
      &::v-deep .el-input__inner {
        width: 400px;
        background-color: #09152f;
        border: 1px solid #17324c;
        //background-color: #09152f;
        //border: 1px solid #17324c;
      }
      .message-item__left {
@@ -416,7 +470,7 @@
        span {
          margin-left: 20px;
          color: #4b9bb7;
          color: #606266;
        }
      }
@@ -428,10 +482,10 @@
        width: 400px;
      }
      &::v-deep .el-textarea__inner {
        background-color: #09152f;
        border: 1px solid #17324c;
      }
      // &::v-deep .el-textarea__inner {
      //   //background-color: #09152f;
      //   //border: 1px solid #17324c;
      // }
      .el-form-item__content {
        width: 400px;
@@ -465,4 +519,4 @@
    }
  }
}
</style>
</style>