<template>
  <!-- 报废确认 -->
  <basic-container>
    <avue-crud
      ref="crud"
      :data="data"
      id="avue-id"
      :option="option"
      :page.sync="page"
      @on-load="onLoad"
      @search-reset="reset"
      @row-update="rowUpdate"
      :table-loading="loading"
      @search-change="searchChangeScope"
    >
      <template slot="menuLeft">
        <el-form
          ref="searchForm"
          :model="searchForm"
          label-width="120px"
          style="border: 0px solid red; margin-bottom: 8px"
        >
          <el-row>
            <el-col :span="2.5" v-show="[1, 3].includes(searchText.flag)">
              <!-- placeholder="支持模糊搜索、联想" -->
              <el-input
                v-model="searchForm.name"
                class="search-input"
                clearable
                placeholder="搜索关键字"
                suffix-icon="el-icon-search"
                @clear="searchHandle(1)"
              ></el-input>
            </el-col>
            
            <el-col
              style="margin-left: 18px"
              :span="3.5"
              v-show="[1, 3].includes(searchText.flag)"
            >
              <el-button class="search" @click="searchHandle(0)"
                >查询</el-button
              >
              <el-button class="reset" @click="searchHandle(1)">重置</el-button>
            </el-col>
          </el-row>
        </el-form>
      </template>
      <template slot-scope="{ row }" slot="status">
        <span v-if="row.status === 0" style="color: #ee922f">●待确认</span>
        <span v-if="row.status === 1" style="color: #e56926">●待审核</span>
        <span v-if="row.status === 2" style="color: #1e62f6">●待审批</span>
        <span v-if="row.status === 3" style="color: #999">●已完成</span>
      </template>
      <template slot-scope="{ row, index }" slot="menu">
        <el-button
          @click="checkApplyDetail(row, index)"
          class="look"
          v-if="row.status === 0 && permission.repair_confirm_btn"
          >确 认</el-button
        >
         <el-button
          v-if="row.status === 1 && permission.repair_audit_btn"
          @click="checkApplyDetail(row, index)"
          class="look"
          >审 核</el-button
        >
         <el-button
          v-if="row.status === 2 && permission.repair_approval_btn"
          @click="checkApplyDetail(row, index)"
          class="look"
          >审 批</el-button
        >
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import { mapGetters } from "vuex"
import { tableOption } from '@/const/repair/confirm.js'
import { equipmentList } from '@/api/lims/confirm' //新的列表数据接口
export default {
  data () {
    return {
      loading: false,
      page: [
        {
          currentPage: 1,
          total: 1,
          pageSize: 10,
        },
      ],
      searchForm: {
        name: "",
      },
      searchText: {
        flag: 3
      },
      option: tableOption,
      data: [],
    }
  },
  computed: {
    ...mapGetters(["permission"]),
  },
  mounted() {
    if(JSON.stringify(this.$store.state.client.confirmParams) !== '{}') {
      this.searchForm = this.$store.state.client.confirmParams
    }
    this.onLoad(this.page[0], this.searchForm)
  },
  methods: {

    /**
     * 验收
     */
    checkApplyDetail (row) {
      row = JSON.stringify(row)
      this.$router.push({ path: "/repair/repairConfirmDetail", query: { row } })
    },
    /**
     * 加载页面数据
     */
    onLoad (page, param = {}, loading) {
      this.loading = true
      equipmentList(Object.assign({ current: page.currentPage, size: page.pageSize }, param)).then((res) => {
        this.data = res.data.data.records
        this.data.forEach(d => {
          if (d.totalCost === -1) {
            d.totalCost = '--'
          }
        })
        this.page.total = res.data.data.total
        this.loading = false
      })
    },
    /**
     * 查找分页
     */
    searchChangeScope (params, done) {
      this.onLoad(this.page[0])
      done()
    },

    /**
     * 搜索
     */
    searchHandle (index) {
      this.page[0].currentPage = 1
      if (index === 1) {
        this.searchForm = { name: ''}
        this.onLoad(this.page[0])
      } else {
        this.onLoad(this.page[0], {name: this.searchForm.name})
      }
      this.$store.dispatch("changeSetting", {title:'confirmParams',form: this.searchForm})
    },
  },
};
</script>

<style lang="scss" scoped>
.search-input {
  width: 255px;
  height: 46px;
  /deep/ .el-input__inner {
    width: 255px;
    height: 46px;
  }
}
.search {
  color: #fff;
  background-color: #1e60f5;
  border-color: #1e60f5;
  height: 46px;
  width: 100px;
  border-radius: 0px;
  // margin-left:18px!important;
  margin-right: 0 !important;
}
// 重置按钮
.reset {
  color: #999999;
  background-color: #fff;
  border-color: #e4e7ec;
  height: 46px;
  width: 100px;
  margin-left: 18px !important;
  border-radius: 0px;
}
.search-picker {
  width: 240px;
  height: 46px;
  border-radius: 0;
  margin-left: 10px;
}
/deep/ .avue-crud__pagination {
  height: 20px;
  padding: 10px;
  // padding-top: 30px;
  // padding-bottom: 30px;
}
</style>
