gift/unpackage/dist/dev/mp-weixin/pages/index/index.js
2025-07-31 20:06:59 +08:00

297 lines
10 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_utils = require("../../common/utils.js");
const common_assets = require("../../common/assets.js");
const uniNoticeBar = () => "../../uni_modules/uni-notice-bar/components/uni-notice-bar/uni-notice-bar.js";
const _sfc_main = {
components: {
uniNoticeBar
},
onLoad() {
var userId = common_vendor.index.getStorageSync("user_id");
if (!userId || userId == 0) {
this.login();
}
this.userId = userId;
},
data() {
return {
userId: 0,
imagePath: "",
name: "",
phone: "",
base64: "",
workUnit: "",
address: "",
createTime: "",
number: "",
model: "",
recordList: []
};
},
methods: {
request(url, method, data) {
return new Promise((resolve, reject) => {
const header = {};
if (method == "post") {
header["content-type"] = "application/json";
}
common_vendor.index.request({
url: "http://localhost:8888/" + url,
method,
data,
header,
timeout: 1e4,
success: (res) => {
common_vendor.index.__f__("log", "at pages/index/index.vue:194", "API响应:", res);
if (res.statusCode === 200) {
resolve(res.data);
} else {
reject(new Error(`请求失败,状态码: ${res.statusCode}`));
}
},
fail: (err) => {
common_vendor.index.__f__("error", "at pages/index/index.vue:202", "API请求失败:", err);
reject(err);
}
});
});
},
wxLogin() {
return new Promise((resolve, reject) => {
common_vendor.index.login({
provider: "weixin",
//使用微信登录
onlyAuthorize: true,
success: async function(res) {
resolve(res.code);
},
fail: function(err) {
reject(err);
}
});
});
},
async login() {
try {
const wxCode = await this.wxLogin();
if (wxCode) {
const res = await this.request("userLogin?code=" + wxCode, "post", {});
if (res.code == 200) {
common_vendor.index.setStorageSync("user_id", res.data.user_id);
this.userId = res.data.user_id;
common_vendor.index.__f__("log", "at pages/index/index.vue:232", "登录成功, userId:", this.userId);
} else {
common_vendor.index.__f__("error", "at pages/index/index.vue:234", "登录失败:", res.message);
}
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/index/index.vue:238", "登录过程出错:", error);
}
},
openReceivePop() {
this.$refs.receivePop.open();
},
closeReceivePop() {
this.$refs.receivePop.close();
},
async openRecordPop() {
await this.loadRecordList();
this.$refs.recordPop.open();
},
async loadRecordList() {
try {
common_vendor.index.showLoading({ title: "加载中..." });
const result = await this.request("getRecord?userId=" + this.userId, "GET", {});
common_vendor.index.__f__("log", "at pages/index/index.vue:259", result);
this.recordList = result.data;
common_vendor.index.__f__("log", "at pages/index/index.vue:264", "加载领取记录...");
} catch (error) {
common_vendor.index.__f__("error", "at pages/index/index.vue:266", "加载领取记录失败:", error);
}
common_vendor.index.hideLoading();
},
closeRecordPop() {
this.$refs.recordPop.close();
},
async seleImg() {
try {
common_vendor.index.showLoading({ title: "处理中..." });
const { base64, path } = await common_utils.processImage();
common_vendor.index.__f__("log", "at pages/index/index.vue:280", "最终Base64长度:", base64.length, path);
this.imagePath = path;
this.base64 = base64;
common_vendor.index.showToast({ title: "上传成功" });
} catch (err) {
common_vendor.index.__f__("error", "at pages/index/index.vue:285", "处理失败", err);
common_vendor.index.showToast({ title: "处理失败", icon: "none" });
} finally {
common_vendor.index.hideLoading();
}
},
validateForm() {
if (!this.name.trim()) {
common_vendor.index.showToast({ title: "请填写姓名", icon: "none" });
return false;
}
if (!this.phone.trim()) {
common_vendor.index.showToast({ title: "请填写联系方式", icon: "none" });
return false;
}
if (!this.workUnit.trim()) {
common_vendor.index.showToast({ title: "请填写工作单位", icon: "none" });
return false;
}
if (!this.address.trim()) {
common_vendor.index.showToast({ title: "请填写收货地址", icon: "none" });
return false;
}
if (!this.model.trim()) {
common_vendor.index.showToast({ title: "请填写设备型号", icon: "none" });
return false;
}
if (!this.number.trim()) {
common_vendor.index.showToast({ title: "请填写出品编号", icon: "none" });
return false;
}
if (!this.createTime.trim()) {
common_vendor.index.showToast({ title: "请填写出品年月", icon: "none" });
return false;
}
if (!this.imagePath) {
common_vendor.index.showToast({ title: "请上传产品铭牌照片", icon: "none" });
return false;
}
return true;
},
async submitForm() {
if (!this.validateForm()) {
return;
}
common_vendor.index.showLoading({ title: "提交中..." });
try {
const formData = {
UserId: this.userId,
Name: this.name,
Phone: this.phone,
Company: this.workUnit,
Address: this.address,
ProductModel: this.model,
ProductSerialNumber: this.number,
ProductDate: this.createTime,
ProductImage: this.base64
};
const result = await this.request("addRecord", "POST", formData);
common_vendor.index.__f__("log", "at pages/index/index.vue:351", result);
if (result.code == 200) {
common_vendor.index.showToast({ title: "提交成功,请等待审核", icon: "success" });
this.closeReceivePop();
this.clearForm();
} else {
common_vendor.index.showToast({ title: "提交失败,请重试", icon: "none" });
}
common_vendor.index.hideLoading();
} catch (error) {
common_vendor.index.hideLoading();
common_vendor.index.showToast({ title: "提交失败,请重试", icon: "none" });
common_vendor.index.__f__("error", "at pages/index/index.vue:365", "提交失败:", error);
}
},
clearForm() {
this.name = "";
this.phone = "";
this.workUnit = "";
this.address = "";
this.model = "";
this.number = "";
this.createTime = "";
this.imagePath = "";
this.base64 = "";
},
previewImage() {
if (this.imagePath) {
common_vendor.index.previewImage({
current: this.imagePath,
urls: [this.imagePath],
success: function(res) {
common_vendor.index.__f__("log", "at pages/index/index.vue:387", "预览图片成功");
},
fail: function(err) {
common_vendor.index.__f__("error", "at pages/index/index.vue:390", "预览图片失败:", err);
common_vendor.index.showToast({ title: "预览失败", icon: "none" });
}
});
}
}
}
};
if (!Array) {
const _component_uniNoticeBar = common_vendor.resolveComponent("uniNoticeBar");
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
(_component_uniNoticeBar + _easycom_uni_popup2)();
}
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
_easycom_uni_popup();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.p({
showIcon: true,
single: true,
scrollable: true,
text: "赠品仅限线下购买设备的用户领取需人工审核预计3个工作日内完成",
["background-color"]: "transparent",
color: "#000"
}),
b: common_vendor.o((...args) => $options.openReceivePop && $options.openReceivePop(...args)),
c: common_vendor.o((...args) => $options.openRecordPop && $options.openRecordPop(...args)),
d: $data.name,
e: common_vendor.o(($event) => $data.name = $event.detail.value),
f: $data.phone,
g: common_vendor.o(($event) => $data.phone = $event.detail.value),
h: $data.workUnit,
i: common_vendor.o(($event) => $data.workUnit = $event.detail.value),
j: -1,
k: $data.address,
l: common_vendor.o(($event) => $data.address = $event.detail.value),
m: $data.model,
n: common_vendor.o(($event) => $data.model = $event.detail.value),
o: $data.number,
p: common_vendor.o(($event) => $data.number = $event.detail.value),
q: $data.createTime,
r: common_vendor.o(($event) => $data.createTime = $event.detail.value),
s: common_vendor.o((...args) => $options.seleImg && $options.seleImg(...args)),
t: $data.imagePath
}, $data.imagePath ? {
v: $data.imagePath,
w: common_vendor.o((...args) => $options.previewImage && $options.previewImage(...args))
} : {}, {
x: common_vendor.o((...args) => $options.closeReceivePop && $options.closeReceivePop(...args)),
y: common_vendor.o((...args) => $options.submitForm && $options.submitForm(...args)),
z: common_vendor.sr("receivePop", "6e486efd-1"),
A: common_vendor.p({
type: "center",
["is-mask-click"]: false
}),
B: common_assets._imports_0,
C: common_vendor.o(($event) => $options.closeRecordPop()),
D: common_vendor.f($data.recordList, (item, k0, i0) => {
return {
a: common_vendor.t(item.name),
b: common_vendor.t(item.phone),
c: common_vendor.t(item.time),
d: common_vendor.t(item.address),
e: item.phone + item.time
};
}),
E: common_vendor.sr("recordPop", "6e486efd-2"),
F: common_vendor.p({
type: "center"
})
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/index.js.map