| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- var intervalRefresh = 0;
- var arrOrder = [
- {},
- { Name: "最近添加", Value: "ac.MiaoguoCardID desc", CSS: "numberContainerFooter1121Select" },
- { Name: "较早添加", Value: "ac.MiaoguoCardID asc" },
- { Name: "练习较多", Value: "ac.LearnNumber desc,ac.MiaoguoCardID desc" },
- { Name: "练习较少", Value: "ac.LearnNumber,ac.MiaoguoCardID" },
- { Name: "最近练习", Value: "ac.LastTime desc" },
- ];
- Page({
- data: {
- HasPage: false,
- ArrOrder: arrOrder,
- OrderType: 0,
- },
- onLoad: function (options) {
- var that = this;
- var Search = "", IsToday = 0, IsCollect = 0;
- if (options.search) {
- Search = options.search;
- wx.setNavigationBarTitle({
- title: "搜索结果"
- });
- }
- else if (options.type == 1) {
- IsToday = 1;
- wx.setNavigationBarTitle({
- title: "任务清单"
- });
- }
- else if (options.IsCollect == 1) {
- wx.setNavigationBarTitle({
- title: "收藏夹"
- });
- IsCollect = 1;
- }
- var count = 0;
- if (options.count)
- count = options.count;
- that.setData({
- IsCollect: IsCollect,
- Search: Search,
- IsToday: IsToday,
- Count: count,
- Containnerheight: main.getWindowHeight(),
- PageType:options.type,
- IsNew:options.IsNew,
- });
- },
- onShow: function () {
- var that = this;
- if (that.data.IsNew)
- that.onOrder({ currentTarget: { dataset: { value: 4 } } });
- else
- that.getList();
- //题卡主题色
- var arrColorIndex = wx.getStorageSync("ColorIndexArr");
- if (!arrColorIndex) {
- app.globalData.ColorIndex = common.random(1, 4);
- }
- else {
- app.globalData.ColorIndex = arrColorIndex[common.random(0, arrColorIndex.length - 1)];
- }
- },
- onPullDownRefresh: function () {
- var that = this;
- if (!that.data.IsCollect && !that.data.IsToday) {
- app.globalData.CardList = [];
- that.gotoNextPage({ currentTarget: { dataset: { id: 0 } } });
- }
- wx.stopPullDownRefresh();
- },
- getList: function () {
- var that = this;
- var list = app.globalData.CardList;
- var len = 16;
- for (var i = 0; i < list.length; i++) {
- var item = list[i];
- item.ScrollLeft = 0;
- item.DeleteStr = "删除";
- item.Content[1].ContentStr = replaceString(item.Content[1].Content);
- if (item.Content[1].ContentStr.length > len)
- item.Content[1].ContentStr = replaceString(item.Content[1].ContentStr.substr(0, len)) + "...";
- item.Content[2].ContentStr = replaceString(item.Content[2].Content);
- if (item.Content[2].ContentStr.length > len)
- item.Content[2].ContentStr = replaceString(item.Content[2].ContentStr.substr(0, len)) + "...";
- var imageUrl = getImage(item.Content[1].Content);
- if (imageUrl.length == 0 && item.Content[2].Content)
- imageUrl = getImage(item.Content[2].Content);
- if (imageUrl.length == 0 && item.Content[3].Content)
- imageUrl = getImage(item.Content[3].Content);
- if (imageUrl.length > 0) {
- item.ImageUrlTemp = main.getTempImage(imageUrl);
- item.ImageUrlServer = imageUrl;
- }
- }
- // if (that.data.IsToday==1){
- // var tempList=[];
- // for (var i = 0; i < list.length; i++) {
- // var item = list[i];
- // var limitTimeStr = common.formatDateCHS(item.LimitTime);
- // var today = common.formatDateCHS(common.formatTime(new Date()));
- // if (limitTimeStr <= today) {
- // tempList.push(list[i]);
- // }
- // }
- // list=tempList;
- // app.globalData.CardList=list;
- // }
- if (!that.data.IsCollect && !that.data.IsToday && !that.data.Search) {
- main.getData("GetUserCardCount?UserID=" + app.globalData.userInfo.UserID, function (data) {
- if (data) {
- that.setData({
- Count: data.CardNumber,
- });
- var hasPage = false;
- if (list.length < that.data.Count && that.data.IsToday == 0 && !that.data.IsCollect)
- hasPage = true;
- that.setData({
- List: list,
- HasPage: hasPage,
- });
- if (that.data.PageType === "2") {
- wx.redirectTo({
- url: './preview?type=show&id=' + list[0].MiaoguoCardID,
- })
- }
- }
- });
- }
- else if (that.data.Search) {
- that.setData({
- List: list,
- Count: list.length,
- HasPage: true,
- });
- }
- else {
- that.setData({
- Count: list.length,
- });
- var hasPage = false;
- if (list.length < that.data.Count && that.data.IsToday == 0 && !that.data.IsCollect)
- hasPage = true;
- that.setData({
- List: list,
- HasPage: hasPage,
- });
- }
- wx.hideLoading();
- function getImage(str) {
- var result = "";
- if (str.indexOf("[图") >= 0) {
- result = str.substring(str.indexOf("[图") + 3, str.indexOf("[/图]"));
- result = result.substring(result.indexOf("]") + 1);
- }
- //console.log(result);
- return result;
- }
- function replaceString(str) {
- str = str.replace(/\[读]/g, "");
- str = str.replace(/\[\/读\]/g, "");
- str = str.replace(/\[图]/g, "");
- str = str.replace(/\[\/图\]/g, "");
- var str2 = "";
- if (str.indexOf("[读") >= 0) {
- str2 = str.substr(str.indexOf("[读"));
- str2 = str2.substring(0, str2.indexOf("]") + 1);
- }
- str = str.replace(str2, "");
- if (str.indexOf("[读") >= 0) {
- str2 = str.substr(str.indexOf("[读"));
- str2 = str2.substring(0, str2.indexOf("]") + 1);
- }
- str = str.replace(str2, "");
- var str3 = "";
- if (str.indexOf("[图") >= 0) {
- str3 = str.substr(str.indexOf("[图"));
- str3 = str3.substring(0, str3.indexOf("]") + 1);
- }
- str = str.replace(str3, "");
- str = str.replace(/\[线]/g, "");
- str = str.replace(/\[\/线\]/g, "");
- str = main.encryptUrl(str);
- return str;
- }
- },
- onPreview: function (e) {
- var id = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: './preview?type=show&id=' + id,
- })
- },
- playPPT: function () {
- wx.navigateTo({
- url: './preview?type=play',
- })
- },
- onBindError: function (e) {
- var that = this;
- var id = e.currentTarget.dataset.id;
- var serverUrl = e.currentTarget.dataset.serverurl;
- wx.downloadFile({
- url: serverUrl, // 仅为示例,并非真实的资源
- success(res) {
- if (res.statusCode === 200) {
- main.saveTempImage(serverUrl, res.tempFilePath);
- }
- }
- });
- // clearTimeout(intervalRefresh);
- // intervalRefresh = setTimeout(function () {
- // that.getList();
- // }, 1000);
- },
- gotoNextPage: function (e) {
- wx.showLoading({
- title: '请稍候',
- });
- setTimeout(function () {
- wx.hideLoading();
- }, 5000);
- var that = this;
- var url = 'GetMiaoguoCardList?UserID=' + app.globalData.userInfo.UserID + "&IsToday=" + that.data.IsToday;
- var id = e.currentTarget.dataset.id;
- if (id && id > 0)
- url += "&PageID=" + id;
- if (that.data.Search)
- url += "&Key=" + that.data.Search;
- var orderType = that.data.OrderType;
- if (orderType)
- url += "&OrderType=" + arrOrder[orderType].Value;
- main.getData(url, function (data) {
- if (data) {
- var list = app.globalData.CardList;
-
- for (var i = 0; i < data.List.length; i++) {
- data.List[i].LastTimeStr = common.formatDateCHS(data.List[i].LastTime);
-
- list.push(data.List[i]);
- }
- app.globalData.CardList = list;
- that.getList();
- if (data.List.length < 20) {
- that.setData({
- HasPage: false,
- });
- }
- if (orderType>0){
- wx.setNavigationBarTitle({
- title: "全部题卡:" + arrOrder[orderType].Name,
- });
- }
- }
- });
- },
- addCard: function () {
- wx.redirectTo({
- url: './add?type=add&id=0',
- });
- },
- onSearch: function () {
- wx.navigateBack({
- delta: 1,
- });
- },
- onOrder: function (e) {
- var that = this;
- var value = e.currentTarget.dataset.value;
- for (var i = 0; i < this.data.ArrOrder.length; i++) {
- if (i == value)
- this.data.ArrOrder[i].CSS = "numberContainerFooter1121Select";
- else
- this.data.ArrOrder[i].CSS = "";
- }
- this.setData({
- IsOrder: false,
- ArrOrder: this.data.ArrOrder,
- OrderType: value,
- });
- if (!that.data.IsCollect && !that.data.IsToday) {
- app.globalData.CardList = [];
- that.gotoNextPage({ currentTarget: { dataset: { id: 0, OrderType: value } } });
- }
- },
- showOrder: function () {
- this.setData({
- IsOrder: true,
- });
- },
- closeOrder: function () {
- this.setData({
- IsOrder: false,
- });
- },
- DeleteItem: function (e) {
- var that = this;
- var id = e.currentTarget.dataset.id;
- var list = this.data.List;
- var b = true;
- for (var i = 0; i < list.length; i++) {
- var item = list[i];
- if (id == item.MiaoguoCardID) {
- if (item.DeleteStr == "删除") {
- item.ScrollLeft = 160;
- item.DeleteStr = "确认删除";
- }
- else if (item.DeleteStr == "确认删除") {
- b = false;
- item.DeleteStr = "删除";
- item.ScrollLeft = 0;
- var url = 'DeleteMiaoguoCard?UserID=' + app.globalData.userInfo.UserID;
- url += "&ID=" + id;
- main.getData(url, function (data) {
- var list = app.globalData.CardList;
- for (var i = 0; i < list.length; i++) {
- if (id == list[i].MiaoguoCardID) {
- list.splice(i, 1);
- break;
- }
- }
- app.globalData.CardList = list;
- that.setData({
- List: list,
- Count: --that.data.Count,
- });
- });
- }
- }
- else {
- item.DeleteStr = "删除";
- item.ScrollLeft = 0;
- }
- }
- if (b) {
- that.setData({
- List: list,
- });
- }
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|