<template>
  <div v-authority="'financeProductPrice'">
    <gridToolbar
			:query.sync="query"
			@refresh="refresh"
			@add="add"
			addAuthority="financeProductPriceAdd" />
    <data-grid
			v-if="onOff"
			:api="request_api.finance_product_price"
			:query="requestQuery"
			ref="dataGrid"
			@change="handleChange">
      <a-table-column
				title="所属平台"
				dataIndex="platform_code"
				:filters="columnFilters(platform_code_options)"
				:filterMultiple="false">
        <template slot-scope="text">{{ text | platform_code }}</template>
      </a-table-column>
      <a-table-column
				title="产品"
				dataIndex="product_uuid"
				:defaultFilteredValue="$route.params.product_uuid && onOff ? [$route.params.product_uuid] : null"
				:filters="columnFilters(product_options)"
				:filterMultiple="false">
        <template slot-scope="text">{{ product_obj[text] || text }}</template>
      </a-table-column>
      <a-table-column
				title="产品编码"
				dataIndex="product_code"
				:filterIcon="filterSearchIcon"
				:filterDropdown="filterSearchDropdown" />
      <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="actual_sell_price">
				<div class="multi_line" slot-scope="text, record">
					<span>成本价: {{ record.cost_price }}</span>
					<span>原定出售价: {{ record.sell_price }}</span>
					<span>实际出售价: {{ text }}</span>
				</div>
      </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('financeProductPriceEdit') || allow.includes('financeProductPriceDel')">
				<div class="table-btn-group" slot-scope="text, record">
					<a-button @click="edit(record)" v-authority="'financeProductPriceEdit'">编辑</a-button>
          <a-popconfirm
            title="是否确定删除?"
            v-authority="'financeProductPriceDel'"
            @confirm="del(record)">
            <a-button :loading="record.deleting" type="danger">删除</a-button>
          </a-popconfirm>
				</div>
      </a-table-column>
    </data-grid>
  </div>
</template>
<script>
import DataGrid from '../../components/DataGrid'
import gridToolbar from '../../components/gridToolbar/default'

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

import store from '../../store'
export default {
	mixins: [common, mix, tableFilter],
	components: {
		DataGrid, gridToolbar
	},
  data() {
    return {
			onOff: false,
      // 混入配置
      mixConofig: {
        addTitle: '新增产品价格',
        editTitle: '编辑产品价格',
        apiName: 'finance_product_price',
        modalName: 'financeProductPrice',
        modalWidth: 600
      }
    }
	},
  activated () {
		this.onOff = true
    if (!this.product || !this.product.length) store.dispatch('getProduct')
		if (!this.property_type_cas || !this.property_type_cas.length) store.dispatch('getPropertyType')
  },
	deactivated () {
		this.onOff = false
		this.resetQuery()
	},
  computed: {
    product() {
      return store.state.product || []
    },
    product_options() {
      return store.getters.product_options || []
    },
    product_obj() {
      return store.getters.product_obj || {}
    },
		property_type_cas() {
			return store.state.property_type_cas || []
		},
		property_type_cas_obj() {
			return store.getters.property_type_cas_obj || {}
		},
		extendQuery() {
			return {
				...(this.$route.params.product_uuid && this.onOff && { product_uuid: this.$route.params.product_uuid })
			}
		}
  }
}
</script>
