Skip to content

Instantly share code, notes, and snippets.

@wisetc
Created January 30, 2018 02:11
Show Gist options
  • Select an option

  • Save wisetc/c35693e9026f86b998a7c4a178f44309 to your computer and use it in GitHub Desktop.

Select an option

Save wisetc/c35693e9026f86b998a7c4a178f44309 to your computer and use it in GitHub Desktop.
LoadData composition of searcher for xtits
import { Simple } from 'vue-element-crud'
import Pagination from './Pagination'
export default {
mixins: [Simple, Pagination],
data() {
return {
api: {},
loading: false
}
},
methods: {
loadData() {
let kw = { ...this.searcher.kw }
// 如果不是时间和ID
for (let k in kw) {
let isDate = k.indexOf('Date') > -1
let isID = /id$/i.test(k)
if (!kw[k]) {
kw[k] = undefined
} else if (!isDate && !isID) {
kw[k] = `%${kw[k]}%`
}
}
this.api.list({ ...this._pagination, ...kw }).then(({ status, data }) => {
this.data = data.data.data
this.setPagination(data.data.count, data.data.data.length)
})
},
// element-ui date v-model value changed to date string.
beforeCreate() {},
handleSubmit(status, closeDialog) {
const submitSuccess = (data) => {
this.loadData()
closeDialog()
}
this.loading = true
if (status === 0) {
this.beforeCreate()
this.api.create(this.form).then(({status, data}) => {
this.loading = false
this.$report(data, 'create', submitSuccess)
})
} else {
this.api.update(this.form).then(({status, data}) => {
this.loading = false
this.$report(data, 'update', submitSuccess)
})
}
},
handleDestroy(row) {
this.api.destroy(row.id).then(({status, data}) => {
this.$report(data, 'destroy', this.loadData)
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment