jiangchengfeiyi-xiaochengxu/unpackage/dist/dev/mp-weixin/pages/mine/Contact/Contact.js
2024-12-04 13:33:43 +08:00

186 lines
5.8 KiB
JavaScript

"use strict";
const common_vendor = require("../../../common/vendor.js");
const api_request = require("../../../api/request.js");
if (!Array) {
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
_easycom_uni_popup2();
}
const _easycom_uni_popup = () => "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
_easycom_uni_popup();
}
const _sfc_main = {
__name: "Contact",
setup(__props) {
common_vendor.onMounted(() => {
getContacts();
});
const contacts = common_vendor.ref([{}]);
const getContacts = async () => {
const res = await common_vendor.index.request({
url: api_request.baseUrl + "/contacts/list",
method: "POST",
header: {
cookie: common_vendor.wx$1.getStorageSync("cookie")
}
});
console.log(res);
if (res.data.code === 1) {
filteredContacts.value = res.data.data;
} else {
common_vendor.index.showToast({
icon: "error",
title: "获取失败"
});
}
};
const newContact = common_vendor.ref({
ame: "",
phone: "",
isDefault: 0
});
const searchText = common_vendor.ref("");
const filteredContacts = common_vendor.ref([]);
common_vendor.onMounted(() => {
filteredContacts.value = contacts.value;
});
common_vendor.watch(searchText, () => {
if (searchText.value === "") {
filteredContacts.value = contacts.value;
} else {
filteredContacts.value = contacts.value.filter((contact) => {
return contact.name.includes(searchText.value) || contact.phone.includes(
searchText.value
);
});
}
});
const addContact = async () => {
popup.value.close();
const res = await common_vendor.index.request({
url: api_request.baseUrl + "/contacts/add",
method: "POST",
header: {
cookie: common_vendor.wx$1.getStorageSync("cookie")
},
data: {
name: newContact.value.name,
phone: newContact.value.phone,
isDefault: 0
}
});
console.log(res, 添加);
if (res.data.code === 1) {
console.log("添加成功");
} else {
common_vendor.index.showToast({
icon: "error",
title: "添加失败"
});
}
getContacts();
};
const deleteContact = async (item, index) => {
const res = await common_vendor.index.request({
url: api_request.baseUrl + "/contacts/delete",
method: "POST",
header: {
cookie: common_vendor.wx$1.getStorageSync("cookie")
},
data: {
id: item.value[index].id
}
});
console.log(item.value[index].id);
console.log(res, "1111111111111");
if (res.data.code === 1) {
console.log("删除成功");
} else {
common_vendor.index.showToast({
icon: "error",
title: "删除失败"
});
}
getContacts();
};
const indexToModify = common_vendor.ref(null);
const editContact = (index) => {
popup1.value.open("center");
indexToModify.value = index;
const contactToModify = contacts.value[index];
newContact.value = {
name: contactToModify.name,
phone: contactToModify.phone
};
};
const saveModifiedContact = () => {
if (indexToModify.value !== null) {
const Index = indexToModify.value;
const contact = contacts.value[Index];
contact.name = newContact.value.name;
contact.phone = newContact.value.phone;
newContact.value = {
name: "",
phone: ""
};
popup1.value.close();
filteredContacts.value = contacts.value;
}
};
const popup = common_vendor.ref(null);
const popup1 = common_vendor.ref(null);
const open = () => {
popup.value.open("center");
};
const close = () => {
popup.value.close();
};
const close1 = () => {
popup1.value.close();
};
return (_ctx, _cache) => {
return {
a: newContact.value.name,
b: common_vendor.o(($event) => newContact.value.name = $event.detail.value),
c: newContact.value.phone,
d: common_vendor.o(($event) => newContact.value.phone = $event.detail.value),
e: common_vendor.o(addContact),
f: common_vendor.o(close),
g: common_vendor.sr(popup, "0aa6b83b-0", {
"k": "popup"
}),
h: common_vendor.p({
["mask-click"]: false,
["background-color"]: "white"
}),
i: newContact.value.name,
j: common_vendor.o(($event) => newContact.value.name = $event.detail.value),
k: newContact.value.phone,
l: common_vendor.o(($event) => newContact.value.phone = $event.detail.value),
m: common_vendor.o(saveModifiedContact),
n: common_vendor.o(close1),
o: common_vendor.sr(popup1, "0aa6b83b-1", {
"k": "popup1"
}),
p: common_vendor.p({
["mask-click"]: false,
["background-color"]: "white"
}),
q: common_vendor.f(filteredContacts.value, (item, index, i0) => {
return {
a: common_vendor.t(item.name),
b: common_vendor.t(item.phone),
c: common_vendor.t(item.id),
d: common_vendor.o(($event) => editContact(item), index),
e: common_vendor.o(($event) => deleteContact(item, index), index),
f: index
};
}),
r: common_vendor.o(open)
};
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-0aa6b83b"], ["__file", "D:/jiangchengfeiyi-xiaochengxu/pages/mine/Contact/Contact.vue"]]);
wx.createPage(MiniProgramPage);