<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="案件编号" prop="caseNum">
                <el-input v-model="queryParams.caseNum" placeholder="请输入案件编号" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="dataList" style="width: 100%">
            <el-table-column label="序号" type="index" align="center">
                <template slot-scope="scope">
                    <span>{{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
        }}</span>
                </template>
            </el-table-column>
            <el-table-column label="案件编号" align="center" prop="caseNum" :show-overflow-tooltip="true" />
            <el-table-column label="手机号" align="center" prop="phone" :show-overflow-tooltip="true" />
            <el-table-column label="发送时间" align="center" prop="sendTime" />
            <el-table-column label="发送状态" align="center" prop="sendStatus" />
            <el-table-column label="发送内容" align="center" prop="sendContent" :show-overflow-tooltip="true"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" @click="copyContent(scope.row.sendContent)" type="text"
                        icon="el-icon-document-copy">复制内容</el-button>
                    <el-button size="mini" @click="resend(scope.row)" type="text" icon="el-icon-s-promotion">编辑内容</el-button>
                </template>
            </el-table-column>
        </el-table>
        <resend :resendVidable="resendVidable" :rowData="rowData" @getList="getList" @cancelSend="cancelSend" :queryParams="queryParams"></resend>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList({ caseNum: queryParams.caseNum }, { pageNum: queryParams.pageNum, pageSize: queryParams.pageSize })" />

    </div>
</template>

<script>
import {
    smsList,
} from "@/api/deliveryRecord/deliveryRecord.js";
import resend from "./components/resend.vue";
import { getDicts } from '@/api/system/dict/data.js'
export default {
    name: "paymentList",
    dicts: ["case_status"],
    components: {resend},
    data() {
        return {
            queryParams: {
                pageNum: 1,
                pageSize: 10,
            },
            caseStatus: [],
            // 遮罩层
            loading: false,
            // 总条数
            total: 0,
            // 表格数据
            form: {},
            // 校验表单
            rules: {},
            dataList: [],
            rowData:{},
            resendVidable:false
        };
    },
    created() {
        getDicts("case_status").then(res => {
            this.getList({ caseNum: this.queryParams.caseNum }, { pageNum: this.queryParams.pageNum, pageSize: this.queryParams.pageSize });
        })
    },
    methods: {
        /** 复制内容 */
        copyContent(row) {
            const el = document.createElement('textarea');
            el.value = row;
            document.body.appendChild(el);
            el.select();
            document.execCommand('copy');
            document.body.removeChild(el);
            this.$message.success('复制成功');
        },
        /**重新发送 */
        resend(row){
            this.resendVidable = true;
            this.rowData = row;
        },
        /**关闭弹窗 */
        cancelSend(){
            this.resendVidable = false;
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList({ caseNum: this.queryParams.caseNum }, { pageNum: this.queryParams.pageNum, pageSize: this.queryParams.pageSize });
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 查询列表数据
        getList(data, params) {
            this.loading = true;
            smsList(data, params).then((response) => {
                this.dataList = response.rows;
                this.dataList.forEach(item => {
                    if (item.sendStatus == 0) {
                        item.sendStatus = "发送失败"
                    } else if (item.sendStatus == 1) {
                        item.sendStatus = "已送达"
                    } else if (item.sendStatus == 2) {
                        item.sendStatus = "已读取"
                    } else {
                        item.sendStatus = "发送失败"
                    }
                })
                this.total = response.total;
                this.loading = false;
            });
        },
    },
};
</script>

<style lang="scss" scoped></style>