<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">id</label>
        <el-input v-model="query.id" clearable placeholder="id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">支付方式</label>
        <el-input v-model="query.payType" clearable placeholder="支付方式" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">店铺Id</label>
        <el-input v-model="query.shopId" clearable placeholder="店铺Id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">交易单号（第三方交易单号）</label>
        <el-input v-model="query.transactionId" clearable placeholder="交易单号（第三方交易单号）" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">金额</label>
        <el-input v-model="query.amount" clearable placeholder="金额" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">状态 </label>
        <el-input v-model="query.status" clearable placeholder="状态 " style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">备注</label>
        <el-input v-model="query.remark" clearable placeholder="备注" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">到期时间</label>
        <el-input v-model="query.expiredAt" clearable placeholder="到期时间" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">创建时间</label>
        <el-input v-model="query.createdAt" clearable placeholder="创建时间" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="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="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支付方式">
            <el-input v-model="form.payType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="店铺Id">
            <el-input v-model="form.shopId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="交易单号（第三方交易单号）">
            <el-input v-model="form.transactionId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="金额" prop="amount">
            <el-input v-model="form.amount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="状态 ">
            <el-input v-model="form.status" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="到期时间">
            <el-input v-model="form.expiredAt" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建时间">
            <el-input v-model="form.createdAt" 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-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="id" label="id" />
        <el-table-column prop="payType" label="支付方式">
          <template slot-scope="scope">
            {{ dict.label.pay_type[scope.row.payType] }}
          </template>
        </el-table-column>
        <el-table-column prop="shopId" label="店铺Id" />
        <el-table-column prop="transactionId" label="交易单号（第三方交易单号）" />
        <el-table-column prop="amount" label="金额" />
        <el-table-column prop="status" label="状态 ">
          <template slot-scope="scope">
            {{ dict.label.renewals_status[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" />
        <el-table-column prop="expiredAt" label="到期时间" />
        <el-table-column prop="createdAt" label="创建时间" />
        <el-table-column v-if="checkPer(['admin','tbRenewalsPayLog:edit','tbRenewalsPayLog:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudTbRenewalsPayLog from '@/api/tbRenewalsPayLog'
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'

const defaultForm = { id: null, payType: null, shopId: null, orderId: null, openId: null, userId: null, transactionId: null, amount: null, status: null, remark: null, attach: null, expiredAt: null, createdAt: null, updatedAt: null }
export default {
  name: 'TbRenewalsPayLog',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['pay_type', 'renewals_status'],
  cruds() {
    return CRUD({ title: '/shop/renewals', url: 'api/tbRenewalsPayLog', idField: 'id', sort: 'id,desc', crudMethod: { ...crudTbRenewalsPayLog }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'tbRenewalsPayLog:add'],
        edit: ['admin', 'tbRenewalsPayLog:edit'],
        del: ['admin', 'tbRenewalsPayLog:del']
      },
      rules: {
        amount: [
          { required: true, message: '金额不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'id', display_name: 'id' },
        { key: 'payType', display_name: '支付方式' },
        { key: 'shopId', display_name: '店铺Id' },
        { key: 'transactionId', display_name: '交易单号（第三方交易单号）' },
        { key: 'amount', display_name: '金额' },
        { key: 'status', display_name: '状态 ' },
        { key: 'remark', display_name: '备注' },
        { key: 'expiredAt', display_name: '到期时间' },
        { key: 'createdAt', display_name: '创建时间' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
