<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="false" :before-close="crud.cancelCU" :visible="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="用户">
            <el-input v-model="form.userNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="卡号">
            <el-input v-model="form.cardNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="充值金额">
            <el-input v-model="form.rechargeAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="充值后金额">
            <el-input v-model="form.amountAfterRecharge" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="充值时间">
            <el-date-picker v-model="form.rechargeTime" type="datetime" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--详情组件-->
      <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.user && detail.user.contacts }}</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="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 crudDmRechargeRecord from '@/api/dmRechargeRecord'
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 }
const optShow = {
  add: false,
  edit: false,
  del: false,
  download: true,
  reset: true
}
export default {
  name: 'DmRechargeRecord',
  components: { pagination, crudOperation, rrOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['user_type'],
  cruds() {
    return CRUD({ title: 'api/dmRechargeRecord', url: 'api/dmRechargeRecord', idField: 'id', sort: 'rechargeTime,desc', crudMethod: { ...crudDmRechargeRecord }, optShow })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'dmRechargeRecord:add'],
        edit: ['admin', 'dmRechargeRecord:edit'],
        del: ['admin', 'dmRechargeRecord: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>
