<template>
|
<view class="uni-project-event-list">
|
<!-- @refresherrefresh="onRefresh" -->
|
<scroll-view class="uni-panel-list" enable-flex scroll-y refresher-enabled="true"
|
:refresher-triggered="triggered" :scroll-top="scrollTop" :refresher-threshold="100"
|
@refresherpulling="onPulling" @refresherrefresh="onRefresh" @refresherrestore="onRestore" @refresherabort="onAbort" @scroll="scrollView"
|
@scrolltolower="scrollEnd">
|
<view v-if="emptyTip" class="uni-panel-center">
|
<text style="color: gray;display: flex;justify-content: center;">{{emptyTip}}</text>
|
<image mode="center" src="@/static/open-box.png"> </image>
|
</view>
|
<view class="uni-panel-item" v-for="(item, index) in listBody" :key="item.CN_G_ID">
|
<eventItem :eventData="item" :pagesign="pagesign" @clickItem="triggerItem"></eventItem>
|
</view>
|
<view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
|
</scroll-view>
|
</view>
|
</template>
|
|
<script>
|
import eventItem from "./event-item.vue"
|
import TaskInit from "@/common/extend.js"
|
import {
|
showModal,
|
showToast,
|
showLoading,
|
hideLoading
|
} from "@/common/Page.js"
|
import {
|
queryList as prjEventQueryList
|
} from "@/api/gungho/prjevent.js"
|
|
export default {
|
components: {
|
eventItem,
|
},
|
name: "pageProjectEventList",
|
props: {
|
listType: {
|
type: String,
|
default () {
|
return "";
|
}
|
},
|
sql: {
|
type: String,
|
default () {
|
return "";
|
}
|
},
|
order: {
|
type: String,
|
default () {
|
return "";
|
}
|
},
|
type: {
|
type: Array,
|
default () {
|
return [];
|
}
|
},
|
status: {
|
type: Array,
|
default () {
|
return [];
|
}
|
},
|
quadrant: {
|
type: Array,
|
default () {
|
return [];
|
}
|
},
|
},
|
data() {
|
return {
|
firstLoadData: true,
|
listBody: [],
|
sessionId: "",
|
token: "",
|
emptyTip: "",
|
loadMoreText: "加载中...",
|
showLoadMore: false,
|
triggered: false,
|
pagesign: "",
|
scrollTop: 0,
|
old: {
|
triggered: 0,
|
scrollTop: 0
|
},
|
};
|
},
|
watch: {
|
sql(value) {
|
|
this.loadData()
|
},
|
|
|
},
|
methods: {
|
loadData() {
|
var _this = this;
|
_this.errmsg = '';
|
_this.pindex = 1;
|
_this.psize = 15;
|
_this.totalcount = 0;
|
_this.ptotal = 0;
|
_this.sessionId = "";
|
|
|
showLoading("加载中,请稍后...")
|
_this.showLoadMore = false;
|
_this.pageGetList().then((resData) => {
|
|
_this.scrollTop = _this.old.scrollTop
|
_this.$nextTick(function() {
|
_this.scrollTop = 0
|
});
|
_this.listBody = resData;
|
|
_this.setData({
|
listBody: _this.listBody,
|
})
|
hideLoading()
|
if (_this.firstLoadData)
|
showToast('数据装载完毕', 'none')
|
else
|
showToast('列表已刷新', 'none')
|
_this.setData({
|
firstLoadData: false
|
})
|
_this.$forceUpdate();
|
}).catch(() => {
|
hideLoading()
|
_this.setData({
|
listBody: [],
|
firstLoadData: false
|
})
|
_this.$forceUpdate();
|
});
|
},
|
setData: function(obj) {
|
let that = this;
|
let keys = [];
|
let val, data;
|
|
Object.keys(obj).forEach(function(key) {
|
keys = key.split(".");
|
val = obj[key];
|
data = that.$data;
|
keys.forEach(function(key2, index) {
|
if (index + 1 == keys.length) {
|
that.$set(data, key2, val);
|
} else {
|
if (!data[key2]) {
|
that.$set(data, key2, {});
|
}
|
}
|
data = data[key2];
|
});
|
});
|
},
|
triggerItem(item) {
|
uni.navigateTo({
|
url: '/pages/project/event/detail?eventId=' + item.CN_G_ID,
|
success(res) {},
|
fail(res) {},
|
})
|
},
|
pageGetList() {
|
var _this = this;
|
return new Promise(async (resolve, reject) => {
|
try {
|
if (_this.sql == "") {
|
_this.emptyTip = 'sql没有完成'
|
_this.loadMoreText = ""
|
_this.showLoadMore = false;
|
resolve([])
|
return
|
}
|
_this.emptyTip = ''
|
const attrs =
|
"CN_S_TITLE,CN_G_ID,CN_S_E_TYPE,CN_S_STATE,CN_S_PRJ_NAME,CN_N_QUADRANT,CN_S_CREATOR,CN_S_TAKEON_ID,CN_S_TAKEON_NAME,CN_T_CREATE,CN_T_PLAN_CLOSE,CN_N_GAP_DAY,CN_N_REPLY_COUNT"
|
let res = {}
|
|
res = await prjEventQueryList({
|
page: _this.pindex,
|
size: _this.psize,
|
sql: _this.sql,
|
attrs,
|
order: _this.order,
|
type: "0",
|
|
})
|
|
|
if (res) {
|
_this.totalcount = res.record_count
|
_this.ptotal = res.page_count
|
_this.query_id = res.query_id
|
|
let nRecords = res.rows.length
|
|
if (_this.pindex < res.page_count) {
|
_this.loadMoreText = "加载更多"
|
|
}
|
if (nRecords > 0) {
|
showToast('加载了' + nRecords + '条数据', 'none')
|
resolve(_this.getDefaultData(res.rows))
|
} else {
|
//_this.loadMoreText = "没有更多数据了!"
|
showToast('没有更多数据了', 'none')
|
resolve([])
|
}
|
} else {
|
//_this.loadMoreText = "没有更多数据了!"
|
showToast('没有更多数据了', 'none')
|
resolve([])
|
}
|
|
} catch (ex) {
|
console.log("pageGetList failed", ex)
|
_this.loadMoreText = "加载数据失败!"
|
reject(ex)
|
this.showError(ex)
|
}
|
})
|
},
|
getEventData(data) {
|
|
if (data.CN_T_CREATE) {
|
data.CN_T_CREATE = TaskInit.dateUtils.format(data.CN_T_CREATE, "notime");
|
}
|
if (data.CN_T_PLAN_CLOSE) {
|
data.CN_T_PLAN_CLOSE = TaskInit.dateUtils.format(data.CN_T_PLAN_CLOSE,
|
"notime");
|
}
|
data.CN_S_TITLE = (data.CN_S_TITLE || data.CN_S_TITLE);
|
const {
|
icon,
|
color
|
} = this.getTypeIconInfo(data.CN_S_E_TYPE);
|
data.typeIcon = icon
|
data.typeIconColor = color
|
|
data.Minute = data.Minute || "";
|
if (data.Minute) {
|
console.log(data.Minute)
|
if (data.Minute < 0) { //超期
|
const minute = data.Minute * -1;
|
Math.ceil(minute / 60 / 24)
|
if (Math.ceil(minute / 60) == 0) {
|
data.Minute = "超期0小时";
|
} else if (Math.ceil(minute / 60) < 24) {
|
// console.log(Math.ceil(minute/60));
|
data.Minute = "超期" + Math.ceil(minute / 60) + "小时";
|
} else {
|
data.Minute = "超期" + Math.ceil(minute / 60 / 24) + "天";
|
}
|
} else { //将要超期
|
const minute = data.Minute;
|
if (Math.ceil(minute / 60) < 24) {
|
data.Minute = Math.ceil(minute / 60) + "小时后";
|
} else {
|
data.Minute = Math.ceil(minute / 60 / 24) + "天后";
|
}
|
}
|
} else if (data.CN_N_GAP_DAY) {
|
if (data.CN_N_GAP_DAY > 0) {
|
data.Minute = "超期" + data.CN_N_GAP_DAY + "天";
|
}
|
}
|
data.Minutechaoqi = data.Minute.indexOf('超期') > -1;
|
data.Minutetoday = data.Minute.indexOf('今天') > -1;
|
return data
|
},
|
getDefaultData(arr) {
|
let ret = {
|
data: {
|
Body: arr
|
}
|
}
|
for (let i = 0; i < ret.data.Body.length; i++) {
|
ret.data.Body[i] = this.getEventData(ret.data.Body[i])
|
}
|
// console.log(JSON.stringify(ret.data.Body))
|
return ret.data.Body
|
},
|
getTypeIconInfo(type) {
|
let ret = {
|
icon: "",
|
color: ""
|
}
|
if (type == "问题") {
|
ret = {
|
icon: "fs-question2",
|
color: "#ffac0c"
|
}
|
} else if (type == "错误") {
|
ret = {
|
icon: "fs-bug",
|
color: "#ea5610"
|
}
|
} else if (type == "需求") {
|
ret = {
|
icon: "fs-CirclPlus",
|
color: "#2dc3e8"
|
}
|
} else if (type == "建议") {
|
ret = {
|
icon: "fs-suggest",
|
color: "#60ae60"
|
}
|
} else if (type == "讨论") {
|
ret = {
|
icon: "fs-discuss",
|
color: "#aaa"
|
}
|
}
|
|
return ret
|
},
|
|
addPageData() {
|
var _this = this;
|
_this.pindex += 1;
|
_this.pageGetList().then((resData) => {
|
_this.listBody = _this.listBody.concat(resData);
|
})
|
|
},
|
scrollView(e) { //nvue暂不支持滚动监听,可用bindingx代替
|
//console.log("scrollView:" + e.scrollTop);
|
this.old.scrollTop = e.detail.scrollTop
|
},
|
scrollEnd() {
|
var _this = this;
|
_this.showLoadMore = true;
|
if (_this.ptotal == _this.pindex) {
|
_this.loadMoreText = "没有更多数据了!"
|
return
|
}
|
_this.loadMoreText = "加载中..."
|
setTimeout(() => {
|
_this.addPageData();
|
}, 500)
|
|
},
|
onPulling(e) {
|
//console.log("onPulling", e);
|
this.old.triggered = e.detail.triggered
|
},
|
onRefresh() {
|
var _this = this;
|
showLoading("加载中,请稍后...")
|
_this.errmsg = '';
|
_this.pindex = 1;
|
_this.psize = 15;
|
_this.totalcount = 0;
|
_this.ptotal = 0;
|
_this.showLoadMore = false;
|
_this.pageGetList().then((resData) => {
|
console.log("onRefresh", resData);
|
_this.listBody = resData;
|
_this.triggered = _this.old.triggered
|
hideLoading()
|
_this.$nextTick(function() {
|
_this.triggered = 'restore'; // 需要重置
|
});
|
|
_this.setData({
|
listBody: _this.listBody
|
})
|
_this.$forceUpdate();
|
|
showToast('列表已刷新', 'none')
|
}).catch(() => {
|
hideLoading()
|
_this.setData({
|
listBody: []
|
})
|
_this.$forceUpdate();
|
});
|
|
},
|
onRestore() {
|
// console.log("onRestore");
|
this.triggered = 'restore'; // 需要重置
|
},
|
onAbort() {
|
// console.log("onAbort");
|
},
|
prjEventDataChange(data) {
|
var _this = this
|
|
console.log("prjEventDataChange", data);
|
var bChanged = false;
|
let body = _this.listBody;
|
if (data.change == '新建') {
|
const app = getApp()
|
let sLogin = app.globalData.userdata.user_login;
|
data.eventBody = this.getEventData(data.eventBody)
|
if (data.eventBody) {
|
let bFlag = false
|
if (Array.isArray(_this.status)) {
|
_this.status.indexOf("提出") != -1
|
if (_this.status.length > 0) {
|
if (_this.status.indexOf("提出") != -1 || _this.status.indexOf("未关闭") != -1)
|
bFlag = true
|
} else
|
bFlag = true
|
} else
|
bFlag = true
|
if (_this.listType == "我创建的" || (data.eventBody.CN_S_TAKEON_ID == sLogin &&
|
_this.listType == "我负责的" && bFlag)) {
|
body.unshift(data.eventBody);
|
_this.setData({
|
listBody: body,
|
})
|
}
|
}
|
return
|
}
|
|
for (let i = 0; i < body.length; i++) {
|
let item = body[i];
|
if (item.CN_G_ID == data.id) {
|
bChanged = true
|
let bRemove = false
|
let cnstate = ""
|
cnstate = data.change;
|
if (data.change == '删除') {
|
bRemove = true
|
|
} else {
|
if (data.change == '更改状态') {
|
if (Array.isArray(_this.status)) {
|
if (_this.status.length > 0) {
|
bRemove = false
|
if (_this.status.indexOf(data.status) != -1) {
|
bRemove = true
|
}
|
} else {
|
bRemove = false
|
}
|
|
} else {
|
bRemove = false
|
}
|
}
|
}
|
if (bRemove) {
|
body.splice(i, 1);
|
break;
|
}
|
body[i].CN_S_STATE = cnstate;
|
console.log('prjEventDataChange break' + i)
|
break;
|
}
|
}
|
if (bChanged) {
|
_this.setData({
|
listBody: body
|
})
|
}
|
},
|
showError(ex) {
|
let tip = typeof ex === 'string' ? ex :( ex.message || ex.err_msg || ex.errMsg || ex.err_info || "")
|
|
showModal(tip, "提示", false)
|
},
|
|
},
|
mounted() {
|
var _this = this;
|
|
// #ifdef MP-DINGTALK
|
setTimeout(() => {
|
_this.loadData();
|
}, 200)
|
// #endif
|
uni.$on('prjEventDataChange', this.prjEventDataChange)
|
},
|
destroyed() {
|
uni.$off('prjEventDataChange', this.prjEventDataChange)
|
}
|
}
|
</script>
|
|
<style lang="scss">
|
.uni-project-event-list {
|
padding: 0px 10rpx 4px;
|
background-color: #e5eaee;
|
width: 730rpx;
|
height: 100%;
|
|
.uni-panel-list {
|
height: 100%;
|
/* calc(100% - 54px); */
|
width: 730rpx;
|
flex-direction: column !important;
|
}
|
|
.uni-panel-center {
|
display: flex;
|
align-items: center;
|
margin: 100px 10px 10px;
|
width: calc(100% - 20px);
|
flex-direction: column !important;
|
}
|
|
.uni-panel-body {
|
height: 100%;
|
}
|
|
.uni-panel-item {
|
margin: 8px 12px 8px 10px;
|
border: solid 1px #ddd;
|
background-color: white;
|
border-radius: 5px;
|
-webkit-box-shadow: 0 10px 6px -6px #ddd;
|
-moz-box-shadow: 0 10px 6px -6px #ddd;
|
box-shadow: 0 10px 6px -6px #ddd;
|
//height: 64px;
|
}
|
|
.clearfix {
|
content: " ";
|
box-sizing: border-box;
|
}
|
|
/* loadmore */
|
.uni-loadmore {
|
height: 80rpx;
|
line-height: 80rpx;
|
text-align: center;
|
padding-bottom: 30rpx;
|
}
|
}
|
</style>
|