<template>
  <div v-if="allow.includes('financeOrderDetail')">
    <gridToolbar
			:query.sync="query"
			@refresh="refresh"
			:showAdd="false"
			:selectOptions="selectOptions"
			:defaultSelected="defaultSelected" />
    <data-grid
			v-if="onOff"
			:api="request_api.finance_order_detial"
			:query="requestQuery"
			ref="dataGrid"
			@change="handleChange">
      <a-table-column
				title="产品内容"
				dataIndex="product_content">
				<div class="domain_box" slot-scope="text">
					<span v-for="(item, i) in split_text(text)" :key="i" :class="{'suffix': i === 1}">{{ item }}</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="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="order_type"
				:filters="columnFilters(order_type_options)"
				:filterMultiple="false">
        <template slot-scope="value">{{ value | order_type }}</template>
      </a-table-column>
			<a-table-column title="价格信息(总金额)" dataIndex="property_type">
        <template slot-scope="text, record">
					<div class="multi_line">
						<div class="line_item">
							<span>成本：</span>
							<a-tag color="blue">{{ record.cost_amount | setZero }}</a-tag>
						</div>
						<div class="line_item">
							<span>出售：</span>
							<a-tag color="blue">{{ record.sell_amount | setZero }}</a-tag>
						</div>
						<!-- <div class="line_item">
							<span>成本：</span>
							<a-tag color="blue">注册:{{ record.cost_price_register }}</a-tag>
							<a-tag color="cyan">续费:{{ record.cost_price_renew }}</a-tag>
							<a-tag color="green">转入:{{ record.cost_price_transfer }}</a-tag>
							<a-tag color="orange">赎回:{{ record.cost_price_redemption }}</a-tag>
						</div>
						<div class="line_item">
							<span>原价：</span>
							<a-tag color="blue">注册:{{ record.sell_price_register }}</a-tag>
							<a-tag color="cyan">续费:{{ record.sell_price_renew }}</a-tag>
							<a-tag color="green">转入:{{ record.sell_price_transfer }}</a-tag>
							<a-tag color="orange">赎回:{{ record.sell_price_redemption }}</a-tag>
						</div>
						<div class="line_item">
							<span>优惠：</span>
							<a-tag color="blue">注册:{{ record.actual_sell_price_register }}</a-tag>
							<a-tag color="cyan">续费:{{ record.actual_sell_price_renew }}</a-tag>
							<a-tag color="green">转入:{{ record.actual_sell_price_transfer }}</a-tag>
							<a-tag color="orange">赎回:{{ record.actual_sell_price_redemption }}</a-tag>
						</div> -->
					</div>
        </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(order_detail_status_options)"
				:filterMultiple="false">
        <template slot-scope="value">{{ value | order_detail_status }}</template>
      </a-table-column>
      <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)" v-if="allow.includes('financeOrderStatus') && [5,8].includes(record.status)">修改</a-button>
					<a-button @click="edit(record)" v-else type="primary">详情</a-button>
					<a-button
						@click="propertyDetail(record, record.property_detail_uuid)"
						:loading="record.p_d_loading"
						type="link"
						v-if="allow.includes('financePropertyDetail') && record.property_detail_uuid">资产明细</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 {
			onOff: false,
      // 混入配置
      mixConofig: {
        editTitle: '订单明细详情',
        modalName: 'order​Detail',
        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: 'main_order_uuid', placeholder: '请输入主订单的UUID' },
				{ label: '域名', value: 'product_content', placeholder: '请输入完整的域名' }
			]
		},
		defaultSelected() {
			if (this.$route.params.main_order_uuid) return 'main_order_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.main_order_uuid && { [this.defaultSelected]: this.$route.params.main_order_uuid || '' })
		}
	},
	deactivated () {
		this.onOff = false
		this.resetQuery()
	}
}
</script>