zhanghua
2024-01-09 778039b40c8fcbe205f9a4a5fab27518d0c0a90d
src/views/operate/sms/smsIndex/createSms/index.vue
@@ -2,47 +2,90 @@
    <div class="createUser">
        <main>
            <div class="mainContent">
                <el-form ref="user" label-width="140px" autoComplete="on" :model="role" :rules="rules"
                    label-position="right">
                <el-form
                    ref="user"
                    label-width="140px"
                    autoComplete="on"
                    :model="role"
                    :rules="rules"
                    label-position="right"
                >
                    <!-- 消息栏目 -->
                    <el-form-item class="optionItem" label="短信模板:" prop="messageType">
                    <el-form-item
                        class="optionItem"
                        label="短信模板:"
                        prop="messageType"
                    >
                        <div class="message-item">
                            <div class="message-item__left">
                                <el-select v-model="role.messageType" placeholder="请选择短信模板" @change="setTemplateValue">
                                    <el-option v-for="item in colList" :key="item.id" :label="item.title"
                                        :value="item.id">
                                <el-select
                                    v-model="role.messageType"
                                    placeholder="请选择短信模板"
                                    @change="setTemplateValue"
                                >
                                    <el-option
                                        v-for="item in colList"
                                        :key="item.id"
                                        :label="item.title"
                                        :value="item.id"
                                    >
                                    </el-option>
                                </el-select>
                            </div>
                        </div>
                    </el-form-item>
                    <!-- 消息标题 -->
                    <el-form-item class="optionItems" label="短信标题:" prop="head">
                    <el-form-item
                        class="optionItems"
                        label="短信标题:"
                        prop="head"
                    >
                        <div class="message-item__left">
                            <el-input v-model="role.head" placeholder="请选择短信标题"></el-input>
                            <el-input
                                v-model="role.head"
                                placeholder="请选择短信标题"
                            ></el-input>
                        </div>
                    </el-form-item>
                    <!-- 接收对象 -->
                    <el-form-item class="optionItem" label="接收手机号:" prop="targetTo">
                    <el-form-item
                        class="optionItem"
                        label="接收手机号:"
                        prop="targetTo"
                    >
                        <div class="message-item__left">
                            <el-select v-model="role.targetTo" placeholder="请选择接收接收手机号" >
                            <el-input v-model="role.targetTo"></el-input>
                            <!-- <el-select v-model="role.targetTo" placeholder="请选择接收接收手机号" >
                                <el-option :value="role.targetTo">
                                    <el-tree ref="tree" :data="departList" :props="defaultProps" show-checkbox
                                        @check="handleCheck" default-expand-all node-key="id">
                                    </el-tree>
                                </el-option>
                            </el-select>
                            </el-select> -->
                        </div>
                    </el-form-item>
                    <!-- 消息内容 -->
                    <el-form-item class="optionItem" label="消息内容:" prop="body">
                    <el-form-item
                        class="optionItem"
                        label="消息内容:"
                        prop="body"
                    >
                        <MyEditor ref="edit"></MyEditor>
                    </el-form-item>
                    <el-form-item>
                        <div class="optionBtn">
                            <el-button type="primary" @click.native.prevent="handleSubmit(1)" class="btn submit">发布</el-button>
                            <el-button class="btn cancel" @click.native.prevent="handleReset">重置</el-button>
                            <el-button
                                type="primary"
                                @click.native.prevent="handleSubmit(1)"
                                class="btn submit"
                                >发布</el-button
                            >
                            <el-button
                                class="btn cancel"
                                @click.native.prevent="handleReset"
                                >重置</el-button
                            >
                        </div>
                    </el-form-item>
                </el-form>
@@ -59,12 +102,12 @@
    components: { MyEditor },
    data() {
        const validateMessageContent = (rule, value, callback) => {
          if (!value) {
            callback(new Error('请输入短信内容'));
          } else {
            callback();
          }
      }
            if (!value) {
                callback(new Error('请输入短信内容'));
            } else {
                callback();
            }
        }
        return {
            role: {
                messageType: '',
@@ -82,10 +125,10 @@
                    { required: true, trigger: "blur", message: '请输入短信标题' },
                ],
                targetTo: [
                    { required: true  , trigger: "blur", message: '请选择接收对象' },
                    { required: true, trigger: "blur", message: '请选择接收对象' },
                ],
                body: [
                  { required: true, trigger: ['blur', 'change'], validator: validateMessageContent }
                    { required: true, trigger: ['blur', 'change'], validator: validateMessageContent }
                ]
            },
            colList: [],
@@ -93,14 +136,14 @@
            typeList: [],
            dialogCreate: false,
            dialogView: false,
            defaultProps: {
                children: 'children',
                label: 'departName'
            },
            // defaultProps: {
            //     children: 'children',
            //     label: 'departName'
            // },
            checkedList: [],
            tempNameArr:[],
            tempNameArr: [],
            info: {},
            sendUser:""
            sendUser: ""
        }
    },
    created() {
@@ -118,11 +161,11 @@
        },
        getSMSTemplateList() {
          SMS.getSMSTemplateList({ current: 1, pageSize: 100 })
              .then(({ records }) => {
                this.colList = records;
              })
              .catch(err => this.$message.error(err))
            SMS.getSMSTemplateList({ current: 1, pageSize: 100 })
                .then(({ records }) => {
                    this.colList = records;
                })
                .catch(err => this.$message.error(err))
        },
        // 关闭弹窗
@@ -174,7 +217,7 @@
        handleCheck(data, node) {
            this.checkedList = []
            node.checkedNodes.forEach(item => {
                if(!item.hasOwnProperty('departType')){
                if (!item.hasOwnProperty('departType')) {
                    this.checkedList.push(item.id)
                    this.tempNameArr.push(item.departName)
                }
@@ -183,28 +226,28 @@
        },
        // 新建/保存消息(1:新建,0保存消息)
        handleSubmit(mystatus) {
          this.role.body = this.$refs.edit.editor.txt.html();
          this.$refs.user.validate((valid) => {
            this.role.body = this.$refs.edit.editor.txt.html();
            this.$refs.user.validate((valid) => {
                if (valid) {
                  const params = Object.assign({}, this.role);
                  params.targetTo = this.checkedList.join(',');
                  params.status = mystatus;
                  sendMessage(params)
                      .then(() => {
                        this.$message({ type: 'success', message: '操作成功' });
                        this.$emit('closeMyDialog');
                      })
                      .catch(err => this.$message({ type: 'error', message: err }));
                    const params = Object.assign({}, this.role);
                    // params.targetTo = this.checkedList.join(',');
                    params.status = mystatus;
                    sendMessage(params)
                        .then(() => {
                            this.$message({ type: 'success', message: '操作成功' });
                            this.$emit('closeMyDialog');
                        })
                        .catch(err => this.$message({ type: 'error', message: err }));
                } else {
                  this.$message.warning('请检查必填项');
                    this.$message.warning('请检查必填项');
                }
            })
        },
        setTemplateValue(obj){
            var _this=this
            SMS.getSMSTemplateById(obj).then((result) =>{
                _this.role.head=result.title
                _this.role.body=result.body
        setTemplateValue(obj) {
            var _this = this
            SMS.getSMSTemplateById(obj).then((result) => {
                _this.role.head = result.title
                _this.role.body = result.body
                _this.$refs.edit.editor.txt.html(result.body)
            })
        },
@@ -325,7 +368,6 @@
                    padding: 12px 50px;
                }
            }
        }
    }
}