launch.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. content: cc.Node,
  5. prefab: cc.Prefab,
  6. GoldBG: cc.SpriteFrame,
  7. GoldMedal: cc.SpriteFrame,
  8. SilverMedal: cc.SpriteFrame,
  9. BronzeMedal: cc.SpriteFrame,
  10. },
  11. onLoad() {
  12. this.nodes = [];
  13. this.ranklist = cc.find("Canvas/ranklist");
  14. this.info = cc.find("Canvas/info");
  15. },
  16. finished: function () {
  17. // console.log("动画回调了吗",this.Transcendnode);
  18. if (this.Transcendnode != null) {
  19. this.Transcendnode.active = false;
  20. }
  21. },
  22. getFriend: function () {
  23. this.removeAll();
  24. if (cc.sys.platform === cc.sys.WECHAT_GAME) {
  25. wx.getFriendCloudStorage({
  26. keyList: ['score'],
  27. success: function (res) {
  28. //添加排行榜为 自己的条目在下面
  29. this.testListView(this.initData(res.data));
  30. this.addMyItem();
  31. }.bind(this),
  32. fail: function (res) {
  33. console.error(res);
  34. }.bind(this)
  35. });
  36. } else {
  37. this.testListView(this.initData(null));
  38. //添加排行榜为 自己的条目在下面
  39. this.addMyItem();
  40. }
  41. },
  42. removeAll: function () {
  43. for (var i = 0; i < this.nodes.length; i++) {
  44. if (this.nodes[i] != null) {
  45. this.nodes[i].destroy();
  46. }
  47. }
  48. this.nodes = [];
  49. },
  50. //获取到当前名字
  51. getRanking: function (callback) {
  52. if (cc.sys.platform === cc.sys.WECHAT_GAME) {
  53. wx.getFriendCloudStorage({
  54. keyList: ['score'],
  55. success: function (res) {
  56. this.initData(res.data, callback);
  57. }.bind(this),
  58. fail: function (res) {
  59. console.error(res);
  60. }.bind(this)
  61. });
  62. } else {
  63. this.initData(null, callback);
  64. }
  65. },
  66. initData: function (data, callback) {
  67. var list = [
  68. {
  69. name: "汉堡店",
  70. id: 9527,
  71. Price: 100,
  72. Fluctuate: "15%",
  73. TotalPossession: 3500
  74. },
  75. {
  76. name: "汉堡店1",
  77. id: 9527,
  78. Price: 100,
  79. Fluctuate: "15%",
  80. TotalPossession: 3500
  81. },
  82. {
  83. name: "汉堡店3",
  84. id: 9527,
  85. Price: 100,
  86. Fluctuate: "15%",
  87. TotalPossession: 3500
  88. },
  89. ];
  90. var listdata = [
  91. {
  92. id: 2,
  93. name: "22",
  94. avatarUrl: "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=607947196,2238683854&fm=26&gp=0.jpg",
  95. listData: list,
  96. openId: "oGxOa5bd61v9jI_indIdQtI2T5P8",
  97. // num : 0
  98. },
  99. {
  100. id: 6,
  101. name: "22",
  102. avatarUrl: "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=607947196,2238683854&fm=26&gp=0.jpg",
  103. listData: list,
  104. openId: "oGxOa5bjKLaCSbkPev09yVze0WSA",
  105. // num : 1
  106. },
  107. {
  108. id: 3,
  109. name: "22",
  110. avatarUrl: "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=607947196,2238683854&fm=26&gp=0.jpg",
  111. listData: list,
  112. openId: "oGxOa5bjKLaCSbkPev09yVze0WSA",
  113. // num : 2
  114. },
  115. {
  116. id: 3,
  117. name: "22",
  118. avatarUrl: "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=607947196,2238683854&fm=26&gp=0.jpg",
  119. listData: list,
  120. openId: "oGxOa5bjKLaCSbkPev09yVze0WSA",
  121. // num : 3
  122. },
  123. {
  124. id: 7,
  125. name: "汪汪333",
  126. avatarUrl: "https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83eohXLEIOV99ic2JosrQDgIgL4cU4ZlmmvkWzGpygkNV9aEJ6nCC2mVf4kYBDHogNOHgXo2wZhv85jA/132?aa=a.jpg",
  127. listData: list,
  128. openId: "oGxOa5SQ1ltBWWsVRirUvXUBGRRY",
  129. // num : 4
  130. },
  131. {
  132. id: 8,
  133. name: "汪汪",
  134. avatarUrl: "https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83eohXLEIOV99ic2JosrQDgIgL4cU4ZlmmvkWzGpygkNV9aEJ6nCC2mVf4kYBDHogNOHgXo2wZhv85jA/132?aa=a.jpg",
  135. listData: list,
  136. openId: "11",
  137. // num : 4
  138. },
  139. {
  140. id: 9,
  141. name: "汪汪",
  142. avatarUrl: "https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83eohXLEIOV99ic2JosrQDgIgL4cU4ZlmmvkWzGpygkNV9aEJ6nCC2mVf4kYBDHogNOHgXo2wZhv85jA/132?aa=a.jpg",
  143. listData: list,
  144. openId: "11",
  145. // num : 4
  146. },
  147. {
  148. id: 10,
  149. name: "汪汪",
  150. avatarUrl: "https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83eohXLEIOV99ic2JosrQDgIgL4cU4ZlmmvkWzGpygkNV9aEJ6nCC2mVf4kYBDHogNOHgXo2wZhv85jA/132?aa=a.jpg",
  151. listData: list,
  152. openId: "11",
  153. // num : 4
  154. },
  155. ]
  156. if (data != null) {
  157. listdata = [];
  158. for (let i = 0; i < data.length; i++) {
  159. let friendInfo = data[i];
  160. let nickName = friendInfo.nickname;
  161. let avatarUrl = friendInfo.avatarUrl + "?aa=a.jpg";
  162. let ScoreValue = friendInfo.KVDataList[0].value;
  163. var d = {}
  164. d.id = parseInt(ScoreValue);
  165. d.name = nickName;
  166. d.openId = friendInfo.openid;
  167. d.avatarUrl = avatarUrl;
  168. d.listData = list;
  169. // d.num = i;
  170. // console.log("每条",d);
  171. listdata.push(d);
  172. // if (friendInfo.openid == userData.openId) {
  173. // userData.httpData.data.avatarUrl = avatarUrl + "?aa=a.jpg";
  174. // userData.httpData.data.nickName = nickName;
  175. // userData.httpData.data.id = d.id;
  176. // // userData.httpData.data.num = d.num;
  177. // console.log('1111=', userData.httpData.data.avatarUrl);
  178. // }
  179. }
  180. }
  181. var lists = this.getSortArr(listdata);
  182. //获取自己的排名信息
  183. for (let index = 0; index < lists.length; index++) {
  184. const element = lists[index];
  185. if (element.openId == userData.openId) {
  186. userData.ranking = index + 1;
  187. userData.httpData.data.avatarUrl = element.avatarUrl;
  188. userData.httpData.data.nickName = element.name;
  189. userData.httpData.data.id = element.id;
  190. // console.log( element.avatarUrl,'==333=', userData.httpData.data.avatarUrl);
  191. break;
  192. }
  193. }
  194. if (callback != null) {
  195. callback(lists);
  196. }
  197. return lists;
  198. },
  199. getSortArr: function (arr) {
  200. return arr.sort(this.sortNumberfunction);
  201. },
  202. sortNumberfunction: function (a, b) {
  203. return b.id - a.id;
  204. },
  205. addMyItem: function () {
  206. if (userData.httpData.data.avatarUrl == "")
  207. return;
  208. let node = cc.instantiate(this.prefab);
  209. node.parent = this.node;
  210. node.y -= 340;
  211. this.nodes.push(node);
  212. // // getUserInfo will return the nickName, getFriendCloudStorage will return the nickname.
  213. let nickName = userData.httpData.data.nickName;
  214. let avatarUrl = userData.httpData.data.avatarUrl;
  215. let ScoreValue = userData.httpData.data.id;
  216. // // console.log("ScoreValue="+ScoreValue);
  217. let userName = node.getChildByName('userName').getComponent(cc.Label);
  218. let userIcon = node.getChildByName('mask').getChildByName('userIcon').getComponent(cc.Sprite);
  219. let Scorelabel = node.getChildByName('Score').getComponent(cc.Label);
  220. node.getChildByName('ranking').getChildByName('RankText').getComponent(cc.Label).string = userData.ranking;
  221. console.log('1111=', avatarUrl);
  222. userName.string = nickName;
  223. Scorelabel.string = ScoreValue;
  224. cc.loader.load({ url: avatarUrl, type: 'png' }, (err, texture) => {
  225. if (err) console.error(err);
  226. // userIcon.spriteFrame = new cc.SpriteFrame(texture);
  227. this.setsprite(userIcon, new cc.SpriteFrame(texture));
  228. });
  229. },
  230. setsprite(targetSprite, texture) {
  231. targetSprite.spriteFrame = texture;
  232. },
  233. testListView: function (listdata) {
  234. for (let i = 0; i < listdata.length; i++) {
  235. let friendInfo = listdata[i];
  236. this.createtest(friendInfo, i);
  237. }
  238. this.setOnClickItem(function (index) {
  239. // console.log("条目点击",listdata[index],"点了索引了",index);
  240. UtilsPrefabs
  241. .init(this.node.parent)
  242. .addPrefabs(UtilsPrefabs.PrefabsName[5], null, function (node) {
  243. this.initcreateUserInfo(listdata[index], node);
  244. var PCloseButton = UtilsPrefabs.getNode("PCloseButton", node);
  245. UtilsPrefabs.setOff(PCloseButton);
  246. UtilsPrefabs.setOn(PCloseButton, function () {
  247. UtilsPrefabs.removePrefabs(this.node.parent, node.name);
  248. }.bind(this))
  249. }.bind(this));
  250. }.bind(this));
  251. },
  252. createtest(user, index) {
  253. let node = this.createPrefab(index);
  254. // getUserInfo will return the nickName, getFriendCloudStorage will return the nickname.
  255. let nickName = user.name;
  256. let avatarUrl = user.avatarUrl;
  257. let ScoreValue = user.id;
  258. // console.log("ScoreValue="+ScoreValue);
  259. let userName = node.getChildByName('userName').getComponent(cc.Label);
  260. let userIcon = node.getChildByName('mask').getChildByName('userIcon').getComponent(cc.Sprite);
  261. let Scorelabel = node.getChildByName('Score').getComponent(cc.Label);
  262. node.__itemID = index;
  263. if (userName != null) {
  264. userName.string = nickName;
  265. }
  266. if (Scorelabel != null) {
  267. Scorelabel.string = ScoreValue;
  268. }
  269. console.log('avatarUrl=', avatarUrl);
  270. // console.log(nickName + '\'s info has been getten.');
  271. cc.loader.load({
  272. url: avatarUrl, type: 'png'
  273. }, (err, texture) => {
  274. if (err) console.error(err);
  275. userIcon.spriteFrame = new cc.SpriteFrame(texture);
  276. });
  277. },
  278. Transcendfun: function (a, b) {
  279. this.Transcendnode = UtilsPrefabs.getNode("Transcend", cc.find("Canvas"));
  280. this.Transcendnode.active = true;
  281. this.animCtrl = this.Transcendnode.getComponent("cc.Animation");
  282. if (a != null && b != null) {
  283. this.setItemDataA(a);
  284. this.setItemDataB(b);
  285. }
  286. if (this.animCtrl != null) {
  287. this.animCtrl.play('Transcend');
  288. this.animCtrl.on('finished', this.finished, this);
  289. }
  290. },
  291. getCurrs: function (x, lists) {
  292. // console.log("近来数据全不全",x,lists);
  293. this.ranklist.active = true;
  294. if (x == null && lists == null) {
  295. this.initData(null, function (list) {
  296. var listdata = [];
  297. for (var i = 0; i < list.length; i++) {
  298. if (list[i].openId == userData.openId) {
  299. // console.log("我 前面",list[i-1]);
  300. // console.log("我 ",list[i]);
  301. // console.log("我 后面",list[i+1]);
  302. if (list[i - 1] != null) {
  303. list[i - 1].num = i;
  304. }
  305. if (list[i] != null) {
  306. list[i].num = i + 1;
  307. }
  308. if (list[i + 1] != null) {
  309. list[i + 1].num = i + 2;
  310. }
  311. listdata.push(list[i - 1]);
  312. listdata.push(list[i]);
  313. listdata.push(list[i + 1]);
  314. this.setleftmidrightRankListData(listdata);
  315. }
  316. }
  317. }.bind(this))
  318. } else {
  319. // console.log("我在统计数组4",lists);
  320. var listdata = [];
  321. for (var i = 0; i < lists.length; i++) {
  322. if (lists[i].openId == userData.openId) {
  323. // console.log("我 前面",lists[i-1]);
  324. // console.log("我 ",lists[i]);
  325. // console.log("我 后面",lists[i+1]);
  326. if (lists[i - 1] != null) {
  327. lists[i - 1].num = i;
  328. }
  329. if (lists[i] != null) {
  330. lists[i].num = i + 1;
  331. }
  332. if (lists[i + 1] != null) {
  333. lists[i + 1].num = i + 2;
  334. }
  335. listdata.push(lists[i - 1]);
  336. listdata.push(lists[i]);
  337. listdata.push(lists[i + 1]);
  338. this.setleftmidrightRankListData(listdata);
  339. }
  340. }
  341. }
  342. },
  343. curr: function (data) {
  344. this.info.active = true;
  345. let layou = UtilsPrefabs.getNode("layou", this.info);
  346. let ic = layou.children[1];
  347. let name = layou.children[2];
  348. let money = layou.children[3];
  349. name.getComponent(cc.Label).string = data.name;
  350. money.getComponent(cc.Label).string = data.id;
  351. cc.loader.load({
  352. url: data.avatarUrl, type: 'png'
  353. }, (err, texture) => {
  354. if (err) console.error(err);
  355. ic.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
  356. });
  357. setTimeout(function () {
  358. this.info.active = false;
  359. }.bind(this), 4000)
  360. },
  361. setleftmidrightRankListData: function (listdata) {
  362. // console.log("进来的数据是",listdata);
  363. this.closeRanklist();
  364. // console.log("我在统计数组5",listdata);
  365. this.ranklist.active = true;
  366. for (var i = 0; i < listdata.length; i++) {
  367. if (listdata[i] != null) {
  368. var bg = this.ranklist.getChildByName("bg");
  369. bg.children[i].active = true;
  370. let num = UtilsPrefabs.getNode("num", bg.children[i]);
  371. let ic = UtilsPrefabs.getNode("ic", bg.children[i]);
  372. let name = UtilsPrefabs.getNode("name", bg.children[i]);
  373. let money = UtilsPrefabs.getNode("money", bg.children[i]);
  374. num.getComponent(cc.Label).string = listdata[i].num + "名";
  375. name.getComponent(cc.Label).string = listdata[i].name;
  376. money.getComponent(cc.Label).string = listdata[i].id;
  377. cc.loader.load({
  378. url: listdata[i].avatarUrl, type: 'png'
  379. }, (err, texture) => {
  380. if (err) console.error(err);
  381. ic.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
  382. });
  383. }
  384. }
  385. this.ranklist.getChildByName("sub").on(cc.Node.EventType.TOUCH_END, function (event) {
  386. this.closeRanklist();
  387. }.bind(this));
  388. setTimeout(function () {
  389. this.closeRanklist();
  390. }.bind(this), 5000)
  391. },
  392. closeRanklist: function () {
  393. for (var i = 0; i < this.ranklist.getChildByName("bg").children.length; i++) {
  394. this.ranklist.getChildByName("bg").children[i].active = false;
  395. }
  396. this.ranklist.getChildByName("sub").off(cc.Node.EventType.TOUCH_END);
  397. this.ranklist.active = false;
  398. },
  399. setItemDataA: function (a) {
  400. let nickName = a.name;
  401. let avatarUrl = a.avatarUrl;
  402. let ScoreValue = a.id;
  403. // console.log("ScoreValue="+ScoreValue);i
  404. this.Transcendnode = UtilsPrefabs.getNode("Transcend", cc.find("Canvas"));
  405. this.Other = UtilsPrefabs.getNode("i", this.Transcendnode);
  406. var block = UtilsPrefabs.getNode("block", this.Other);
  407. let userName = block.getChildByName('userName').getComponent(cc.Label);
  408. let userIcon = block.getChildByName('mask').children[0].getComponent(cc.Sprite);
  409. let Scorelabel = block.getChildByName('Score').getComponent(cc.Label);
  410. userName.string = nickName;
  411. Scorelabel.string = ScoreValue;
  412. // console.log(nickName + '\'s info has been getten.');
  413. cc.loader.load({
  414. url: avatarUrl, type: 'png'
  415. }, (err, texture) => {
  416. if (err) console.error(err);
  417. userIcon.spriteFrame = new cc.SpriteFrame(texture);
  418. });
  419. },
  420. setItemDataB: function (b) {
  421. let nickName = b.name;
  422. let avatarUrl = b.avatarUrl;
  423. let ScoreValue = b.id;
  424. // console.log("ScoreValue="+ScoreValue);
  425. this.Transcendnode = UtilsPrefabs.getNode("Transcend", cc.find("Canvas"));
  426. var Other = UtilsPrefabs.getNode("Other", this.Transcendnode);
  427. var block = UtilsPrefabs.getNode("block", Other);
  428. let userName = block.getChildByName('userName').getComponent(cc.Label);
  429. let userIcon = block.getChildByName('mask').children[0].getComponent(cc.Sprite);
  430. let Scorelabel = block.getChildByName('Score').getComponent(cc.Label);
  431. userName.string = nickName;
  432. Scorelabel.string = ScoreValue;
  433. // console.log(nickName + '\'s info has been getten.');
  434. cc.loader.load({
  435. url: avatarUrl, type: 'png'
  436. }, (err, texture) => {
  437. if (err) console.error(err);
  438. userIcon.spriteFrame = new cc.SpriteFrame(texture);
  439. });
  440. },
  441. onClickItem: function () {
  442. },
  443. setOnClickItem: function (onClickItem) {
  444. this.onClickItem = onClickItem;
  445. },
  446. createUserBlock(user, index) {
  447. let node = this.createPrefab(index);
  448. // getUserInfo will return the nickName, getFriendCloudStorage will return the nickname.
  449. let nickName = user.nickName ? user.nickName : user.nickname;
  450. let avatarUrl = user.avatarUrl;
  451. let ScoreValue = (user.KVDataList)[0].value;
  452. // console.log("ScoreValue="+ScoreValue);
  453. let userName = node.getChildByName('userName').getComponent(cc.Label);
  454. let userIcon = node.getChildByName('mask').children[0].getComponent(cc.Sprite);
  455. let Scorelabel = node.getChildByName('Score').getComponent(cc.Label);
  456. userName.string = nickName;
  457. Scorelabel.string = ScoreValue;
  458. // console.log(nickName + '\'s info has been getten.');
  459. cc.loader.load({
  460. url: avatarUrl, type: 'png'
  461. }, (err, texture) => {
  462. if (err) console.error(err);
  463. userIcon.spriteFrame = new cc.SpriteFrame(texture);
  464. });
  465. },
  466. createPrefab(index) {
  467. let node = cc.instantiate(this.prefab);
  468. node.parent = this.content;
  469. this.nodes.push(node);
  470. switch (index) {
  471. case 0:
  472. node.getComponent(cc.Sprite).spriteFrame = this.GoldBG;
  473. node.getChildByName('ranking').getChildByName('RankIcon').getComponent(cc.Sprite).spriteFrame = this.GoldMedal;
  474. break;
  475. case 1:
  476. node.getChildByName('ranking').getChildByName('RankIcon').getComponent(cc.Sprite).spriteFrame = this.SilverMedal;
  477. break;
  478. case 2:
  479. node.getChildByName('ranking').getChildByName('RankIcon').getComponent(cc.Sprite).spriteFrame = this.BronzeMedal;
  480. break;
  481. default:
  482. node.getChildByName('ranking').getChildByName('RankText').getComponent(cc.Label).string = index + 1;
  483. }
  484. return node;
  485. },
  486. initcreateUserInfo: function (listdata, node) {
  487. cc.loader.loadRes(UtilsPrefabs.PrefabsName[6], function (err, texture) {
  488. this.itemprefab = cc.instantiate(texture);
  489. for (let i = 0; i < listdata.listData.length; i++) {
  490. let info = listdata.listData[i];
  491. var StockSort = UtilsPrefabs.getNode("StockSort", node);
  492. var ScrollView = UtilsPrefabs.getNode("ScrollView", StockSort);
  493. var view = UtilsPrefabs.getNode("view", ScrollView);
  494. var content = UtilsPrefabs.getNode("content", view);
  495. this.createUserInfo(info, i, content);
  496. }
  497. }.bind(this));
  498. },
  499. createUserInfo(user, index, nodes) {
  500. var itemnode = cc.instantiate(this.itemprefab);
  501. nodes.addChild(itemnode);
  502. var Layout = UtilsPrefabs.getNode("Layout", itemnode);
  503. var Name = UtilsPrefabs.getNode("Name", Layout);
  504. var Code = UtilsPrefabs.getNode("Code", Layout);
  505. var Price = UtilsPrefabs.getNode("Price", Layout);
  506. var Fluctuate = UtilsPrefabs.getNode("Fluctuate", Layout);
  507. var TotalPossession = UtilsPrefabs.getNode("TotalPossession", Layout);
  508. Name.getComponent(cc.Label).string = user.name;
  509. Code.getComponent(cc.Label).string = user.id;
  510. Price.getComponent(cc.Label).string = user.Price;
  511. Fluctuate.getComponent(cc.Label).string = user.Fluctuate;
  512. TotalPossession.getComponent(cc.Label).string = user.TotalPossession;
  513. // console.log("来了吗",user,index,nodes);
  514. },
  515. });