| import { MessageBox } from 'element-ui' |
| |
| export default { |
| data() { |
| return { |
| items: null, |
| pagedata: {}, |
| recordCount: null, |
| listLoading: true, |
| dialogStatus: '', |
| dialogFormVisible: false, |
| temp: {}, |
| textMap: { |
| update: '修改', |
| create: '新增' |
| }, |
| dialogPvVisible: false, |
| listQuery: { |
| pageIndex: 1, |
| pageSize: 20 |
| }, |
| height: 500 |
| } |
| } |
| } |
| |
| export function crudPageList(page, _pagelist, _callback) { |
| page.listLoading = true |
| _pagelist(Object.assign({}, page.listQuery)).then(response => { |
| page.items = response.items |
| page.listLoading = false |
| page.recordCount = response.recordCount |
| page.pageIndex = response.pageIndex |
| page.pageSize = response.pageSize |
| page.pagedata = response |
| if (typeof _callback === 'function') { |
| _callback() |
| } |
| }) |
| } |
| export function crudGetItem(page, _get, rowid, initData, _callback) { |
| if (rowid) { |
| _get({ id: rowid }).then(response => { |
| if (!response.data) { |
| MessageBox.alert('数据不存在,请确认是否已删除。', '消息', { |
| confirmButtonText: '确定' |
| }) |
| return |
| } |
| page.temp = response.data |
| page.dialogFormVisible = true |
| page.$nextTick(() => { |
| page.$refs['dataForm'].clearValidate() |
| }) |
| if (typeof _callback === 'function') { |
| _callback() |
| } |
| }) |
| } else { |
| page.temp = Object.assign({}, initData) |
| page.dialogFormVisible = true |
| page.$nextTick(() => { |
| page.$refs['dataForm'].clearValidate() |
| }) |
| if (typeof _callback === 'function') { |
| _callback() |
| } |
| } |
| } |
| export function crudCreate(page, _create, _callback) { |
| page.$refs['dataForm'].validate((valid) => { |
| if (valid) { |
| _create(page.temp).then(response => { |
| if (typeof _callback === 'function') { |
| _callback() |
| } |
| page.dialogFormVisible = false |
| page.$notify({ |
| title: '成功', |
| message: (page.dialogStatus === 'create') ? '创建成功' : '修改成功', |
| type: 'success', |
| duration: 2000 |
| }) |
| }) |
| } |
| }) |
| } |
| export function crudDelete(page, _delete, rowid, _callback) { |
| MessageBox.confirm('确认删除记录吗?', '删除', { |
| confirmButtonText: '确认', |
| cancelButtonText: '取消', |
| type: 'warning' |
| }).then(() => { |
| _delete({ id: rowid }).then(response => { |
| if (typeof _callback === 'function') { |
| _callback() |
| } |
| page.$notify({ |
| title: '成功', |
| message: '删除成功', |
| type: 'success', |
| duration: 2000 |
| }) |
| }) |
| }) |
| } |