blob: 06e7bc0b2246d81632f7325ef19a626b4e025a1e [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}
huibing.xie84425172018-08-28 19:41:13 +080041export function crudGetItem(page, _get, rowid, initData, _callback) {
huibing.xie1f1606f2018-08-20 15:46:55 +080042 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 })
huibing.xie84425172018-08-28 19:41:13 +080055 if (typeof _callback === 'function') {
56 _callback()
57 }
huibing.xie1f1606f2018-08-20 15:46:55 +080058 })
59 } else {
60 page.temp = Object.assign({}, initData)
61 page.dialogFormVisible = true
62 page.$nextTick(() => {
63 page.$refs['dataForm'].clearValidate()
64 })
huibing.xie84425172018-08-28 19:41:13 +080065 if (typeof _callback === 'function') {
66 _callback()
67 }
huibing.xie1f1606f2018-08-20 15:46:55 +080068 }
69}
70export function crudCreate(page, _create, _callback) {
71 page.$refs['dataForm'].validate((valid) => {
72 if (valid) {
73 _create(page.temp).then(response => {
74 if (typeof _callback === 'function') {
75 _callback()
76 }
77 page.dialogFormVisible = false
78 page.$notify({
79 title: '成功',
80 message: (page.dialogStatus === 'create') ? '创建成功' : '修改成功',
81 type: 'success',
82 duration: 2000
83 })
84 })
85 }
86 })
87}
88export function crudDelete(page, _delete, rowid, _callback) {
89 MessageBox.confirm('确认删除记录吗?', '删除', {
90 confirmButtonText: '确认',
91 cancelButtonText: '取消',
92 type: 'warning'
93 }).then(() => {
94 _delete({ id: rowid }).then(response => {
95 if (typeof _callback === 'function') {
96 _callback()
97 }
98 page.$notify({
99 title: '成功',
100 message: '删除成功',
101 type: 'success',
102 duration: 2000
103 })
104 })
105 })
106}