| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- const WORD_LENGTH=18;
- Page({
- data: {
- IsStart: false,
- Searching: false,
- SearchList: [],
- SearchInfo: "",
- IsMore:true,
- },
- onLoad: function () {
- var that = this;
- that.setData({
- Containnerheight: main.getWindowHeight(),
- });
- },
- onShow: function () {
- var that = this;
- common.getStorageValue(that, "SearchTextList", [], function () {});
- common.getStorageValue(that, "SearchWord3", [], function () {
- var list = that.data.SearchWord3;
- for (var i = 0; i < list.length; i++) {
- var item = list[i];
- if (item.Type == "shici") {
- item.TypeName = "S";
- item.Remark = item.Author + " " + item.Dynasty;
- } else if (item.Type == "eng") {
- item.TypeName = "D";
- } else {
- if (item.Key.length == 1)
- item.TypeName = "Z";
- else
- item.TypeName = "C";
- }
- if (item.Content && item.Content.length > WORD_LENGTH)
- item.Content = item.Content.substr(0, WORD_LENGTH) + "...";
- }
- that.setData({
- SearchWord3: list,
- IsMore:true,
- });
- });
- },
- goto: function (e) {
- var url = e.currentTarget.dataset.url;
- wx.navigateTo({
- url: './' + url,
- })
- },
- onKeyInput: function (e) {
- var search = e.detail.value;
- var that = this;
- that.setData({
- SearchInfo: search,
- });
- },
- onSearchHistory: function (e) {
- var index = Number(e.currentTarget.dataset.index);
- var obj = {};
- if (e.currentTarget.dataset.type == "SearchWord3")
- obj = this.data.SearchWord3[index];
- else
- obj = this.data.SearchList[index];
- main.updateSearchList(obj);
- app.globalData.TempSearchBackNumber = 2;
- app.globalData.CardList2=[];
- wx.navigateTo({
- url: './addInfomationDetail',
- });
- },
- searchResult: function (e) {
- var that = this;
- var search = that.data.SearchInfo;
- if (e.currentTarget.dataset.search) {
- search = e.currentTarget.dataset.search;
- that.setData({
- SearchInfo:search,
- });
- }
- var searchtype=e.currentTarget.dataset.searchtype;
- var author=e.currentTarget.dataset.author;
- var shiciurl=e.currentTarget.dataset.shiciurl;
- main.searchInfomation(search,searchtype,author,shiciurl,function(list,obj){
-
- if (obj){
- main.updateSearchList(obj,function(){
- updateData(that,search);
- wx.navigateTo({
- url: './addInfomationDetail',
- });
-
- });
- }
- else{
- wx.setNavigationBarTitle({
- title: "搜索结果"
- });
- that.setData({
- SearchList: list,
- IsStart: true,
- IsMore:true,
- });
- that.getCardList();
- updateData(that,search);
- }
- });
- function updateData(obj,search) {
- setTimeout(function () {
- var arr = obj.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);
- obj.setData({
- SearchTextList: arr,
- });
- }, 2000);
- }
- },
- getCardList: function () {
- var that = this;
- var url = 'GetMiaoguoCardList2?UserID=' + app.globalData.userInfo.UserID;
- url += "&Key=" + that.data.SearchInfo;
- that.setData({
- Searching: true,
- });
- main.getData(url, function (data) {
- that.setData({
- Searching: false,
- });
- if (data) {
- if (data.List.length > 0) {
- var list=data.List;
- for (var i = 0; i < list.length; i++) {
- var item = list[i];
- item.Content[1].ContentStr = main.replaceCardInfoString(item.Content[1].Content);
- if (item.Content[1].ContentStr.length > WORD_LENGTH)
- item.Content[1].ContentStr = main.replaceCardInfoString(item.Content[1].ContentStr.substr(0, WORD_LENGTH)) + "...";
-
- item.Content[2].ContentStr = main.replaceCardInfoString(item.Content[2].Content);
- if (item.Content[2].ContentStr.length > WORD_LENGTH)
- item.Content[2].ContentStr = main.replaceCardInfoString(item.Content[2].ContentStr.substr(0, WORD_LENGTH)) + "...";
-
- 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;
- }
- }
- that.setData({
- SearchCardList:list,
- });
- app.globalData.CardList2=list;
- }
- else{
- that.setData({
- SearchCardList:[],
- });
- }
- }
- });
- 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;
- }
- },
- clearInput: function () {
- this.setData({
- IsStart: false,
- Searching: false,
- SearchInfo: "",
- Focus:true,
- });
- },
- close: function (e) {
- wx.navigateBack({
- delta: 1,
- });
- },
- deleteItem: function (e) {
- var that = this;
- that.setData({
- SearchTextList: [],
- });
- wx.removeStorageSync("SearchTextList");
- },
- deleteItem2: function (e) {
- var that = this;
- var index = e.currentTarget.dataset.index;
- that.data.SearchWord3.splice(index, 1);
- that.setData({
- SearchWord3: that.data.SearchWord3,
- });
- wx.setStorageSync("SearchWord3", that.data.SearchWord3);
- },
- setMoreHide:function(){
- this.setData({
- IsMore:false,
- });
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- });
|