<template>
    <div class="test_cli admin_page">
		<div class="admin_table_search">
			<div class="admin_state">
			
				<div class="admin_state_item">
					<span>State Time:</span>
					<a-range-picker
						class="range_picker"
						v-model:value="rangePickerValue"
						:placeholder="[
							$t('HistoryPage.StartDate'),
							$t('HistoryPage.EndDate'),
						]"
						valueFormat="YYYY-MM-DD"
					>
						<template #suffixIcon>
							<span
								class="icon iconfont range_picker_icon icon-rili"
							></span>
						</template>
					</a-range-picker>
				</div>
				<div class="admin_state_item">
					<span>End Time:</span>
					<a-time-range-picker class="range_picker" valueFormat="HH:mm:ss" v-model:value="rangeTimeValue" />
				</div>

			</div>
			<div class="admin_search">
				<div class="admin_search_item" @click="searchHistoryList">Search</div>
			</div>
		</div>

		<div class="admin_table_content" ref="historyTable">
			<a-table
				@resizeColumn="handleResizeColumn"
				:columns="columns"
				:data-source="dataList"
				:scroll="{ y: historyTableHeight }"
				@change="changePage"
				:pagination="{
					showSizeChanger: true,
					current: currentPage,
					pageSize: pageSize,
					total: total,
					showQuickJumper: true,
					bordered: false,
				}"
			>
			</a-table>
		</div>
    </div>
</template>
<script lang="ts">
import { defineComponent, ref, createVNode, computed } from "vue";
import { Https } from "@/tool/https";
export default defineComponent({
    components: {
    },
    setup() {
        let rangePickerValue: any = ref([]);
        let rangeTimeValue: any = ref([]);
        let renameData: any = ref({}); //修改名字选中的数据
        const columns: any = computed(() => {
            return [
                {
                    title: 'Email',
                    align: "center",
                    ellipsis: true,
                    dataIndex: "userEmail",
                    key: "userEmail",
                },
				{
                    title: 'User Id',
                    align: "center",
                    ellipsis: true,
                    dataIndex: "accountId",
                    key: "accountId",
                },
                {
                    title: 'User Name',
                    align: "center",
                    ellipsis: 200,
                    dataIndex: "userName",
                    key: "userName",
                    // customRender: (record: any) => {
                    //     let time = formatTime(
                    //         record.text / 1000,
                    //         "YYYY-MM-DD hh:mm:ss"
                    //     );
                    //     return time;
                    // },
                },
				{
                    title: 'isTrial',
                    align: "center",
                    ellipsis: true,
                    dataIndex: "isTrial",
                    key: "isTrial",
					   customRender: (record: any) => {
                        let str
						if(record.value == 1){
							str ='Yes'
						}else{
							str ='No'
						}
                        return str;
                    },
                },
                {
                    title: 'Frequency',
                    align: "center",
                    ellipsis: true,
                    dataIndex: "designTimes",
                    key: "designTimes",
                },
				{
                    title: 'Country',
                    align: "center",
                    ellipsis: true,
                    dataIndex: "country",
                    key: "country",
                },
				{
                    title: 'Title',
                    align: "center",
                    ellipsis: true,
                    dataIndex: "title",
                    key: "title",
                },
				{
                    title: 'Surname',
                    align: "center",
                    ellipsis: true,
                    dataIndex: "surname",
                    key: "surname",
                },
				{
                    title: 'Given Name',
                    align: "center",
                    ellipsis: true,
                    dataIndex: "givenName",
                    key: "givenName",
                },
				{
                    title: 'Create Time',
                    align: "center",
                    ellipsis: true,
					// width: 150,
					// minWidth: 100,
        			// maxWidth: 200,
					// resizable: true,
                    dataIndex: "createTime",
                    key: "createTime",
                },
				{
                    title: 'Occupation',
                    align: "center",
                    ellipsis: true,
					// width: 150,
					// minWidth: 100,
        			// maxWidth: 200,
					// resizable: true,
                    dataIndex: "occupation",
                    key: "occupation",
                },
				{
                    title: 'Trial Order Id',
                    align: "center",
                    ellipsis: true,
					// width: 150,
					// resizable: true,
                    dataIndex: "trialOrderId",
                    key: "trialOrderId",
                },
            ];
        });

		let state:any = ref([
			{
				name:'all',
				value:'',
			},
			{
				name:'unprocessed',
				value:0,
			},
			{
				name:'pending',
				value:1,
			},
			{
				name:'rejected',
				value:2,
			},
		])
        let dataList: any = ref([]);
        let status: any = ref(0);
        return {
            rangePickerValue,
			rangeTimeValue,
            columns,
            dataList,
            renameData,
            status,
			state,
        };
    },
    data() {
        return {
            currentPage: 1,
            pageSize: 10,
            total: 0,
            historyTableHeight: 0,
			handleResizeColumn: (w:any, col:any) => {
				col.width = w;
			},
        };
    },
    mounted() {
        let historyTable: any = this.$refs.historyTable;
        this.historyTableHeight = historyTable.clientHeight - 200;
        this.gettrialList();
    },
    methods: {
        //改变页码
        changePage(e: any) {
            this.currentPage = e.current;
            this.pageSize = e.pageSize;
            // this.gettrialList();
        },

        //查询列表
        searchHistoryList() {
            this.currentPage = 1;
            this.gettrialList();
        },

		//获取列表
        gettrialList() {
			let startTime: any = this.rangeTimeValue[0]
                ? this.rangeTimeValue[0]
                : '00:00:00';
            let endTime: any = this.rangeTimeValue[1]
                ? this.rangeTimeValue[1]
                : '00:00:00';
			let startDate: any = this.rangePickerValue[0]
                ? this.rangePickerValue[0]+' '+startTime
                : "";
            let endDate: any = this.rangePickerValue[1]
                ? this.rangePickerValue[1]+' '+endTime
                : "";
			let data = {
				endTime:endDate,
				startTime:startDate,
			}
			Https.axiosGet(Https.httpUrls.getDesignStatistic,{params:data}).then((rv: any) => {
				if (rv) {
					this.dataList = rv
					// this.workspaceItem.position = this.singleTypeList[0].label
				}
			})
        },
		
        //删除分组
        // deleteGroup(record: any, index: number) {
        //     let deleteGroupFun = (id: any, index: number) => {
        //         let data = {
        //             userGroupId: id,
        //         };
        //         Https.axiosPost(Https.httpUrls.deleteUserGroup, data).then(
        //             (rv: any) => {
        //                 this.dataList.splice(index, 1);
        //             }
        //         );
        //     };
        //     Modal.confirm({
        //         title: "",
        //         icon: createVNode(ExclamationCircleOutlined),
        //         okText: "Yes",
        //         cancelText: "No",
        //         centered: true,
        //         mask: false,
        //         onOk() {
        //             deleteGroupFun(record.id, index);
        //         },
        //     });
        // },
		
		
    },
});
</script>
