<template>
    <d2-container>
        <div class="d2-table-view-full">
            <div class="d2-table-view-header">
                <el-form label-width="100px" labelPosition="right" size="small" :inline="true" :model="filter"
                         @keyup.enter.native="handleList" class="demo-form-inline">
                    <el-form-item label="车牌号码">
                        <el-input style="width: 192px" v-model.trim="filter.vehicleNo" placeholder="车牌号码" clearable/>
                    </el-form-item>
                    <el-form-item label="使用状态" prop="veUseSts">
                        <el-select v-model="filter.veUseSts" placeholder="请选择" clearable>
                            <el-option  label="正常" value="0"></el-option>
                            <el-option  label="已退卡" value="1"></el-option>
                            <!--<el-option  label="已报停" value="2"></el-option>-->
                            <!--<el-option  label="已过期" value="3"></el-option>-->
                        </el-select>
                    </el-form-item>
                    <el-form-item label="发行时间">
                        <el-date-picker
                                v-model="time"
                                type="datetimerange"
                                value-format="yyyy-MM-dd"
                                @change="dateChange"
                                range-separator="至"
                                start-placeholder="开始时间"
                                end-placeholder="结束时间">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="handleList('1')">查询</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <!--<div class="d2-table-view-header">-->
                <!--<el-form label-width="100px" labelPosition="center" size="small" :inline="true" :model="form"-->
                         <!--class="demo-form-inline">-->
                    <!--<el-form-item label=" 退卡金额">-->
                       <!-- <el-input style="width: 192px" v-model.trim="form.blockRefund" placeholder="0" clearable/>-->
                    <!--</el-form-item>-->
                    <!--<el-form-item>-->
                        <!--<el-button   type="primary" @click="onBackCardClick">退卡</el-button>-->
                    <!--</el-form-item>-->
                <!--</el-form>-->
            <!--</div>-->
            <div class="d2-table-view-content">
                <div class="d2-table-view-handle">
                </div>
                <d2-crud
                        title="车牌号"
                        ref="d2Crud"
                        :options="tableOptions"
                        :loading="loading"
                        :rowHandle="rowHandle"
                        :columns="columns"
                        :data="data"
                        @delete="handleRowRemove"
                >
                </d2-crud>
            </div>
            <div class="d2-table-view-footer">
                <el-pagination
                        @current-change="handleCurrentChange"
                        @size-change="handleSizeChange"
                        :page-size="tableOptions.pageList[0]"
                        :page-sizes="tableOptions.pageList"
                        :current-page.sync="currentPage"
                        layout="total,sizes, prev, pager, next,jumper"
                        :total="pagination.total"
                ></el-pagination>
            </div>
        </div>
    </d2-container>
</template>
<script>
  import { tableOptions } from '@/assets/options'
  import {getCarCateOptions} from '@/api/parking/mangeCar/userRights'
  import {getBackCardList,submitBackCard} from '@/api/parking/mangeCar/backCard'
  export default {
    name: 'cateUser',
    components: {

    },
    data () {
      return {
        options1:[],
        flag:true,
        time:"",
        options:[],
        userId:"",
        staLoading: false,
        func: {
          add: false,
          delete: false,
          update: false,
          select: false
        },
        falg: true,
        isExpend: true,
        tableOptions,
        loading: false,
        lanuchs: [],
        filter: {
          pageSize: 10,
          pageNum: 1,
          bgTm: '',
          endTm: '',
          vehicleNo: '',
          veUseSts: ''
        },
        pagination: {
          total: 0
        },
        currentPage: 1,
        treeData: [],
        defaultProps: {
          children: 'children',
          label: 'name'
        },
        columns: [
          {
            title: '用户编号',
            key: 'userNo',
            minWidth: '120',
            showOverflowTooltip: true
          },
          {
            title: '用户名称',
            key: 'userNm',
            minWidth: '140',
            showOverflowTooltip: true
          },
          {
            title: '部门名称',
            key: 'depNm',
            minWidth: '90',
            showOverflowTooltip: true
          },
          {
            title: '车牌编号',
            key: 'vehicleNo',
            minWidth: '150',
            showOverflowTooltip: true
          },
          {
            title: '使用状态',
            key: 'veUseSts',
            minWidth: '90',
            formatter (row, column, cellValue, index) {
              if (cellValue === "0") {
                return '正常'
              }else if(cellValue === "1"){
                return '已退卡'
              }else if(cellValue === "2"){
                return '已报停'
              }else if(cellValue === "3"){
                return '已过期'
              }
            }
          },
          {
            title: '车辆类别',
            key: 'carTypNm',
            minWidth: '120',
            showOverflowTooltip: true
          },
          {
            title: '有效起始日',
            key: 'bgTm',
            minWidth: '180',
            showOverflowTooltip: true
          },
          {
            title: '有效终止日',
            key: 'endTm',
            minWidth: '180',
            showOverflowTooltip: true
          },
          {
            title: '押金',
            key: 'costDeposit',
            minWidth: '90',
            showOverflowTooltip: true
          },
          {
            title: '储值金额',
            key: 'accountMoney',
            minWidth: '90',
            showOverflowTooltip: true
          },
          // {
          //   title: '车位编号',
          //   key: 'areaNm',
          //   minWidth: '150',
          //   showOverflowTooltip: true
          // },
          {
            title: '卡号',
            key: 'cardId',
            minWidth: '120',
            showOverflowTooltip: true
          },
          {
            title: '车牌颜色',
            key: 'vehicleColor',
            minWidth: '120',
            showOverflowTooltip: true
          },
        ],
        rowHandle: {
          columnHeader: '操作',
          minWidth: '180',
          align: 'center',
          custom: [
            {
              text: '退卡',
              type: 'danger',
              size: 'small',
              emit: 'delete'
            }
          ]
        },
        data: [],
      }
    },

    methods: {
      // clearform(){
      //   this.form={}
      // },
      onBackCardClick(){

      },
      dateChange (val) {
        if(val == null){
          this.filter.bgTm = ''
          this.filter.endTm = ''
        }else{
          this.filter.bgTm = val[0]
          this.filter.endTm = val[1]
        }
      },
      handleTreeNode () {
        this.handleList()
      },
      handleList (val) {
        if (val) {
          this.filter.pageNum = 1
          this.currentPage = 1
        }
        this.loading = true
        getBackCardList(this.filter)
          .then(res => {
            this.loading = false
            this.data = res.page.list
            this.pagination.total = res.page.total
          })
          .catch(err => {
            this.loading = false
          })
      },
      handleCurrentChange (val) {
        this.filter.pageNum = val
        this.handleList()
      },
      handleSizeChange (val) {
        this.filter.pageNum = 1
        this.filter.pageSize = val
        this.handleList()
      },
      handleRowRemove ({index, row}) {
        if(row.veUseSts==="1"){
          this.$message({
            message: '已退卡',
            type: 'warning'
          })
          return
        }
        let messageNo=`储值余额为${row.accountMoney},确定退卡吗`
        this.$confirm(messageNo, '确认操作', {
          confirmButtonText: '确定',
          cancelButtonText: '放弃',
          type: 'warning'
        }).then(() => {
          submitBackCard({veId:row.veId,userId:row.userId}).then(res=>{
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.handleTreeNode()
          })
        })
      },
    },
    mounted () {
      getCarCateOptions().then(res=>{
        this.options1=res.list
      })
      this.filter.pageSize = this.tableOptions.pageList[0]
      this.tableOptions = this.$calcTableHeight(tableOptions, 102)
      this.handleTreeNode()
    }
  }
</script>
<style>
    .d2-table-view-header .el-radio{
        margin-right: 15px;
    }
    .d2-table-view-full{
        height: 100%;
    }
    .timeBox{
        margin-top: 10px;
    }
    .timePay{
        margin-left: 8px;
    }
    .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    .avatar-uploader .el-upload:hover {
        border-color: #409eff;
    }

    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }

    .avatar {
        width: 178px;
        height: 178px;
        display: block;
    }
    .timeLabel label{
        width: 110px !important;
    }
    .bankLabel label{
        font-size: 13px;
    }
    .el-form-item__label {
        text-align: left !important;
    }
    .d2-table-view{
        overflow: hidden;
    }
    .d2-table-view-content{
        height: 100%;
    }
    .el-table{
        height: 450px !important;
    }
</style>