<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :span="4">
                        <a-form-item>
                            <a-input placeholder="关键字" v-model="queryParam.keyWord" allowClear></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item>
                            <a-select
                                    v-model="queryParam.customerType"
                                    placeholder="请选择客户类型"
                                    :allowClear="true"
                            >
                                <a-select-option :value="item.id" v-for="(item,index) in customerTypeList" :key="index">{{ item.itemText }}</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item>
                            <a-select
                                    v-model="queryParam.status"
                                    placeholder="请选择客户状态"
                                    :allowClear="true"
                            >
                                <a-select-option :value="item.id" v-for="(item,index) in customerStatusList" :key="index">{{ item.itemText }}</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :span="4">
                        <a-form-item>
                            <j-dict-select-tag allowClear="true" v-model="queryParam.accountStatus" placeholder="请选择账号状态" dictCode="agreement_status"/>
                        </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="8">
                        <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                            <a-button type="primary" @click="searchReset" icon="reload"
                                      style="margin-left: 8px">重置</a-button>
                        </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
<!--            <a-button type="primary" icon="download" @click="handleExportXls('协议单位')">导出</a-button>-->
<!--            <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--                <a-button type="primary" icon="import">导入</a-button>-->
<!--            </a-upload>-->
<!--            &lt;!&ndash; 高级查询区域 &ndash;&gt;-->
<!--            <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
            <a-dropdown v-if="selectedRowKeys.length > 0">
<!--                <a-menu slot="overlay">-->
<!--                    <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
<!--                </a-menu>-->
<!--                <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
                <a-button @click="batchDel" type="danger" icon="delete">批量删除</a-button>
            </a-dropdown>
        </div>

        <!-- table区域-begin -->
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>

            <a-table
                    ref="table"
                    size="middle"
                    :scroll="{x:true}"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="ipagination"
                    :loading="loading"
                    :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                    class="j-table-force-nowrap"
                    @change="handleTableChange">

                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="imgSlot" slot-scope="text,record">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                    <a-button
                            v-else
                            :ghost="true"
                            type="primary"
                            icon="download"
                            size="small"
                            @click="downloadFile(text)">
                        下载
                    </a-button>
                </template>

                <span slot="action" slot-scope="text, record">
                     <a @click="toBilling(record)">账务管理</a>
                    <a-divider type="vertical" />
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetails(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

            </a-table>
        </div>

        <agreement-unit-modal ref="modalForm" @ok="modalFormOk"></agreement-unit-modal>
        <agreement-unit-detail-modal ref="modalDetailForm" @ok="modalFormOk"></agreement-unit-detail-modal>
    </a-card>
</template>

<script>

    import '@/assets/less/TableExpand.less'
    import { mixinDevice } from '@/utils/mixin'
    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import agreementUnitModal from './modules/agreementUnit/agreementUnitModal'
    import AgreementUnitDetailModal from './modules/agreementUnit/agreementUnitDetailModal'
    import { httpAction, getAction } from '@/api/manage'



    export default {
        name: 'agreementunit',
        mixins:[JeecgListMixin, mixinDevice],
        components: {
            AgreementUnitDetailModal,
            agreementUnitModal
        },
        data () {
            return {
                description: '协议单位管理页面',
                // 表头
                columns: [
                    {
                        title:'商家名称',
                        align:"center",
                        dataIndex: 'hotelName'
                    },
                    {
                        title:'账号',
                        align:"center",
                        dataIndex: 'accountNo'
                    },
                    {
                        title:'客户名称',
                        align:"center",
                        dataIndex: 'customerName'
                    },
                    {
                        title:'客户类型',
                        align:"center",
                        dataIndex: 'customerType_dictText'
                    },
                    {
                        title:'客户状态',
                        align:"center",
                        dataIndex: 'status_dictText'
                    },
                    {
                        title:'记账额度',
                        align:"center",
                        dataIndex: 'bookkeeping',
                        customRender:function (text) {
                            return (text == null || text == 0 ? "无限制" : text)
                        }
                    },
                    {
                        title:'已用额度',
                        align:"center",
                        dataIndex: 'amountUsed'
                    },
                    {
                        title:'剩余额度',
                        align:"center",
                        dataIndex: 'balance'
                    },
                    {
                        title:'备注',
                        align:"center",
                        dataIndex: 'remarks'
                    },
                    {
                        title:'账号状态',
                        align:"center",
                        dataIndex: 'accountStatus_dictText'
                    },
                    {
                        title:'审核状态',
                        align:"center",
                        dataIndex: 'checkStatus_dictText'
                    },
                    {
                        title:'审核时间',
                        align:"center",
                        dataIndex: 'checkTime',
                        customRender:function (text) {
                            return !text?"":(text.length>10?text.substr(0,10):text)
                        }
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align:"center",
                        fixed:"right",
                        width:147,
                        scopedSlots: { customRender: 'action' }
                    }
                ],
                url: {
                    list: "/business/busMarketAgreementUnit/list",
                    delete: "/business/busMarketAgreementUnit/delete",
                    deleteBatch: "/business/busMarketAgreementUnit/deleteBatch",
                    exportXlsUrl: "/business/busMarketAgreementUnit/exportXls",
                    importExcelUrl: "business/busMarketAgreementUnit/importExcel",

                },
                dictOptions:{},
                superFieldList:[],
                customerTypeList:[],
                customerStatusList:[],
            }
        },
        created() {
            this.getSuperFieldList();
            this.initDictConfig();
        },
        computed: {
            importExcelUrl: function(){
                return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
            },
        },
        methods: {
            initDictConfig(){
                var that = this;
                //客户类型
                var param = {
                    dictName:'协议客户类型设置'
                }
                // var values = JSON.parse(JSON.stringify(param))
                that.confirmLoading = true;
                getAction('/business/busDictItem/queryList',param).then((res)=>{
                    console.log(res)
                    if(res.success){
                        if (res.code == 200 && res.result) {
                            this.customerTypeList = res.result;
                        }
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                })

                //客户状态
                var param = {
                    dictName:'协议客户状态设置'
                }
                // var values = JSON.parse(JSON.stringify(param))
                that.confirmLoading = true;
                getAction('/business/busDictItem/queryList',param).then((res)=>{
                    console.log(res)
                    if(res.success){
                        if (res.code == 200 && res.result) {
                            this.customerStatusList = res.result;
                        }
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                })
            },
            getSuperFieldList(){
                let fieldList=[];
                fieldList.push({type:'string',value:'tenantId',text:'关联租户'})
                fieldList.push({type:'string',value:'hotelId',text:'关联酒店'})
                fieldList.push({type:'string',value:'customerName',text:'客户全称'})
                fieldList.push({type:'string',value:'customerShortName',text:'客户简称'})
                fieldList.push({type:'string',value:'customerNo',text:'客户编号'})
                fieldList.push({type:'string',value:'contactsName',text:'联系人'})
                fieldList.push({type:'string',value:'systemType',text:'系统类型'})
                fieldList.push({type:'string',value:'customerType',text:'客户类型'})
                fieldList.push({type:'string',value:'sellerId',text:'销售人员'})
                fieldList.push({type:'string',value:'phone',text:'手机号'})
                fieldList.push({type:'string',value:'status',text:'客户状态'})
                fieldList.push({type:'string',value:'region',text:'地区'})
                fieldList.push({type:'string',value:'postalCode',text:'邮编'})
                fieldList.push({type:'string',value:'address',text:'地址'})
                fieldList.push({type:'string',value:'companyPhone',text:'公司电话'})
                fieldList.push({type:'string',value:'fax',text:'传真'})
                fieldList.push({type:'string',value:'customerSource',text:'客户来源'})
                fieldList.push({type:'string',value:'homepage',text:'主页'})
                fieldList.push({type:'string',value:'email',text:'邮箱'})
                fieldList.push({type:'string',value:'customerIndustry',text:'客户行业'})
                fieldList.push({type:'int',value:'checkStatus',text:'审核状态'})
                fieldList.push({type:'date',value:'checkTime',text:'审核时间'})
                fieldList.push({type:'string',value:'checkBy',text:'审核人'})
                fieldList.push({type:'string',value:'checkRemarks',text:'审核备注'})
                fieldList.push({type:'string',value:'accountNo',text:'账户编号'})
                fieldList.push({type:'int',value:'accountStatus',text:'账户状态'})
                fieldList.push({type:'number',value:'amountUsed',text:'已用额度'})
                fieldList.push({type:'number',value:'balance',text:'余额'})
                fieldList.push({type:'number',value:'bookkeeping',text:'记账限额'})
                fieldList.push({type:'int',value:'bookkStatus',text:'不允许该单位记账'})
                fieldList.push({type:'int',value:'commission',text:'前台是否查询'})
                fieldList.push({type:'int',value:'reception',text:'是否返佣'})
                fieldList.push({type:'string',value:'remark',text:'备注'})
                fieldList.push({type:'int',value:'delFlag',text:'删除状态'})
                this.superFieldList = fieldList
            },
            handleDetails:function(record){
                this.$refs.modalDetailForm.edit(record);
                this.$refs.modalDetailForm.title="详情";
                this.$refs.modalDetailForm.disableSubmit = true;
            },
            toBilling(record){
                var url = '/tenant/marketinfo/agreementaccount';//'markets/agreementunit/agreementAccount';
                //缓存选择的协议id
                console.log(record)
                localStorage.removeItem("agreementUnitInfo")
                localStorage.setItem("agreementUnitInfo", JSON.stringify(record))
                this.$router.push({
                    path:url,
                    query: { agreementUnitInfo: record },
                });
                // this.$router.push({
                //     // path: "/room/scheduledetail",
                //     // query: { id: e },
                //     name: "markets/agreementunit/agreementAccount",
                //     params: { id: record.id },
                // });
            }
        }
    }
</script>
<style scoped>
    @import '~@assets/less/common.less';
</style>
