<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 :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>
        <div>
            

            <a-table ref="table" size="middle" :scroll="{ x: true }" bordered rowKey="id" :columns="columns"
                :dataSource="dataSource" :pagination="ipagination" :loading="loading"
                
              >
                <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-time-picker  v-model="record.leaveTime" format="HH:mm">
                    </a-time-picker>
                    <a-button type="primary" size="small" @click="setLeaveTime(record)">
                        保存
                    </a-button>
                </span>

            </a-table>
        </div>
    </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { httpAction, putAction } from '@/api/manage'
import moment from 'moment'


export default {
    name: 'agreementunit1',
    mixins: [JeecgListMixin],
    components: {
    },
    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: 200,
                    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() {
       
    },
    computed: {
       
    },
    watch:{
        dataSource(old, nVal) {
            this.dataSource.forEach(s=> {
                s.leaveTime = s.leaveTime?moment(s.leaveTime,"HH:mm").utcOffset(8):null
            })
        }
    },
    methods: {
        setLeaveTime(record) {
            let data = JSON.parse(JSON.stringify(record))
            if(data.leaveTime) {
                data.leaveTime = data.leaveTime ? moment(new Date(data.leaveTime),"HH:mm").utcOffset(8).format("HH:mm") : null
            }
            putAction("/business/busMarketAgreementUnit/edit",data).then(res=> {
                if(res.success) {
                    this.$message.success("保存成功")
                }
            })
        },
        
        
       
        
    }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
