You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.5 KiB
112 lines
3.5 KiB
// pages/process/order-list/index.js
|
|
import Scene from '../../index/scene'
|
|
import Dialog from '../../../components/dialog/dialog'
|
|
import { getCarList, deleteCar } from "../../../api/saas"
|
|
const event = require('../../../utils/event')
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Scene({
|
|
// * 页面的初始数据
|
|
data: {
|
|
type: 0,
|
|
height: app.globalData.fragmentHeight,
|
|
loading: true,
|
|
requesting: false,
|
|
finished: false,
|
|
orderList: [],
|
|
form: {
|
|
plateNumber: '',
|
|
pageNum: 1,
|
|
pageSize: 15
|
|
},
|
|
page: -1,
|
|
index: -1
|
|
},
|
|
// * 生命周期函数--监听页面加载
|
|
onLoad: function (options) {
|
|
if(options.type){
|
|
this.data.type = Number(options.type)
|
|
}
|
|
event.on('OrderMessage', this, this.onEvent)
|
|
this.setData({ height: app.globalData.fragmentHeight - 100 })
|
|
this.fetchOrderList()
|
|
},
|
|
onEvent: function(message){
|
|
if (message.what == 201) {
|
|
this.onRefreshList()
|
|
} else if (message.what == 202) {
|
|
this.setData({ [`orderList[${this.data.page}][${this.data.index}]`]: message.detail })
|
|
}
|
|
},
|
|
onChange: function({detail}) {
|
|
this.data.form.plateNumber = detail
|
|
},
|
|
onSearch: function(){
|
|
this.onRefreshList()
|
|
},
|
|
onRefreshList: function () {
|
|
if (this.data.requesting) {
|
|
return
|
|
}
|
|
this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false })
|
|
this.fetchOrderList()
|
|
},
|
|
fetchOrderList: function () {
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
this.data.requesting = true
|
|
getCarList(this.data.form).then(result => {
|
|
if (result.data && result.data.records && result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `orderList[${this.data.orderList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = ((num - 1) * this.data.form.pageSize + respList.length) >= result.data.total
|
|
this.setData({ [nowList]: respList, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false })
|
|
} else {
|
|
this.setData({ finished: true, requesting: false, loading: false })
|
|
}
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false })
|
|
util.showToast(err)
|
|
}).then(() => {
|
|
this.refresh = this.refresh || this.selectComponent('#refresh')
|
|
this.refresh.setRefresh(false)
|
|
})
|
|
},
|
|
lookItem: function (e) {
|
|
if(e.currentTarget.dataset.page >= 0){
|
|
this.data.page = e.currentTarget.dataset.page
|
|
this.data.index = e.currentTarget.dataset.index
|
|
var item = this.data.orderList[this.data.page][this.data.index]
|
|
if(this.data.type == 1){
|
|
const channel = this.getOpenerEventChannel()
|
|
channel.emit('onCallback', { what: 140, detail: item })
|
|
wx.navigateBack()
|
|
} else {
|
|
wx.navigateTo({ url: `/pages/setting/vehicle-detial/index?id=${item.id}` })
|
|
}
|
|
} else {
|
|
wx.navigateTo({ url: `/pages/setting/vehicle-detial/index` })
|
|
}
|
|
},
|
|
deleteForm: function(e){
|
|
var item = this.data.orderList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
Dialog.confirm({ title: '温馨提示', message: '确定删除该车辆信息?' }).then(() => {
|
|
wx.showLoading({ title: '正在处理', mask: true })
|
|
deleteCar(item.id).then(result => {
|
|
wx.hideLoading()
|
|
this.onRefreshList()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}).catch(err => {
|
|
})
|
|
},
|
|
onUnload: function(){
|
|
event.remove('OrderMessage', this)
|
|
}
|
|
|
|
})
|