﻿<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-select v-model="query.kdhy" placeholder="开单会员" clearable >
								<el-option v-for="(item, index) in kdhyOptions" :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.kdhyc" placeholder="开单会员名称" clearable />	
						</el-form-item>
					</el-col>
					<template v-if="showAll">
					<el-col :span="6">
						<el-form-item label="会员手机号">
							<el-input v-model="query.kdhysjh" placeholder="会员手机号" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="单据门店">
							<el-select v-model="query.djmd" placeholder="单据门店" clearable >
								<el-option v-for="(item, index) in djmdOptions" :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.jsj" placeholder="金三角" clearable >
								<el-option v-for="(item, index) in jsjOptions" :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.kdrq" 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.gjlx" placeholder="顾客类型" clearable >
								<el-option v-for="(item, index) in gjlxOptions" :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.hgjg" placeholder="合作机构" clearable >
								<el-option v-for="(item, index) in hgjgOptions" :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.zdyj" placeholder="整单业绩" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="实付业绩">
							<el-input v-model="query.sfyj" placeholder="实付业绩" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="欠款">
							<el-input v-model="query.qk" placeholder="欠款" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="储扣方式">
							<el-select v-model="query.ckfs" placeholder="储扣方式" clearable >
								<el-option v-for="(item, index) in ckfsOptions" :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.ckmx" placeholder="储扣明细" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="付款方式">
							<el-select v-model="query.fkfs" placeholder="付款方式" clearable >
								<el-option v-for="(item, index) in fkfsOptions" :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.fkyy" placeholder="付款医院" clearable >
								<el-option v-for="(item, index) in fkyyOptions" :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.fkpd" placeholder="付款判断" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="客户来源">
							<el-select v-model="query.khly" placeholder="客户来源" clearable >
								<el-option v-for="(item, index) in khlyOptions" :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-select v-model="query.sfskdd" placeholder="是否首开订单" >
								<el-option v-for="(item, index) in sfskddOptions" :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.jj" placeholder="简介" />	
						</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-input v-model="query.jksyj" placeholder="健康师业绩" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="科技部老师业绩">
							<el-input v-model="query.kjblsyj" placeholder="科技部老师业绩" clearable />	
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="品项信息">
							<el-input v-model="query.pxxx" 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 label="开单会员" prop="kdhy" align="left">
							<template slot-scope="scope">{{ scope.row.kdhy | dynamicText(kdhyOptions) }}</template>
					</el-table-column>
					<el-table-column prop="kdhyc" label="开单会员名称" align="left" />
					<el-table-column prop="kdhysjh" label="会员手机号" align="left" />
					<el-table-column label="单据门店" prop="djmd" align="left">
							<template slot-scope="scope">{{ scope.row.djmd | dynamicText(djmdOptions) }}</template>
					</el-table-column>
					<el-table-column label="金三角" prop="jsj" align="left">
							<template slot-scope="scope">{{ scope.row.jsj | dynamicText(jsjOptions) }}</template>
					</el-table-column>
					<el-table-column prop="kdrq" label="开单日期" align="left" />
					<el-table-column label="顾客类型" prop="gjlx" align="left">
							<template slot-scope="scope">{{ scope.row.gjlx | dynamicText(gjlxOptions) }}</template>
					</el-table-column>
					<el-table-column label="合作机构" prop="hgjg" align="left">
							<template slot-scope="scope">{{ scope.row.hgjg | dynamicText(hgjgOptions) }}</template>
					</el-table-column>
					<el-table-column prop="zdyj" label="整单业绩" align="left" />
					<el-table-column prop="sfyj" label="实付业绩" align="left" />
					<el-table-column prop="qk" label="欠款" align="left" />
					<el-table-column label="储扣方式" prop="ckfs" align="left">
							<template slot-scope="scope">{{ scope.row.ckfs | dynamicText(ckfsOptions) }}</template>
					</el-table-column>
					<el-table-column prop="ckmx" label="储扣明细" align="left" />
					<el-table-column label="付款方式" prop="fkfs" align="left">
							<template slot-scope="scope">{{ scope.row.fkfs | dynamicText(fkfsOptions) }}</template>
					</el-table-column>
					<el-table-column label="付款医院" prop="fkyy" align="left">
							<template slot-scope="scope">{{ scope.row.fkyy | dynamicText(fkyyOptions) }}</template>
					</el-table-column>
					<el-table-column prop="fkpd" label="付款判断" align="left" />
					<el-table-column label="客户来源" prop="khly" align="left">
							<template slot-scope="scope">{{ scope.row.khly | dynamicText(khlyOptions) }}</template>
					</el-table-column>
					<el-table-column prop="tjr" label="推荐人" align="left" />
					<el-table-column label="是否首开订单" prop="sfskdd" align="left">
							<template slot-scope="scope">{{ scope.row.sfskdd | dynamicText(sfskddOptions) }}</template>
					</el-table-column>
					<el-table-column prop="jj" label="简介" align="left" />
					<el-table-column prop="bz" label="备注" align="left" />
					<el-table-column prop="jksyj" label="健康师业绩" align="left" />
					<el-table-column prop="kjblsyj" label="科技部老师业绩" align="left" />
					<el-table-column prop="pxxx" 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,
                    kdhy:undefined,
                    kdhyc:undefined,
                    kdhysjh:undefined,
                    djmd:undefined,
                    jsj:undefined,
                    kdrq:undefined,
                    gjlx:undefined,
                    hgjg:undefined,
                    zdyj:undefined,
                    sfyj:undefined,
                    qk:undefined,
                    ckfs:undefined,
                    ckmx:undefined,
                    fkfs:undefined,
                    fkyy:undefined,
                    fkpd:undefined,
                    khly:undefined,
                    tjr:undefined,
                    sfskdd:undefined,
                    jj:undefined,
                    bz:undefined,
                    jksyj:undefined,
                    kjblsyj:undefined,
                    pxxx:undefined,
				},
                list: [],
                listLoading: true,
                multipleSelection: [], total: 0,
                listQuery: {
                    currentPage: 1,
                    pageSize: 20,
					sort: "desc",
                    sidx: "",
                },
                formVisible: false,
                exportBoxVisible: false,
                columnList: [
                    { prop: 'id', label: '开单编号' },
                    { prop: 'kdhy', label: '开单会员' },
                    { prop: 'kdhyc', label: '开单会员名称' },
                    { prop: 'kdhysjh', label: '会员手机号' },
                    { prop: 'djmd', label: '单据门店' },
                    { prop: 'jsj', label: '金三角' },
                    { prop: 'kdrq', label: '开单日期' },
                    { prop: 'gjlx', label: '顾客类型' },
                    { prop: 'hgjg', label: '合作机构' },
                    { prop: 'zdyj', label: '整单业绩' },
                    { prop: 'sfyj', label: '实付业绩' },
                    { prop: 'qk', label: '欠款' },
                    { prop: 'ckfs', label: '储扣方式' },
                    { prop: 'ckmx', label: '储扣明细' },
                    { prop: 'fkfs', label: '付款方式' },
                    { prop: 'fkyy', label: '付款医院' },
                    { prop: 'fkpd', label: '付款判断' },
                    { prop: 'khly', label: '客户来源' },
                    { prop: 'tjr', label: '推荐人' },
                    { prop: 'sfskdd', label: '是否首开订单' },
                    { prop: 'jj', label: '简介' },
                    { prop: 'bz', label: '备注' },
                    { prop: 'jksyj', label: '健康师业绩' },
                    { prop: 'kjblsyj', label: '科技部老师业绩' },
                    { prop: 'pxxx', label: '品项信息' },
				],
				kdhyOptions : [],
				djmdOptions : [],
				jsjOptions : [],
				gjlxOptions:[{"fullName":"会员","id":"会员"},{"fullName":"非会员","id":"非会员"}],
				hgjgOptions : [],
				ckfsOptions:[{"fullName":"储值卡","id":"储值卡"},{"fullName":"扣项","id":"扣项"},{"fullName":"套餐","id":"套餐"}],
				fkfsOptions:[{"fullName":"现金","id":"现金"},{"fullName":"微信","id":"微信"},{"fullName":"支付宝","id":"支付宝"},{"fullName":"银行卡","id":"银行卡"},{"fullName":"医院","id":"医院"}],
				fkyyOptions : [],
				khlyOptions:[{"fullName":"自然到店","id":"自然到店"},{"fullName":"会员推广","id":"会员推广"},{"fullName":"网络推广","id":"网络推广"}],
				sfskddOptions:[{"fullName":"是","id":"是"},{"fullName":"否","id":"否"}],
			}
        },
		computed: {},
		created() {
			this.initData()
			this.getkdhyOptions();
			this.getdjmdOptions();
			this.getjsjOptions();
			this.gethgjgOptions();
			this.getfkyyOptions();
		},
		methods: {
			getkdhyOptions(){
				previewDataInterface('730998109110273285').then(res => {
					this.kdhyOptions = res.data
				});
			},
			getdjmdOptions(){
				previewDataInterface('730960205902251269').then(res => {
					this.djmdOptions = res.data
				});
			},
			getjsjOptions(){
				previewDataInterface('733894897408410885').then(res => {
					this.jsjOptions = res.data
				});
			},
			gethgjgOptions(){
				previewDataInterface('733896629660157189').then(res => {
					this.hgjgOptions = res.data
				});
			},
			getfkyyOptions(){
				previewDataInterface('733898797075137797').then(res => {
					this.fkyyOptions = res.data
				});
			},
			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/LqKdKdjlb`,
                    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/LqKdKdjlb/${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/LqKdKdjlb/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/LqKdKdjlb/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>