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.
582 lines
25 KiB
582 lines
25 KiB
"use strict";
|
|
var __assign = (this && this.__assign) || function () {
|
|
__assign = Object.assign || function(t) {
|
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
s = arguments[i];
|
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
t[p] = s[p];
|
|
}
|
|
return t;
|
|
};
|
|
return __assign.apply(this, arguments);
|
|
};
|
|
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 };
|
|
}
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var tools_1 = require("../../../../utils/tools");
|
|
var promise_wx_api_1 = require("../../../../utils/promise-wx-api");
|
|
var location_1 = require("../../../../utils/location");
|
|
var index_js_1 = require("../../../../utils/validate/index.js");
|
|
var app = getApp();
|
|
Page({
|
|
data: {
|
|
groupId: "",
|
|
topicId: "",
|
|
showedHint: false,
|
|
tabRecord: false,
|
|
textHeight: "320rpx",
|
|
viewHeight: "100%",
|
|
submitStatus: "not-started",
|
|
placeholderText: "1\u3001\u53D1\u8D77\u60A8\u7684\u8BDD\u9898\uFF0C\u8BF7\u5C06\u8BDD\u9898\u63CF\u8FF0\u6E05\u6670\u3002\n2\u3001\u5728\u5C0F\u7EC4\u5F97\u5230\u5E2E\u52A9\u3001\u5EFA\u8BAE\uFF0C\u80FD\u6709\u52A9\u4E8E\u66F4\u5FEB\u7684\u89E3\u51B3\u95EE\u9898\u3002\n3\u3001\u8FD8\u6709\u673A\u4F1A\u88AB\u8F6C\u53D1\u5230\u3010\u515A\u7FA4\u8BAE\u4E8B\u3011\uFF0C\u8BA9\u95EE\u9898\u66F4\u5FEB\u89E3\u51B3",
|
|
fmData: {
|
|
wx_form_id: "",
|
|
gridId: "",
|
|
customerId: "",
|
|
groupId: "",
|
|
topicDraftId: "",
|
|
topicContent: "",
|
|
longitude: "",
|
|
dimension: "",
|
|
province: "",
|
|
city: "",
|
|
area: "",
|
|
address: "",
|
|
videoList: [],
|
|
voiceList: [],
|
|
docList: [],
|
|
imageList: [],
|
|
locateAddress: "",
|
|
locateLongitude: "",
|
|
locateDimension: "",
|
|
},
|
|
imgList: [],
|
|
maxLimitImg: 3,
|
|
submitBtnIsAllowed: false,
|
|
dialogVisible: false,
|
|
templateList: [],
|
|
},
|
|
$afterUpdateData: function () {
|
|
this.computeSubmitBtnIsAllowed();
|
|
if (this.data.fmData.voiceList.length > 0)
|
|
this.setData({ submitBtnIsAllowed: true });
|
|
},
|
|
computeSubmitBtnIsAllowed: function (isQuiet) {
|
|
if (isQuiet === void 0) { isQuiet = true; }
|
|
var _a = this.data, fmData = _a.fmData, submitStatus = _a.submitStatus, vlt = index_js_1.default(fmData, {
|
|
topicContent: [
|
|
{
|
|
rule: "required",
|
|
message: "请输入话题内容",
|
|
},
|
|
],
|
|
address: [
|
|
{
|
|
rule: "required",
|
|
message: "请输入定位地址",
|
|
},
|
|
],
|
|
voiceList: [],
|
|
});
|
|
if (!vlt.valid) {
|
|
if (!isQuiet) {
|
|
wx.showToast({
|
|
title: vlt.error,
|
|
icon: "none",
|
|
duration: 1500,
|
|
});
|
|
}
|
|
this.setData({
|
|
submitBtnIsAllowed: false,
|
|
});
|
|
return false;
|
|
}
|
|
else {
|
|
this.setData({
|
|
submitBtnIsAllowed: submitStatus !== "success",
|
|
});
|
|
return true;
|
|
}
|
|
},
|
|
onLoad: function (query) {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
var gid, tid;
|
|
return __generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
wx.showLoading({
|
|
title: "",
|
|
mask: true,
|
|
});
|
|
return [4, tools_1.doAfterLogin()];
|
|
case 1:
|
|
_a.sent();
|
|
gid = query.gid, tid = query.tid;
|
|
this.setData({ groupId: gid, topicId: tid });
|
|
if (tid) {
|
|
this.getInfo();
|
|
}
|
|
this.getTemplate();
|
|
this.getLocation();
|
|
wx.hideLoading();
|
|
return [2];
|
|
}
|
|
});
|
|
});
|
|
},
|
|
onShow: function () { },
|
|
onReady: function () {
|
|
this.computedViewHeight();
|
|
},
|
|
inputSync: tools_1.inputSync,
|
|
toughGetLocation: function () {
|
|
var _this = this;
|
|
this.getLocation(false);
|
|
wx.chooseLocation({
|
|
success: function (res) {
|
|
console.log("resadddres", res);
|
|
var fmData = _this.data.fmData;
|
|
_this.setData({
|
|
fmData: __assign(__assign({}, fmData), { address: res.address, longitude: res.longitude, dimension: res.latitude }),
|
|
});
|
|
},
|
|
});
|
|
},
|
|
getInfo: function () {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
var topicId, _a, _b, code, data, msg, _c, fmData, imgList, n;
|
|
return __generator(this, function (_d) {
|
|
switch (_d.label) {
|
|
case 0:
|
|
topicId = this.data.topicId;
|
|
return [4, promise_wx_api_1.wxRequestPost("resi/group/topicdraft/detail", {
|
|
topicDraftId: topicId,
|
|
}, {})];
|
|
case 1:
|
|
_a = _d.sent(), _b = _a.data.data, code = _b.code, data = _b.data, msg = _a.msg;
|
|
if (msg === "success" && code === 0) {
|
|
_c = this.data, fmData = _c.fmData, imgList = _c.imgList;
|
|
for (n in data) {
|
|
fmData[n] = data[n];
|
|
}
|
|
imgList = fmData.imageList.map(function (item) {
|
|
return {
|
|
tempFilePath: item,
|
|
src: item,
|
|
valid: true,
|
|
};
|
|
});
|
|
console.log("datafffff", data);
|
|
this.setData({ fmData: fmData, imgList: imgList });
|
|
}
|
|
return [2];
|
|
}
|
|
});
|
|
});
|
|
},
|
|
getLocation: function (isQuiet) {
|
|
if (isQuiet === void 0) { isQuiet = true; }
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
var _a, msg, data, fmData;
|
|
return __generator(this, function (_b) {
|
|
switch (_b.label) {
|
|
case 0: return [4, location_1.default(isQuiet)];
|
|
case 1:
|
|
_a = _b.sent(), msg = _a.msg, data = _a.data;
|
|
console.log(msg, data);
|
|
if (msg === "success") {
|
|
fmData = this.data.fmData;
|
|
this.setData({
|
|
fmData: __assign(__assign({}, fmData), { address: data.address, province: data.province, city: data.city, area: data.district, longitude: data.longitude, dimension: data.latitude, locateAddress: data.address, locateLongitude: data.longitude, locateDimension: data.latitude }),
|
|
});
|
|
this.computeSubmitBtnIsAllowed();
|
|
}
|
|
return [2];
|
|
}
|
|
});
|
|
});
|
|
},
|
|
previewImg: function (e) {
|
|
var index = e.target.dataset.index;
|
|
var imgList = this.data.imgList, currentImg = imgList[index].tempFilePath, imgArr = imgList.map(function (item) { return item.tempFilePath; });
|
|
wx.previewImage({
|
|
current: currentImg,
|
|
urls: imgArr,
|
|
});
|
|
},
|
|
delImg: function (e) {
|
|
var index = e.target.dataset.index;
|
|
var imgList = this.data.imgList;
|
|
imgList.splice(index, 1);
|
|
this.setData({
|
|
imgList: imgList,
|
|
});
|
|
},
|
|
addImg: function () {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
var _a, imgList, maxLimitImg, len, _b, msg, data, tempFilePaths, newImgList;
|
|
return __generator(this, function (_c) {
|
|
switch (_c.label) {
|
|
case 0:
|
|
_a = this.data, imgList = _a.imgList, maxLimitImg = _a.maxLimitImg, len = imgList.length;
|
|
if (!(len >= maxLimitImg)) return [3, 1];
|
|
return [2, wx.showToast({
|
|
title: "\u6700\u591A\u4E0A\u4F20 " + maxLimitImg + " \u5F20\u56FE\u7247\u3002",
|
|
icon: "none",
|
|
duration: 1500,
|
|
})];
|
|
case 1: return [4, promise_wx_api_1.wxChooseImage({
|
|
count: maxLimitImg - len,
|
|
sizeType: ["compressed"],
|
|
})];
|
|
case 2:
|
|
_b = _c.sent(), msg = _b.msg, data = _b.data;
|
|
if (msg === "success") {
|
|
tempFilePaths = data.tempFilePaths;
|
|
newImgList = tempFilePaths.map(function (tempFilePath) {
|
|
return {
|
|
tempFilePath: tempFilePath,
|
|
src: "",
|
|
valid: true,
|
|
};
|
|
});
|
|
this.setData({
|
|
imgList: imgList.concat(newImgList),
|
|
});
|
|
}
|
|
_c.label = 3;
|
|
case 3: return [2];
|
|
}
|
|
});
|
|
});
|
|
},
|
|
uploadImgs: function () {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
var uploadedImgList, imgsValid, imgsAllUploaded;
|
|
var _this = this;
|
|
return __generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
if (this.data.imgList.length === 0) {
|
|
return [2];
|
|
}
|
|
wx.showLoading({
|
|
title: "上传图片中",
|
|
mask: true,
|
|
});
|
|
return [4, new Promise(function (reslove) { return __awaiter(_this, void 0, void 0, function () {
|
|
var imgList, residueNum;
|
|
var _this = this;
|
|
return __generator(this, function (_a) {
|
|
imgList = this.data.imgList, residueNum = imgList.length;
|
|
imgList.forEach(function (img, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
var _a, data, msg;
|
|
return __generator(this, function (_b) {
|
|
switch (_b.label) {
|
|
case 0:
|
|
if (!(img.src == "")) return [3, 2];
|
|
return [4, promise_wx_api_1.wxUploadFile("oss/file/uploadimg", img.tempFilePath, {})];
|
|
case 1:
|
|
_a = _b.sent(), data = _a.data.data, msg = _a.msg;
|
|
if (msg === "success" && data.code === 0) {
|
|
img.src = data.data.url;
|
|
img.valid = true;
|
|
}
|
|
_b.label = 2;
|
|
case 2:
|
|
imgList[index] = img;
|
|
residueNum -= 1;
|
|
if (residueNum === 0) {
|
|
reslove(imgList);
|
|
}
|
|
return [2];
|
|
}
|
|
});
|
|
}); });
|
|
return [2];
|
|
});
|
|
}); })];
|
|
case 1:
|
|
uploadedImgList = _a.sent();
|
|
wx.hideLoading();
|
|
console.log(uploadedImgList);
|
|
this.setData({ imgList: uploadedImgList });
|
|
imgsValid = uploadedImgList.every(function (item) { return item.valid; }), imgsAllUploaded = uploadedImgList.every(function (item) { return item.src != ""; });
|
|
if (!imgsValid) {
|
|
wx.showToast({
|
|
title: "图片可能包含非法内容",
|
|
icon: "none",
|
|
duration: 1500,
|
|
});
|
|
return [2, Promise.reject()];
|
|
}
|
|
else if (!imgsAllUploaded) {
|
|
wx.showToast({
|
|
title: "上传图片出错,请重试",
|
|
icon: "none",
|
|
duration: 1500,
|
|
});
|
|
return [2, Promise.reject()];
|
|
}
|
|
else {
|
|
return [2];
|
|
}
|
|
return [2];
|
|
}
|
|
});
|
|
});
|
|
},
|
|
submit: function (e) {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
var _a, fmData, groupId, imgList, retConfirm, _b, data, msg;
|
|
return __generator(this, function (_c) {
|
|
switch (_c.label) {
|
|
case 0:
|
|
_a = this.data, fmData = _a.fmData, groupId = _a.groupId, imgList = _a.imgList;
|
|
if (!this.computeSubmitBtnIsAllowed(false) && fmData.voiceList.length === 0) {
|
|
return [2];
|
|
}
|
|
fmData.topicContent = fmData.topicContent.trim();
|
|
console.log("topicContent", fmData.topicContent.length);
|
|
if (fmData.topicContent === "" && fmData.voiceList.length === 0) {
|
|
console.log("fmData.voiceList.length", fmData.voiceList.length);
|
|
return [2, wx.showToast({
|
|
title: "话题内容或话题语音不能为空",
|
|
icon: "none",
|
|
duration: 1500,
|
|
})];
|
|
}
|
|
return [4, promise_wx_api_1.wxShowModal({
|
|
title: "确认提交?",
|
|
})];
|
|
case 1:
|
|
retConfirm = _c.sent();
|
|
if (retConfirm.msg !== "success" || !retConfirm.data.confirm) {
|
|
return [2];
|
|
}
|
|
return [4, this.uploadImgs()];
|
|
case 2:
|
|
_c.sent();
|
|
if (e.detail.formId) {
|
|
fmData.wx_form_id = e.detail.formId;
|
|
}
|
|
fmData.groupId = groupId;
|
|
fmData.gridId = app.globalData.gridId;
|
|
fmData.customerId = app.globalData.customerId;
|
|
fmData.imageList = imgList.map(function (item) {
|
|
return item.src;
|
|
});
|
|
this.setData({ fmData: fmData });
|
|
wx.showLoading({
|
|
title: "正在提交中",
|
|
mask: true,
|
|
});
|
|
return [4, promise_wx_api_1.wxRequestPost("resi/group/topicdraft/createtopic", fmData, {})];
|
|
case 3:
|
|
_b = _c.sent(), data = _b.data.data, msg = _b.msg;
|
|
wx.hideLoading();
|
|
if (msg === "success" && data.code === 0) {
|
|
this.setData({
|
|
dialogVisible: true,
|
|
});
|
|
}
|
|
return [2];
|
|
}
|
|
});
|
|
});
|
|
},
|
|
getTemplate: function () {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
var _a, _b, code, data, msg;
|
|
return __generator(this, function (_c) {
|
|
switch (_c.label) {
|
|
case 0: return [4, promise_wx_api_1.wxRequestPost("message/wxmpmessage/templatelistv2", {
|
|
app: "resi",
|
|
customerId: app.globalData.customerId,
|
|
}, {})];
|
|
case 1:
|
|
_a = _c.sent(), _b = _a.data.data, code = _b.code, data = _b.data, msg = _a.msg;
|
|
console.log("ddddatattt", data);
|
|
if (msg === "success" && code === 0) {
|
|
this.setData({
|
|
templateList: data,
|
|
});
|
|
}
|
|
return [2];
|
|
}
|
|
});
|
|
});
|
|
},
|
|
handleRequestMsg: function () {
|
|
var _this = this;
|
|
var templateList = this.data.templateList;
|
|
var hasAgree = false;
|
|
wx.requestSubscribeMessage({
|
|
tmplIds: templateList.map(function (item) { return item.templateId; }),
|
|
success: function (res) {
|
|
console.log("res", res);
|
|
if (res.errMsg === "requestSubscribeMessage:ok") {
|
|
templateList.forEach(function (item) {
|
|
if (res[item.templateId] === "accept")
|
|
hasAgree = true;
|
|
});
|
|
if (hasAgree) {
|
|
wx.showToast({
|
|
title: "订阅成功",
|
|
icon: "none",
|
|
duration: 1500,
|
|
});
|
|
}
|
|
console.log("successss", res);
|
|
}
|
|
},
|
|
fail: function (err) {
|
|
console.log("err", err);
|
|
wx.showToast({
|
|
title: err.errMsg,
|
|
icon: "none",
|
|
duration: 1500,
|
|
});
|
|
},
|
|
complete: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
return __generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
this.setData({
|
|
submitStatus: "success",
|
|
});
|
|
if (this.data.topicId) {
|
|
wx.reLaunch({
|
|
url: "/subpages/mine/pages/works/topic-part/start-topic/index",
|
|
});
|
|
return [2];
|
|
}
|
|
return [4, tools_1.nextTick(1000)];
|
|
case 1:
|
|
_a.sent();
|
|
wx.navigateBack({
|
|
delta: 1,
|
|
});
|
|
return [2];
|
|
}
|
|
});
|
|
}); },
|
|
});
|
|
},
|
|
submitComfire: function () {
|
|
return __awaiter(this, void 0, void 0, function () {
|
|
return __generator(this, function (_a) {
|
|
switch (_a.label) {
|
|
case 0:
|
|
this.setData({
|
|
dialogVisible: false,
|
|
});
|
|
if (!(this.data.templateList && this.data.templateList.length > 0)) return [3, 2];
|
|
return [4, this.handleRequestMsg()];
|
|
case 1:
|
|
_a.sent();
|
|
return [3, 4];
|
|
case 2:
|
|
this.setData({
|
|
submitStatus: "success",
|
|
});
|
|
if (this.data.topicId) {
|
|
wx.reLaunch({
|
|
url: "/subpages/mine/pages/works/topic-part/start-topic/index",
|
|
});
|
|
return [2];
|
|
}
|
|
return [4, tools_1.nextTick(1000)];
|
|
case 3:
|
|
_a.sent();
|
|
wx.navigateBack({
|
|
delta: 1,
|
|
});
|
|
_a.label = 4;
|
|
case 4: return [2];
|
|
}
|
|
});
|
|
});
|
|
},
|
|
computedViewHeight: function (height) {
|
|
if (height === void 0) { height = 0; }
|
|
var that = this;
|
|
var query = wx.createSelectorQuery().in(this);
|
|
var ress = wx.getSystemInfoSync();
|
|
var _height = height || 20;
|
|
query
|
|
.selectAll(".btn, .topic-record")
|
|
.boundingClientRect(function (res) {
|
|
console.log(ress.windowHeight, res[0].height, res[1].height);
|
|
var _h = 0;
|
|
_h = ress.windowHeight - res[0].height - _height - 50;
|
|
if (res[1].height)
|
|
_h = ress.windowHeight - res[1].height - _height;
|
|
console.log("++++++", _h);
|
|
that.setData({
|
|
viewHeight: _h + "px",
|
|
});
|
|
})
|
|
.exec();
|
|
},
|
|
handleTapRecord: function () {
|
|
this.setData({
|
|
tabRecord: !this.data.tabRecord,
|
|
});
|
|
this.computedViewHeight();
|
|
},
|
|
handleRecordFinish: function (e) {
|
|
var voiceList = this.data.fmData.voiceList;
|
|
var _a = e.detail, url = _a.url, duration = _a.duration;
|
|
voiceList.push({ url: url, duration: duration });
|
|
console.log("eeeeee", e.detail);
|
|
this.setData({
|
|
"fmData.voiceList": voiceList,
|
|
tabRecord: false,
|
|
submitBtnIsAllowed: true,
|
|
});
|
|
this.computedViewHeight();
|
|
},
|
|
handleAudioDel: function () {
|
|
var voiceList = this.data.fmData.voiceList;
|
|
voiceList.shift();
|
|
this.setData({
|
|
"fmData.voiceList": voiceList,
|
|
});
|
|
this.computeSubmitBtnIsAllowed();
|
|
console.log("dddddddddel");
|
|
},
|
|
});
|
|
|