blob: 70eb9e2eb063ac50ba22c5368c5ca854f665dfa3 [file] [log] [blame]
huibing.xie1f1606f2018-08-20 15:46:55 +08001import { MessageBox } from 'element-ui'
2
3export default {
4 data() {
5 return {
6 items: null,
7 recordCount: null,
8 listLoading: true,
9 dialogStatus: '',
10 dialogFormVisible: false,
11 temp: {},
12 textMap: {
13 update: '修改',
14 create: '新增'
15 },
16 dialogPvVisible: false,
17 listQuery: {
18 pageIndex: 1,
19 pageSize: 20
20 },
21 height: 500
22 }
23 }
24}
25
26export function crudPageList(page, _pagelist) {
27 page.listLoading = true
28 _pagelist(Object.assign({}, page.listQuery)).then(response => {
29 page.items = response.items
30 page.listLoading = false
31 page.recordCount = response.recordCount
32 page.pageIndex = response.pageIndex
33 page.pageSize = response.pageSize
34 })
35}
36export function crudGetItem(page, _get, rowid, initData) {
37 if (rowid) {
38 _get({ id: rowid }).then(response => {
39 if (!response.data) {
40 MessageBox.alert('数据不存在,请确认是否已删除。', '消息', {
41 confirmButtonText: '确定'
42 })
43 return
44 }
45 page.temp = response.data
46 page.dialogFormVisible = true
47 page.$nextTick(() => {
48 page.$refs['dataForm'].clearValidate()
49 })
50 })
51 } else {
52 page.temp = Object.assign({}, initData)
53 page.dialogFormVisible = true
54 page.$nextTick(() => {
55 page.$refs['dataForm'].clearValidate()
56 })
57 }
58}
59export function crudCreate(page, _create, _callback) {
60 page.$refs['dataForm'].validate((valid) => {
61 if (valid) {
62 _create(page.temp).then(response => {
63 if (typeof _callback === 'function') {
64 _callback()
65 }
66 page.dialogFormVisible = false
67 page.$notify({
68 title: '成功',
69 message: (page.dialogStatus === 'create') ? '创建成功' : '修改成功',
70 type: 'success',
71 duration: 2000
72 })
73 })
74 }
75 })
76}
77export function crudDelete(page, _delete, rowid, _callback) {
78 MessageBox.confirm('确认删除记录吗?', '删除', {
79 confirmButtonText: '确认',
80 cancelButtonText: '取消',
81 type: 'warning'
82 }).then(() => {
83 _delete({ id: rowid }).then(response => {
84 if (typeof _callback === 'function') {
85 _callback()
86 }
87 page.$notify({
88 title: '成功',
89 message: '删除成功',
90 type: 'success',
91 duration: 2000
92 })
93 })
94 })
95}