<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">一卡通卡号</label>
        <el-input v-model="query.cardNumber" clearable placeholder="一卡通卡号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">消费时间</label>
        <date-range-picker
          v-model="query.rechargeTime"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          class="date-item"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--详情组件-->
      <el-dialog :close-on-click-modal="true" :visible.sync="detailDialog" title="消费记录详情" width="500px">
        <el-descriptions :column="2">
          <el-descriptions-item label="卡号">{{ detail.cardNumber }}</el-descriptions-item>
          <el-descriptions-item label="持卡人姓名">{{ detail.userName }}</el-descriptions-item>
          <!-- <el-descriptions-item label="持卡人种类">{{ detail.user && dict.label.user_type[detail.user.usertype] }}</el-descriptions-item> -->
          <el-descriptions-item label="持卡人手机号">{{ detail.userPhone }}</el-descriptions-item>
          <el-descriptions-item label="消费金额">{{ detail.rechargeAmount }}</el-descriptions-item>
          <el-descriptions-item label="消费后金额">{{ detail.amountAfterRecharge }}</el-descriptions-item>
          <el-descriptions-item label="消费时间">{{ detail.rechargeTime }}</el-descriptions-item>
        </el-descriptions>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column prop="cardNumber" label="一卡通卡号" />
        <el-table-column prop="userName" label="持卡人姓名" />
        <!-- <el-table-column prop="user.usertype" label="持卡人种类">
          <template slot-scope="scope">
            {{ scope.row.user && dict.label.user_type[scope.row.user.usertype] }}
          </template>
        </el-table-column> -->
        <el-table-column prop="userPhone" label="持卡人手机号" />
        <el-table-column prop="rechargeAmount" label="消费金额" />
        <el-table-column prop="amountAfterRecharge" label="消费后金额" />
        <el-table-column prop="content" label="消费内容" />
        <el-table-column prop="rechargeTime" label="消费时间" />
        <el-table-column v-if="checkPer(['admin','dmRechargeRecord:edit','dmRechargeRecord:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <!-- <udOperation
              :data="scope.row"
              :permission="permission"
            /> -->
            <el-button size="mini" type="primary" icon="el-icon-tickets" @click="toDetail(scope.row)" />
            <!-- <el-button v-permission="permission.edit" :loading="crud.status.cu === 2" size="mini" type="primary" icon="el-icon-edit" @click="crud.toEdit(scope.row)" /> -->
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDmExpenseCalendar from '@/api/dmExpenseCalendar'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
// import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker/index'

const defaultForm = { id: null, userNumber: null, cardNumber: null, rechargeAmount: null, amountAfterRecharge: null, rechargeTime: null, content: null }
const optShow = {
  add: false,
  edit: false,
  del: false,
  download: true,
  reset: true
}
export default {
  name: 'DmExpenseCalendar',
  components: { pagination, crudOperation, rrOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['user_type'],
  cruds() {
    return CRUD({ title: '/api/dmExpenseCalendar', url: 'api/dmExpenseCalendar', idField: 'id', sort: 'rechargeTime,desc', crudMethod: { ...crudDmExpenseCalendar }, optShow })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'dmExpenseCalendar:add'],
        edit: ['admin', 'dmExpenseCalendar:edit'],
        del: ['admin', 'dmExpenseCalendar:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'cardNumber', display_name: '一卡通卡号' }
      ],
      detailDialog: false,
      detail: {}
    }
  },
  methods: {
    toDetail(row) {
      this.detail = row
      this.$forceUpdate()
      this.detailDialog = true
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
