<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="paramCode">
                        <custom-select :value="filter.paramCode" v-model="filter.paramCode" typeName="停车卡类型" style="width: 100%"></custom-select>
                    </el-form-item>
                    <!--<el-form-item label="车辆类别" prop="carTypId">-->
                        <!--<el-select v-model="filter.carTypId" placeholder="请选择" clearable>-->
                            <!--<el-option-->
                                    <!--v-for="item in options1"-->
                                    <!--:key="item.carTypId"-->
                                    <!--:label="item.carTypNm"-->
                                    <!--:value="item.carTypId">-->
                            <!--</el-option>-->
                        <!--</el-select>-->
                    <!--</el-form-item>-->
                    <el-form-item label="停车区域" prop="areaId" >
                        <el-select v-model="filter.areaId" placeholder="请选择" style="width: 100%" clearable>
                            <el-option
                                    v-for="item in options"
                                    :key="item.areaId"
                                    :label="item.areaNm"
                                    :value="item.areaId">
                            </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-content">
                <div class="d2-table-view-handle">
                    <!--<el-button @click="onCreateClick" size="small" icon="el-icon-plus">新增</el-button>-->
                    <!--<el-button size="small" @click="onMutilDelClick">批量删除</el-button>-->
                </div>
                <d2-crud
                        title="场内车辆报表"
                        ref="d2Crud"
                        :options="tableOptions"
                        :loading="loading"
                        :rowHandle="rowHandle"
                        @edit="handleRowEdit"
                        :columns="columns"
                        :data="data"
                >
                </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>
        <el-dialog
                :title="diaLogName"
                :visible.sync="operVisible"
                @close="clearForm"
                width="40%"
                :close-on-click-modal="false"
        >
            <el-form ref="form" :model="form" label-width="80px" labelPosition="right" :rules="rules">
                <el-row :gutter="15">
                    <el-col :span="22">
                        <el-form-item label="人员编号" prop="userNo">
                            <el-input maxlength="20" disabled v-model="form.userNo"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="22">
                        <el-form-item label="人员姓名" prop="userNm">
                            <el-input maxlength="15" v-model.trim="form.userNm" disabled/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="22">
                        <el-form-item label="车牌号码" prop="vehicleNo">
                            <el-input maxlength="50" v-model.trim="form.vehicleNo"/>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
        <zl-button :loading="staLoading" @click="operInstance">保存</zl-button>
      </span>
        </el-dialog>
    </d2-container>
</template>
<script>
  import { tableOptions } from '../../../../assets/options'
  import {getAreaOptions} from '@/api/parking/costRules'
  import {getCarCateOptions} from '@/api/parking/mangeCar/userRights'
  import {getInnerCarList,editVehicleNo} from '@/api/parking/carExcel/innnerCarExcel'

  export default {
    name: 'cateUser',
    components: {},
    data () {
      return {
        operVisible:false,
        diaLogName:"纠正车牌",
        // options1:[],
        flag:true,
        dateList:[],
        isChangeDate:false,
        veIds:[],
        schannelIds: [],
        schannelIdss: '',
        equipmentOptions: [],
        workStationOptions: [],
        time: '',
        options: [],
        stationId: [],
        stationIds: '',
        isCreate: false,
        userId: '',
        checkList: [],
        // classVisible:false,
        staLoading: false,
        multipleSelection: [],
        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: '',
          paramCode: '',
        areaId:"",
        },
        form: {
          vehicleNo:"",
          userNm:"",
          userNo:"",
          veId:""
        },
        pagination: {
          total: 0
        },
        currentPage: 1,
        treeData: [],
        defaultProps: {
          children: 'children',
          label: 'name'
        },
        columns: [
          {
            title: '序号',
            key: 'index',
            minWidth: '50',
            formatter (row, column, cellValue, index) {
              return index+1
            }
          },
          {
            title: '车牌号码',
            key: 'vehicleNo',
            minWidth: '150',
            showOverflowTooltip: true
          },
          {
            title: '卡片号码',
            key: 'cardId',
            minWidth: '120',
            showOverflowTooltip: true
          },
          // {
          //   title: '车辆类别',
          //   key: 'carTypNm',
          //   minWidth: '140',
          //   showOverflowTooltip: true
          // },
          {
            title: '停车卡类型',
            key: 'paramData',
            minWidth: '120',
            showOverflowTooltip: true
          },
          {
            title: '人员编号',
            key: 'userNo',
            minWidth: '120',
            showOverflowTooltip: true
          },
          {
            title: '人员姓名',
            key: 'userNm',
            minWidth: '140',
            showOverflowTooltip: true
          },
          {
            title: '部门名称',
            key: 'depNm',
            minWidth: '90',
            showOverflowTooltip: true
          },
          {
            title: '入场时间',
            key: 'creTm',
            minWidth: '180',
            showOverflowTooltip: true
          },
          {
            title: '工作站',
            key: 'staticonNm',
            minWidth: '120',
            showOverflowTooltip: true
          },
          {
            title: '入场通道',
            key: 'channelNm',
            minWidth: '90',
            showOverflowTooltip: true
          },
          {
            title: '入场操作员',
            key: 'workNm',
            minWidth: '120',
            showOverflowTooltip: true
          },
          {
            title: '区域名称',
            key: 'areaNm',
            minWidth: '120',
            showOverflowTooltip: true
          },
          {
            title: '备注',
            key: 'rmk',
            minWidth: '120',
            showOverflowTooltip: true
          },
        ],
        rowHandle: {
          columnHeader: '操作',
          minWidth: '180',
          align: 'center',
          custom: [
            {
              text: '纠正车牌',
              type: 'primary',
              size: 'small',
              emit: 'edit'
            },
          ]
        },
        data: [],
        rules:{ vehicleNo:[{required: true, message: '车牌号码不能为空', trigger: 'blur'}],}
      }
    },

    methods: {
      clearForm () {
        if (this.$refs['form']!==undefined) {
          this.$refs['form'].resetFields();
        }
      },
      handleRowEdit ({index, row}) {
        this.diaLogName = '修改车牌号'
        this.form.userNo=row.userNo
        this.form.userNm=row.userNm
        this.form.veId=row.veId
        // this.form.vehicleNo=row.vehicleNo
        this.$set(this.form,"vehicleNo",row.vehicleNo)
        this.operVisible = true
      },
      operInstance (val) {
        this.$refs['form'].validate(valid => {
          if (valid) {
            this.staLoading = true
            editVehicleNo(this.form).then(res => {
              this.staLoading = false
                this.operVisible = false
                this.$message({
                  message: '操作成功',
                  type: 'success'
                })
                this.handleTreeNode()
                this.clearForm()
            }).catch(err => {
              this.staLoading = false
            })
          }
        })
      },
      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
        getInnerCarList(this.filter)
          .then(res => {
            // console.log(res)
            this.loading = false
            this.data = res.pageDriveway.list
            this.pagination.total = res.pageDriveway.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()
      },
    },
    mounted () {
      getAreaOptions().then((res)=>{
        this.options=res.list
      })
      // 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>