基于vue-easytable实现数据的增删改查

基于vue-easytable实现数据的增删改查

原理:利用vue的数据绑定和vue-easetable的ui完成增删改查

后端接口:

1.条件查询表中数据

http://localhost:47953/Home/GetJtncSelectJsonResult

2.通过id查询单条数据

http://localhost:47953/Home/UploadJtnc

3.保存数据

http://localhost:47953/Home/SaveJtnc

4.删除数据

http://localhost:47953/Home/DeleteJtnc

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<template>
  <div id="vueeasytable"  style="background: #ccc;padding:40px;min-height: 1500px;" >
    <h3 style="text-align: left;margin-top: 30px">
      家庭农场
      <div style="float:right">
        <at-button type="primary" @click="seeData">查看</at-button>
        <at-button type="primary" @click="addModalframe=true">添加</at-button>
        <at-button type="success" @click="modifyData">修改</at-button>
        <at-button type="warning" @click="deleData">删除</at-button>
      </div>
    </h3>
    <hr>
    <div style="margin-bottom: 20px">
      <span> 身份证号:</span><at-input v-model="sfzhcx" placeholder="输入提示"  status="info" style="width:280px;display:inline-block"></at-input>
      <at-button type="primary" @click="selectData">查询</at-button>
    </div>
    <div class="col-md-24 col-sm-24 col-xs-24" style="padding:30px;">
      <v-table
        is-horizontal-resize
        style="width:100%"
        :columns="columns"
        :table-data="tableData"
        :show-vertical-border="false"
        :select-change = "GetSelectObj"
      ></v-table>
      <div style="padding:20px;float:right;">
        <v-pagination :total="dataNum" :page-size="10" @page-change="pageChange" @page-size-change="pageSizeChange"></v-pagination>
      </div>
    </div>
 
    <!--单条信息查看模态框-->
    <at-modal v-model="seeModalframe" title="查看" >
      企业编码:{{seeobjs.QYBM}}
      <br>
      ...
      <br>
      备注:{{seeobjs.BZ}}
    </at-modal><br>    <!--添加模态框-->
    <at-modal v-model="addModalframe" title="添加" @on-confirm="addConfirm"><!-- @on-cancel="handleCancel"-->
      <span style="width:70px;margin-bottom: 10px;">企业编码:</span><at-input v-model="addModel.QYBM" placeholder="输入提示"  status="info"  style="margin-bottom: 10px;width:420px;display: inline-block"></at-input>
      <br>
      ...
      <br>
      <span style="width:70px;margin-bottom: 10px;">备注:</span><at-input v-model="addModel.BZ" placeholder="输入提示"  status="info"  style="margin-bottom: 10px;width:420px;display: inline-block"></at-input>
    </at-modal><br>    <!--修改模态框-->
    <at-modal v-model="modifyModalframe" title="修改" @on-confirm="modifyConfirm"><!--@on-confirm="handleConfirm" @on-cancel="handleCancel"-->
      <span style="width:70px;margin-bottom: 10px;">企业编码:</span><at-input v-model="modifyModel.QYBM=seeobjs.QYBM"   status="info"  style="margin-bottom: 10px;width:420px;display: inline-block"></at-input>
      <br>
      ...
      <br>
      <span style="width:70px;margin-bottom: 10px;">备注:</span><at-input v-model="modifyModel.BZ=seeobjs.BZ"   status="info"  style="margin-bottom: 10px;width:420px;display: inline-block"></at-input>
    </at-modal>
 
  </div>
</template>
 
<script>
export default {
  name: 'vueeasytable',
  data() {
    return {
      /*获取数据*/
      GetData:[],
      /*表格信息*/
      pageIndex:1,/*页码*/
      pageSize:10,/*每页条数*/
      dataNum:0,/*数据总条数*/
      columns: [
        {width: 60, titleAlign: 'center',columnAlign:'center',type: 'selection'},
        {field: 'QYBM', title:'企业编码', width: 100, titleAlign: 'center',columnAlign:'center',isResize:true},
        {field: 'ZTMC', title: '主体名称', width: 260, titleAlign: 'center',columnAlign:'center',isResize:true},
        {field: 'SFZH', title: '身份证号', width: 100, titleAlign: 'center',columnAlign:'center',isResize:true},
        {field: 'NCMC', title: '农场名称', width: 100, titleAlign: 'center',columnAlign:'center',isResize:true},
        {field: 'ZTDJ', title: '主体等级', width: 100, titleAlign: 'center',columnAlign:'center',isResize:true},
        {field: 'XYDJ', title: '信用等级', width: 100, titleAlign: 'center',columnAlign:'center',isResize:true}
      ],/*列表项*/
      tableData: [],/*表格数据*/
      /*查询条件*/
      sfzhcx:"",/*身份证号*/
      /*选中的对象*/
      SelectObj:[],
      seeobjs:{},
      /*查看单条信息开关*/
      seeModalframe:false,
      /*添加单条信息开关*/
      addModalframe:false,
      /*修改单条信息开关*/
      modifyModalframe:false,
      /*添加的数据model*/
      addModel:{},
      /*修改数据*/
      modifyModel:{},
    }
  },
  created(){
    /*数据初始化*/
    this.getTableData();
  },
  mounted: function () {
  },
  methods: {
    /*数据获取*/
    Getwebsites(){
      var websites;
      $.ajax({
        type: 'post',
        async: false,
        url: 'http://localhost:47953/Home/GetJtncSelectJsonResult',
        data:{selectobj:this.sfzhcx},
        success:function (response) {
          websites = response;
        },
        error:function (error) {
          console.log(error)
        }});
      return websites;
    },
    /*数据处理*/
    websitesHandle () {
      /*获取条件查询结果*/
      var websites = this.Getwebsites();
      /*数据处理*/
      var websit;
      var websitArrtys=[];
      for(var i in websites){
        websit = {
          ID:websites[i].ID,
          QYBM:websites[i].QYBM,
          ZTMC:websites[i].ZTMC,
          SFZH:websites[i].SFZH,
          NCMC:websites[i].NCMC,
          ZTDJ:websites[i].ZTDJ,
          XYDJ:websites[i].XYDJ,
        };
        websitArrtys.push(websit)
      }
      const data = websitArrtys;
      let pageData = [];
      pageData = pageData.concat(data);
      this.GetData = pageData;
      this.dataNum = this.GetData.length;
    },
    /*分页处理*/
    getTableData(){
      this.websitesHandle();
      this.tableData =this.GetData.slice((this.pageIndex-1)*this.pageSize,(this.pageIndex)*this.pageSize);
    },
    /*页码触发更新*/
    pageChange(pageIndex){
      this.pageIndex = pageIndex;
      this.getTableData();
    },
    /*每页条数触发更新*/
    pageSizeChange(pageSize){
      this.pageIndex = 1;
      this.pageSize = pageSize;
      this.getTableData();
    },
    /*条件查询*/
    selectData(){
      this.websitesHandle();
      this.tableData =this.GetData.slice((this.pageIndex-1)*this.pageSize,(this.pageIndex)*this.pageSize);
    },
    /*获取选中对象*/
    GetSelectObj(obj){
      this.SelectObj=[];
      this.SelectObj = this.SelectObj.concat(obj);
    },
    /*查看单条记录详细信息*/
    seeData(){
      /*判断已经选择数据的条数*/
      if(this.SelectObj.length ==0){
        this.$Modal.alert({
          title: '错误信息',
          content: '请先选择一条记录'
        })
      }
      else if(this.SelectObj.length >1){
        this.$Modal.alert({
          title: '错误信息',
          content: '每次只可以查看一条记录'
        })
      }
      else if(this.SelectObj.length ==1){
        this.seeModalframe=true;
        var Data;
        $.ajax({
          type: 'post',
          async: false,
          url: 'http://localhost:47953/Home/UploadJtnc',
          data:{id:this.SelectObj[0].ID},
          success:function (response) {
            Data =  response;
          },
          error:function (error) {
            console.log(error)
          }
        });
        this.seeobjs = Data;
      }
    },
    /*将数据渲染在修改模态框上*/
    modifyData(){
      if(this.SelectObj.length ==0){
        this.$Modal.alert({
          title: '错误信息',
          content: '请先选择一条记录'
        })
      }
      else if(this.SelectObj.length >1){
        this.$Modal.alert({
          title: '错误信息',
          content: '每次只可以查看一条记录'
        })
      }
      else if(this.SelectObj.length ==1){
        this.modifyModalframe=true;
        var Data;
        $.ajax({
          type: 'post',
          async: false,
          url: 'http://localhost:47953/Home/UploadJtnc',
          data:{id:this.SelectObj[0].ID},
          success:function (response) {
            Data =  response;
          },
          error:function (error) {
            console.log(error)
          }
        });
        this.seeobjs = Data;
      }
    },
    /*修改确认,将数据修改到数据库*/
    modifyConfirm(){
      console.log(this.modifyModel)
      $.ajax({
        type: 'post',
        async: false,
        url: 'http://localhost:47953/Home/SaveJtnc',
        data:this.modifyModel,
        success:function (response) {
          console.log(response)
        },
        error:function (error) {
          console.log(error)
        }
      });
      $.ajax({
        type: 'post',
        async: false,
        url: 'http://localhost:47953/Home/DeleteJtnc',
        data:{id:this.SelectObj[0].ID},
        success:function (response) {
          console.log(response)
        },
        error:function (error) {
          console.log(error)
        }
      });
      this.selectData();
      this.SelectObj=[];
    },
    /*添加数据*/
    addConfirm(){
      $.ajax({
        type: 'post',
        async: false,
        url: 'http://localhost:47953/Home/SaveJtnc',
        data:this.addModel,
        success:function (response) {
          console.log(response)
        },
        error:function (error) {
          console.log(error)
        }
      });
      this.selectData();
    },
    /*删除数据*/
    deleData(){
      $.ajax({
        type: 'post',
        async: false,
        url: 'http://localhost:47953/Home/DeleteJtnc',
        data:{id:this.SelectObj[0].ID},
        success:function (response) {
          console.log(response)
        },
        error:function (error) {
          console.log(error)
        }
      });
      this.selectData();
      this.SelectObj=[];
 
    }
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>

  

原创不易:转载请注明出处

 

posted @   莫小龙  阅读(7365)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示