|
@@ -22,17 +22,20 @@
|
|
|
<script lang="ts" setup>
|
|
|
import { onLoad } from "@dcloudio/uni-app";
|
|
|
import { reactive, ref } from "vue";
|
|
|
-import { addCustomer, subscribeToMessage } from "@/services/ams";
|
|
|
+import { addCustomer, getOpenId } from "@/services/ams";
|
|
|
+
|
|
|
const fileList = ref<any[]>([]);
|
|
|
const imgList = ref<string[]>([]);
|
|
|
-const aData = JSON.parse(uni.getStorageSync("activityData"));
|
|
|
-const openid = uni.getStorageSync("openid");
|
|
|
-const phone = uni.getStorageSync("phone");
|
|
|
+
|
|
|
const routerInfo = reactive({ discountId: "", discountLevel: "" });
|
|
|
-const action =
|
|
|
- import.meta.env.VITE_API_URL + "/miniApp/oss/upload/" + aData.brandId;
|
|
|
|
|
|
const customUpload = (file: any, formData: any, options: any) => {
|
|
|
+ const aData = JSON.parse(uni.getStorageSync("activityData"));
|
|
|
+ const brandId = uni.getStorageSync("brandId");
|
|
|
+
|
|
|
+ const action =
|
|
|
+ import.meta.env.VITE_API_URL + "/miniApp/oss/upload/" + aData.brandId ||
|
|
|
+ brandId;
|
|
|
uni.uploadFile({
|
|
|
url: action,
|
|
|
header: options.header,
|
|
@@ -65,26 +68,55 @@ const handleRemove = (file: any) => {
|
|
|
};
|
|
|
|
|
|
const loading = ref(false);
|
|
|
-const onAdd = () => {
|
|
|
- // if(loading.value) return
|
|
|
- // loading.value = true
|
|
|
+const onAdd = async () => {
|
|
|
+ const aData = JSON.parse(uni.getStorageSync("activityData"));
|
|
|
+ const brandId = uni.getStorageSync("brandId");
|
|
|
+
|
|
|
const location = uni.getStorageSync("location")
|
|
|
? JSON.parse(uni.getStorageSync("location"))
|
|
|
: {};
|
|
|
if (imgList.value.length === 0)
|
|
|
return uni.showToast({ title: "请上传图片", icon: "none" });
|
|
|
- const params = {
|
|
|
- openid,
|
|
|
- mobile: phone,
|
|
|
+ const query: any = {
|
|
|
+ openid: uni.getStorageSync("openid"),
|
|
|
+ mobile: uni.getStorageSync("phone") || "",
|
|
|
latitude: location.latitude || "",
|
|
|
longitude: location.longitude || "",
|
|
|
discountId: routerInfo.discountId || "",
|
|
|
discountLevel: routerInfo.discountLevel || "",
|
|
|
receiptImages: imgList.value.join(","),
|
|
|
marketingActivityId: aData.id,
|
|
|
- brandId: aData.brandId,
|
|
|
+ brandId: aData.brandId || brandId,
|
|
|
};
|
|
|
- addCustomer(params).then((res: any) => {
|
|
|
+ if (!query.openid) {
|
|
|
+ uni.login({
|
|
|
+ //获取code,
|
|
|
+ success: async (res) => {
|
|
|
+ const params = {
|
|
|
+ code: res.code,
|
|
|
+ appid: uni.getAccountInfoSync().miniProgram.appId,
|
|
|
+ };
|
|
|
+ getOpenId(params).then((response: any) => {
|
|
|
+ if (response.code === 200) {
|
|
|
+ query.openid = response.data.openid;
|
|
|
+ onUpload(query);
|
|
|
+ uni.setStorageSync("openid", response.data.openid);
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: "获取openid失败",
|
|
|
+ icon: "none",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ onUpload(query);
|
|
|
+ }
|
|
|
+};
|
|
|
+const onUpload = async (params: any) => {
|
|
|
+ const res: any = await addCustomer(params);
|
|
|
+ try {
|
|
|
if (res.code === 200) {
|
|
|
uni.showToast({ title: "操作成功!", icon: "none" });
|
|
|
|
|
@@ -95,7 +127,7 @@ const onAdd = () => {
|
|
|
if (
|
|
|
response["k-wHQGcGv7KlvDeXb6AXoP4HWBb6nz4HliV41-NcpFw"] === "accept"
|
|
|
) {
|
|
|
- // uni.showToast({ title: "操作成功!", icon: "none" });
|
|
|
+ uni.showToast({ title: "操作成功!", icon: "none" });
|
|
|
}
|
|
|
setTimeout(() => {
|
|
|
uni.navigateBack();
|
|
@@ -109,7 +141,9 @@ const onAdd = () => {
|
|
|
} else {
|
|
|
uni.showToast({ title: res.msg, icon: "none" });
|
|
|
}
|
|
|
- });
|
|
|
+ } catch (err) {
|
|
|
+ uni.showToast({ title: res.msg || "网络错误", icon: "none" });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
const throttle = (func: any, limit: any) => {
|