<template>
  <div class="container">
    <basic-crumb></basic-crumb>
    <div class="title">客户管理</div>
    <div class="english_box">
        <div class="top_bottom">
            <el-form
                ref="searchForm"
                :model="searchForm"
                label-width="160px"
                :rules="formRules"
            >
                <el-row>
                    <el-col :span="8" >
                        <el-form-item style="margin-right:5px;" label="客户名称" prop="name">
                            <el-input placeholder="客户名称" v-model="searchForm.companyName" ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" >
                        <el-form-item style="margin-right:5px;" label="所属国家" prop="name">
                            <!-- <el-input placeholder="所属国家" v-model="searchForm.name" ></el-input> -->
                            <el-select v-model="searchForm.country" placeholder="请选择所属国家">
                                <el-option v-for="item in countryList" :key="item.id" :value="item.dictKey" :label="item.dictValue"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" >
                        <el-form-item style="margin-right:5px;" label="客户联系人" prop="contactName">
                            <el-input placeholder="客户联系人" v-model="searchForm.contactName" ></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8" >
                        <el-form-item style="margin-right:5px;" label="创建人" prop="createUserName">
                            <el-input placeholder="创建人" v-model="searchForm.createUserName" ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="16" style="display:flex;justify-content: flex-end;">
                        <el-button size="small" type="primary" @click="handleSearch">搜索</el-button>
                        <el-button size="small"  @click="handleReset">重置</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </div>
    </div>
    <div class="btn_box">
        <el-button type="primary" @click="handleAdd">新增</el-button>
        <el-button type="danger" @click="handleDelete">批量删除</el-button>
    </div>
    <div class="table_box">
        <el-table :data="tableData" border height="425"  @selection-change="selectionChange">
            <el-table-column type="selection" fixed="left"></el-table-column>
            <el-table-column label="编号" prop="code" width="200"></el-table-column>
            <el-table-column label="客户公司名称" prop="companyName" width="200"></el-table-column>
            <el-table-column label="所属国家" prop="countryValue" width="200"></el-table-column>
            <el-table-column label="客户来源" prop="fromTypeValue" width="200"></el-table-column>
            <el-table-column label="客户联系人" prop="name" width="200">
                <template slot-scope="scope">
                    <span>{{scope.row.contactMain.name}}</span>
                </template>
            </el-table-column>
            <el-table-column label="联系人手机号" prop="phone" width="200">
                <template slot-scope="scope">
                    <span>{{scope.row.contactMain.phone}}</span>
                </template>
            </el-table-column>
            <el-table-column label="联系人邮箱" prop="email" width="200">
                <template slot-scope="scope">
                    <span>{{scope.row.contactMain.email}}</span>
                </template>
            </el-table-column>
            <el-table-column label="通讯地址" prop="address1" width="200"></el-table-column>
            <el-table-column label="最近成交时间" prop="lastOrderDealDateTime" width="200"></el-table-column>
            <el-table-column label="近期订单状态" prop="lastOrderStatusValue" width="200"></el-table-column>
            <el-table-column label="备注" prop="remark" width="200"></el-table-column>
            <el-table-column label="创建人" prop="createUserRealName" width="200"></el-table-column>
            <el-table-column label="创建时间" prop="createTime" width="200"></el-table-column>
            <el-table-column label="更新人" prop="updateUserRealName" width="200"></el-table-column>
            <el-table-column label="更新时间" prop="updateTime" width="200"></el-table-column>
            <el-table-column
                fixed="right"
                label="操作"
                width="100">
                <template slot-scope="scope">
                    <el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
                </template>
                </el-table-column>
        </el-table>
        <el-pagination
            style="display: flex;justify-content: flex-end;margin-top:10px;"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="current"
            :page-sizes="[10, 20, 30, 40,50,100]"
            :page-size="size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
    </div>
    <!-- <avue-crud :option="option"
        :search.sync="search"
        :table-loading="loading"
        :data="data"
        ref="crud"
        v-model="form"
        @row-del="rowDel"
        @row-update="rowUpdate"
        @row-save="rowSave"
        :before-open="beforeOpen"
        :page.sync="page"
        @search-change="searchChange"
        @search-reset="searchReset"
        @selection-change="selectionChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="refreshChange"
        @on-load="onLoad">
        <template slot="menuLeft">
            <el-button type="primary" @click="handleAdd">新增</el-button>
            <el-button type="danger">删除</el-button>
        </template>
    </avue-crud> -->
  </div>
</template>

<script>
import basicCrumb from "@/components/basic-crumb/main"
import {getCustomer,deleteCustomer,getCountry,searchData} from '@/api/customer/customer'
export default {
    components:{
        basicCrumb
    },
    data(){
        return{
            searchForm:{},
            tableData:[],
            countryList:[],
            total:0,
            current:1,
            size:10,
            selectionList:[]
        }
    },
    mounted(){
        this.getCountryData()
        // this.getList()
        this.searchList()
    },
    methods:{
        selectionChange(list){
            this.selectionList = list
        },
        handleSizeChange(val){
            this.size = val
            this.searchList()
        },
        searchList(){
            searchData({
                ...this.searchForm,
                current:this.current,
                size:this.size
            }).then(res =>{
                this.tableData = res.data.data.records
                this.total = res.data.data.total
            })
        },
        handleCurrentChange(val) {
            this.current = val
            this.searchList()
        },
        handleSearch(){
            this.current = 1
            this.size = 10
            this.searchList()
        },
        handleReset(){
            this.current = 1
            this.size = 10
            this.searchForm = {}
            this.searchList()
        },
        getCountryData(){
            getCountry().then(res =>{
                this.countryList = res.data.data
            })
        },
        handleAdd(){
            this.$router.push({ path: '/customerAdd' });
        },
        handleDelete(){
            if(this.selectionList.length == 0){
                this.$message.error('请选择一条数据')
                return
            }
            this.$confirm('确定将选择数据删除?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() =>{
                deleteCustomer({ids:this.selectionList.map(item => item.id).join(',')}).then(res =>{
                    if(res.data.code == 200){
                        this.$message.success('删除成功')
                        this.getList()
                    }
                })
            })
            
        },
        handleEdit(row){
            this.$router.push({ path: '/customerAdd',query:{customerId:row.id} });
        },
        getList(){
            getCustomer({
                ...this.searchForm,
                current:this.current,
                size:this.size
            }).then(res =>{
                this.tableData = res.data.data.records
                this.total = res.data.data.total
            })
        }
    }
}
</script>

<style scoped lang="scss">
.container{
    width: 99%;
    height: 99%;
    background: rgb(255, 255, 255);
    margin: 0 auto;
    margin-top: 8px;
    padding: 20px !important;

    .title{
        // font-size: 26px;
        font-size: 1.4vw;
        margin-bottom: 10px;
        width: 100%;
        text-align: center;
    }

    .top_box{
        width: 98%;
        padding: 10px;
        border: 1px solid #ccc;
        border-radius: 10px;
    }

    .english_box{
        width: 98%;
        padding: 10px 10px 0 10px;
        margin: 0 auto;
        border: 1px solid #ccc;
        border-radius: 10px;

        &.info_box{
            margin-top: 10px;
        }

        .top_box{
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-bottom: 10px;
            border-bottom: 1px solid #ccc;

            &.info_top{
                border: none;
            }

            &.info_top{
                border: none;
            }

            .top_left{
                // font-size: 26px;
                font-size: 1.4vw;
            }
        }

        .top_bottom{
            margin-top: 10px;

            .el-col{
                margin-bottom: 0px;
            }

            
        }
    }

    .btn_box{
        margin: 10px 0;
    }

    .table_box{
        margin-top: 10px;
    }
}

</style>