huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 1 | import { MessageBox } from 'element-ui' |
| 2 | |
| 3 | export default { |
| 4 | data() { |
| 5 | return { |
| 6 | items: null, |
huibing.xie | 41e0d91 | 2018-08-28 14:26:11 +0800 | [diff] [blame] | 7 | pagedata: {}, |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 8 | 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.xie | f40b2b9 | 2018-08-22 17:12:47 +0800 | [diff] [blame] | 27 | export function crudPageList(page, _pagelist, _callback) { |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 28 | 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.xie | 41e0d91 | 2018-08-28 14:26:11 +0800 | [diff] [blame] | 35 | page.pagedata = response |
huibing.xie | f40b2b9 | 2018-08-22 17:12:47 +0800 | [diff] [blame] | 36 | if (typeof _callback === 'function') { |
| 37 | _callback() |
| 38 | } |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 39 | }) |
| 40 | } |
huibing.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame^] | 41 | export function crudGetItem(page, _get, rowid, initData, _callback) { |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 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 | }) |
huibing.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame^] | 55 | if (typeof _callback === 'function') { |
| 56 | _callback() |
| 57 | } |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 58 | }) |
| 59 | } else { |
| 60 | page.temp = Object.assign({}, initData) |
| 61 | page.dialogFormVisible = true |
| 62 | page.$nextTick(() => { |
| 63 | page.$refs['dataForm'].clearValidate() |
| 64 | }) |
huibing.xie | 8442517 | 2018-08-28 19:41:13 +0800 | [diff] [blame^] | 65 | if (typeof _callback === 'function') { |
| 66 | _callback() |
| 67 | } |
huibing.xie | 1f1606f | 2018-08-20 15:46:55 +0800 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | export 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 | } |
| 88 | export 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 | } |