<template>
  <div v-if="allow.includes('financePropertyList')">
    <gridToolbar
			:query.sync="query"
			@refresh="refresh"
			:selectOptions="selectOptions"
			:showAdd="false" />
    <data-grid
			:api="request_api.finance_property"
			:query="requestQuery"
			ref="dataGrid"
			@change="handleChange">
      <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="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="历史累积总额"
				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="is_lock"
				:filters="columnFilters(lock_options)"
				:filterMultiple="false">
        <template slot-scope="value, record">
					<a-tag :color="['green', 'red'][value] || 'red'" @click="lock(record, 'financePropertyLock')">{{ value | lock }}</a-tag>
        </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="memo" class="memo" :customCell="cellTitle('memo')" />
      <a-table-column title="操作" v-if="allow.includes('financePropertyDetail')">
				<div class="table-btn-group" slot-scope="text, record">
					<a-button @click="detail(record)" type="primary" v-authority="'financePropertyDetail'">资金明细</a-button>
					<a-button @click="correct(record)" v-authority="'financePropertyCorrect'">修正</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 store from '../../store'
export default {
	mixins: [common, mix, tableFilter, finance()],
	components: {
		DataGrid, gridToolbar, userInfo
	},
  data() {
    return {
      // 混入配置
      mixConofig: {
        apiName: 'finance_property'
			}
    }
	},
	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: '请输入完整的手机号' }
			]
		}
	},
  activated() {
		if (!this.property_type_cas || !this.property_type_cas.length) store.dispatch('getPropertyType')
  },
	methods: {
		detail (v) {
			if (!v.uuid) return
			this.$router.push({
				name: 'financePropertyDetail',
				params: {
					login_id: v.login_id
				}
			})
		},
		correct (v) {
			this._fnModal.propertyCorrect({
        title: '临时修正资产',
        width: 520,
        data: v,
        done: () => this.refresh()
      })
		}
	}
}
</script>
