const api = require('../../../../api/conflict') import { formatTimestamp } from '../../../../utils/util' Page({ /** * 页面的初始数据 */ data: { loadMoreType: 'loading', loadMoreVisible: true, tabList:['编辑上报','历史上报'],//tab列表 currentTabIndex:0, pageNo: 1, // 分页页码 pageSize: 20, // 分页页长 isLoading: true, timestamp:'', conflictType:'', reason:'', peopleNumber:'', peopleLeader:'', dutyUnit:'', dutyPerson:'', mainMeasure:'', statusNow:'', remark:'', temp_datetime:[], datetime:'', historyList:[], pickerVisible:false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let date=new Date(); this.setData({ temp_datetime:[date.getFullYear().toString(),date.getMonth().toString(),date.getDate().toString()] }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { if(this.data.currentTabIndex ==='1' && !this.data.isLoading && this.data.loadMoreType!='none'){ this.setData({ loadMoreType:'loading', loadMoreVisible:true, pageNo:this.data.pageNo+1, isLoading:true }) let param = { pageIndex:this.data.pageNo, pageSize:this.data.pageSize, timestamp:this.data.timestamp } this.getHistory(param) } }, onConfirmDatetime(e){ console.log(e.detail) this.setData({ datetime:e.detail.label, pickerVisible:false }) }, changeTab(e){ this.setData({ currentTabIndex:e.detail.key }) if(e.detail.key==="1"){ this.setData({ loadMoreType:'loading', loadMoreVisible:true, pageNo:1, historyList:[], isLoading:true, timestamp:formatTimestamp(new Date()) }) let param = { pageIndex:this.data.pageNo, pageSize:this.data.pageSize, timestamp:this.data.timestamp } this.getHistory(param) } }, getHistory(param){ api.getHistory(param).then((res)=>{ this.setData({ historyList:this.data.historyList.concat(res.data), isLoading:false }) if(res.data.length<20){ this.setData({ loadMoreType:'none', loadMoreVisible:true, }) }else{ this.setData({ loadMoreType:"more", loadMoreVisible:false }) } }) }, handleConflictType(e){ this.setData({ conflictType:e.detail.value }) }, handleReason(e){ this.setData({ reason:e.detail.value }) }, handlePeopleNumber(e){ this.setData({ peopleNumber:e.detail.value }) }, handlePeopleLeader(e){ this.setData({ peopleLeader:e.detail.value }) } , handleDutyUnit(e){ this.setData({ dutyUnit:e.detail.value }) }, handleDutyPerson(e){ this.setData({ dutyPerson:e.detail.value }) }, handleMainMeasure(e){ this.setData({ mainMeasure:e.detail.value }) }, handleStatusNow(e){ this.setData({ statusNow:e.detail.value }) }, handleRemark(e){ this.setData({ remark:e.detail.value }) }, showPicker(){ this.setData({ pickerVisible:!this.data.pickerVisible }) }, navigateToDetail(e){ wx.navigateTo({ url: '../historyDetail/historyDetail?id='+e.currentTarget.dataset.id, }) }, submit(){ if(this.data.conflictType===''){ wx.showToast({ title: '请输入矛盾纠纷类型', icon:"none" }) return false } if(this.data.reason===''){ wx.showToast({ title: '请输入形成原因', icon:"none" }) return false } if(this.data.peopleNumber===''){ wx.showToast({ title: '请输入涉及人数', icon:"none" }) return false } if(this.data.peopleLeader===''){ wx.showToast({ title: '请输入挑头骨干人员', icon:"none" }) return false } if(this.data.dutyUnit===''){ wx.showToast({ title: '请输入责任单位', icon:"none" }) return false } if(this.data.dutyPerson===''){ wx.showToast({ title: '请输入责任人', icon:"none" }) return false } if(this.data.mainMeasure===''){ wx.showToast({ title: '请输入主要采取措施', icon:"none" }) return false } if(this.data.statusNow===''){ wx.showToast({ title: '请输入目前稳控状况', icon:"none" }) return false } if(this.data.datetime===''){ wx.showToast({ title: '请选择提报时间', icon:"none" }) return false } let num = new Number(this.data.peopleNumber) if(isNaN(num)||num<0 || this.data.peopleNumber.indexOf('.')!=-1){ wx.showToast({ title: '请输入正确的人数', icon:"none" }) return false } let param = { conflictType:this.data.conflictType, conflictReason:this.data.reason, involvedNum:parseInt(this.data.peopleNumber), mainstayLeader:this.data.peopleLeader, responsibleDept:this.data.dutyUnit, responsiblePeople:this.data.dutyPerson, majorMeasures:this.data.mainMeasure, currentSituation:this.data.statusNow, remark:this.data.remark, submitTime:this.data.datetime } wx.showLoading({ title:'提交中' }) api.submitConflict(param).then(()=>{ this.setData({ conflictType:'', reason:'', peopleNumber:'', peopleLeader:'', dutyUnit:'', dutyPerson:'', mainMeasure:'', statusNow:'', remark:'', datetime:'' }) wx.hideLoading({ complete: (res) => { wx.showToast({ title: '上报成功', icon:'none' })}, }) }).catch(err=>{ wx.hideLoading({ }) }) } })