<template>
  <div>
    <!-- 搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="关键字" prop="ticketNo">
        <el-input style="width: 20rem" type="text" placeholder="工单号、车牌号、联系电话" v-model="queryParams.ticketNo"/>
      </el-form-item>
      <el-form-item label="时间" prop="searchTimeArray">
        <el-date-picker
          value-format="yyyy-MM-dd HH:mm:ss"
          v-model="queryParams.searchTimeArray"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作 -->
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="序号" align="center">
        <template scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单编号" align="center" prop="ticketNo" width="200"/>
      <el-table-column label="维修类别" align="center" prop="repairType" width="180">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.REPAIR_TYPE" v-model="scope.row.repairType"/>
        </template>
      </el-table-column>
      <el-table-column label="客户名称" align="center" prop="userName" width="180"/>
      <el-table-column label="车牌号" align="center" prop="carNo" width="180"/>
      <el-table-column label="车系" align="center" prop="carBrandName" width="180"/>
      <el-table-column label="手机号" align="center" prop="userMobile" width="180"/>
      <el-table-column label="操作" fixed="right" align="center" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleShow(scope.row)"
          >查看
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-document-add" @click="handleGet(scope.row)">
            申请领料
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="listTickets"
    />
    <TicketsShow ref="ticketsShow"/>
  </div>
</template>

<script>
import {getPageType} from "@/api/repair/tickets/Tickets";
import TicketsShow from "@/views/repair/tickets/Components/TicketsShow.vue";

export default {
  name: "TicketManagerItem",
  components: {TicketsShow},
  props: {
    isFinish: {
      type: Boolean,
    }
  },
  data() {
    return {
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        ticketNo: null,
        searchTimeArray: [],
        isFinish: this.isFinish ? "1" : "0"
      },
      showSearch: true,
      loading: false,
      list: [],
      total: 0
    }
  },
  mounted() {
    this.listTickets()
  },
  methods: {
    async listTickets() {
      try {
        this.loading = true
        const res = await getPageType(this.queryParams)
        if (res.data) {
          this.list = res.data.records
          this.total = res.data.total
        }
      }finally {
        this.loading = false
      }
    },
    handleQuery() {
      this.queryParams.pageNo = 1
      this.listTickets()
    },
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    handleShow(row) {
      this.$refs.ticketsShow.open(row)
    },
    handleGet(row){

    }
  }
}
</script>

<style scoped lang="scss">

</style>
