import { wxRequestPost, wxNavigateTo } from "@utils/promise-wx-api"; import validate from "@utils/validate/index.js"; import words from "@config/words"; import copyKeyHave from "@npm/dai-mp/tools/copyKeyHave.js"; import dateFormat from "@npm/dai-mp/tools/dateFormat.js"; import computedBehavior from "@npm/dai-mp/mixins/computed-component/index.js"; import commonBehavior from "@mixins/common"; import listBehavior from "@mixins/list"; const app = getApp(); const testPic = "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3015922630,3907554494&fm=26&gp=0.jpg"; Component({ behaviors: [commonBehavior, computedBehavior, listBehavior], properties: { issueId: { type: String, value: "", }, shareLinkId: { type: String, value: "", }, }, data: { iniLoaded: false, refreshFlag: false, haveRegistered: false, myShareLinkId: "", awaitAudit: false, inAnyGroup: true, inGroup: true, voted: false, voterst: "", votedNum: {}, info: { issueTitle: "--", issuePublisherMobile: "", sourceType: "", sourceId:"", issueStatus: "", issueSuggestion: "", belongsGridName: "", issueInitiator: "", joinVote: false, projectStatus: false, projectId: "", issueIdea: "", publishIdeaFlag: false, }, topicInfo: { topicId: "", groupName: "", topicContent: "", publishedUser: "", publishedTime: 0, topicPublisherMobile: "", }, eventInfo:{}, topicContentFolded: true, topicImgList: [ // "/assets/images/login/bg.png", // "/assets/images/login/bg.png", ], voteInfo: { shouldVoteCount: 0, realityVoteCount: 0, supportAmount: 0, oppositionAmount: 0, }, chartData: [], voiceList: [], //语音文件 progressList: [ // { // "progressName": "进展名称", // "progressTime": "进展时间戳", // "handleDepartment": "处理部门", // "progressDesc": "进展说明", // "processId": "进展id" // } ], showedCloseFm: false, //是否显示关闭表单 fmData: { resolveType: "resloved", //解决状态(已解决resloved、未解决unresloved,对应在关闭议题时所选的checkbox) closeReason: "", }, resolveTypeList: [ { name: "已解决", value: "resloved", }, { name: "无需解决", value: "unresloved", }, ], // 评论列表相关 listUrl: "resi/hall/issue/projectevaluationlist", listIsMock: false, listParams: {}, classTag: { //标签分类 class: "", tag: "", }, }, computed: { // 提交前预验证错误,为空说明可以提交 errBeforeSubmit(data) { const { fmData } = data, vlt = validate(fmData, { closeReason: [ { rule: "required", message: "请先输入【处理答复】", }, ], }); if (!vlt.valid) { return vlt.error; } else { return ""; } }, }, methods: { //inputSync, onLoad() { this.init(); }, async onShow() { if (this.data.refreshFlag) { await app.enterGridData(); this.syncRoleInfo(); this.getInfo(); } }, toTagPage() { wxNavigateTo("tag/index", { issueId: this.data.issueId }); }, onShareAppMessage() { const { topicImgList, myShareLinkId } = this.data; const { userInfo: { userStreetName, nickname }, } = app.globalData; const name = userStreetName || nickname; return { title: `${name}分享给您一条议题,请查看`, path: `${this.route}?shareLinkId=${myShareLinkId}`, imageUrl: topicImgList.length > 0 ? topicImgList[0] : "", success(shareTickets) { log("转发成功", shareTickets); }, }; }, shiftFoldTopicContent() { this.setData({ topicContentFolded: !this.data.topicContentFolded, }); }, async init() { const { shareLinkId } = this.data; if (shareLinkId) { await app.loginGetToken(); await this.getShareInfo(); await app.enterGridData(); } else { await app.doAfterLogin(); } this.syncRoleInfo(); await this.voteNum(); await this.getApiData(); this.getMyShareLinkId(); if (shareLinkId) { await this.getGroupRelation(); } this.setData({ iniLoaded: true, refreshFlag: true, }); }, // 用户是否注册过居民 syncRoleInfo() { const haveRegistered = app.globalData.userRoleList.indexOf("registered_resi") !== -1; this.setData({ haveRegistered, }); if (haveRegistered) { this.selectComponent("#modalReg").hide(); } }, // 获取话题详情 async getShareInfo() { const { shareLinkId } = this.data; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "gov/issue/issuesharelink/visit", { shareLinkId, }, { // isMock: true, } ); if (msg === "success" && code === 0) { this.setData({ issueId: data.issueId, }); app.globalData.gridId = data.gridId; app.globalData.customerId = data.customerId; } }, // 获取话题详情 async getGroupRelation() { const { shareLinkId } = this.data; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "resi/group/topicsharelink/getstatus", { id: shareLinkId, type: "issue", }, { // isMock: true, } ); if (msg === "success" && code === 0) { this.setData({ inGroup: data.inGroup, inAnyGroup: data.inAnyGroup, awaitAudit: data.awaitAudit, }); } }, async getApiData() { this.getChartInfo(); await this.getInfo(); this.getClassTagInfo(); await this.getAttechment(); }, async share() { return await this.beforeAct(); }, async beforeAct() { const { inAnyGroup, awaitAudit, haveRegistered } = this.data; if (awaitAudit) { wx.showToast({ title: "已提交入组申请,请等待组长确认", icon: "none", duration: 2000, }); return false; } else if (!inAnyGroup) { const $modal = this.selectComponent("#modal"); const confirm = await $modal.show({ title: "加入小组", content: "您还不是该小组成员,请确认加入小组", }); $modal.hide(); if (confirm) { if (!haveRegistered) { await this.selectComponent("#modalReg").show(); if (this.data.haveRegistered) { return this.joinGroup(); } } else { return this.joinGroup(); } } else { return false; } } else { return true; } }, // 获取话题详情 async joinGroup() { const { shareLinkId } = this.data; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "resi/group/member/applyenterbylink", { shareLinkId, shareLinkType: "issue", }, { // isMock: true, // isQuiet: true, } ); if (msg === "success" && code === 0) { const { status } = data; if (status == "entered") { wx.showToast({ title: "入组成功", icon: "success", duration: 1500, }); this.setData({ inAnyGroup: true, inGroup: true, }); return true; } else if (status == "auditing") { wx.showToast({ title: "已提交入组申请,请等待组长确认", icon: "none", duration: 1500, }); this.setData({ awaitAudit: true, }); } } return false; }, // 获取话题详情 async getMyShareLinkId() { const { issueId } = this.data; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "gov/issue/issuesharelink/createurl", { issueId, customerId: app.globalData.customerId, }, { // isMock: true, isQuiet: true, } ); if (msg === "success" && code === 0) { this.setData({ myShareLinkId: data.shareLinkId }); } }, // 议题详情 async getInfo() { const { issueId } = this.data; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "resi/hall/issue/detail", { issueId, }, { //isMock: true, // isQuiet: true } ); if (msg === "success" && code === 0) { let { info, topicImgList, topicInfo } = this.data; info = copyKeyHave(info, data); // 话题详情相关 topicInfo = copyKeyHave(topicInfo, data.topicInfo); topicImgList = Array.isArray(data.topicInfo.topicImgs) ? data.topicInfo.topicImgs : []; console.log("info", info); // 进展列表 if ( info.issueStatus == "closed" || info.issueStatus == "shift_project" ) { this.getProgressInfo(); } // 满意度评价 if (info.issueStatus == "closed") { this.setData({ listUrl: "resi/hall/issue/evaluationlist", ["listParams.issueId"]: this.data.issueId, }); console.log("给老子出来", this.data.listParams); this.resetList(); this.getList(); } if (info.issueStatus == "shift_project") { this.setData({ listUrl: "resi/hall/issue/projectevaluationlist", ["listParams.projectId"]: info.projectId, }); console.log("给老子出来", this.data.listParams); this.resetList(); this.getList(); } this.setData({ info, topicInfo, topicImgList, }); if (info.sourceType == "ic_event"){ this.getEventInfo() } } }, //获取事件详情 async getEventInfo(){ const { info } = this.data; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "gov/project/icEvent/detail", { icEventId:info.sourceId, }, { // isMock: true } ); console.log('ddddata', data) if (msg === "success" && code === 0) { this.setData({ eventInfo: data }) } }, // 获取话题附件 async getAttechment() { const { topicId } = this.data.topicInfo; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "resi/group/topic/topicattachmentlist", { topicId, }, { // isMock: true } ); console.log("ddddata", data); if (msg === "success" && code === 0) { this.setData({ voiceList: data.voiceList, }); } }, // 获取分类标签 async getClassTagInfo() { const { issueId } = this.data; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "gov/issue/issuecategory/categorytaglist", { issueId, }, { //isMock: true, // isQuiet: true } ); if (msg === "success" && code === 0) { if (Object.keys(data).length > 0) { let { categoryList, tagList } = data; categoryList = categoryList.map((item) => item.name).join("\n"); tagList = tagList.map((item) => item.name).join(" "); let classTag = { class: categoryList, tag: tagList }; this.setData({ classTag, }); } } }, // 获取当前组织信息 async getChartInfo() { const { issueId } = this.data; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "resi/hall/issue/votingtrend", { issueId, }, { //isMock: true, // isQuiet: true } ); if (msg === "success" && code === 0) { let { voteInfo, chartData } = this.data; voteInfo = copyKeyHave(voteInfo, data); chartData = []; data.polyLine.forEach((item) => { let date = dateFormat(new Date(item.voteDate * 1000), "yyyy-MM-dd"); console.log("date:" + date); chartData.push( { date, value: item.supportIncrement, type: "支持", }, { date, value: item.oppositionIncrement, type: "反对", } ); }); console.log("chartData", chartData); this.setData({ voteInfo, chartData, }); } }, // 处理进展 async getProgressInfo() { const { issueId } = this.data; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "resi/hall/issue/processlist", { issueId, }, { //isMock: true, // isQuiet: true } ); if (msg === "success" && code === 0) { this.setData({ progressList: data, }); } }, // 点击查看作品图集 previewImg(e) { const { target: { dataset: { index }, }, } = e; const { topicImgList } = this.data, currentImg = topicImgList[index], imgArr = topicImgList; wx.previewImage({ current: currentImg, urls: imgArr, }); }, // 打电话 callPhone(e) { const { target: { dataset: { phone }, }, } = e; wx.makePhoneCall({ phoneNumber: phone, }); }, // 支持数、反对数 async voteNum() { const { issueId } = this.data; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "resi/hall/issue/vote", { issueId, }, { //isMock: true, } ); if (msg === "success" && code === 0) { this.setData({ votedNum: data, }); if (data.voteFlag) { this.setData({ voted: true, voterst: data.voteType, }); } } }, async rate(e) { console.log(e.currentTarget.dataset.tit); let issueid = e.currentTarget.dataset.issueid, projectid = e.currentTarget.dataset.projectid, type = e.currentTarget.dataset.type, tit = e.currentTarget.dataset.tit; wx.navigateTo({ url: `/subpages/discussion/pages/rate/index?type=${type}&issueid=${issueid}&projectid=${projectid}&tit=${tit}`, }); }, // 支持 async support() { if (!(await this.beforeAct())) return; if (!this.data.votedNum.voteAuthorization) { wx.showToast({ title: words.topic.vote, icon: "none", duration: 3000, }); return false; } const { issueId } = this.data; wx.showLoading({ title: words.common.submitting, mask: true, }); const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "resi/hall/issue/support", { issueId, }, { //isMock: true, } ); wx.hideLoading(); if (msg === "success" && code === 0) { await this.voteNum(); this.setData({ voted: true, voterst: "support", }); } }, // 支持 async oppose() { if (!(await this.beforeAct())) return; if (!this.data.votedNum.voteAuthorization) { wx.showToast({ title: words.topic.vote, icon: "none", duration: 3000, }); return false; } const { issueId } = this.data; wx.showLoading({ title: words.common.submitting, mask: true, }); const { data: { data: { code, data }, }, msg, } = await wxRequestPost( "resi/hall/issue/oppose", { issueId, }, { //isMock: true, } ); wx.hideLoading(); if (msg === "success" && code === 0) { await this.voteNum(); this.setData({ voted: true, voterst: "opposition", }); } }, }, });