<template>
        <div class="dialog-content dialog-sms-single">
            <div class="p-16">
                <el-collapse-transition>
                    <el-row :gutter="56">
                        <el-col :span="24">
                            <div class="flex-row-center align-items-center height-40 mb-24">
                            <span class="tabs__search-criteria-title flex-shrink-0 pr-16">短信模板</span>
                            <el-select v-model="ObjectInfo.scene"
                                        placeholder="请选择短信模板"
                                        class="width100" @change="smsChange">
                                <el-option
                                    v-for="item in smsOptions"
                                    :key="item.template"
                                    :label="item.name"
                                    :value="item.template">
                                </el-option>
                            </el-select>
                            </div>
                        </el-col>
                        <el-col :span="24">
                            <div class="flex-row-center align-items-center mb-24">
                            <span class="tabs__search-criteria-title flex-shrink-0 pr-16">模板内容</span>
                            <el-input class="mt-8" type="textarea" v-model="ObjectInfo.content" :rows="4" disabled></el-input>
                            </div>
                        </el-col>

                    </el-row>
                </el-collapse-transition>
            </div>
            <span class="dialog-footer">
                <el-button size="small" @click="handleClose()">取消</el-button>
                <el-button size="small" type="primary" @click="handleSubmit()">发送短信</el-button>
            </span>
        </div>
</template>
<script>
import caseManagement from "@/services/caseManagement";
    export default {
        components: {
           
        },
        props: {
            caseId: {
                type: String,
                default: () => {},
            },
        },
        data() {
            return {
                smsOptions:[],
                ObjectInfo: {
                    scene: '',
                    content: ''
                },
            };
        },
        mounted () {
            this.getSmsTemplate()
        },
        methods: {
            getSmsTemplate() {
                caseManagement.getSmsTemplate().then(res => {
                    if (!res.code) {
                    this.smsOptions = res;
                    if (res.length){
                        this.ObjectInfo.scene = res[0].template;
                        this.ObjectInfo.content = res[0].content;
                    }
                    }
                })
            },
            smsChange() {
                let jsonData = this.smsOptions.find(item => {
                    return this.ObjectInfo.scene == item.template
                })
                this.ObjectInfo.content = jsonData.content
            },
            handleSubmit() {
                // console.log(this.eventTraDialog, 'eventTraDialog')
                if (!this.ObjectInfo.scene){
                    this.$message.warning("请选择短信模板！");
                    return
                }
                if(!this.$clickThrottle()) { return }//防止重复点击
                let caseIdList = [this.caseId];
                caseManagement.smsBatchSend({...this.ObjectInfo, caseIdList: caseIdList}).then(res => {
                    this.$message.success("发起短信成功");
                    this.handleClose()
                    this.$parent.getWritCaseList()
                })
            },
            handleClose() {
                this.$emit('update:singlesmsvisible', false)
            },
        }
    };
</script>

<style scoped lang="scss">
.dialog-sms-single {
  width: 495px;
  max-height: 500px;

  .tabs__search-criteria-title {
    width: 80px;
  }

  .case-batch-num {
    background-color: rgba(236, 238, 241, 0.8196078431);
    padding: 15px 20px;
    border-radius: 4px;

    a {
      font-size: 16px;
      font-weight: 500;
      color: #C66A5B;
    }
  }

 
  .dialog-footer{
    display: inline-block;
    width: 500px;
    text-align: right;
    border-top: solid 1px #E5E6EB;
    padding: 10px;
  }
}
</style>