<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="name">
        <el-input v-model="queryParams.name" 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">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)">新增
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></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="名称" prop="name" align="center"/>
      <el-table-column label="价格" prop="price" align="center"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row)">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(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="getList"/>
    <OtherForm ref="otherForm" @success="getList"/>
  </div>
</template>

<script>
import OtherForm from "@/views/repair/other/OtherForm.vue";
import {getOtherPage, deleteOther} from "@/api/repair/other";

export default {
  name: "RepairOther",
  components: {OtherForm},
  data() {
    return {
      queryParams: {
        pageNo: 1,
        pageSize: 10
      },
      showSearch: true,
      total: 0,
      list: [],
      loading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      const res = await getOtherPage(this.queryParams)
      this.list = res.data.records
      this.total = res.data.total
    },
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    openForm(row) {
      this.$refs.otherForm.open(row)
    },
    async handleDelete(row) {
      const id = row.id;
      const name = row.name
      try {
        await this.$modal.confirm('是否确认删除"' + name + '"的数据项?')
        await deleteOther(id)
        this.$modal.msgSuccess("删除成功");
        await this.getList()
      }catch{}
    }
  }
}
</script>

<style scoped lang="scss">

</style>
