<template>
  <div class="mod-driverMsg app-container">
    <!-- 卡片视图区域 -->

    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.name" placeholder="驾驶员姓名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.fTel" placeholder="联系电话" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button
          type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <!--        <el-button v-if="isAuth('fleet:driverMsg:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="companyName"
        header-align="center"
        align="center"
        :show-overflow-tooltip="true"
        width="150"
        label="所属公司">
      </el-table-column>
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        width="150"
        label="驾驶员姓名">
      </el-table-column>
      <el-table-column
        prop="fFax"
        header-align="center"
        align="center"
        width="150"
        :formatter="formatSex"
        label="性别">
      </el-table-column>
      <el-table-column
        prop="fContractb"
        header-align="center"
        align="center"
        :show-overflow-tooltip="true"
        width="160"
        :formatter="timestampToTime"
        label="出生日期">
      </el-table-column>
      <el-table-column
        prop="fEaddr"
        header-align="center"
        align="center"
        label="准驾车型">
      </el-table-column>
      <el-table-column
        prop="fContracte"
        header-align="center"
        align="center"
        :show-overflow-tooltip="true"
        :formatter="dateFormat"
        width="160"
        label="初次领证日期">
      </el-table-column>
      <el-table-column
        prop="fScale"
        header-align="center"
        align="center"
        :show-overflow-tooltip="true"
        width="170"
        label="身份证号">
      </el-table-column>
      <el-table-column
        prop="fTel"
        header-align="center"
        align="center"
        width="150"
        label="联系电话">
      </el-table-column>
      <el-table-column
        prop="fAddr"
        header-align="center"
        align="center"
        :show-overflow-tooltip="true"
        label="家庭住址">
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        width="150"
        label="个人照片">
        <template slot-scope="scope">
          　　　　<img v-if="scope.row.registerdAddress? 'true':''" :src="scope.row.registerdAddress" width="80" height="60" class="head_pic"/>
          　　</template>
      </el-table-column>
      <el-table-column
        prop="manageScope"
        header-align="center"
        align="center"
        width="150"
        label="驾驶证照片">
        <template slot-scope="scope">
          　　　　<img v-if="scope.row.manageScope? 'true':''" :src="scope.row.manageScope" width="80" height="60" class="head_pic"/>
          　　</template>
      </el-table-column>
      <el-table-column
        prop="creatTime"
        header-align="center"
        align="center"
        width="160"
        :show-overflow-tooltip="true"
        label="注册时间">
      </el-table-column>

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
<!--          <el-tooltip class="item" effect="dark" content="修改" :enterable="false" placement="top">-->
<!--            <el-button type="primary"-->
<!--                       v-hasPermi="['fleet:driverMsg:edit']"-->
<!--                       icon="el-icon-edit"-->
<!--                       content="修改"-->
<!--                       size="mini"-->
<!--                       circle @click="addOrUpdateHandle(scope.row)"></el-button>-->
<!--          </el-tooltip>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="addOrUpdateHandle(scope.row)"
          >查看
          </el-button>
            <el-button
              type="text"
              icon="el-icon-delete"
              size="mini"
              circle @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="dataForm.pageNum"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="dataForm.pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList" :dataForm="editModel"></add-or-update>

  </div>
</template>

<script>
import {listFtmsorderbills, deleted} from '@/api/fleet/driverMsg'
  import AddOrUpdate from './driverMsg-add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          name: null,
          fTel: null,
          pageNum: 1,
          pageSize: 10
        },
        editModel: {},
        dataList: [],
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      timestampToTime (row, column) {
        const daterc = row[column.property]
        if (daterc != null) {
          const date = new Date(row.fContractb)
          const Y = date.getFullYear() + '-'
          const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
          const D = date.getDate() + ' '
          return Y + M + D
        }
      },
      dateFormat (row, column, cellValue, index) {
        const daterc = row[column.property]
        if (daterc != null) {
          const dateMat = new Date(row.fContracte)
          const year = dateMat.getFullYear()
          const month = dateMat.getMonth() + 1
          const day = dateMat.getDate()
          const timeFormat = year + '-' + month + '-' + day
          return timeFormat
        }
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        listFtmsorderbills(this.dataForm).then(data=>{
          console.log(data)
          if (data && data.code === 200) {
            this.dataList = data.rows
            this.totalPage = data.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        console.log(val)
        this.dataForm.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.dataForm.current = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (row) {
        this.addOrUpdateVisible = true
        if (row) {
          this.editModel = row
        } else {
          this.editModel = {
            id: null,
            fleetCompanyId: null,
            name: null,
            fFax: null,
            fContractb: null,
            fEaddr: null,
            fContracte: null,
            fScale: null,
            fTel: null,
            fAddr: null,
            registerdAddress: null,
            manageScope: null,
            creatTime: null,
            modificationTime: null,
            updateType: null
          }
        }
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init()
        })
      },
      // 删除
      deleteHandle (id) {
        var driverMsgIds = id ? [id] : this.dataListSelections.map(item => {
          return item.userId
        })
        this.$confirm(`确定对[id=${driverMsgIds.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleted(driverMsgIds).then(data=> {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      formatSex: function (row, column) {
        return row.fFax == 0 ? '男' : row.fFax == 1 ? '女' : '未知'
      }
    }
  }
</script>
