186 lines
5.3 KiB
JavaScript
186 lines
5.3 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const common_js_util = require("../../common/js/util.js");
|
|
const api_index = require("../../api/index.js");
|
|
if (!Array) {
|
|
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
|
|
_easycom_uni_icons2();
|
|
}
|
|
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
|
|
if (!Math) {
|
|
_easycom_uni_icons();
|
|
}
|
|
const _sfc_main = {
|
|
__name: "newFriend",
|
|
setup(__props) {
|
|
const store = common_vendor.useStore();
|
|
const userinfo = common_vendor.computed(() => {
|
|
let result = store.state.userinfo;
|
|
return result;
|
|
});
|
|
const userList = common_vendor.reactive({
|
|
data: [],
|
|
pageNum: 1,
|
|
pageSize: 10,
|
|
total: 0
|
|
});
|
|
const keyword = common_vendor.ref("");
|
|
common_vendor.onLoad(() => {
|
|
getFriendList();
|
|
});
|
|
common_vendor.onReachBottom(() => {
|
|
getMoreFriendList();
|
|
});
|
|
common_vendor.onPullDownRefresh(() => {
|
|
refreshFriendList();
|
|
});
|
|
function getSearchFriendList() {
|
|
userList.data = [];
|
|
userList.pageNum = 1;
|
|
userList.pageSize = 10;
|
|
userList.total = 0;
|
|
api_index.api.video.searchFriendByName({
|
|
path: [keyword.value],
|
|
query: {
|
|
pageNum: userList.pageNum,
|
|
pageSize: userList.pageSize
|
|
}
|
|
}).then((rs) => {
|
|
console.log(rs);
|
|
if (rs.code == 200) {
|
|
if (userList.pageNum)
|
|
userList.data.length = 0;
|
|
userList.data.push(...rs.rows.map((item) => {
|
|
item.format_userPortrait = common_js_util.util.format_url(item.userPortrait, "img");
|
|
return item;
|
|
}));
|
|
userList.total = rs.total;
|
|
return;
|
|
}
|
|
common_js_util.util.alert({
|
|
content: rs.msg,
|
|
showCancel: false
|
|
});
|
|
}).finally(() => {
|
|
common_vendor.index.stopPullDownRefresh();
|
|
});
|
|
}
|
|
function refreshFriendList() {
|
|
userList.pageNum = 1;
|
|
userList.total = 0;
|
|
getFriendList();
|
|
}
|
|
function getMoreFriendList() {
|
|
if (userList.data.length >= userList.total)
|
|
return;
|
|
userList.pageNum++;
|
|
getFriendList();
|
|
}
|
|
function agreeFriend(item) {
|
|
api_index.api.video.agreeFriend({
|
|
path: [userinfo.value.userId, item.userId],
|
|
query: {}
|
|
}).then((rs) => {
|
|
if (rs.code === 200) {
|
|
common_vendor.index.showToast({
|
|
title: "同意成功",
|
|
icon: "success",
|
|
duration: 1500
|
|
});
|
|
} else {
|
|
common_vendor.index.showToast({
|
|
title: rs.msg,
|
|
icon: "error",
|
|
duration: 1500
|
|
});
|
|
}
|
|
}).finally(() => {
|
|
});
|
|
}
|
|
function refuseFriend(item) {
|
|
api_index.api.video.refuseFriend({
|
|
path: [userinfo.value.userId, item.userId],
|
|
query: {}
|
|
}).then((rs) => {
|
|
if (rs.code === 200) {
|
|
common_vendor.index.showToast({
|
|
title: "拒绝成功",
|
|
icon: "success",
|
|
duration: 1500
|
|
});
|
|
} else {
|
|
common_vendor.index.showToast({
|
|
title: rs.msg,
|
|
icon: "error",
|
|
duration: 1500
|
|
});
|
|
}
|
|
}).finally(() => {
|
|
});
|
|
}
|
|
function getFriendList() {
|
|
api_index.api.video.getFriendListPage({
|
|
path: [userinfo.value.userId],
|
|
query: {
|
|
pageNum: userList.pageNum,
|
|
pageSize: userList.pageSize
|
|
}
|
|
}).then((rs) => {
|
|
console.log(rs);
|
|
if (rs.code == 200) {
|
|
if (userList.pageNum)
|
|
userList.data.length = 0;
|
|
userList.data.push(...rs.rows.map((item) => {
|
|
item.format_userPortrait = common_js_util.util.format_url(item.userPortrait, "img");
|
|
return item;
|
|
}));
|
|
userList.total = rs.total;
|
|
return;
|
|
}
|
|
common_js_util.util.alert({
|
|
content: rs.msg,
|
|
showCancel: false
|
|
});
|
|
}).finally(() => {
|
|
common_vendor.index.stopPullDownRefresh();
|
|
});
|
|
}
|
|
function handleSearch() {
|
|
getSearchFriendList();
|
|
}
|
|
function handleUser(item) {
|
|
common_vendor.index.navigateTo({
|
|
url: common_js_util.util.setUrl("/pages/index/videoHome", {
|
|
userId: item.userId
|
|
})
|
|
});
|
|
}
|
|
return (_ctx, _cache) => {
|
|
return {
|
|
a: common_vendor.p({
|
|
type: "search"
|
|
}),
|
|
b: keyword.value,
|
|
c: common_vendor.o$1(($event) => keyword.value = $event.detail.value),
|
|
d: common_vendor.o$1(handleSearch),
|
|
e: common_vendor.f(userList.data, (item, index, i0) => {
|
|
return common_vendor.e({
|
|
a: item.format_userPortrait,
|
|
b: common_vendor.t(item.userNickname),
|
|
c: common_vendor.t(item.createTime),
|
|
d: item.friendState == 1
|
|
}, item.friendState == 1 ? {
|
|
e: common_vendor.o$1(($event) => agreeFriend(item), index),
|
|
f: common_vendor.o$1(($event) => refuseFriend(item), index)
|
|
} : item.friendState == 2 ? {} : {}, {
|
|
g: item.friendState == 2,
|
|
h: index,
|
|
i: common_vendor.o$1(($event) => handleUser(item), index)
|
|
});
|
|
})
|
|
};
|
|
};
|
|
}
|
|
};
|
|
wx.createPage(_sfc_main);
|