import common from '../../utils/util'; import main from '../../utils/main'; const app = getApp(); Page({ data: { IsNull:false, Searching:true, SearchList:[], InfoArr:["拼音","默写","书写","组词","诗词","译文","发音","释义","反义词","近义词","部首","作者","翻译","例句"], }, onLoad: function () { var that = this; that.setData({ Containnerheight: main.getWindowHeight(), IsShowNull: false, Searching:true, }); common.getStorageValue(that, "SearchTextList", [], function () {}); }, onShow:function(){ this.setData({ Focus: true, }); }, onKeyInput: function (e) { var search = e.detail.value; var that = this; that.setData({ SearchInfo: search, }); }, onFocus: function (e) { var that = this; that.setData({ Searching:true, IsNull:false, }); }, onSearch: function (e) { if (e.currentTarget.dataset.search){ this.data.SearchInfo = e.currentTarget.dataset.search; this.setData({ SearchInfo:this.data.SearchInfo, }); } if (this.data.SearchInfo && this.data.SearchInfo.length > 0) { var search = this.data.SearchInfo; var that = this; var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID; if (search) url += "&Key=" + search; var timeoutGetData=0; wx.showLoading({ title: '请稍后...', }); main.getData(url, function (data) { wx.hideLoading(); clearTimeout(timeoutGetData); if (data) { if (data.List.length==0){ that.setData({ IsNull:true, }); that.getSearchData(); } else{ app.globalData.CardList= data.List; wx.navigateTo({ url: './mainlist?search=' + search+'&Count='+data.Count, }); } } }); timeoutGetData=setTimeout(function(){ wx.hideLoading(); },10000); setTimeout(function () { var arr = that.data.SearchTextList; for (var i = 0; i < arr.length; i++) { if (arr[i] == search) { arr.splice(i, 1); break; } } arr.unshift(search); while (arr.length > 10) { arr.pop(); } wx.setStorageSync("SearchTextList", arr); that.setData({ SearchTextList: arr, }); }, 2000); } else { wx.showToast({ title: '请输搜索内容', }) } }, getSearchData:function(){ var that=this; var url = 'GetMiaoguoAISearch2?UserID=' + app.globalData.userInfo.UserID; url += "&Word=" + that.data.SearchInfo; main.getData(url, function (data) { if (data) { var len = 26; var list = []; if (!data.List){ list=[]; var obj={}; obj.Value = data; if (data.CHN){ obj.Key=data.CHN.HanZi; obj.Content=data.CHN.PinYin[0].explain; if (obj.Key.length==1) obj.TypeName="Z"; else obj.TypeName="C"; obj.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+obj.Key; } else if (data.ENG){ obj.Key=data.ENG.Word; obj.TypeName="D"; obj.Remark=data.ENG.Soundmark.Eng; obj.Content=data.ENG.Paraphrase[0].ParaphraseList; obj.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+obj.Key; } if (data.CHN && data.CHN.PinYin && data.CHN.PinYin.length>0){ obj.Remark=data.CHN.PinYin[0].pinyin; } if (obj.Content && obj.Content.length > len) obj.Content = obj.Content.substr(0, len) + "..."; list.push(obj); } else { list=data.List; for (var i = 0; i < list.length; i++) { var item = list[i]; if (item.TypeName=="字词"){ if (item.Key.length==1) item.TypeName="Z"; else item.TypeName="C"; } else if (item.TypeName=="诗词"){ item.TypeName="S"; item.Remark=item.Author+" ["+item.Dynasty+"]"; } else if (item.TypeName=="翻译"){ item.TypeName="D"; } if (item.Type=="shici") item.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+item.Key+"&Author="+item.Author+"&SearchType="+item.Type+"&Url="+item.Url; else item.Url="&UserID="+app.globalData.userInfo.UserID+"&Word="+item.Key; if (item.Content && item.Content.length > len) item.Content = item.Content.substr(0, len) + "..."; } } that.setData({ SearchList:list, Searching:false, }); } else{ that.setData({ Searching:false, SearchList:[], }); } }); }, goto: function (e) { var url = e.currentTarget.dataset.url; var url2 = e.currentTarget.dataset.url2; if (url2){ url+=url2; if (url2.indexOf("&Url=")>0){ var url3=url2.substr(url2.indexOf("&Url=")+5); app.globalData.TempStr=url3; url+=url.substr(0,url2.indexOf("&Url=")); } } wx.navigateTo({ url: url, }); }, clearInput:function(){ this.setData({ SearchInfo:"", IsNull:false, SearchList:[], }); }, close: function (e) { wx.navigateBack({ delta: 1, }); }, deleteItem: function (e) { var that = this; that.setData({ SearchTextList: [], }); wx.removeStorageSync("SearchTextList"); }, onShareAppMessage: function () { return { title: app.globalData.ShareTitle, path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID, imageUrl: app.globalData.ShareImage, } }, })