<!--
 * @Author: zhp
 * @Date: 2024-07-12 13:28:21
 * @LastEditTime: 2024-07-23 13:44:46
 * @LastEditors: zhp
 * @Description:
-->
<template>
  <div>
    <el-drawer title="配置巡检项目" :visible.sync="drawer" :direction="direction" size="50%">
      <div style="padding: 0px 16px;">
        <el-form :inline="true" class="">
          <el-form-item>
            <el-button :plain='true' type="success" @click="handleAdd">新增</el-button>
          </el-form-item>
        </el-form>
        <base-table v-loading="dataListLoading" :table-props="tableProps" :table-data="tableData">
          <method-btn v-if="tableBtn.length" slot="handleBtn" :width="80" label="操作" :method-list="tableBtn"
            @clickBtn="handleClick" />
        </base-table>
      </div>
    </el-drawer>
    <base-dialog :dialogTitle="addOrEditTitle" :dialogVisible="addOrUpdateVisible" @cancel="handleCancel"
      @confirm="handleConfirm" :before-close="handleCancel" width="30%">
      <add-or-update ref="addOrUpdate" @refreshDataList="successSubmit"></add-or-update>
    </base-dialog>
  </div>

</template>

<script>
const tableProps = [
  {
    prop: 'program',
    label: '巡检项目',
    align:'center',
  },
  {
    prop: 'checkResult',
    label: '默认巡检结果',
    align: 'center',
  },
]
const topBtnConfig = [
  {
    type: 'add',
    btnName: 'btn.add'
  }
]
// import basicPageMixin from '@/mixins/lb/basicPageMixin';
import AddOrUpdate from './components/add-or-updata';
import {
  getItemPageData,
  deleteData
} from '@/api/equipment/base/inspection/items';
import basicPage from './components/basic-page';
export default {
  mixins: [basicPage],
  components: {
    AddOrUpdate,
  },
    data() {
      return {
        drawer: false,
        urlOptions: {
          getDataListURL: getItemPageData,
          deleteURL: deleteData,
          // exportURL: exportFactoryExcel,
        },
        direction: 'rtl',
        dataListLoading:false,
        addOrUpdateVisible: false,
        addOrEditTitle: '',
        queryParams: {
          pageNo:1,
          pageSize:10,
          equipmentTypeId:null,
        },
        tableProps,
        basePath: 'base/equipment-check-program',
        tableData: [],
        tableBtn: [
          {
            type: 'edit',
            name: '编辑'
          },
          {
            type: 'delete',
            name: '删除'
          }
        ],
        addButtonShow: '新增'
      }
  },
  methods: {
    inputChange(val) {
      // console.log('=======')
      console.log(val)
      this.tableData[val._pageIndex - 1][val.prop] = val[val.prop]
      // console.log(this.tableData)
    },
    getDataList(id) {
      console.log(id)
      this.dataListLoading = true;
      this.queryParams.equipmentTypeId = id
      console.log(this.queryParams.equipmentTypeId)
      this.urlOptions.getDataListURL(this.queryParams).then(response => {
        this.tableData = response.data.list;
        this.listQuery.total = response.data.total;
        this.dataListLoading = false
      });
    },
    handleAdd() {
      this.addOrUpdateVisible = true
      this.addOrEditTitle = '新增'
      let obj = {
        equipmentTypeId: this.queryParams.equipmentTypeId
      }
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(obj)
      });
    },
    init(id) {
      this.drawer = true
      this.getDataList(id)
      }
    },
  }
</script>

<style lang="scss" scoped>

</style>
