SysAnnouncementModal.vue 9.04 KB
<template>
  <a-modal
    :title="title"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :okButtonProps="{ props: {disabled: disabled} }"
    :cancelText="$t('button.close')">

    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgCategory" :label="$t('system.messageType')">
          <a-radio-group v-model="model.msgCategory" :disabled="disableSubmit">
            <a-radio value="1">{{ $t('system.notification') }}</a-radio>
            <a-radio value="2">{{ $t('system.systemMessages') }}</a-radio>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="titile" :label="$t('system.title')">
          <a-input :placeholder="$t('system.pleaseEnterTheTitle')" v-model="model.titile" :readOnly="disableSubmit"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgAbstract" :label="$t('system.summary')">
          <a-textarea :placeholder="$t('system.pleaseEnterTheSummary')" v-model="model.msgAbstract"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endTime" :label="$t('system.deadline')" class="endTime">
          <j-date style="width: 100%" :getCalendarContainer="node => node.parentNode" v-model="model.endTime"
                  :placeholder="$t('system.pleaseSelectTheEndTime')" showTime dateFormat="YYYY-MM-DD HH:mm:ss" class="query-group-cust"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgType" :label="$t('system.receivingUsers')">
          <a-radio-group v-model="model.msgType" :disabled="disableSubmit" @change="chooseMsgType">
            <a-radio value="USER">{{ $t('system.specifyUsers') }}</a-radio>
            <a-radio value="ALL">{{ $t('system.allUsers') }}</a-radio>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('system.specifyUsers')" v-if="userType">
          <j-select-multi-user :returnKeys="returnKeys" :placeholder="$t('system.pleaseSelectDesignatedUsers')" v-model="userIds" :trigger-change="true"></j-select-multi-user>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('system.priority')">
          <a-radio-group v-model="model.priority" :placeholder="$t('system.pleaseSelectThePriority')" :disabled="disableSubmit">
            <a-radio value="L">{{ $t('system.low') }}</a-radio>
            <a-radio value="M">{{ $t('system.medium') }}</a-radio>
            <a-radio value="H">{{ $t('system.high') }}</a-radio>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelColX1" :wrapperCol="wrapperColX1" :label="$t('system.content')" class="j-field-content">
          <j-editor v-model="model.msgContent"/>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import {httpAction} from '@/api/manage'
import pick from 'lodash.pick'
import {getAction} from '@/api/manage'
import JDate from '@/components/jeecg/JDate'
import JEditor from '@/components/jeecg/JEditor'
import SelectUserListModal from "./SelectUserListModal";
import moment from 'moment'
import { translateResultMessage } from '@/api/api'

export default {
  components: {JEditor, JDate, SelectUserListModal},
  name: "SysAnnouncementModal",
  data() {
    return {
      title: this.$t('system.options'),
      visible: false,
      disableSubmit: false,
      model: {},
      labelCol: {
        xs: {span: 24},
        sm: {span: 4},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 18},
      },
      labelColX1: {
        xs: {span: 24},
        sm: {span: 4},
      },
      wrapperColX1: {
        xs: {span: 24},
        sm: {span: 18},
      },
      confirmLoading: false,
      validatorRules: {
        titile: [{required: true, message: this.$t('system.pleaseEnterTheTitle')}],
        msgCategory: [{required: true, message: this.$t('system.pleaseSelectTheMessageType')}],
        msgType: [{required: true, message: this.$t('system.SelectTheRecipientType!')}],
        endTime: [{required: true, message: this.$t('system.pleaseSelectTheEndTime')}, {validator: this.endTimeValidate}],
        startTime: [{required: true, message: this.$t('task.inputStartTime')}, {validator: this.startTimeValidate}],
        msgAbstract: [{required: true, message: this.$t('system.pleaseEnterTheSummary')}],
      },
      url: {
        queryByIds: "/sys/user/queryByIds",
        add: "/sys/annountCement/add",
        edit: "/sys/annountCement/edit",
      },
      userType: false,
      userIds: '',
      selectedUser: [],
      disabled: false,
      msgContent: "",
      userList: [],
      returnKeys: ['id', 'id'] //用户选择返回字段
    }
  },
  created() {
  },
  methods: {
    add() {
      this.edit({});
    },
    edit(record) {
      this.model = {}
      this.disable = false;
      this.visible = true;
      this.getUser(record);
    },
    getUser(record) {
      //update-begin---author:wangshuai ---date:20211227  for:[JTC-191]系统通告参考vue3的来改,为单选按钮附默认值------------
      record.msgCategory = record.msgCategory ? record.msgCategory : "1"
      record.msgType = record.msgType ? record.msgType : "ALL"
      record.priority = record.priority ? record.priority : "H"
      //update-begin---author:wangshuai ---date:20211227  for:[JTC-191]系统通告参考vue3的来改,为单选按钮附默认值------------
      this.model = Object.assign({}, record);
      // 指定用户
      if (record && record.msgType === "USER") {
        this.userType = true;
        //update-begin---author:wangshuai ---date:20220104  for:[JTC-304]指定人员不支持分页勾选,换通用的用户组件------------
        this.userIds = record.userIds.substr(0, record.userIds.length - 1);
        //update-end---author:wangshuai ---date:20220104  for:[JTC-304]指定人员不支持分页勾选,换通用的用户组件------------
      }
    },
    close() {
      this.$emit('close');
      this.selectedUser = [];
      this.visible = false;
      this.$refs.form.resetFields();
    },
    handleOk() {
      const that = this;
      //当设置指定用户类型,但用户为空时,后台报错
      if (this.userType && !(this.userIds != null && this.userIds.length > 0)) {
        this.$message.warning(this.$t('task.theSpecifiedUsersCannotBeEmpty'))
        return;
      }
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          if (this.userType) {
            //update-begin---author:wangshuai ---date:20220104  for:[JTC-304]指定人员不支持分页勾选,换通用的用户组件------------
            this.model.userIds = this.userIds + ",";
            //update-end---author:wangshuai ---date:20220104  for:[JTC-304]指定人员不支持分页勾选,换通用的用户组件------------
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(translateResultMessage(res, res.message))
              that.$emit('ok');
              that.resetUser();
            } else {
              that.$message.warning(translateResultMessage(res, res.message))
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })

        } else {
          return false;
        }
      })
    },
    handleCancel() {
      this.visible = false;
      this.$emit('close');
      this.$refs.form.resetFields();
      this.resetUser();
    },
    resetUser() {
      this.userType = false;
      this.userIds = '';
      this.disabled = false;
      // this.$refs.UserListModal.edit(null, null);
    },
    chooseMsgType(e) {
      if ("USER" == e.target.value) {
        this.userType = true;
      } else {
        this.userType = false;
        this.userIds = '';
      }
    },
    startTimeValidate(rule, value, callback) {
      let endTime = this.model.endTime
      if (!value || !endTime) {
        callback()
      } else if (moment(value).isBefore(endTime)) {
        callback()
      } else {
        callback(this.$t('task.startTimeShouldBeEarlierThanTheEndTime'))
      }
    },
    endTimeValidate(rule, value, callback) {
      let startTime = this.model.startTime;
      if (!value || !startTime) {
        callback()
      } else if (moment(startTime).isBefore(value)) {
        callback()
      } else {
        callback(this.$t('task.endTimeShouldBeLaterThanTheStartTime'))
      }
    },
  }
}
</script>

<style scoped>

</style>