<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="6">
                        <a-form-item>
                            <j-input placeholder="协议主题" v-model="queryParam.name" allowClear></j-input>
                        </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('bus_market_agreement_customer_info')">导出</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>
            <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="priceSlot" slot-scope="text,record">
                    <a-button type="primary" @click="e=>handleHousePrice(e,record)">
                        查看
                    </a-button>
                </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="handleEdit(record)">编辑</a>
                     <a-divider type="vertical" />
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                        <a>删除</a>
                    </a-popconfirm>
<!--                    <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="handleDetail(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>

        <market-agreement-customer-info-modal ref="modalCustomerForm" @ok="modalFormOk" :agreementModel="agreementModel"></market-agreement-customer-info-modal>
        <market-agreement-house-price-modal ref="modalHousePriceForm" @ok="modalFormOk" :agreementModel="agreementModel"></market-agreement-house-price-modal>
    </a-card>
</template>

<script>

    import '@/assets/less/TableExpand.less'
    import { mixinDevice } from '@/utils/mixin'
    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import marketAgreementCustomerInfoModal from './modules/marketAgreementCustomerInfoModal'
    import MarketAgreementHousePriceModal from './modules/marketAgreementHousePriceModal'

    export default {
        name: 'customerList',
        mixins:[JeecgListMixin, mixinDevice],
        components: {
            MarketAgreementHousePriceModal,
            marketAgreementCustomerInfoModal
        },
        props: {
            agreementModel:{
                type: Object,
                required: false,
                default: () => {
                }
            }
        },
        data () {
            return {
                description: 'bus_market_agreement_customer_info管理页面',
                // 表头
                queryParam: {},
                columns: [
                    {
                        title: '协议类型',
                        align: "center",
                        dataIndex: 'type_dictText'
                    },
                    {
                        title: '协议主题',
                        align: "center",
                        dataIndex: 'name'
                    },
                    {
                        title: '客户签约人',
                        align: "center",
                        dataIndex: 'customerSignatory'
                    },
                    {
                        title: '本司签约人',
                        align: "center",
                        dataIndex: 'companySignatory'
                    },
                    {
                        title: '协议单号',
                        align: "center",
                        dataIndex: 'number'
                    },
                    {
                        title: '签约时间',
                        align: "center",
                        dataIndex: 'signTime',
                        customRender: function (text) {
                            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
                        }
                    },
                    {
                        title: '折扣值',
                        align: "center",
                        dataIndex: 'discount'
                    },
                    {
                        title: '更新时间',
                        align: "center",
                        dataIndex: 'updateTime',
                        customRender: function (text) {
                            return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
                        }
                    },
                    {
                        title: '协议房价',
                        align: "center",
                        dataIndex: 'id',
                        scopedSlots: { customRender: "priceSlot" },
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align: "center",
                        fixed: "right",
                        width: 147,
                        scopedSlots: { customRender: 'action' }
                    }
                ],
                url: {
                    list: "/business/busMarketAgreementCustomer/list?agreementId="+this.agreementModel.id,
                    delete: "/business/busMarketAgreementCustomer/delete",
                    deleteBatch: "/business/busMarketAgreementCustomer/deleteBatch",
                    exportXlsUrl: "/business/busMarketAgreementCustomer/exportXls",
                    importExcelUrl: "business/busMarketAgreementCustomer/importExcel",

                },
                dictOptions: {},
                superFieldList: [],
            }
        },
        created() {
            this.getSuperFieldList();
            console.log(this.agreementModel)
        },
        computed: {
            importExcelUrl: function(){
                return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
            },
        },
        methods: {
            initDictConfig(){
            },
            getSuperFieldList(){
                let fieldList=[];
                fieldList.push({type:'string',value:'tenantId',text:'关联租户'})
                fieldList.push({type:'string',value:'agreementId',text:'关联协议'})
                fieldList.push({type:'string',value:'hotelId',text:'关联酒店'})
                fieldList.push({type:'string',value:'name',text:'协议主题'})
                fieldList.push({type:'string',value:'type',text:'协议类型'})
                fieldList.push({type:'string',value:'number',text:'协议单号'})
                fieldList.push({type:'date',value:'signTime',text:'签约时间'})
                fieldList.push({type:'date',value:'effective',text:'有效期'})
                fieldList.push({type:'int',value:'secrecy',text:'佣金信息保密'})
                fieldList.push({type:'string',value:'customerSignatory',text:'客户签约人'})
                fieldList.push({type:'string',value:'companySignatory',text:'本司签约人'})
                fieldList.push({type:'string',value:'content',text:'内容'})
                fieldList.push({type:'string',value:'remarks',text:'备注'})
                fieldList.push({type:'int',value:'roomType',text:'计佣类型(0-固定计佣；1-房类计佣)'})
                fieldList.push({type:'int',value:'commissionUnit',text:'佣金单位(0-元；1-%)'})
                fieldList.push({type:'number',value:'dailyCommission',text:'每日佣金'})
                fieldList.push({type:'int',value:'commission',text:'每日计佣(0-否；1-是)'})
                fieldList.push({type:'int',value:'fixedDiscount',text:'使用固定房价折扣(0-否；1-是)'})
                fieldList.push({type:'number',value:'discount',text:'房价固定折扣'})
                fieldList.push({type:'int',value:'delFlag',text:'删除状态(0-正常,1-已删除)'})
                this.superFieldList = fieldList
            },
            handleEdit: function (record) {
                this.$refs.modalCustomerForm.edit(record);
                this.$refs.modalCustomerForm.title = "编辑";
                this.$refs.modalCustomerForm.disableSubmit = false;
            },
            handleAdd: function () {
                this.$refs.modalCustomerForm.add();
                this.$refs.modalCustomerForm.title = "新增";
                this.$refs.modalCustomerForm.disableSubmit = false;
            },
            handleHousePrice(e,record){
                console.log(e,record)

                this.$refs.modalHousePriceForm.edit(record);
                this.$refs.modalHousePriceForm.title = "协议房价列表";
                this.$refs.modalHousePriceForm.disableSubmit = false;
            }
        }
    }
</script>
<style scoped>
    @import '~@assets/less/common.less';
</style>
