<template>
    <div class="layout-tabs-content-box">
        <div class="">
            <div class="height-56 flex-row align-items-center justify-content-between">
                <div class="f22 color-text-primary">调解话术模板</div>
                <div class="flex-row">
                    <div class="mr-16">
                        <el-input
                            placeholder="请输入搜索内容"
                            suffix-icon="el-icon-search"
                            v-model.trim="queryParam.name"
                            size="small"
                            clearable
                            @change="handleSearch"
                            @keydown.enter.native="handleSearch"
                            >
                        </el-input>
                    </div>
                    <el-button size="small" type="primary" @click="handleAddForm">新增话术模板</el-button>
                </div>
                
            </div>

            <div class="" >
                <el-table :data="tableData" :height="`${contentHeight}`">
                    <el-table-column type="index" label="序号" width="55"></el-table-column>
                    <el-table-column prop="name" label="模板名称" width="400"></el-table-column>
                    <el-table-column  label="金融产品" width="200">
                        <template slot-scope="scope">
                            <div class="flex-row">
                                {{getDictName(scope.row.productTypeId)}}
                            </div>
                        </template>
                    </el-table-column>

                    <el-table-column prop="remark" label="备注"></el-table-column>
                    <el-table-column  label="操作" width="150">
                        <template slot-scope="scope">
                            <div class="flex-row align-items-center">
                                <div class="f14 color-1960F4 cursor-pointer mr-8" @click="handleAddForm(scope)">编辑</div>
                                <div class="f14 color-1960F4 cursor-pointer" @click="handleDelete(scope)">删除</div>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="text-center pt-16">
                <el-pagination
                    @size-change="getMediateDataList"
                    @current-change="getMediateDataList"
                    :current-page="queryParam.current"
                    :page-size="queryParam.size"
                    layout="total, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
            </div>


        </div>
         <!-- 新增金融机构弹框 -->
        <addSpeechcraftDialog v-if="addSpeechcraftDialog" :dictList.sync="dictList" :addSpeechcraftDialog.sync="addSpeechcraftDialog" />

    </div>
</template>
<script>

import basicApi from "@/services/basicManage";
    export default {
        components: {
            addSpeechcraftDialog: () => import('./components/addSpeechcraftDialog.vue'),
        },
        data() {
            return {
                queryParam: {
                    type:2,
                    name: '',//
                    current:1,
                    size:10
                },
                tableData: [],
                total:0,
                addSpeechcraftDialog:null,
                dictList:[]
            }
        },
        created() {
            this.getDictDataList()
            this.getMediateDataList(1)
        },
        computed:{
            // 获取抽屉drawer的内容高度
            contentHeight(){
                let oh = document.documentElement.clientHeight;
                return oh-56-48-56-50-32          
            }  
        },
        methods: {
            getDictName(val){
                let dictItem= this.dictList.find(item =>{
                    return item.code === val
                })
                if(dictItem){return dictItem.codeName;}
                else{return '';}
            },
            getDictDataList(val){
                basicApi.getDictList({current:1,size:100}).then(res => {
                    if (!res.code) {
                        this.dictList = res.records;
                    }
                })
            },
            getMediateDataList(val){
                this.queryParam.current = val
                basicApi.getTemplateList(this.queryParam).then(res => {
                    if (!res.code) {
                        this.tableData = res.records;
                        this.total = res.total;
                    }
                })
            },
            // 搜索
            handleSearch() {
                this.queryParam.current = 1
                this.queryParam.size = 10
                this.getMediateDataList(1)
            },
           // 新增弹窗  
            handleAddForm(scope){
                let title = scope.row?'编辑话术模板':'新增话术模板'
                let data = scope.row?scope.row:''
                this.addSpeechcraftDialog={
                    title:title,
                    data: data
                }
            },
            // 删除
            handleDelete(scope){
                this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }).then(() => {
                    if(!this.$clickThrottle()) { return }//防止重复点击
                    basicApi.deleteTemplateById({ id: scope.row.id }).then((res) => {
                        
                        this.$message.success("成功");
                        this.getMediateDataList(1)
                    });
                }).catch(() => {});
            },
            
        }
    }
</script>