<template>
  <div v-authority="'financeProductList'">
    <gridToolbar
			:query.sync="query"
			@refresh="refresh"
			@add="add"
			addAuthority="financeProductAdd" />
    <data-grid
			:api="request_api.finance_product"
			: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_name" />
      <a-table-column
				title="产品编码"
				dataIndex="product_code"
				:filterIcon="filterSearchIcon"
				:filterDropdown="filterSearchDropdown" />
      <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="description" class="memo" :customCell="cellTitle('description')" />
      <a-table-column title="备注" dataIndex="memo" class="memo" :customCell="cellTitle('memo')" />
      <a-table-column title="操作" v-if="allow.includes('financeProductEdit') || allow.includes('financeProductDel') || allow.includes('financeProductPrice')">
				<div class="table-btn-group" slot-scope="text, record">
					<a-button @click="toPrice(record)" v-authority="'financeProductPrice'">产品价格</a-button>
					<a-button @click="edit(record)" v-authority="'financeProductEdit'">编辑</a-button>
          <a-popconfirm
            title="是否确定删除?"
            v-authority="'financeProductDel'"
            @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'

export default {
	mixins: [common, mix, tableFilter],
	components: {
		DataGrid, gridToolbar
	},
  data() {
    return {
      // 混入配置
      mixConofig: {
        addTitle: '新增产品',
        editTitle: '编辑产品',
        apiName: 'finance_product',
        modalName: 'financeProduct',
        modalWidth: 600,
				actionsDone: () => {
					this.$store.dispatch('getProduct')
				}
      }
    }
	},
  methods: {
    toPrice(v) {
			if (!v.uuid) return
			this.$router.push({
				name: 'financeProductPrice',
				params: {
					product_uuid: v.uuid
				}
			})
    }
  }
}
</script>
