<template>
  <div v-if="allow.includes('financeAccountingSnapshotList')">
    <gridToolbar
			:query="query"
			@submitQuery="submitQuery"
			@refresh="refresh"
			:showAdd="false"
			:selectOptions="selectOptions"
			:defaultSelected="defaultSelected">
			<a-form-model-item label="起止时间">
				<a-range-picker
					v-model="date_range"
					style="width: 300px"
					:ranges="ranges"
					:show-time="{
						hideDisabledOptions: true,
						format: 'HH:mm',
						defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('11:59:59', 'HH:mm:ss')],
					}"
			    format="YYYY-MM-DD HH:mm"
					:placeholder="['开始时间', '结束时间']" />
			</a-form-model-item>
		</gridToolbar>
    <data-grid
			v-if="onOff"
			:api="request_api.finance_accounting_snapshot"
			:query="requestQuery"
			ref="dataGrid"
			@change="handleChange">
      <a-table-column
				title="资产类型"
				dataIndex="property_type">
				<div class="multi_line" slot-scope="text, record" v-if="property_type_cas_obj[text]">
					<span>{{ property_type_cas_obj[text].name }}</span>
					<span>{{ property_type_cas_obj[text][record.property_coin_type] }}</span>
				</div>
      </a-table-column>
      <a-table-column
				title="用户信息"
				align="left"
				dataIndex="real_name">
        <template slot-scope="text, record">
					<user-info
						:name="text"
						:user_id="record.login_id"
						:phone="record.phone"
						:email="record.email" />
        </template>
      </a-table-column>
      <a-table-column
				title="是否锁定"
				dataIndex="is_lock"
				:filters="columnFilters(lock_options)"
				:filterMultiple="false">
        <template slot-scope="value"><a-tag :color="['green', 'red'][value] || 'red'">{{ value | lock }}</a-tag></template>
      </a-table-column>
      <a-table-column
				title="历史累积总额"
				dataIndex="history_total_count"
				:sorter="true"
				:sortOrder="sortedInfo.columnKey === 'history_total_count' && sortedInfo.order">
        <template slot-scope="text">{{ text | setZero }}</template>
      </a-table-column>
      <a-table-column
				title="总额"
				dataIndex="total_count"
				:sorter="true"
				:sortOrder="sortedInfo.columnKey === 'total_count' && sortedInfo.order">
        <template slot-scope="text">{{ text | setZero }}</template>
      </a-table-column>
      <a-table-column
				title="冻结金额"
				dataIndex="total_freeze_count"
				:sorter="true"
				:sortOrder="sortedInfo.columnKey === 'total_freeze_count' && sortedInfo.order">
        <template slot-scope="text">{{ text | setZero }}</template>
      </a-table-column>
      <a-table-column title="创建/更新时间" dataIndex="created_date">
        <template slot-scope="text, record">
					<div class="multi_line">
						<span>{{ text | moment }}</span>
						<span>{{ record.updated_date | moment }}</span>
					</div>
        </template>
      </a-table-column>
			<a-table-column
				title="状态"
				dataIndex="status"
				:filters="columnFilters(finance_accounting_options)"
				:filterMultiple="false">
        <template slot-scope="value">{{ value | finance_accounting }}</template>
      </a-table-column>
      <a-table-column
				title="异常信息"
				dataIndex="exception_info"
				:customCell="() => ({class: 'word_wrap_medium'})" />
      <a-table-column title="备注" dataIndex="memo" class="memo" :customCell="cellTitle('memo')" />
      <a-table-column title="操作">
				<div class="table-btn-group" slot-scope="text, record">
					<a-button @click="edit(record)" type="primary">详情</a-button>
				</div>
      </a-table-column>
    </data-grid>
  </div>
</template>

<script>
import DataGrid from '../../components/DataGrid'
import gridToolbar from '../../components/gridToolbar/default'
import userInfo from '../../components/info/user'

import mix from '../../mixins/mixins'
import tableFilter from '../../mixins/tableFilter'
import finance from '../../mixins/finance'
import common from '../../mixins/common'
import momentDate from '../../mixins/momentDate'

import store from '../../store'
export default {
	mixins: [common, mix, tableFilter, finance(), momentDate],
	components: {
		DataGrid, gridToolbar, userInfo
	},
  data() {
    return {
			onOff: false,
			date_range: [],
      // 混入配置
      mixConofig: {
        editTitle: '核算快照详情',
        modalName: 'accountingSnapshot',
        modalWidth: 900
      }
    }
	},
	computed: {
		property_type_cas() {
			return store.state.property_type_cas || []
		},
		property_type_cas_obj() {
			return store.getters.property_type_cas_obj || []
		},
		selectOptions () {
			return [
				{ label: '模糊搜索', value: 'keyword', placeholder: '关键词' },
				{ label: '用户ID', value: 'login_id', placeholder: '请输入完整的用户ID' },
				{ label: '用户名', value: 'real_name', placeholder: '请输入完整的用户名' },
				{ label: '用户邮箱', value: 'email', placeholder: '请输入完整的邮箱号' },
				{ label: '用户手机', value: 'phone', placeholder: '请输入完整的手机号' },
				{ label: '快照组UUID', value: 'snapshot_group_uuid', placeholder: '请输入快照组的UUID' }
			]
		},
		defaultSelected() {
			if (this.$route.params.snapshot_group_uuid) return 'snapshot_group_uuid'
			return 'keyword'
		}
	},
  activated () {
		this.onOff = true
		if (!this.property_type_cas || !this.property_type_cas.length) store.dispatch('getPropertyType')
		let { domain } = this.$route.query
		if (domain) {
			this.$router.replace(this.$route.path)
		}
		this.query = {
			...(domain && { product_content: domain }),
			...(this.$route.params.snapshot_group_uuid && { [this.defaultSelected]: this.$route.params.snapshot_group_uuid || '' })
		}
	},
	deactivated () {
		this.onOff = false
		this.resetQuery()
	},
	methods: {
		submitQuery(_query) {
			this.query = _query
			this.extendQuery = {
				...(this.date_range[0] && { date_from: new Date(this.date_range[0]).getTime() * 1000000 }),
				...(this.date_range[1] && { date_end: new Date(this.date_range[1]).getTime() * 1000000 })
			}
		}
	}
}
</script>