Device.vue 5.96 KB
Newer Older
wanli's avatar
wanli committed
1 2 3 4 5
<template>
  <a-page-header-wrapper title="查询表格">
    <a-card :bordered="false">
      <div class="tableList">
        <div class="tableListForm">
6
          <a-form layout="inline">
wanli's avatar
wanli committed
7 8
            <a-row :gutter="{ md: 8, lg: 24, xl: 48 }">
              <a-col :md="8" :sm="24">
wanli's avatar
wanli committed
9
                <a-form-item label="设备名" v-decorator="['name']">
10
                  <a-input v-model="query.name" placeholder="请输入" />
wanli's avatar
wanli committed
11 12 13
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
14 15
                <a-form-item label="IMEI" v-decorator="['imei']">
                  <a-input v-model="query.imei" placeholder="请输入" />
wanli's avatar
wanli committed
16 17 18 19
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <span class="submitButtons">
20 21 22 23 24 25 26 27 28 29
                  <a-button
                    type="primary"
                    htmlType="submit"
                    @click="getDataList"
                  >
                    查询
                  </a-button>
                  <a-button :style="{ marginLeft: '8px' }" @click="resetForm">
                    重置
                  </a-button>
wanli's avatar
wanli committed
30 31 32 33 34 35
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <div class="tableListOperator">
36 37 38
          <a-button icon="plus" type="primary" @click="handleAdd">
            新建
          </a-button>
wanli's avatar
wanli committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
          <span v-show="selectedRowKeys.length > 0">
            <a-button>批量操作</a-button>
            <!-- <a-dropdown overlay={menu}>
                  <a-button>
                    更多操作 <icon type="down" />
                  </a-button>
                </a-dropdown> -->
          </span>
        </div>
        <!-- <StandardTable
              selectedRows={selectedRows}
              loading={loading}
              data={data}
              columns={this.columns}
              onSelectRow={this.handleSelectRows}
              onChange={this.handleStandardTableChange}
            /> -->
        <a-table
          :columns="columns"
          :rowKey="(record) => record.uuid"
wanli's avatar
wanli committed
59 60
          :dataSource="tableData.list"
          :pagination="tableData.pagination"
wanli's avatar
wanli committed
61 62 63 64
          :loading="loading"
          @change="handleTableChange"
        >
          <template slot="action" slot-scope="text, record">
65
            <a href="javascript:void(0);" @click="handleEdit(record)">编辑</a>
wanli's avatar
wanli committed
66
            <a-divider type="vertical" />
67
            <a href="javascript:void(0);" @click="handleDelete(record)">删除</a>
wanli's avatar
wanli committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
          </template>
        </a-table>
      </div>
    </a-card>
  </a-page-header-wrapper>
</template>

<script>
import {
  Avatar,
  Row,
  Col,
  Card,
  List,
  Button,
  Form,
  Icon,
  Table,
  Divider,
  Dropdown,
  Input,
  Select,
  DatePicker,
wanli's avatar
wanli committed
91
  message,
wanli's avatar
wanli committed
92 93 94 95 96
} from "ant-design-vue";
import PageHeaderWrapper from "@/components/PageHeaderWrapper";
import DescriptionItem from "@/components/DescriptionItem";
const columns = [
  {
wanli's avatar
wanli committed
97 98
    title: "IMEI",
    dataIndex: "imei",
wanli's avatar
wanli committed
99 100 101
    width: "15%",
  },
  {
wanli's avatar
wanli committed
102 103
    title: "设备名称",
    dataIndex: "name",
wanli's avatar
wanli committed
104 105
  },
  {
wanli's avatar
wanli committed
106 107
    title: "设备类型",
    dataIndex: "type",
wanli's avatar
wanli committed
108 109
  },
  {
wanli's avatar
wanli committed
110 111
    title: "设备描述",
    dataIndex: "desc",
wanli's avatar
wanli committed
112 113 114 115 116 117 118 119
  },
  {
    title: "Action",
    key: "action",
    scopedSlots: { customRender: "action" },
  },
];

wanli's avatar
wanli committed
120
import { mapTrim } from "@/utils/index";
121
import { getDeviceList, deleteDevice } from "@/api/openapi";
wanli's avatar
wanli committed
122

wanli's avatar
wanli committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
export default {
  name: "DeviceIndex",
  data: () => ({
    selectedRowKeys: [],
    columns,
    sya: {
      fontSize: "16px",
      color: "rgba(0,0,0,0.85)",
      lineHeight: "24px",
      display: "block",
      marginBottom: "16px",
    },
    syb: {
      marginBottom: "24px",
    },
wanli's avatar
wanli committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    loading: false,
    tableData: {
      list: [],
      pagination: {
        total: 0,
        pageSize: 15,
      },
    },
    query: {
      imei: null,
      name: null,
      type: null,
    },
    post: {
      page: 1,
      pageSize: 15,
    },
wanli's avatar
wanli committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
  }),
  components: {
    APageHeaderWrapper: PageHeaderWrapper,
    AAvatar: Avatar,
    ARow: Row,
    ACol: Col,
    ACard: Card,
    ACardGrid: Card.Grid,
    ACardMeta: Card.Meta,
    AList: List,
    AButton: Button,
    AForm: Form,
    AFormItem: Form.Item,
    AIcon: Icon,
    ATable: Table,
    ADescriptionItem: DescriptionItem,
    ADivider: Divider,
    ADropdown: Dropdown,
    AInput: Input,
    ASelect: Select,
    AOption: Select.Option,
    ARangePicker: DatePicker.RangePicker,
  },
  methods: {
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    resetForm() {
      this.query = {
        imei: null,
        name: null,
        type: null,
      };
      this.getDataList();
    },
    handleAdd() {
      this.$router.push({ name: "DeviceForm", params: { title: "添加" } });
    },
    handleEdit(record) {
      this.$router.push({
        name: "DeviceForm",
        params: { title: "编辑", record },
      });
wanli's avatar
wanli committed
195
    },
196 197 198 199 200 201 202 203 204
    handleDelete(record) {
      deleteDevice(record.uuid)
        .then((res) => {
          message.success(res.msg);
          this.getDataList();
        })
        .catch((err) => {
          message.error(err.msg);
        });
wanli's avatar
wanli committed
205 206 207 208 209 210
    },
    onSelectChange(selectedRowKeys) {
      window.console.log("selectedRowKeys changed: ", selectedRowKeys);
      this.selectedRowKeys = selectedRowKeys;
    },
    handleTableChange(pagination, filters, sorter) {
wanli's avatar
wanli committed
211
      console.log(pagination, filters, sorter);
wanli's avatar
wanli committed
212
    },
wanli's avatar
wanli committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
    getDataList() {
      this.loading = true;
      let opts = mapTrim(this.query);
      opts = Object.assign(opts, this.post);

      getDeviceList(opts)
        .then((res) => {
          message.success(res.msg);
          if (res.code == 200) {
            this.tableData.list = res.data;
            this.tableData.pagination.pageSize = res.pageSize;
            this.tableData.pagination.total = res.total;
          }
        })
        .catch((err) => {
          message.error(err.msg);
        })
        .finally(() => {
          this.loading = false;
        });
    },
  },
  created() {
    this.getDataList();
wanli's avatar
wanli committed
237 238 239 240 241 242
  },
};
</script>
<style lang="less">
@import url("styles/tableList.less");
</style>