<template>
  <!-- 自动售卖机  -->
  <div class="app-container">
    <el-row :gutter="10" class="mb8"  style="margin-left: 0; margin-top: 10px">
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAdd"
        v-hasPermi="['device:robot:list']"
      >新增</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table ref="tables" v-loading="loading" :data="dataList" border>
      <el-table-column label="序号" align="center" type="index" width="60"></el-table-column>
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="设备编码" align="center" prop="deviceNo" />
      <el-table-column label="IP" align="center" prop="deviceAddress" />
      <el-table-column label="设备类型" align="center" prop="deviceType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.device_sys_type" :value="scope.row.deviceType"/>
        </template>
      </el-table-column>
      <el-table-column label="添加时间" align="center" prop="createTime" width="160" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="openDetails(scope.row)"
            v-hasPermi="['device:robot:details']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['device:robot:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row,scope.index)"
            v-hasPermi="['device:robot:delete']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 详情 -->
    <!-- 新增/编辑弹框 -->
    <data-box
      ref="addAndEdit"
      @getList="getList"
    />
  </div>
</template>

<script>
import { pageList,deleteById } from "@/api/device/pda";
import dataBox from "./dialog/dataBox.vue";
export default {
  name: "Robot",
  components: { dataBox },
  dicts: ['device_sys_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      dataList: null,
      // 弹出层标题
      title: "",

      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      handleExportLoading: false,
      tableData: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      pageList({...this.queryParams,deviceType:2})
      .then(response => {
          this.dataList = response.data.rows;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.$set(this.queryParams, 'id', '');
      this.$set(this.queryParams, 'businessType', '');
      this.$set(this.queryParams, 'incomeExpenses', '');
      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    /** 详情按钮操作 */
    openDetails(row, type) {
      this.$refs["addAndEdit"].openDialog("详情", row,3);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs["addAndEdit"].openDialog("新增数据", null,1);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs["addAndEdit"].openDialog("修改数据", row,2);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const dataIds = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据编号为"' + dataIds + '"的数据项？').then(function() {
        return deleteById(dataIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch((e) => {console.log("e====",e) });
    }
  }
};
</script>
