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