<template>
    <div>
        <div class="search-content">
            <el-form :inline="true">
                <el-form-item>
                    <el-select v-model="searchForm.project_id" clearable placeholder="请选择项目">
                        <el-option label="全部" value></el-option>
                        <el-option v-for="(item, index) in 	projectList" :key="index" :label="item.project_name" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="searchForm.type_name" clearable placeholder="请输入推广形式"></el-input>
                </el-form-item>
                <el-form-item class="ml-10">
                    <el-button icon="el-icon-search" type="primary" @click="searchSubmit">查询</el-button>
                </el-form-item>
                <el-form-item class="ml-10" v-if="projectList.length > 0 && hasPermission('add-promote-type')">
                    <el-button icon="el-icon-plus" type="primary" @click="add">添加</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-table :data="tableData" v-loading="tableLoading" border fit>
            <el-table-column prop="create_time" label="创建时间"></el-table-column>
            <el-table-column prop="id" label="ID"></el-table-column>
            <el-table-column prop="project.project_name" label="所属项目"></el-table-column>
            <el-table-column prop="type_name" label="推广形式"></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button v-permission="'add-promote-type'" type="text" @click="edit(scope.row)">修改</el-button>
                    <el-button v-permission="'delete-promote-type'" type="text" @click="del(scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
            class="marginT-20"
            @current-change="handleCurrentChange"
            :hide-on-single-page="false"
            :current-page="pageNo"
            :page-size="pageSize"
            background
            layout="total, prev, pager, next, jumper"
            :total="totalCount"
        />
        <edit v-if="editDialog.show" v-model="editDialog.show" :exData="editDialog.exData" @success="init"></edit>
    </div>
</template>

<script>
import page from '@/mixin/page'
import projectList from '../../mixin/projectList';
import edit from './_dialog/edit'
export default {
    mixins: [page, projectList],
    components: {
        edit,
    },
    data() {
        return {
            editDialog: {
                show: false,
                exData: {}
            },
            tableData: [],
            searchForm: {
                sources_name: undefined,
                project_id: undefined
            },
            tableUrl: '/listPromoteType',
        }
    },
    methods: {
        edit(row) {
            this.editDialog.exData = {...row, projectList: this.projectList}
            this.editDialog.show = true
        },
        add() {
            this.editDialog.exData = {projectList: this.projectList}
            this.editDialog.show = true
        },
        async del(row) {
            this.$confirm('是否删除', '确认', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                const data = await this.$fetch('/deletePromoteType', {id: row.id})
                if (data.code == 200) {
                    this.$message.success('删除成功')
                    this.init()
                }
            }).catch(() => {});
        }
    },
    async mounted() {
        this.init()
    },
}
</script>

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