﻿<template>
	<div class="NCC-common-layout">
		<div class="NCC-common-layout-center">
			<el-row class="NCC-common-search-box" :gutter="16">
				<el-form @submit.native.prevent>
					<el-col :span="6">
						<el-form-item label="客户编码">
							<el-input v-model="query.id" placeholder="客户编码" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="客户名称">
							<el-input v-model="query.khmc" placeholder="客户名称" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="手机号">
							<el-input v-model="query.sjh" placeholder="手机号" clearable />	
						</el-form-item>
					</el-col>
					<template v-if="showAll">
					<el-col :span="6">
						<el-form-item label="档案号">
							<el-input v-model="query.dah" placeholder="档案号" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="性别">
							<el-select v-model="query.xb" placeholder="性别" clearable >
								<el-option v-for="(item, index) in xbOptions" :key="index" :label="item.fullName" :value="item.id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="公众号状态">
							<el-select v-model="query.gzhzt" placeholder="公众号状态" clearable >
								<el-option v-for="(item, index) in gzhztOptions" :key="index" :label="item.fullName" :value="item.id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="微信昵称">
							<el-input v-model="query.wxnc" placeholder="微信昵称" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="小程序状态">
							<el-select v-model="query.wxxcxzt" placeholder="小程序状态" clearable >
								<el-option v-for="(item, index) in wxxcxztOptions" :key="index" :label="item.fullName" :value="item.id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="最近登录时间">
							<el-date-picker v-model="query.zjdlsj" type="daterange" value-format="timestamp" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="客户目前归属">
							<el-select v-model="query.khmqgs" placeholder="客户目前归属" clearable >
								<el-option v-for="(item, index) in khmqgsOptions" :key="index" :label="item.fullName" :value="item.id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="归属门店">
							<el-input v-model="query.gsmd" placeholder="归属门店" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="注册时间">
							<el-date-picker v-model="query.zcsj" type="daterange" value-format="timestamp" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="客户类型">
							<el-select v-model="query.khlx" placeholder="客户类型" clearable >
								<el-option v-for="(item, index) in khlxOptions" :key="index" :label="item.fullName" :value="item.id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="客户阶段">
							<el-select v-model="query.khjd" placeholder="客户阶段" clearable >
								<el-option v-for="(item, index) in khjdOptions" :key="index" :label="item.fullName" :value="item.id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="客户消费">
							<el-select v-model="query.khxf" placeholder="客户消费" >
								<el-option v-for="(item, index) in khxfOptions" :key="index" :label="item.fullName" :value="item.id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="消费频次">
							<el-select v-model="query.xfpc" placeholder="消费频次" clearable >
								<el-option v-for="(item, index) in xfpcOptions" :key="index" :label="item.fullName" :value="item.id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="推荐人">
							<el-input v-model="query.tjr" placeholder="推荐人" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="负责顾问">
							<el-input v-model="query.fzgw" placeholder="负责顾问" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="美容师">
							<el-input v-model="query.mrs" placeholder="美容师" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="进店渠道">
							<el-input v-model="query.jdqd" placeholder="进店渠道" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="联系地址">
							<el-input v-model="query.lxdz" placeholder="联系地址" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="备注">
							<el-input v-model="query.bz" placeholder="备注" />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="首次到店">
							<el-date-picker v-model="query.scdd" type="daterange" value-format="timestamp" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="最近到店">
							<el-date-picker v-model="query.zjdd" type="daterange" value-format="timestamp" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="未到店天数">
							<el-input v-model="query.wddts" placeholder="未到店天数" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="阳历生日">
							<el-date-picker v-model="query.yanglsr" type="daterange" value-format="timestamp" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="阴历生日">
							<el-date-picker v-model="query.yinlsr" type="daterange" value-format="timestamp" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="年龄">
							<el-input v-model="query.ml" placeholder="年龄" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="最近服务人员">
							<el-input v-model="query.zjycfwry" placeholder="最近服务人员" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="期间到店频次">
							<el-input v-model="query.qjddpc" placeholder="期间到店频次" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="期间服务单次">
							<el-input v-model="query.qjfwdc" placeholder="期间服务单次" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="期间现金消费">
							<el-input v-model="query.qjxjxf" placeholder="期间现金消费" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="期间项目耗卡">
							<el-input v-model="query.qjxmhk" placeholder="期间项目耗卡" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="期间储值消耗">
							<el-input v-model="query.qjczxh" placeholder="期间储值消耗" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="剩余储值">
							<el-input v-model="query.sycz" placeholder="剩余储值" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="剩余积分">
							<el-input v-model="query.syjf" placeholder="剩余积分" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="剩余品项金额">
							<el-input v-model="query.sypxje" placeholder="剩余品项金额" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="剩余套餐金额">
							<el-input v-model="query.sytcje" placeholder="剩余套餐金额" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="项目耗卡金额">
							<el-input v-model="query.ljxmhkje" placeholder="项目耗卡金额" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="累计储值消耗">
							<el-input v-model="query.ljczxh" placeholder="累计储值消耗" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="累计消费次数">
							<el-input v-model="query.ljxfcs" placeholder="累计消费次数" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="累计服务次数">
							<el-input v-model="query.ljfwcs" placeholder="累计服务次数" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="现金消费金额">
							<el-input v-model="query.ljxjxfje" placeholder="现金消费金额" clearable />	
						</el-form-item>
					</el-col>
					</template>
					<el-col :span="6">
						<el-form-item>
							<el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
							<el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
							<el-button type="text" icon="el-icon-arrow-down" @click="showAll=true" v-if="!showAll">展开</el-button>
							<el-button type="text" icon="el-icon-arrow-up" @click="showAll=false" v-else>收起</el-button>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
			<div class="NCC-common-layout-main NCC-flex-main">
				<div class="NCC-common-head">
					<div>
						<el-button type="primary" icon="el-icon-plus" @click="addOrUpdateHandle()">新增</el-button>
						<el-button type="text" icon="el-icon-download" @click="exportData()">导出</el-button>
						<el-button type="text" icon="el-icon-delete" @click="handleBatchRemoveDel()">批量删除</el-button>
					</div>
					<div class="NCC-common-head-right">
						<el-tooltip effect="dark" content="刷新" placement="top">
							<el-link icon="icon-ym icon-ym-Refresh NCC-common-head-icon" :underline="false" @click="reset()" />
						</el-tooltip>
						<screenfull isContainer />
					</div>
				</div>
                <NCC-table v-loading="listLoading" :data="list" has-c @selection-change="handleSelectionChange">
					<el-table-column prop="id" label="客户编码" align="left" />
					<el-table-column prop="khmc" label="客户名称" align="left" />
					<el-table-column prop="sjh" label="手机号" align="left" />
					<el-table-column prop="dah" label="档案号" align="left" />
					<el-table-column label="性别" prop="xb" align="left">
							<template slot-scope="scope">{{ scope.row.xb | dynamicText(xbOptions) }}</template>
					</el-table-column>
					<el-table-column label="公众号状态" prop="gzhzt" align="left">
							<template slot-scope="scope">{{ scope.row.gzhzt | dynamicText(gzhztOptions) }}</template>
					</el-table-column>
					<el-table-column prop="wxnc" label="微信昵称" align="left" />
					<el-table-column label="小程序状态" prop="wxxcxzt" align="left">
							<template slot-scope="scope">{{ scope.row.wxxcxzt | dynamicText(wxxcxztOptions) }}</template>
					</el-table-column>
					<el-table-column prop="zjdlsj" label="最近登录时间" align="left" />
					<el-table-column label="客户目前归属" prop="khmqgs" align="left">
							<template slot-scope="scope">{{ scope.row.khmqgs | dynamicText(khmqgsOptions) }}</template>
					</el-table-column>
					<el-table-column prop="gsmd" label="归属门店" align="left" />
					<el-table-column prop="zcsj" label="注册时间" align="left" />
					<el-table-column label="客户类型" prop="khlx" align="left">
							<template slot-scope="scope">{{ scope.row.khlx | dynamicText(khlxOptions) }}</template>
					</el-table-column>
					<el-table-column label="客户阶段" prop="khjd" align="left">
							<template slot-scope="scope">{{ scope.row.khjd | dynamicText(khjdOptions) }}</template>
					</el-table-column>
					<el-table-column label="客户消费" prop="khxf" align="left">
							<template slot-scope="scope">{{ scope.row.khxf | dynamicText(khxfOptions) }}</template>
					</el-table-column>
					<el-table-column label="消费频次" prop="xfpc" align="left">
							<template slot-scope="scope">{{ scope.row.xfpc | dynamicText(xfpcOptions) }}</template>
					</el-table-column>
					<el-table-column prop="tjr" label="推荐人" align="left" />
					<el-table-column prop="fzgw" label="负责顾问" align="left" />
					<el-table-column prop="mrs" label="美容师" align="left" />
					<el-table-column prop="jdqd" label="进店渠道" align="left" />
					<el-table-column prop="lxdz" label="联系地址" align="left" />
					<el-table-column prop="bz" label="备注" align="left" />
					<el-table-column prop="scdd" label="首次到店" align="left" />
					<el-table-column prop="zjdd" label="最近到店" align="left" />
					<el-table-column prop="wddts" label="未到店天数" align="left" />
					<el-table-column prop="yanglsr" label="阳历生日" align="left" />
					<el-table-column prop="yinlsr" label="阴历生日" align="left" />
					<el-table-column prop="ml" label="年龄" align="left" />
					<el-table-column prop="zjycfwry" label="最近服务人员" align="left" />
					<el-table-column prop="qjddpc" label="期间到店频次" align="left" />
					<el-table-column prop="qjfwdc" label="期间服务单次" align="left" />
					<el-table-column prop="qjxjxf" label="期间现金消费" align="left" />
					<el-table-column prop="qjxmhk" label="期间项目耗卡" align="left" />
					<el-table-column prop="qjczxh" label="期间储值消耗" align="left" />
					<el-table-column prop="sycz" label="剩余储值" align="left" />
					<el-table-column prop="syjf" label="剩余积分" align="left" />
					<el-table-column prop="sypxje" label="剩余品项金额" align="left" />
					<el-table-column prop="sytcje" label="剩余套餐金额" align="left" />
					<el-table-column prop="ljxmhkje" label="项目耗卡金额" align="left" />
					<el-table-column prop="ljczxh" label="累计储值消耗" align="left" />
					<el-table-column prop="ljxfcs" label="累计消费次数" align="left" />
					<el-table-column prop="ljfwcs" label="累计服务次数" align="left" />
					<el-table-column prop="ljxjxfje" label="现金消费金额" align="left" />
					<el-table-column label="操作" fixed="right" width="100">
							<template slot-scope="scope">
							<el-button type="text" @click="addOrUpdateHandle(scope.row.id)" >编辑</el-button>
							<el-button type="text" @click="handleDel(scope.row.id)" class="NCC-table-delBtn" >删除</el-button>
						</template>
					</el-table-column>
				</NCC-table>
                <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />
            </div>
        </div>
		<NCC-Form v-if="formVisible" ref="NCCForm" @refresh="refresh" />
		<ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download" />
	</div>
</template>
<script>
    import request from '@/utils/request'
    import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
    import NCCForm from './Form'
    import ExportBox from './ExportBox'
    import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
        components: { NCCForm, ExportBox },
        data() {
            return {
                showAll: false,
				query: {
                    id:undefined,
                    khmc:undefined,
                    sjh:undefined,
                    dah:undefined,
                    xb:undefined,
                    gzhzt:undefined,
                    wxnc:undefined,
                    wxxcxzt:undefined,
                    zjdlsj:undefined,
                    khmqgs:undefined,
                    gsmd:undefined,
                    zcsj:undefined,
                    khlx:undefined,
                    khjd:undefined,
                    khxf:undefined,
                    xfpc:undefined,
                    tjr:undefined,
                    fzgw:undefined,
                    mrs:undefined,
                    jdqd:undefined,
                    lxdz:undefined,
                    bz:undefined,
                    scdd:undefined,
                    zjdd:undefined,
                    wddts:undefined,
                    yanglsr:undefined,
                    yinlsr:undefined,
                    ml:undefined,
                    zjycfwry:undefined,
                    qjddpc:undefined,
                    qjfwdc:undefined,
                    qjxjxf:undefined,
                    qjxmhk:undefined,
                    qjczxh:undefined,
                    sycz:undefined,
                    syjf:undefined,
                    sypxje:undefined,
                    sytcje:undefined,
                    ljxmhkje:undefined,
                    ljczxh:undefined,
                    ljxfcs:undefined,
                    ljfwcs:undefined,
                    ljxjxfje:undefined,
				},
                list: [],
                listLoading: true,
                multipleSelection: [], total: 0,
                listQuery: {
                    currentPage: 1,
                    pageSize: 20,
					sort: "desc",
                    sidx: "",
                },
                formVisible: false,
                exportBoxVisible: false,
                columnList: [
                    { prop: 'id', label: '客户编码' },
                    { prop: 'khmc', label: '客户名称' },
                    { prop: 'sjh', label: '手机号' },
                    { prop: 'dah', label: '档案号' },
                    { prop: 'xb', label: '性别' },
                    { prop: 'gzhzt', label: '公众号状态' },
                    { prop: 'wxnc', label: '微信昵称' },
                    { prop: 'wxxcxzt', label: '小程序状态' },
                    { prop: 'zjdlsj', label: '最近登录时间' },
                    { prop: 'khmqgs', label: '客户目前归属' },
                    { prop: 'gsmd', label: '归属门店' },
                    { prop: 'zcsj', label: '注册时间' },
                    { prop: 'khlx', label: '客户类型' },
                    { prop: 'khjd', label: '客户阶段' },
                    { prop: 'khxf', label: '客户消费' },
                    { prop: 'xfpc', label: '消费频次' },
                    { prop: 'tjr', label: '推荐人' },
                    { prop: 'fzgw', label: '负责顾问' },
                    { prop: 'mrs', label: '美容师' },
                    { prop: 'jdqd', label: '进店渠道' },
                    { prop: 'lxdz', label: '联系地址' },
                    { prop: 'bz', label: '备注' },
                    { prop: 'scdd', label: '首次到店' },
                    { prop: 'zjdd', label: '最近到店' },
                    { prop: 'wddts', label: '未到店天数' },
                    { prop: 'yanglsr', label: '阳历生日' },
                    { prop: 'yinlsr', label: '阴历生日' },
                    { prop: 'ml', label: '年龄' },
                    { prop: 'zjycfwry', label: '最近服务人员' },
                    { prop: 'qjddpc', label: '期间到店频次' },
                    { prop: 'qjfwdc', label: '期间服务单次' },
                    { prop: 'qjxjxf', label: '期间现金消费' },
                    { prop: 'qjxmhk', label: '期间项目耗卡' },
                    { prop: 'qjczxh', label: '期间储值消耗' },
                    { prop: 'sycz', label: '剩余储值' },
                    { prop: 'syjf', label: '剩余积分' },
                    { prop: 'sypxje', label: '剩余品项金额' },
                    { prop: 'sytcje', label: '剩余套餐金额' },
                    { prop: 'ljxmhkje', label: '项目耗卡金额' },
                    { prop: 'ljczxh', label: '累计储值消耗' },
                    { prop: 'ljxfcs', label: '累计消费次数' },
                    { prop: 'ljfwcs', label: '累计服务次数' },
                    { prop: 'ljxjxfje', label: '现金消费金额' },
				],
				xbOptions:[{"fullName":"男","id":"男"},{"fullName":"女","id":"女"}],
				gzhztOptions:[{"fullName":"已绑定","id":"已绑定"},{"fullName":"未绑定","id":"未绑定"}],
				wxxcxztOptions:[{"fullName":"已绑定","id":"已绑定"},{"fullName":"未绑定","id":"未绑定"}],
				khmqgsOptions:[{"fullName":"会员","id":"会员"},{"fullName":"线索池","id":"线索池"},{"fullName":"会员-归档","id":"会员-归档"}],
				khlxOptions:[{"fullName":"新客","id":"新客"},{"fullName":"老客","id":"老客"},{"fullName":"潜客","id":"潜客"}],
				khjdOptions:[{"fullName":"体验","id":"体验"},{"fullName":"有效","id":"有效"},{"fullName":"沉睡","id":"沉睡"},{"fullName":"流失","id":"流失"}],
				khxfOptions:[{"fullName":"D客","id":"D客"},{"fullName":"有效","id":"有效"}],
				xfpcOptions:[{"fullName":"高频","id":"高频"},{"fullName":"低频","id":"低频"}],
			}
        },
		computed: {},
		created() {
			this.initData()
		},
		methods: {
			initData() {
                this.listLoading = true;
                let _query = {
                    ...this.listQuery,
                    ...this.query
                };
                let query = {}
                for (let key in _query) {
                    if (Array.isArray(_query[key])) {
                        query[key] = _query[key].join()
                    } else {
                        query[key] = _query[key]
                    }
                }
                request({
                    url: `/api/Extend/LqKhxx`,
                    method: 'GET',
                    data: query
                }).then(res => {
                    this.list = res.data.list
                    this.total = res.data.pagination.total
                    this.listLoading = false
                })
            },
			handleDel(id) {
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    type: 'warning'
                }).then(() => {
                    request({
                        url: `/api/Extend/LqKhxx/${id}`,
                        method: 'DELETE'
                    }).then(res => {
                        this.$message({
                            type: 'success',
                            message: res.msg,
                            onClose: () => {
                                this.initData()
                            }
                        });
                    })
                }).catch(() => {
                });
            },
			handleSelectionChange(val) {
                const res = val.map(item => item.id)
                this.multipleSelection = res
            },
            handleBatchRemoveDel() {
                if (!this.multipleSelection.length) {
                    this.$message({
                        type: 'error',
                        message: '请选择一条数据',
                        duration: 1500,
                    })
                    return
                }
                const ids = this.multipleSelection
                this.$confirm('您确定要删除这些数据吗, 是否继续？', '提示', {
                    type: 'warning'
                }).then(() => {
                    request({
                        url: `/api/Extend/LqKhxx/batchRemove`,
                        method: 'POST',
                        data: ids ,
                    }).then(res => {
                        this.$message({
                            type: 'success',
                            message: res.msg,
                            onClose: () => {
                                this.initData()
                            }
                        });
                    })
                }).catch(() => { })
            },
			addOrUpdateHandle(id, isDetail) {
                this.formVisible = true
                this.$nextTick(() => {
                    this.$refs.NCCForm.init(id, isDetail)
                })
            },
			exportData() {
                this.exportBoxVisible = true
                this.$nextTick(() => {
                    this.$refs.ExportBox.init(this.columnList)
                })
            },
            download(data) {
                let query = { ...data, ...this.listQuery, ...this.query }
                request({
                    url: `/api/Extend/LqKhxx/Actions/Export`,
                    method: 'GET',
                    data: query
                }).then(res => {
                    if (!res.data.url) return
                    window.location.href = this.define.comUrl + res.data.url
                    this.$refs.ExportBox.visible = false
                    this.exportBoxVisible = false
                })
            },
			search() {
                this.listQuery = {
                    currentPage: 1,
                    pageSize: 20,
                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            },
            refresh(isrRefresh) {
                this.formVisible = false
                if (isrRefresh) this.reset()
            },
            reset() {
                for (let key in this.query) {
                    this.query[key] = undefined
                }
                this.listQuery = {
                    currentPage: 1,
                    pageSize: 20,
                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            }
		}
    }
</script>