var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp(), e = wx.getRecorderManager(), i = wx.createInnerAudioContext(), s = requirePlugin("chooseLocation"), n = { latitude: 39.89631551, longitude: 116.323459711 }; Page({ data: { uploadCount: 0, uploadVideoCount: 0, currentIndex: 0, columnId: "", uId: "", fieldList: [], textList: [], textareaList: [], audioList: [], videoList: [], photoList: [], linkList: [], locationList: [], isShowText: !1, isShowDesc: !1, isShowPhoto: !1, isShowLink: !1, isShowAudio: !1, isShowVideo: !1, isShowTags: !1, isShowType: !1, tempText: "", tempDesc: "", linkStr: "", map: null, waitFlag: !1, isStartRecord: !1, speck_time: 0, speedStep: 5, setInter: "", currentItem: void 0, isAuthAudio: !1, title: "栏目内容修改", curLat: 0, curLng: 0, isRecording: !1, maxDuration: 60, displayType: [ { name: "九宫格", id: 1 }, { name: "轮播", id: 2 }, { name: "轮播(自动)", id: 3 }, { name: "平铺", id: 4 } ], selDisplayType: 1, displayTypeStr: "九宫格" }, onLoad: function(t) { this.setData({ columnId: t.id, uId: t.uid, title: t.title + "修改" }), wx.setNavigationBarTitle({ title: t.title + "修改" }); this.checkPermission(), this.getMomentContent(); }, getMomentContent: function() { wx.showLoading({ title: "加载中..." }); var t = this; a.http.get(a.urls.getMomentsContent.format({ configColumnId: t.data.columnId, uid: t.data.uId }), { header: { token: a.globalData.token } }).then(function(a) { wx.hideLoading({}), t.buildDetail(a.data); }).catch(function(t) { wx.hideLoading({}), console.log(t); }); }, buildDetail: function(t) { var e = this; t.list.forEach(function(t) { switch (t.dataType) { case "2": var i = t.value.split("@"), s = i[0].split(","); if (i.length > 1) switch (i[1]) { case "1": e.setData({ selDisplayType: "1", displayTypeStr: "九宫格" }); break; case "2": e.setData({ selDisplayType: "2", displayTypeStr: "轮播" }); break; case "3": e.setData({ selDisplayType: "3", displayTypeStr: "轮播(自动)" }); break; case "4": e.setData({ selDisplayType: "4", displayTypeStr: "平铺" }); } var n = []; s.forEach(function(t) { if (t.length > 0) { var e = { id: t, path: a.baseUrls.baseCardUrl + t }; n.push(e); } }), t.valueList = n; break; case "4": s = t.value.split(","), n = []; for (var o = 0; o < s.length; o++) if (s[o].length > 0) { var d = s[o].split("&"), r = a.baseUrls.baseCardUrl + d[0], l = a.baseUrls.baseCardUrl + d[1], u = { id: d[0], thumbId: d[1], path: r, imgPath: l }; n.push(u); } t.valueList = n; break; case "3": s = t.value.split(","), n = []; s.forEach(function(t) { if (t.length > 0) { var e = t.split("&"), i = "00:00", s = 100; if (e.length > 1) { var o = e[1]; s = o; var d = parseInt(o / 60), r = parseInt(o % 60); i = (d > 9 ? d : "0" + d) + ":" + (+r > 9 ? r : "0" + r); } var l = { id: e[0], path: a.baseUrls.baseCardUrl + e[0], isPlay: !1, duration: s, curDuation: 0, curDurationStr: "00:00", totalDurationStr: i }; n.push(l); } }), t.valueList = n; break; case "6": s = t.value.split("-"), n = []; s.forEach(function(t) { if (t.length > 0) { var a = t.split(","), e = { name: "", address: "", latitude: a[0], longitude: a[1] }; n.push(e); } }), t.valueList = n; break; case "8": t.dictionariesList.forEach(function(a) { -1 != t.value.indexOf(a.dataId) && (t.selValue = a.dataName); }); break; case "9": var c = ""; t.dictionariesList.forEach(function(a) { -1 != t.value.indexOf(a.dataId) ? (c += a.dataName + ",", a.isSel = !0) : a.isSel = !1; }), c = c.substr(0, c.length - 1), t.selValue = c; } }), e.setData({ fieldList: t.list }); }, showMutliSel: function(t) { this.setData({ isShowTags: !0, currentIndex: t.currentTarget.dataset.index }); }, pickerChange: function(t) { var a = t.currentTarget.dataset.index, e = t.detail.value; this.data.fieldList[a].index = e, this.data.fieldList[a].value = this.data.fieldList[a].dictionariesList[e].dataId, this.data.fieldList[a].selValue = this.data.fieldList[a].dictionariesList[e].dataName, this.setData({ fieldList: this.data.fieldList }); }, inputText: function(t) { var a = t.currentTarget.dataset.index; this.data.fieldList[a].value = t.detail.value, this.setData({ fieldList: this.data.fieldList }); }, checkPermission: function() { var t = this; wx.getSetting({ success: function(a) { var e = a.authSetting["scope.record"]; void 0 === e ? wx.authorize({ scope: "scope.record", success: function() { t.setData({ isAuthAudio: !0 }); }, fail: function() { t.setData({ isAuthAudio: !1 }); } }) : e || t.openSetting(); } }); }, openSetting: function() { wx.showModal({ title: "提示", content: "发布内容需要您授权录音权限.", success: function(t) { t.confirm && wx.openSetting({ withSubscriptions: !0 }); } }); }, onShow: function() { if (null != s.getLocation()) { var t = this.data.fieldList[this.data.curMapIndex]; t.valueList.length < t.maxCount && (this.data.fieldList[this.data.curMapIndex].valueList.push(s.getLocation()), this.setData({ fieldList: this.data.fieldList })); } var a = this; wx.getSetting({ withSubscriptions: !0, success: function(t) { var e = t.authSetting["scope.record"]; a.setData({ isAuthAudio: e }); } }); }, onUnload: function() { s.setLocation(null), this.setData({ map: null }); }, chooseVideo: function(t) { var a = this, e = t.currentTarget.dataset.item, i = e.maxCount - e.valueList.length, s = t.currentTarget.dataset.index; wx.chooseMedia({ count: Number.parseInt(i), mediaType: [ "video" ], sourceType: [ "camera", "album" ], maxDuration: 60, success: function(t) { t.tempFiles.length > 0 && (t.tempFiles[0].duration <= a.data.maxDuration ? a.doUploadVideo(s, t.tempFiles, a.data.uploadVideoCount) : wx.showToast({ title: "视频最长60秒", icon: "none" })); }, fail: function(t) {} }); }, doUploadVideo: function(t, e, i) { wx.showLoading({ title: "上传中..." }); var s = this, n = e.length; s.data.uploadVideoCount < n ? a.http.upload(a.urls.doUploadVideo, { path: e[s.data.uploadVideoCount].tempFilePath, name: "video", header: { token: a.globalData.token } }).then(function(a) { wx.hideLoading({}); var i = JSON.parse(a).data; s.doUploadVideoImg(t, i, e, s.data.uploadVideoCount); }).catch(function(a) { wx.hideLoading({}), s.setData({ uploadVideoCount: ++s.data.uploadVideoCount }), s.doUploadVideo(t, e, s.data.uploadVideoCount); }) : (wx.hideLoading({}), s.setData({ uploadVideoCount: 0 })); }, doUploadVideoImg: function(t, e, i, s) { wx.showLoading({ title: "上传中..." }); var n = this; a.http.upload(a.urls.doUploadImg, { path: i[n.data.uploadVideoCount].thumbTempFilePath, name: "image", header: { token: a.globalData.token } }).then(function(s) { console.log(s), wx.hideLoading({}); var o = a.baseUrls.baseCardUrl + e, d = a.baseUrls.baseCardUrl + JSON.parse(s).data, r = JSON.parse(s).data, l = { id: e, thumbId: r, path: o, imgPath: d }; n.data.fieldList[t].valueList.push(l), n.setData({ fieldList: n.data.fieldList }), n.setData({ uploadVideoCount: ++n.data.uploadVideoCount }), n.doUploadVideo(t, i, n.data.uploadVideoCount); }).catch(function(a) { console.log(a), wx.hideLoading({}), n.setData({ uploadVideoCount: ++n.data.uploadVideoCount }), n.doUploadVideo(t, i, n.data.uploadVideoCount); }); }, viewVideo: function(t) { var a = [ { url: t.currentTarget.dataset.url, type: "video" } ]; wx.previewMedia({ sources: a, current: 0, showmenu: !1 }); }, delVideo: function(t) { var a = this, e = t.currentTarget.dataset.index, i = t.currentTarget.dataset.idx; wx.showModal({ title: "提示", content: "确定要删除该视频吗?", cancelText: "取消", confirmText: "确定", success: function(t) { t.confirm && (a.data.fieldList[e].valueList.splice(i, 1), a.setData({ fieldList: a.data.fieldList })); } }); }, addLink: function() { for (var t = null, a = 0; a < this.data.items.length; a++) if ("LINK" == this.data.items[a].type) { t = this.data.items[a]; break; } if (this.data.linkList.length < t.count) { if ("" == this.data.linkStr) return void wx.showToast({ title: "请输入文字内容", icon: "error" }); this.data.linkList.push(this.data.linkStr), this.setData({ linkList: this.data.linkList, linkStr: "" }), this.data.linkList.length == t.count && this.setData({ isShowLink: !1 }); } }, addDesc: function() { for (var t = null, a = 0; a < this.data.items.length; a++) if ("TEXTAREA" == this.data.items[a].type) { t = this.data.items[a]; break; } if (this.data.textareaList.length < t.count) { if ("" == this.data.tempDesc) return void wx.showToast({ title: "请输入文字内容", icon: "error" }); this.data.textareaList.push(this.data.tempDesc), this.setData({ textareaList: this.data.textareaList, tempDesc: "" }), this.data.textareaList.length == t.count && this.setData({ isShowDesc: !1 }); } }, addStr: function() { for (var t = null, a = 0; a < this.data.items.length; a++) if ("TEXT" == this.data.items[a].type) { t = this.data.items[a]; break; } if (this.data.textList.length < t.count) { if ("" == this.data.tempText) return void wx.showToast({ title: "请输入文字内容", icon: "error" }); this.data.textList.push(this.data.tempText), this.setData({ textList: this.data.textList, tempText: "" }), this.data.textList.length == t.count && this.setData({ isShowText: !1 }); } }, delText: function(t) { var a = this; wx.showModal({ title: "提示", content: "确定要删除该条数据吗?", cancelText: "取消", confirmText: "确定", success: function(e) { e.confirm && (a.data.textList.splice(t.currentTarget.dataset.index, 1), a.setData({ textList: a.data.textList })); } }); }, delLink: function(t) { var a = this; wx.showModal({ title: "提示", content: "确定要删除该条数据吗?", cancelText: "取消", confirmText: "确定", success: function(e) { e.confirm && (a.data.linkList.splice(t.currentTarget.dataset.index, 1), a.setData({ linkList: a.data.linkList })); } }); }, delDesc: function(t) { var a = this; wx.showModal({ title: "提示", content: "确定要删除该条数据吗?", cancelText: "取消", confirmText: "确定", success: function(e) { e.confirm && (a.data.textareaList.splice(t.currentTarget.dataset.index, 1), a.setData({ textareaList: a.data.textareaList })); } }); }, confirmSel: function(t) { var a = t.detail, e = (a.piacker, a.value); this.setData({ selDisplayType: e.id, displayTypeStr: e.name, isShowType: !1 }); }, cancelSel: function(t) { this.setData({ isShowType: !1 }); }, textInput: function(a) { this.setData(t({}, a.currentTarget.id, a.detail.value)); }, onHide: function(t) { this.setData({ isShowText: !1, isShowDesc: !1, isShowPhoto: !1, isShowLink: !1, isShowAudio: !1, isShowVideo: !1, isShowTags: !1 }); }, chooseTags: function(t) { var a = t.currentTarget.dataset.idx; this.data.fieldList[this.data.currentIndex].dictionariesList[a].isSel = !this.data.fieldList[this.data.currentIndex].dictionariesList[a].isSel, this.setData({ fieldList: this.data.fieldList }); var e = "", i = ""; this.data.fieldList[this.data.currentIndex].dictionariesList.forEach(function(t) { t.isSel && (e += t.dataName + ",", i += t.dataId + ","); }), e = e.substr(0, e.length - 1), i = i.substr(0, i.length - 1), this.data.fieldList[this.data.currentIndex].selValue = e, this.data.fieldList[this.data.currentIndex].value = i, this.setData({ fieldList: this.data.fieldList }); }, selTags: function() { this.setData({ isShowTags: !1 }); }, choosePhoto: function(t) { var a = this, e = t.currentTarget.dataset.item, i = t.currentTarget.dataset.index, s = e.maxCount - e.valueList.length; wx.chooseImage({ count: Number.parseInt(s), sourceType: [ "album", "camera" ], success: function(t) { a.doUploadImg(i, t.tempFilePaths, a.data.uploadCount); }, fail: function(t) {} }); }, delImg: function(t) { var a = this; wx.showModal({ title: "提示", content: "确定要删除该图片吗?", cancelText: "取消", confirmText: "确定", success: function(e) { e.confirm && (a.data.fieldList[t.currentTarget.dataset.itemindex].valueList.splice(t.currentTarget.dataset.index, 1), a.setData({ fieldList: a.data.fieldList })); } }); }, viewImg: function(t) { var a = [ t.currentTarget.dataset.url ]; wx.previewImage({ urls: a, current: t.currentTarget.dataset.url }); }, doUploadImg: function(t, e, i) { wx.showLoading({ title: "上传中..." }); var s = this, n = e.length; s.data.uploadCount < n ? a.http.upload(a.urls.doUploadImg, { path: e[s.data.uploadCount], name: "image", header: { token: a.globalData.token } }).then(function(i) { wx.hideLoading({}); var n = JSON.parse(i).data, o = { id: n, path: a.baseUrls.baseCardUrl + n }; s.data.fieldList[t].valueList.push(o), s.setData({ fieldList: s.data.fieldList }), s.setData({ uploadCount: ++s.data.uploadCount }), s.doUploadImg(t, e, s.data.uploadCount); }).catch(function(a) { wx.hideLoading({}), s.setData({ uploadCount: ++s.data.uploadCount }), s.doUploadImg(t, e, s.data.uploadCount); }) : (wx.hideLoading({}), s.setData({ uploadCount: 0 })); }, chooseLocation: function(t) { var a = t.currentTarget.dataset.index; this.setData({ curMapIndex: a }); var e = JSON.stringify(n); wx.navigateTo({ url: "plugin://chooseLocation/index?key=".concat("HVDBZ-KJGKF-DNMJR-JHEWI-H2HN7-23BMS", "&referer=").concat("市域自治与互助", "&location=").concat(e, "&category=").concat("生活服务,娱乐休闲") }); }, delMap: function(t) { var a = this; wx.showModal({ title: "提示", content: "确定要删除该条数据吗?", cancelText: "取消", confirmText: "确定", success: function(e) { e.confirm && (a.data.fieldList[t.currentTarget.dataset.index].valueList.splice(t.currentTarget.dataset.idx, 1), a.setData({ fieldList: a.data.fieldList })); } }); }, delAudio: function(t) { console.log(t); var a = this; wx.showModal({ title: "提示", content: "确定要删除该音频吗?", cancelText: "取消", confirmText: "确定", success: function(e) { e.confirm && (a.data.fieldList[t.currentTarget.dataset.index].valueList.splice(t.currentTarget.dataset.idx, 1), a.setData({ fieldList: a.data.fieldList })); } }); }, doStartRecord: function() { var t = this; wx.getSetting({ success: function(a) { a.authSetting["scope.record"] ? t.startRecord() : wx.authorize({ scope: "scope.record", success: function() { t.startRecord(); } }); } }); }, startRecord: function() { var t = this; t.data.setInter = setInterval(function() { var a = parseInt(t.data.speck_time + 1); t.setData({ speck_time: parseInt(a), isStartRecord: !0 }), t.data.speck_time > 0 && t.data.speck_time <= 59 ? t.start() : (clearInterval(t.data.setInter), t.stop(), wx.showToast({ title: "录音最长60S哦!", duration: 2e3, icon: "none" })); }, 1e3); }, doEndRecord: function() { clearInterval(this.data.setInter), this.data.speck_time > 3 ? (clearInterval(this.data.setInter), this.stop(!0), this.setData({ speck_time: "0", isStartRecord: !1 })) : (clearInterval(this.data.setInter), this.stop(!1), wx.showToast({ title: "录制时间过短", duration: 2e3, icon: "none" }), this.setData({ speck_time: "0", isStartRecord: !1 })); }, start: function() { e.start({ duration: 6e4, format: "mp3" }), e.onStart(function() { console.log("recorder start"); }), e.onError(function(t) { console.log(t), _self.stop(!1); }); }, stop: function(t) { var a = this; e.stop(), e.onStop(function(e) { t && a.doUploadAudio(e); }); }, doUploadAudio: function(t) { wx.showLoading({ title: "上传中..." }); var e = this; a.http.upload(a.urls.doUploadAudio, { path: t.tempFilePath, name: "audio", header: { token: a.globalData.token } }).then(function(i) { if (wx.hideLoading({}), e.data.fieldList[e.data.currentIndex].valueList.length < e.data.currentItem.maxCount) { wx.hideLoading({}); var s = JSON.parse(i).data, n = a.baseUrls.baseCardUrl + s, o = parseInt(t.duration / 1e3), d = parseInt(o / 60), r = parseInt(o % 60), l = { id: s, path: n, isPlay: !1, duration: o, curDuation: 0, curDurationStr: "00:00", totalDurationStr: (d > 9 ? d : "0" + d) + ":" + (+r > 9 ? r : "0" + r) }; e.data.fieldList[e.data.currentIndex].valueList.push(l), e.setData({ fieldList: e.data.fieldList }), e.data.fieldList[e.data.currentIndex].valueList.length == e.data.currentItem.maxCount && e.setData({ isShowAudio: !1 }); } }).catch(function(t) {}); }, play: function(t) { var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx, s = t.currentTarget.dataset.item, n = this; n.data.fieldList[a].valueList.forEach(function(t) { t.isPlay && i.stop(), t.isPlay = !1, t.curDuation = 0, t.curDuationStr = "00:00"; }), s.isPlay || ((i = wx.createInnerAudioContext()).src = n.data.fieldList[a].valueList[e].path, i.autoplay = !0), i.onPlay(function() { n.data.fieldList[a].valueList[e].isPlay = !0, n.setData({ fieldList: n.data.fieldList }); }), i.onCanplay(function(t) {}), i.onStop(function(t) { n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ fieldList: n.data.fieldList }); }), i.onEnded(function(t) { n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ fieldList: n.data.fieldList }); }), i.onError(function(t) { n.data.fieldList[a].valueList[e].isPlay = !1, n.data.fieldList[a].valueList[e].curDuration = 0, n.data.fieldList[a].valueList[e].curDurationStr = "00:00", n.setData({ fieldList: n.data.fieldList }); }), i.onSeeking(function() { console.log(i.currentTime); }), i.onWaiting(function() {}), i.onTimeUpdate(function() { if (i.duration != 1 / 0) { n.data.fieldList[a].valueList[e].curDuration = parseInt(i.currentTime), n.data.fieldList[a].valueList[e].duration = parseInt(i.duration), console.log(i.duration); var t = parseInt(i.currentTime / 60), s = parseInt(i.currentTime % 60), o = parseInt(i.duration / 60), d = parseInt(i.duration % 60), r = t > 9 ? t : "0" + t, l = s > 9 ? s : "0" + s, u = o > 9 ? o : "0" + o, c = +d > 9 ? d : "0" + d; n.data.fieldList[a].valueList[e].curDurationStr = r + ":" + l, n.data.fieldList[a].valueList[e].totalDurationStr = u + ":" + c, n.setData({ fieldList: n.data.fieldList }); } }); }, rewind: function(t) { var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx; t.currentTarget.dataset.item.isPlay && (this.data.fieldList[a].valueList[e].curDuration = this.data.fieldList[a].valueList[e].curDuration - this.data.speedStep, i.seek(this.data.fieldList[a].valueList[e].curDuration), this.setData({ fieldList: this.data.fieldList })); }, speed: function(t) { var a = t.currentTarget.dataset.index, e = t.currentTarget.dataset.idx; t.currentTarget.dataset.item.isPlay && (this.data.fieldList[a].valueList[e].curDuration = this.data.fieldList[a].valueList[e].curDuration + this.data.speedStep, i.seek(this.data.fieldList[a].valueList[e].curDuration), this.setData({ fieldList: this.data.fieldList })); }, slider4change: function(t) { t.currentTarget.dataset.item.isPlay && i.seek(t.detail.value); }, showDialog: function(t) { console.log(t), this.setData({ isShowAudio: !0, currentItem: t.currentTarget.dataset.item, currentIndex: t.currentTarget.dataset.index }); }, doPublish: function() { if (this.checkParams()) { wx.showToast({ title: "保存中..." }); var t = this.buildParams(); console.log(t), a.http.post(a.urls.doSaveMoments.format({ configColumnId: this.data.columnId }), { data: t, header: { token: a.globalData.token } }).then(function(t) { wx.hideLoading({}); var a = getCurrentPages(); a[a.length - 2].setData({ isRefresh: !0 }), wx.navigateBack({ delta: 1 }); }).catch(function(t) { console.log(t); }); } }, checkParams: function() { for (var t = !0, a = 0; a < this.data.fieldList.length; a++) { var e = this.data.fieldList[a]; if (e.must) if ("1" == e.dataType || "7" == e.dataType || "8" == e.dataType || "9" == e.dataType) { if (e.value.length <= 0) { wx.showToast({ title: "请输入或选择" + e.comment, icon: "none" }), t = !1; break; } } else if (e.valueList.length <= 0) { wx.showToast({ title: "请上传" + e.comment, icon: "none" }), t = !1; break; } } return t; }, buildParams: function() { for (var t = { uid: this.data.uId }, a = 0; a < this.data.fieldList.length; a++) { var e = this.data.fieldList[a]; if ("1" == e.dataType || "7" == e.dataType || "8" == e.dataType || "9" == e.dataType) e.value.length > 0 && (t[e.name] = e.value); else if (e.valueList.length > 0) { var i = ""; "6" == e.dataType ? e.valueList.forEach(function(t) { i += t.latitude + "," + t.longitude + "-"; }) : "4" == e.dataType ? e.valueList.forEach(function(t) { i += t.id + "&" + t.thumbId + ","; }) : "3" == e.dataType ? e.valueList.forEach(function(t) { i += t.id + "&" + t.duration + ","; }) : "2" == e.dataType ? (e.valueList.forEach(function(t) { i += t.id + ","; }), i = i.substr(0, i.length - 1), i += "@" + this.data.selDisplayType) : e.valueList.forEach(function(t) { i += t.id + ","; }), "2" != e.dataType && (i = i.substr(0, i.length - 1)), t[e.name] = i; } } return t; }, showDisplayType: function(t) { this.setData({ isShowType: !0 }); } });