<template>
  <div>
    <!-- 搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="关键字" prop="query">
        <el-input style="width: 20rem" type="text" placeholder="工单号、车牌号、联系电话" v-model="queryParams.query"/>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status">
          <el-option v-for="item in this.getDictDatas(DICT_TYPE.TICKET_WARES_STATUS)" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </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" width="80">
        <template scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单据号" align="center" prop="no" />
      <el-table-column label="服务顾问" align="center" prop="adviserName" />
      <el-table-column label="申请人" align="center" prop="repairName" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.TICKET_WARES_STATUS" v-model="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status !== '01' || userRole === 3 || userRole === 4" type="text" size="mini" icon="el-icon-view" @click="handleShow(scope.row)">
            查看
          </el-button>
          <el-button v-if="userRole === 1 || userRole === 2 && scope.row.status === '01'" @click="handleAudit(scope.row)" type="text" size="mini" icon="el-icon-s-check">
            审核
          </el-button>
          <el-button v-if="userRole === 3 || userRole === 4 && scope.row.status !== '01'" type="text" size="mini" icon="el-icon-finished">
            完成
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />
    <TicketWaresShow ref="ticketWaresShow" :user-role="userRole" @success="getList"/>
  </div>
</template>

<script>
import {getPage} from "@/api/repair/tickets/TicketWares";
import TicketWaresShow from "@/views/repair/tickets/Components/TicketWaresShow.vue";

export default {
  name: "TicketWares",
  components: {TicketWaresShow},
  props:{
    type: Boolean,
    userRole: Number,
  },
  data(){
    return{
      queryParams:{
        pageNo: 1,
        pageSize: 10,
        query: null,
        type: this.type ? "01" : "02",
        status: null
      },
      showSearch: true,
      loading: false,
      list: [],
      total: 0
    }
  },
  mounted() {
    this.getList()
  },
  methods:{
    async getList(){
      try {
        this.loading = true
        const res = await getPage(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.getList()
    },
    resetQuery(){
      this.resetForm('queryForm')
      this.handleQuery()
    },
    handleShow(row){
      this.$refs.ticketWaresShow.open(row)
    },
    handleAudit(row){
      this.handleShow(row)
    }
  }
}
</script>

<style scoped lang="scss">

</style>
