blob: e7639a1abe7de49a8b7db385a3a5dfcf2616eb8f [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
huibing.xief40b2b92018-08-22 17:12:47 +080026export function crudPageList(page, _pagelist, _callback) {
huibing.xie1f1606f2018-08-20 15:46:55 +080027 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
huibing.xief40b2b92018-08-22 17:12:47 +080034 if (typeof _callback === 'function') {
35 _callback()
36 }
huibing.xie1f1606f2018-08-20 15:46:55 +080037 })
38}
39export function crudGetItem(page, _get, rowid, initData) {
40 if (rowid) {
41 _get({ id: rowid }).then(response => {
42 if (!response.data) {
43 MessageBox.alert('数据不存在,请确认是否已删除。', '消息', {
44 confirmButtonText: '确定'
45 })
46 return
47 }
48 page.temp = response.data
49 page.dialogFormVisible = true
50 page.$nextTick(() => {
51 page.$refs['dataForm'].clearValidate()
52 })
53 })
54 } else {
55 page.temp = Object.assign({}, initData)
56 page.dialogFormVisible = true
57 page.$nextTick(() => {
58 page.$refs['dataForm'].clearValidate()
59 })
60 }
61}
62export function crudCreate(page, _create, _callback) {
63 page.$refs['dataForm'].validate((valid) => {
64 if (valid) {
65 _create(page.temp).then(response => {
66 if (typeof _callback === 'function') {
67 _callback()
68 }
69 page.dialogFormVisible = false
70 page.$notify({
71 title: '成功',
72 message: (page.dialogStatus === 'create') ? '创建成功' : '修改成功',
73 type: 'success',
74 duration: 2000
75 })
76 })
77 }
78 })
79}
80export function crudDelete(page, _delete, rowid, _callback) {
81 MessageBox.confirm('确认删除记录吗?', '删除', {
82 confirmButtonText: '确认',
83 cancelButtonText: '取消',
84 type: 'warning'
85 }).then(() => {
86 _delete({ id: rowid }).then(response => {
87 if (typeof _callback === 'function') {
88 _callback()
89 }
90 page.$notify({
91 title: '成功',
92 message: '删除成功',
93 type: 'success',
94 duration: 2000
95 })
96 })
97 })
98}