15102826049 1 هفته پیش
والد
کامیت
b486ee07af

+ 3 - 1
src/App.vue

@@ -1,10 +1,12 @@
 <script setup lang="ts">
 import { onLaunch, onShow, onHide, onLoad } from "@dcloudio/uni-app";
+// import { onLogin } from "@/utils/system";
 
 onLaunch(() => {
   console.log("App Launch");
 });
 onShow(() => {
+  // onLogin();
   const appid = uni.getAccountInfoSync().miniProgram.appId;
   uni.setStorageSync("appid", appid);
 });
@@ -12,7 +14,7 @@ onHide(() => {
   console.log("App Hide");
 });
 onLoad(() => {
-  const appid = wx.getAccountInfoSync().miniProgram.appId;
+  // const appid = wx.getAccountInfoSync().miniProgram.appId;
 });
 </script>
 <style lang="scss">

+ 4 - 3
src/components/customUpload.vue

@@ -27,11 +27,12 @@ import { reactive, ref } from "vue";
 const fileList = ref<any[]>([]);
 const imgList = ref<string[]>([]);
 const aData = JSON.parse(uni.getStorageSync("activityData"));
-const brandId = uni.getStorageSync("brandId");
+// const brandId = uni.getStorageSync("brandId");
 
 const action =
-  import.meta.env.VITE_API_URL + "/miniApp/oss/upload/" + brandId ||
-  aData?.brandId;
+  import.meta.env.VITE_API_URL +
+    "/miniApp/oss/upload/" +
+    uni.getStorageSync("brandId") || aData?.brandId;
 
 const props = defineProps({
   title: String,

+ 4 - 2
src/hooks/useDraw.ts

@@ -3,7 +3,7 @@ import { payment } from "@/services/ams";
 import { claimPayment } from "@/services/claim";
 
 let isBtn = ref(true);
-const appid = uni.getStorageSync("appid");
+// const appid = uni.getStorageSync("appid");
 
 export function useDraw(props?: any, emit?: any) {
   const handleClose = () => {
@@ -38,7 +38,9 @@ export function useDraw(props?: any, emit?: any) {
         ) {
           wx.requestMerchantTransfer({
             mchId: res.data.merchantId,
-            appId: appid,
+            appId:
+              uni.getStorageSync("appid") ||
+              uni.getAccountInfoSync().miniProgram.appId,
             package: res.data.packageInfo,
             success: (response: any) => {
               uni.showToast({ icon: "success", title: "请求成功" });

+ 11 - 13
src/pages/index/index.vue

@@ -46,7 +46,7 @@ import { getActivityData, isGetPhone } from "@/utils/system";
 import UserLoginPopup from "@/components/userLoginPopup.vue";
 
 const current = ref<number>(0);
-const appid = uni.getStorageSync("appid");
+// const appid = uni.getStorageSync("appid");
 
 const path = ref<string>("/pagesOne/winner/index");
 
@@ -56,16 +56,13 @@ const onLogin = () => {
     success: (res) => {
       const params = {
         code: res.code,
-        appid: uni.getAccountInfoSync().miniProgram.appId,
+        appid:
+          uni.getStorageSync("appid") ||
+          uni.getAccountInfoSync().miniProgram.appId,
       };
       getOpenId(params).then((res: any) => {
         if (res.code === 200) {
           uni.setStorageSync("openid", res.data.openid);
-        } else {
-          uni.showToast({
-            title: "获取openid失败",
-            icon: "none",
-          });
         }
       });
     },
@@ -74,6 +71,8 @@ const onLogin = () => {
 
 const bannerList = ref([]);
 const getBanner = () => {
+  const appid =
+    uni.getStorageSync("appid") || uni.getAccountInfoSync().miniProgram.appId;
   getCarousel(appid).then((res: any) => {
     bannerList.value = res.data;
   });
@@ -111,6 +110,8 @@ const toClaim = () => {
 };
 
 const getBrandId = () => {
+  const appid =
+    uni.getStorageSync("appid") || uni.getAccountInfoSync().miniProgram.appId;
   getBrand(appid).then((res: any) => {
     if (res.code === 200) {
       uni.setStorageSync("brandId", res?.data?.brandId || "");
@@ -123,14 +124,11 @@ const getBrandId = () => {
   });
 };
 
-onLoad(() => {
-  onLogin();
-  getBanner();
-  getBrandId();
-});
-
 onShow(() => {
+  getBanner();
+  onLogin();
   getActivityData();
+  getBrandId();
 });
 </script>
 

+ 14 - 9
src/pages/my/index.vue

@@ -106,7 +106,9 @@ import { getNavTop } from "@/utils/system";
 import { pendingWithdrawCount } from "@/services/ams";
 import { getActivityData, isGetPhone, getMobile } from "@/utils/system";
 import UserLoginPopup from "@/components/userLoginPopup.vue";
-import NearlyStoreBox from "./components/nearlyStoreBox.vue";
+// import NearlyStoreBox from "./components/nearlyStoreBox.vue";
+import { onLogin } from "@/utils/system";
+
 // import { validateHeaderName } from "http";
 const imgObj = {
   user: "https://qiuyu-daodian.oss-cn-beijing.aliyuncs.com/images/user.png",
@@ -151,7 +153,7 @@ const openid = uni.getStorageSync("openid");
 const navTop = ref<number>(0);
 const loginRef = <any>ref(null);
 const path = ref<string>("");
-const phone = uni.getStorageSync("phone");
+const phone = uni.getStorageSync("phone") || "";
 
 const toNextPage = (val: string) => {
   path.value = val;
@@ -167,7 +169,9 @@ const toNextPage = (val: string) => {
 const countData = reactive({ quickClaimCount: 0, receiptActivityCount: 0 });
 
 const getCount = async () => {
-  let res: any = await pendingWithdrawCount(openid);
+  const myOpenid = openid || uni.getStorageSync("openid");
+
+  let res: any = await pendingWithdrawCount(myOpenid);
   try {
     countData.quickClaimCount = res.data?.quickClaimCount || 0;
     countData.receiptActivityCount = res.data?.receiptActivityCount || 0;
@@ -188,13 +192,13 @@ const getCount = async () => {
 // };
 
 const mobile = ref<string>("");
-const onLogin = async (e: any) => {
-  path.value = "";
+// const onLogin = async (e: any) => {
+//   path.value = "";
 
-  if (!isGetPhone()) {
-    loginRef.value.show = true;
-  }
-};
+//   if (!isGetPhone()) {
+//     loginRef.value.show = true;
+//   }
+// };
 const getPhone = (res: string) => {
   mobile.value = res;
 };
@@ -211,6 +215,7 @@ onLoad(() => {
   navTop.value = getNavTop();
 });
 onShow(() => {
+  onLogin();
   getCount();
   getActivityData();
 });

+ 5 - 2
src/pagesOne/claim/claimRecord.vue

@@ -15,10 +15,13 @@ import { onLoad } from "@dcloudio/uni-app";
 import ClaimItem from "../record/components/claimItem.vue";
 import { quickclaimsDetail } from "@/services/claim";
 
-const openid = uni.getStorageSync("openid");
+// const openid = uni.getStorageSync("openid");
 const detailData = ref({} as any);
 const getDetail = async (id: string) => {
-  const res: any = await quickclaimsDetail({ openid, id });
+  const res: any = await quickclaimsDetail({
+    openid: uni.getStorageSync("openid"),
+    id,
+  });
   try {
     if (res.code === 200) {
       detailData.value = res.data;

+ 39 - 10
src/pagesOne/claim/uploadRecept.vue

@@ -16,15 +16,14 @@ import { ref, reactive } from "vue";
 import CustomUpload from "@/components/customUpload.vue";
 import type { Claim } from "../../services/interface";
 import { quickclaimSubmit } from "@/services/claim";
+import { getOpenId } from "@/services/ams";
 
 const aData = JSON.parse(uni.getStorageSync("activityData"));
-const phone = uni.getStorageSync("phone");
-const openid = uni.getStorageSync("openid");
-const brandId = uni.getStorageSync("brandId");
+
 const queryParams: Claim = reactive({
-  brandId: brandId || aData?.brandId,
-  mobile: phone,
-  openid: openid,
+  brandId: uni.getStorageSync("brandId") || aData?.brandId,
+  mobile: uni.getStorageSync("phone") || "",
+  openid: uni.getStorageSync("openid"),
   paymentBillImage: "",
   receiptImage: "",
 });
@@ -51,15 +50,45 @@ const onSubmit = async () => {
     });
     return;
   }
-  const res: any = await quickclaimSubmit(queryParams);
+  if (!queryParams.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) {
+            queryParams.openid = response.data.openid;
+            onUpload(queryParams);
+            uni.setStorageSync("openid", response.data.openid);
+          } else {
+            uni.showToast({
+              title: "获取openid失败",
+              icon: "none",
+            });
+          }
+        });
+      },
+    });
+  } else {
+    onUpload(queryParams);
+  }
+};
+
+const onUpload = async (params: Claim) => {
+  const res: any = await quickclaimSubmit(params);
   try {
     uni.showToast({
       title: res.msg,
       icon: res.code === 200 ? "success" : "none",
     });
-    setTimeout(() => {
-      uni.navigateBack();
-    }, 500);
+    if (res.code === 200) {
+      setTimeout(() => {
+        uni.navigateBack();
+      }, 500);
+    }
   } catch (err) {
     uni.showToast({
       title: res.msg || "上传失败",

+ 13 - 11
src/pagesOne/record/claimList.vue

@@ -74,17 +74,19 @@ const getList = (type?: string) => {
   if (type === "search") params.pageNum = 1;
   const currentApi =
     currenType.value === "list" ? auditSuccessList : quickclaimsList;
-  currentApi({ openid, ...params }).then((res: any) => {
-    params.currentPage = Math.ceil(res.total / params.pageSize);
-    list.value = [...list.value, ...res.rows].map((item) => {
-      return {
-        ...item,
-        receiptImageArr: item.receiptImage.split(","),
-        paymentBillImageArr: item.paymentBillImage.split(","),
-      };
-    });
-    // isRefresh.value = false;
-  });
+  currentApi({ openid: uni.getStorageSync("openid"), ...params }).then(
+    (res: any) => {
+      params.currentPage = Math.ceil(res.total / params.pageSize);
+      list.value = [...list.value, ...res.rows].map((item) => {
+        return {
+          ...item,
+          receiptImageArr: item.receiptImage.split(","),
+          paymentBillImageArr: item.paymentBillImage.split(","),
+        };
+      });
+      // isRefresh.value = false;
+    }
+  );
 };
 
 const toDetail = (item: any) => {

+ 0 - 1
src/pagesOne/record/components/claimItem.vue

@@ -63,7 +63,6 @@
 <script lang="ts" setup>
 import { formatTagColor, formatTagBgColor, formatTagStr } from "@/utils/common";
 import { useDraw } from "@/hooks/useDraw";
-import { onLoad } from "@dcloudio/uni-app";
 
 const { onPayment, isWithDraw } = useDraw();
 const props = defineProps({

+ 7 - 5
src/pagesOne/record/uploadList.vue

@@ -40,7 +40,7 @@ const props = defineProps({
   activeName: String,
 });
 
-const openid = uni.getStorageSync("openid");
+// const openid = uni.getStorageSync("openid");
 
 const list = <any>ref([]);
 
@@ -68,10 +68,12 @@ watch(
 
 const getList = (type?: string) => {
   if (type === "search") params.pageNum = 1;
-  rewardList({ openid, ...params }).then((res: any) => {
-    params.currentPage = Math.ceil(res.total / params.pageSize);
-    list.value = [...list.value, ...res.rows];
-  });
+  rewardList({ openid: uni.getStorageSync("openid"), ...params }).then(
+    (res: any) => {
+      params.currentPage = Math.ceil(res.total / params.pageSize);
+      list.value = [...list.value, ...res.rows];
+    }
+  );
 };
 
 // onLoad(() => {

+ 7 - 5
src/pagesOne/record/winnerList.vue

@@ -53,7 +53,7 @@ import { useDraw } from "@/hooks/useDraw";
 
 const { onPayment, isWithDraw } = useDraw();
 
-const openid = uni.getStorageSync("openid");
+// const openid = uni.getStorageSync("openid");
 // const appid = uni.getStorageSync("appid");
 const list = <any>ref([]);
 const params = <any>reactive({
@@ -65,10 +65,12 @@ const params = <any>reactive({
 // let isBtn = ref(true);
 
 const getList = () => {
-  auditSuccessList({ openid, ...params }).then((res: any) => {
-    params.currentPage = Math.ceil(res.total / params.pageSize);
-    list.value = [...list.value, ...res.rows];
-  });
+  auditSuccessList({ openid: uni.getStorageSync("openid"), ...params }).then(
+    (res: any) => {
+      params.currentPage = Math.ceil(res.total / params.pageSize);
+      list.value = [...list.value, ...res.rows];
+    }
+  );
 };
 
 // const onPayment = (data: any) => {

+ 2 - 2
src/pagesOne/winner/components/uploadReceptPopop.vue

@@ -64,7 +64,7 @@ const props = defineProps({
   },
   list: Array<Receipt>,
 });
-const openid = uni.getStorageSync("openid");
+// const openid = uni.getStorageSync("openid");
 
 const emit = defineEmits(["update:show"]);
 const value = ref("1");
@@ -97,7 +97,7 @@ const toUploadImage = (type: string) => {
     return;
   }
   const params = {
-    openid,
+    openid: uni.getStorageSync("openid"),
     marketingActivityId: props.id,
     discountId: discountId.value,
   };

+ 15 - 13
src/pagesOne/winner/index.vue

@@ -114,13 +114,13 @@ let showUpload = ref<boolean>(false);
 let showWiner = ref<boolean>(false);
 let showRecord = ref<boolean>(false);
 let showDesc = ref<boolean>(false);
-const appid = uni.getStorageSync("appid");
+// const appid = uni.getStorageSync("appid");
 const backImage = ref<string>("");
 // const statusBarHeight = uni.getWindowInfo().statusBarHeight * 2;
 let aData: any = reactive({ discounts: [] });
 let list = ref([] as Receipt[]);
 
-const openid = uni.getStorageSync("openid");
+// const openid = uni.getStorageSync("openid");
 
 const isAddress = computed(() => {
   return aData?.authCheck.includes("2") ? true : false;
@@ -139,6 +139,7 @@ const winParams = reactive({
 });
 
 const getList = () => {
+  const appid = uni.getAccountInfoSync().miniProgram.appId;
   getActivity(appid)
     .then((res: any) => {
       aData = res.data[0] || {};
@@ -163,16 +164,17 @@ const getList = () => {
     });
 };
 
-const rewardData = ref([]);
+const rewardData: any = ref([]);
 //获取上传记录
 const getRewardList = () => {
-  console.log("openid", openid);
-  rewardList({ openid, marketingActivityId: aData.id, ...params }).then(
-    (res: any) => {
-      params.currentPage = Math.ceil(res.total / params.pageSize);
-      rewardData.value = [...rewardData.value, ...res.rows];
-    }
-  );
+  rewardList({
+    openid: uni.getStorageSync("openid"),
+    marketingActivityId: aData.id,
+    ...params,
+  }).then((res: any) => {
+    params.currentPage = Math.ceil(res.total / params.pageSize);
+    rewardData.value = [...rewardData.value, ...res.rows];
+  });
 };
 
 const scrolltolower = () => {
@@ -197,11 +199,11 @@ const showUploadRecord = () => {
   showRecord.value = true;
 };
 
-const winnerData = ref([]);
+const winnerData: any = ref([]);
 //获取奖励记录
 const getWinnerList = () => {
   auditSuccessList({
-    openid,
+    openid: uni.getStorageSync("openid"),
     marketingActivityId: aData.id,
     ...winParams,
   }).then((res: any) => {
@@ -224,7 +226,7 @@ const onBack = () => {
 
 const onValidate = async () => {
   const params = {
-    openid,
+    openid: uni.getStorageSync("openid"),
     marketingActivityId: aData.id,
     discountId: "",
   };

+ 50 - 16
src/pagesOne/winner/uploadImage.vue

@@ -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) => {

+ 25 - 3
src/utils/system.ts

@@ -1,4 +1,4 @@
-import { getPhoneNumberInfo, getActivity } from "@/services/ams";
+import { getPhoneNumberInfo, getActivity, getOpenId } from "@/services/ams";
 export const getNavTop = () => {
   // 1.获取屏幕可使用宽度
   let windowWidth = wx.getSystemInfoSync().windowWidth;
@@ -41,7 +41,7 @@ export const getNavBarPaddingTop = () => {
 };
 
 export const getActivityData = () => {
-  const appid = uni.getStorageSync("appid");
+  const appid = uni.getAccountInfoSync().miniProgram.appId;
   let isAuth = false;
   getActivity(appid)
     .then((res: any) => {
@@ -57,7 +57,7 @@ export const getActivityData = () => {
 };
 
 export const getMobile = async (code: string, path: string) => {
-  const appid = uni.getStorageSync("appid");
+  const appid = uni.getAccountInfoSync().miniProgram.appId;
   const params = {
     code,
     appid,
@@ -102,3 +102,25 @@ export const isGetPhone = () => {
     return true;
   }
 };
+
+export const onLogin: any = () => {
+  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) {
+          uni.setStorageSync("openid", response.data.openid);
+        } else {
+          uni.showToast({
+            title: "获取openid失败",
+            icon: "none",
+          });
+        }
+      });
+    },
+  });
+};