<!--
 * @Author: zhp
 * @Date: 2024-07-12 13:28:21
 * @LastEditTime: 2024-07-23 14:00:38
 * @LastEditors: zhp
 * @Description:
-->
<template>
  <div>
    <el-drawer title="配置保养项目" :visible.sync="drawer" :direction="direction" size="50%">
      <div style="padding: 0px 16px;">
        <el-form v-if="this.$auth.hasPermi('equipment:check-program:add')" :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: 'maintainResult',
    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/maintain/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-maintain-program',
        tableData: [],
        tableBtn: [
          this.$auth.hasPermi('equipment:check-program:edit')
            ? {
              type: 'edit',
              btnName: '编辑',
            }
            : undefined,
          this.$auth.hasPermi('equipment:check-program:delete')
            ? {
              type: 'delete',
              btnName: '删除',
            }
            : undefined,
        ],
        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) {
      this.dataListLoading = true;
      this.queryParams.equipmentTypeId = id
      this.urlOptions.getDataListURL(this.listQuery).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>
