<template>
  <div v-authority="'financeOrderList'">
    <gridToolbar
			:query.sync="query"
			@refresh="refresh"
			:selectOptions="selectOptions"
			:showAdd="false" />
    <data-grid
			:api="request_api.finance_order"
			:query="requestQuery"
			ref="dataGrid"
			@change="handleChange">
      <a-table-column
				title="所属平台"
				dataIndex="platform_code">
        <template slot-scope="text">{{ text | platform_code }}</template>
      </a-table-column>
      <!-- <a-table-column title="标题" dataIndex="title" class="memo" :customCell="cellTitle('title')" /> -->
      <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="total_amount"
				:sorter="true"
				:sortOrder="sortedInfo.columnKey === 'total_amount' && sortedInfo.order">
        <template slot-scope="text">{{ text | setZero }}</template>
      </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="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="is_privacy_protect">
        <template slot-scope="value">
					<a-tag :color="['red', 'green'][value]">{{ value | open }}</a-tag>
        </template>
      </a-table-column>
      <a-table-column
				title="状态"
				dataIndex="status"
				:filters="columnFilters(order_status_options)"
				:filterMultiple="false">
        <template slot-scope="value">
					<a-tag :color="['orange', 'green', 'red', 'blue'][value - 1]">{{ value | order_status }}</a-tag>
				</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)" type="primary">详情</a-button>
					<a-button @click="detail(record)" type="link" v-authority="'financeOrderDetail'">订单明细</a-button>
					<a-button
						v-if="allow.includes('financeOrderStatus') && allow.includes('financeOrderRelatedPayment') && record.status === 6"
						@click="preRefundStatus(record)">预退款状态</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: {
        editTitle: '订单详情',
        modalName: 'order​Main',
        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: '请输入完整的手机号' }
			]
		}
	},
  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: 'financeOrderDetail',
				params: {
					main_order_uuid: v.uuid
				}
			})
		},
		preRefundStatus (v) {
			this._fnModal.preRefundStatus({
        title: '判定主订单预退款状态',
        width: 700,
        data: v,
        done: () => this.refresh()
      })
		}
	}
}
</script>
