<template>
    <div class="main-contain">
        <div class="position">
            <bread-crumb :crumbs="crumbs"></bread-crumb>
            <el-button
                :disabled="$store.getters.xt_user.subscibe.state==3?true:false"
                @click="sendAction"
                style="float:right;"
                type="primary"
                icon="el-icon-message"
                size="small"
            >群发短信</el-button>
        </div>
        <div class="app-container" style="padding: 0 5px; background-color: #f6f8f9;">
            <div style="background-color: #fff; padding: 5px 0;">
                <el-table :data="records">
                    <el-table-column label="发送内容" align="center" prop="full_content" :show-overflow-tooltip="true" min-width="48%">
                    </el-table-column>
                    <el-table-column label="发送状态" align="center" min-width="15%">
                        <template slot-scope="scope">
                            {{ send_status_text(scope.row.status) }}
                        </template>
                    </el-table-column>
                    <el-table-column label="发送人数/到达条数" align="center" min-width="22%">
                        <template slot-scope="scope">
                            {{ scope.row.total_count }}/{{ scope.row.success_count }}
                        </template>
                    </el-table-column>
                    <el-table-column label="审核状态" align="center" min-width="15%">
                        <template slot-scope="scope">
                            {{ review_status_text(scope.row.status) }}
                        </template>
                    </el-table-column>
                </el-table>
                <div style="padding-top: 15px; padding-left: 10px;">
                    <el-pagination :total="record_total" :current-page.sync="current_page" :page-size="10" layout="total, prev, pager, next" @current-change="getSendRecords()"></el-pagination>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import BreadCrumb from "@/scrm_pages/components/bread-crumb"
import { fetchBatchSendRecords } from "@/api/sms"

export default {
    name: "SMSManage",
    components: {
        BreadCrumb,
    },
    data() {
        return {
            crumbs: [
                { path: false, name: "客户管理" },
                { path: false, name: "短信管理" },
            ],

            record_total: 0,
            current_page: 1,
            records: [],
        }
    },
    mounted() {
        this.getSendRecords()
    },
    methods: {
        getSendRecords: function() {
            fetchBatchSendRecords(this.current_page).then(rs => {
                var resp = rs.data
                if (resp.state == 1) {
                    this.records = resp.data.records
                    this.record_total = resp.data.total

                } else {
                    this.$message.error(resp.msg)
                }

            }).catch(err => {
                this.$message.error(err)
            })
        },
        sendAction: function() {
            this.$router.push({path:'/sms/send'})
        },

        send_status_text: function(status) {
            if (status == 4) {
                return "已发送"
            } else if (status == 5) {
                return "发送失败"
            } else {
                return "未发送"
            }
        },
        review_status_text: function(status) {
            if (status == 1) {
                return "待审核"
            } else if (status == 2) {
                return "未通过"
            } else {
                return "通过"
            }
        },
    },
}
</script>

<style lang="scss" scoped>

</style>


