You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
12 KiB

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var constant_1 = __importDefault(require("../../utils/constant"));
var util_1 = require("../../utils/util");
var userApi_1 = __importDefault(require("../../api/userApi/userApi"));
var orderApi_1 = __importDefault(require("../../api/orderApi/orderApi"));
Page({
data: {
user: {}
},
getUserInfo: function () {
return __awaiter(this, void 0, void 0, function () {
var res, user, message;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, userApi_1.default.getCurrentUser()];
case 1:
res = _a.sent();
if (res && res.data.success) {
user = JSON.parse(res.data.return_val);
console.log(user);
wx.setStorageSync(constant_1.default.USER_INFO, user);
this.setData({ user: user });
}
else {
message = res.data.message;
wx.showModal({ title: "获取信息错误", content: message, icon: 'error', showCancel: false, duration: 2000 });
}
return [2 /*return*/];
}
});
});
},
onLoad: function () {
return __awaiter(this, void 0, void 0, function () {
var wechatid, user;
return __generator(this, function (_a) {
wechatid = wx.getStorageSync(constant_1.default.WECHATID);
user = wx.getStorageSync(constant_1.default.USER_INFO);
if (!wechatid) {
util_1.wxLogin();
}
if (!user) {
this.getUserInfo().then(function () {
user = wx.getStorageSync(constant_1.default.USER_INFO);
});
}
this.setData({ user: user });
console.log("user", user);
return [2 /*return*/];
});
});
},
onScanValid: function () {
return __awaiter(this, void 0, void 0, function () {
var that;
return __generator(this, function (_a) {
that = this;
wx.scanCode({
success: function (qrCode) {
//TODO get orderInfo by qrID
var qr_code = qrCode.result;
console.log(qr_code);
orderApi_1.default.scanLocationCode(qr_code).then(function (res) {
if (res && res.data.success) {
var val = JSON.parse(res.data.return_val);
console.log(val);
wx.showLoading({ title: "场所码扫描成功,刷新中~" });
that.onLoad();
setTimeout(function () { wx.hideLoading(); }, 2000);
}
else {
var message = res.data.message;
wx.showModal({
title: "扫描场所码失败",
content: message, icon: 'error',
showCancel: false
});
}
});
}
});
return [2 /*return*/];
});
});
},
uploadHealthCard: function () {
var that = this;
wx.showLoading({ title: '健康码上传中' });
this.chooseBase64Image().then(function (suc) {
orderApi_1.default.uploadHealthCode({ ImageBase64: suc.base64File, ext: suc.imgType }).then(function (res) {
wx.hideLoading();
if (res && res.data && res.data.success) {
wx.showLoading({ title: "健康码上传成功,刷新中~" });
that.onLoad();
setTimeout(function () { wx.hideLoading(); }, 2000);
}
else {
var message = res.data.message;
wx.showModal({
title: "健康码上传错误",
content: message,
showCancel: false
});
}
}).catch(function (err) {
wx.hideLoading();
wx.showModal({
title: "健康码上传错误",
content: "uploadHealthCode===" + JSON.stringify(err),
showCancel: false
});
});
}).catch(function (err) {
wx.hideLoading();
wx.showModal({
title: "健康码上传错误",
content: "chooseBase64Image===" + JSON.stringify(err), showCancel: false
});
});
},
uploadTravelCard: function () {
var that = this;
wx.showLoading({ title: '行程码上传中' });
this.chooseBase64Image().then(function (suc) {
orderApi_1.default.uploadTripCode({ ImageBase64: suc.base64File, ext: suc.imgType }).then(function (res) {
wx.hideLoading();
if (res && res.data && res.data.success) {
wx.showLoading({ title: "行程码上传成功,刷新中~" });
that.onLoad();
setTimeout(function () { wx.hideLoading(); }, 2000);
}
else {
var message = res.data.message;
wx.showModal({
title: "行程码上传错误",
content: message,
showCancel: false
});
}
}).catch(function (err) {
wx.hideLoading();
wx.showModal({
title: "行程码上传错误",
content: "uploadTripCode===" + JSON.stringify(err),
showCancel: false
});
});
}).catch(function (err) {
wx.hideLoading();
wx.showModal({
title: "行程码上传错误",
content: "chooseBase64Image===" + JSON.stringify(err),
showCancel: false
});
});
},
chooseBase64Image: function () {
var _this = this;
return new Promise(function (resolve, reject) {
wx.chooseImage({
sizeType: ['original', 'compressed'],
count: 1,
sourceType: ['album'],
success: function (res) {
var tempFile = res.tempFiles[0];
_this.getImageBase64_readFile(tempFile.path).then(function (suc) {
resolve(suc);
}).catch(function (err) {
reject(err);
});
},
fail: function (err) {
reject(err);
}
});
});
},
getImageBase64_readFile: function (tempFilePath) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve, reject) {
wx.getImageInfo({
src: tempFilePath,
success: function (imageInfo) {
var imgType = imageInfo.type;
wx.compressImage({
src: tempFilePath,
quality: 1,
compressedWidth: 200,
success: function (file_path) {
wx.getFileSystemManager().readFile({
filePath: file_path.tempFilePath,
encoding: "base64",
success: function (res) {
//返回base64格式
var base64Str = '' + res.data;
var result = { base64File: base64Str, imgType: imgType };
resolve(result);
},
fail: function (err) {
reject(err);
}
});
}
});
}
});
})];
});
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
});