SysAnnouncementModal.vue 10.1 KB
Newer Older
1 2 3
<template>
  <a-modal
    :title="title"
JEECG低代码平台's avatar
JEECG低代码平台 已提交
4 5

    :width="900"
6 7 8 9
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
10
    :okButtonProps="{ props: {disabled: disabled} }"
11
    cancelText="关闭">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
12

13 14
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
15 16
        <a-row style="width: 100%;">
          <a-col :span="24/2">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
17 18 19 20
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="标题">
21
              <a-input placeholder="请输入标题" v-decorator="['titile', validatorRules.title]" :readOnly="disableSubmit"/>
JEECG低代码平台's avatar
JEECG低代码平台 已提交
22 23
            </a-form-item>
          </a-col>
24
          <a-col :span="24/2">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
25 26 27 28 29 30 31 32
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="消息类型">
              <a-select
                v-decorator="[ 'msgCategory', validatorRules.msgCategory]"
                placeholder="请选择消息类型"
                :disabled="disableSubmit"
33
                :getPopupContainer = "(target) => target.parentNode">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
34 35 36 37 38 39
                <a-select-option value="1">通知公告</a-select-option>
                <a-select-option value="2">系统消息</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
40 41
        <a-row style="width: 100%;">
          <a-col :span="24/2">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
42 43 44
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
45 46
              label="开始时间:">
              <j-date style="width: 100%" :getCalendarContainer="node => node.parentNode" v-decorator="[ 'startTime', validatorRules.startTime]" placeholder="请选择开始时间" showTime dateFormat="YYYY-MM-DD HH:mm:ss" ></j-date>
JEECG低代码平台's avatar
JEECG低代码平台 已提交
47 48
            </a-form-item>
          </a-col>
49
          <a-col :span="24/2">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
50 51 52 53 54
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="结束时间"
              class="endTime">
55
              <j-date style="width: 100%" :getCalendarContainer="node => node.parentNode" v-decorator="[ 'endTime', validatorRules.endTime]" placeholder="请选择结束时间" showTime dateFormat="YYYY-MM-DD HH:mm:ss"></j-date>
JEECG低代码平台's avatar
JEECG低代码平台 已提交
56 57 58
            </a-form-item>
          </a-col>
        </a-row>
59 60
        <a-row style="width: 100%;">
          <a-col :span="24/2">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
61 62 63
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
64
              label="优先级">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
65 66 67 68
              <a-select
                v-decorator="[ 'priority', {}]"
                placeholder="请选择优先级"
                :disabled="disableSubmit"
69
                :getPopupContainer = "(target) => target.parentNode">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
70 71 72 73 74 75
                <a-select-option value="L"></a-select-option>
                <a-select-option value="M"></a-select-option>
                <a-select-option value="H"></a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
76
          <a-col :span="24/2">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
77 78 79
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
80
              label="通告类型">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
81 82
              <a-select
                v-decorator="[ 'msgType', validatorRules.msgType]"
83
                placeholder="请选择通告类型"
JEECG低代码平台's avatar
JEECG低代码平台 已提交
84 85
                :disabled="disableSubmit"
                @change="chooseMsgType"
86
                :getPopupContainer = "(target) => target.parentNode">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
87 88 89 90 91 92
                <a-select-option value="USER">指定用户</a-select-option>
                <a-select-option value="ALL">全体用户</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
93 94
        <a-row style="width: 100%;">
          <a-col :span="24/2">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="指定用户"
              v-if="userType">
              <a-select
                mode="multiple"
                placeholder="请选择用户"
                v-model="selectedUser"
                @dropdownVisibleChange="selectUserIds"
              >
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
110 111
        <a-row style="width: 100%;">
          <a-col :span="24">
JEECG低代码平台's avatar
JEECG低代码平台 已提交
112
            <a-form-item
113 114
              :labelCol="labelColX1"
              :wrapperCol="wrapperColX1"
JEECG低代码平台's avatar
JEECG低代码平台 已提交
115
              label="内容"
116 117
              class="j-field-content">
              <j-editor v-decorator="[ 'msgContent', {} ]" triggerChange></j-editor>
JEECG低代码平台's avatar
JEECG低代码平台 已提交
118 119 120
            </a-form-item>
          </a-col>
        </a-row>
121 122
      </a-form>
    </a-spin>
123
    <select-user-list-modal ref="UserListModal" @choseUser="choseUser"></select-user-list-modal>
124 125 126 127 128 129
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
130 131
  import { getAction } from '@/api/manage'
  import JDate from '@/components/jeecg/JDate'
132
  import JEditor from '@/components/jeecg/JEditor'
133
  import SelectUserListModal from "./SelectUserListModal";
134
  import moment from 'moment'
135 136

  export default {
137
    components: { JEditor, JDate, SelectUserListModal},
138 139 140 141 142
    name: "SysAnnouncementModal",
    data () {
      return {
        title:"操作",
        visible: false,
143
        disableSubmit:false,
144 145 146
        model: {},
        labelCol: {
          xs: { span: 24 },
147
          sm: { span: 6 },
148 149 150
        },
        wrapperCol: {
          xs: { span: 24 },
151 152 153 154 155 156 157 158 159
          sm: { span: 18 },
        },
        labelColX1: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperColX1: {
          xs: { span: 24 },
          sm: { span: 21 },
160 161 162 163 164 165
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
          title:{rules: [{ required: true, message: '请输入标题!' }]},
166 167
          msgCategory:{rules: [{ required: true, message: '请选择消息类型!' }]},
          msgType:{rules: [{ required: true, message: '请选择通告对象类型!' }]},
168 169
          endTime:{rules:[{validator: this.endTimeValidate}]},
          startTime:{rules:[{validator: this.startTimeValidate}]}
170 171
        },
        url: {
172
          queryByIds: "/sys/user/queryByIds",
173 174 175 176
          add: "/sys/annountCement/add",
          edit: "/sys/annountCement/edit",
        },
        userType:false,
177 178 179 180
        userIds:[],
        selectedUser:[],
        disabled:false,
        msgContent:"",
181 182 183 184 185 186 187 188 189 190
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
191
        this.model = {}
192
        this.disable = false;
193
        this.visible = true;
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
        this.getUser(record);
      },
      getUser(record){
        this.model = Object.assign({}, record);
        // 指定用户
        if(record&&record.msgType === "USER"){
          this.userType =  true;
          this.userIds = record.userIds;
          getAction(this.url.queryByIds,{userIds:this.userIds}).then((res)=>{
            if(res.success){
              for(var i=0;i<res.result.length;i++){
                this.selectedUser.push(res.result[i].realname);
              }
              this.$refs.UserListModal.edit(res.result,this.userIds);
            }
          });
        }
211
        this.$nextTick(() => {
212
          this.form.setFieldsValue(pick(this.model,'endTime','startTime','titile','msgContent','sender','priority','msgCategory','msgType','sendStatus','delFlag'))
213 214 215 216
        });
      },
      close () {
        this.$emit('close');
217
        this.selectedUser = [];
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
236 237 238
            if(this.userType){
              formData.userIds =  this.userIds;
            }
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
258 259 260 261 262 263 264 265 266 267 268 269 270
        this.visible = false;
        this.$emit('close');
        this.resetUser();
      },
      resetUser (){
        this.userType =  false;
        this.userIds = [];
        this.selectedUser = [];
        this.disabled = false;
        this.$refs.UserListModal.edit(null,null);
      },
      selectUserIds() {
        this.$refs.UserListModal.add(this.selectedUser,this.userIds);
271 272 273 274 275 276
      },
      chooseMsgType(value) {
        if("USER" == value) {
          this.userType = true;
        } else {
          this.userType = false;
277 278
          this.selectedUser = [];
          this.userIds = [];
279 280
        }
      },
281 282 283 284 285 286 287 288
      // 子modal回调
      choseUser:function(userList){
        this.selectedUser = [];
        this.userIds = [];
        for(var i=0;i<userList.length;i++){
          this.selectedUser.push(userList[i].realname);
          this.userIds += userList[i].id+","
        }
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
      },
      startTimeValidate(rule,value,callback){
        let endTime = this.form.getFieldValue("endTime")
        if(!value || !endTime){
          callback()
        }else if(moment(value).isBefore(endTime)){
          callback()
        }else{
          callback("开始时间需小于结束时间")
        }
      },
      endTimeValidate(rule,value,callback){
        let startTime = this.form.getFieldValue("startTime")
        if(!value || !startTime){
          callback()
        }else if(moment(startTime).isBefore(value)){
          callback()
        }else{
          callback("结束时间需大于开始时间")
        }
309 310 311 312 313 314 315 316 317
      }

    }
  }
</script>

<style scoped>

</style>