<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 v-model="queryParams.ticketNo" style="width: 30rem" placeholder="单号,车牌,客户名称,手机号码,备注"/>
      </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-date-picker>
      </el-form-item>
      <el-form-item v-if="TicketType === 'tp'"  label="服务顾问" prop="userId">
        <StaffChoose />
      </el-form-item>
      <el-form-item v-if="TicketType === 'tu'" label="维修类别" prop="repairType">
        <el-select v-model="queryParams.repairType" size="small">
          <el-option v-for="item in this.getDictDatas(DICT_TYPE.REPAIR_TYPE)" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item v-if="TicketType === 'tp'" label="类型" prop="repairType">
        <RepairTypeChoose @selected="getRepairType" />
      </el-form-item>
      <el-form-item label="门店" prop="corpId">
        <CorpChoose v-model="queryParams.corp"/>
      </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="handleReset">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5" v-if="!(TicketType === 'tv')">
        <el-button type="primary" plain icon="el-icon-download" size="mini"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch"></right-toolbar>
    </el-row>
    <TicketTable :ticket-type="TicketType" :list="list" @setVoid="getPage"/>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
    />
  </div>
</template>

<script>
import StaffChoose from "@/views/repair/Components/StaffChoose.vue";
import TicketTable from "@/views/repair/tickets/Components/TicketTable.vue";
import RepairTypeChoose from "@/views/repair/Components/RepairTypeChoose.vue";
import {getTicketsPage} from "@/api/repair/tickets/Tickets";
import CorpChoose from "@/views/repair/Components/CorpChoose.vue";

export default {
  name: "TicketSearch",
  components: {
    TicketTable,
    StaffChoose,
    RepairTypeChoose,
    CorpChoose
  },
  props:{
    TicketType:{
      type: String,
      defaultValue: 'tp',
      required: true
    }
  },
  data() {
    return {
      queryParams:{
        pageNo: 1,
        pageSize: 10,
        ticketsStatus: null,
        ticketNo: null,
        searchTimeArray: [],
        repairType: null,
        corpId: null,
        corp: null
      },
      showSearch: true,
      total: 0,
      list: []
    }
  },
  mounted() {
    this.getPage()
  },
  methods: {
    // 类型选择
    getRepairType(data){
      console.log(data)
    },
    async getPage(){
      switch (this.TicketType){
        case "tu":
          this.queryParams.ticketsStatus = "01"
          break
        case "tp":
          this.queryParams.ticketsStatus = "02"
          break
        case "tv":
          this.queryParams.ticketsStatus = "03"
          break
        default:
          break
      }
      this.queryParams.corpId = this.queryParams?.corp?.id
      const res = await getTicketsPage(this.queryParams)
      this.list = res.data.records
      this.total = res.data.total
    },
    handleQuery(){
      this.queryParams.pageNo = 1
      this.getPage()
    },
    handleReset(){
      this.resetForm("queryForm")
      this.queryParams.corp = null
      this.handleQuery()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
