StoreView.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. import date from "../Unit/date.js"
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. StoreScrollView: {
  6. default: null,
  7. type: cc.ScrollView
  8. },
  9. Content: {
  10. default: null,
  11. type: cc.Node,
  12. },
  13. Seed: {
  14. default: null,
  15. type: cc.Node,
  16. },
  17. Exchange: {
  18. default: null,
  19. type: cc.Node,
  20. },
  21. SeedBtn: {
  22. default: null,
  23. type: cc.Node,
  24. },
  25. ExchangeBtn: {
  26. default: null,
  27. type: cc.Node,
  28. },
  29. EquipmentCotainer: {
  30. default: null,
  31. type: cc.Node,
  32. },
  33. EquipmentBtn: {
  34. default: null,
  35. type: cc.Node,
  36. },
  37. SelectedFrame: cc.Node,
  38. ManageUI: cc.Node,
  39. //四个按钮对应的sprite
  40. Normal_Seed_Sprite: cc.SpriteFrame,
  41. Selecteded_Seed_Sprite: cc.SpriteFrame,
  42. Normal_Exchange_Sprite: cc.SpriteFrame,
  43. Selecteded_Exchange_Sprite: cc.SpriteFrame,
  44. Normal_EquipmentBtn_Sprite: cc.SpriteFrame,
  45. Selecteded_EquipmentBtn_Sprite: cc.SpriteFrame,
  46. //需要切换节点顺序的父节点
  47. container: cc.Node,
  48. //商城的列表
  49. mySeedList: [],
  50. seedPrefab: cc.Prefab,
  51. //商城的图标列表
  52. seedNodeArry: {
  53. default: [],
  54. type: [cc.Node],
  55. serializable: false,
  56. visible: false,
  57. },
  58. //装备start---
  59. equipmentList: [],
  60. equipPrefab: cc.Prefab,
  61. equipNodeArry: {
  62. default: [],
  63. type: [cc.Node],
  64. serializable: false,
  65. visible: false,
  66. },
  67. equipSpriteFrame: {
  68. default: [],
  69. type: [cc.SpriteFrame],
  70. },
  71. equipIconList: {
  72. default: [],
  73. type: [cc.SpriteFrame],
  74. },
  75. buyEquipIndex: -1,
  76. PayEquipPopView: {
  77. default: null,
  78. type: cc.Node,
  79. },
  80. //装备end---
  81. snbAmount: 0,
  82. luckyAmount: 0,
  83. playAmount: 0,
  84. ExchangePopView: {
  85. default: null,
  86. type: cc.Node,
  87. },
  88. ExchangeLuckyPopView: {
  89. default: null,
  90. type: cc.Node,
  91. },
  92. PayCNTPopView: {
  93. default: null,
  94. type: cc.Node,
  95. },
  96. PaySNBPopView: {
  97. default: null,
  98. type: cc.Node,
  99. },
  100. buySeedIndex: -1,
  101. snbAmountLabel: {
  102. default: null,
  103. type: cc.Label,
  104. },
  105. luckyAmountLabel: {
  106. default: null,
  107. type: cc.Label,
  108. },
  109. //拿到仓库列表的节点
  110. buildingView: {
  111. default: null,
  112. type: cc.Node,
  113. },
  114. myWareHouseSeedList: null,
  115. //轮询种子列表状态
  116. AutoGetSeedsData: null,
  117. //轮询防护包装备等
  118. AutoGetEquipsData: null,
  119. seedsView: {
  120. default: null,
  121. type: cc.Node,
  122. },
  123. // ExchangeView: {
  124. // default: null,
  125. // type: cc.Node,
  126. // },
  127. seedBottomLabel: {
  128. default: null,
  129. type: cc.Node,
  130. },
  131. scrollViewNode: {
  132. default: null,
  133. type: cc.Node,
  134. },
  135. //购买种类数值
  136. toggleInputValue: {
  137. default: '1',
  138. visible: false,
  139. },
  140. PayCNTPopViewNameLabel: {
  141. default: null,
  142. type: cc.Label,
  143. },
  144. PayCNTPopViewCNTLabel: {
  145. default: null,
  146. type: cc.Label,
  147. },
  148. PayCNTPopViewSNBLabel: {
  149. default: null,
  150. type: cc.Label,
  151. },
  152. PayCNTPopViewMutureDurLabel: {
  153. default: null,
  154. type: cc.Label,
  155. },
  156. PopViewSeed: {
  157. default: null,
  158. type: cc.Sprite,
  159. },
  160. isPlaying: false,
  161. //拿到申请列表的节点
  162. applySnbView: {
  163. default: null,
  164. type: cc.Node,
  165. },
  166. },
  167. HiddenAll() {
  168. if (this.Seed.active) this.Seed.active = false
  169. if (this.Exchange.active) this.Exchange.active = false
  170. if (this.EquipmentCotainer.active) this.EquipmentCotainer.active = false;
  171. if (this.StoreScrollView) {
  172. this.StoreScrollView.stopAutoScroll();
  173. this.StoreScrollView.scrollToTop();
  174. }
  175. },
  176. start() {
  177. //获取到仓库列表的脚本
  178. this.buildingViewScript = this.buildingView.getComponent('BuildingView');
  179. //默认设置第一个节点为 最上面
  180. this.SeedBtn.setSiblingIndex(10)
  181. // console.log('SNB=======', GlobalD.GameData.SNB)
  182. this.snbAmountLabel.string = GlobalD.GameData.SNB
  183. this.luckyAmountLabel.string = GlobalD.GameData.GetLucky();
  184. //这里也初始化获取一个数据
  185. GlobalD.GameData.getWarehouseSeedAndFruit((vaule) => {
  186. this.myWareHouseSeedList = vaule.data.seed
  187. })
  188. //获取种子和果实
  189. GlobalD.GameData.getMallSeed((vaule) => {
  190. this.mySeedList = vaule.data
  191. // console.log('this.mySeedList[i]=', this.mySeedList);
  192. for (let i = 0; i < this.mySeedList.length; i++) {
  193. //没有种子数量不显示 todo 看看后续需不需要处理删除
  194. //if (this.mySeedList[i].amount < 1) continue;
  195. let _seed = cc.instantiate(this.seedPrefab)
  196. //if (this.mySeedList[i].amount < 1)
  197. if (this.mySeedList[i].amount < 1) {
  198. _seed.getChildByName("Sell").active = false;
  199. _seed.getChildByName("SellOut").active = true;
  200. } else {
  201. _seed.getChildByName("Sell").active = true;
  202. _seed.getChildByName('SellOut').active = false
  203. }
  204. // _seed.getChildByName("buy_button").active = true;
  205. // _seed.getChildByName("Name").active = false;
  206. // _seed.getChildByName("Name").getChildByName("Num").getComponent(cc.Label).strng = '';//'x'+this.mySeedList[i].amount;
  207. this.seedNodeArry.push(_seed)
  208. _seed.parent = this.Seed;
  209. // this.Seed.addChild(_seed);
  210. let _seedScript = _seed.getComponent('Content_Button')
  211. _seedScript.Name = this.mySeedList[i].name
  212. _seedScript.Price = ''
  213. _seedScript.CNT = this.mySeedList[i].priceCnt
  214. _seedScript.SNB = this.mySeedList[i].priceSnb
  215. _seedScript.Mature = "成熟期:" + this.mySeedList[i].maturity + '天'
  216. _seedScript.Synopsis = this.mySeedList[i].seedDescribe
  217. //设置一个生成点
  218. let _spawnScript = _seed.getComponent('Content_seed')
  219. _spawnScript.myIndex = i
  220. _spawnScript.SpawnPoint = cc.find('Canvas/SpawnParent/SpawnPoint')
  221. _seedScript.NumLabel.string = this.mySeedList[i].amount
  222. _seedScript.NameLabel.string = this.mySeedList[i].name
  223. switch (this.mySeedList[i].picture) {
  224. case 'Cabbage':
  225. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[0];
  226. break
  227. case 'Potato':
  228. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[1];
  229. break
  230. case 'Carrot':
  231. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[2];
  232. break
  233. case 'Broccoli':
  234. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[3];
  235. break
  236. case 'Tomato':
  237. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[4];
  238. break
  239. case 'Squash':
  240. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[5];
  241. break
  242. case 'Eggplant':
  243. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[6];
  244. break
  245. case 'Pepper':
  246. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[7];
  247. break
  248. case 'Lentil':
  249. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[8];
  250. break
  251. //牧场种子
  252. case 'cow':
  253. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[9]
  254. break
  255. case 'sheep':
  256. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[10]
  257. break
  258. case 'pig':
  259. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[11]
  260. break
  261. case 'chicken':
  262. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[12]
  263. break
  264. case 'duck':
  265. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[13]
  266. break
  267. case 'goose':
  268. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[14]
  269. break
  270. case 'carp':
  271. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[15]
  272. break
  273. case 'grassCarp':
  274. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[16]
  275. break
  276. case 'silver':
  277. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[17]
  278. break
  279. case 'seaFish':
  280. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[18]
  281. break
  282. case 'shrimp':
  283. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[19]
  284. break
  285. case 'crab':
  286. _seedScript.bgSprite.spriteFrame = this.buildingViewScript.seedIconSpriteFrame[20]
  287. break
  288. default:
  289. break
  290. }
  291. this.mySeedList[i].bgSpriteFrame = _seedScript.bgSprite.spriteFrame;
  292. }
  293. //第一次设置种子父布局高度
  294. this.Seed.getComponent(cc.Layout).updateLayout();
  295. if (this.Seed.active) {
  296. this.Content.setContentSize(this.Seed.getContentSize());
  297. }
  298. })
  299. //获取装备列表
  300. GlobalD.GameData.onGetMallEquipmentList((vaule) => {
  301. this.equipmentList = vaule.data
  302. // console.log('this.equipmentList=', this.equipmentList);
  303. for (let i = 0; i < this.equipmentList.length; i++) {
  304. let _equip = cc.instantiate(this.equipPrefab)
  305. if (this.equipmentList[i].amount < 1) {
  306. _equip.getChildByName("Sell").active = false;
  307. _equip.getChildByName("SellOut").active = true;
  308. } else {
  309. _equip.getChildByName("Sell").active = true;
  310. _equip.getChildByName('SellOut').active = false
  311. }
  312. this.equipNodeArry.push(_equip)
  313. _equip.parent = this.EquipmentCotainer;
  314. let _equipScript = _equip.getComponent('Content_Button')
  315. _equipScript.Name = this.equipmentList[i].name
  316. // _equipScript.Price = ''
  317. _equipScript.CNT = this.equipmentList[i].priceCnt;
  318. _equipScript.SNB = this.equipmentList[i].priceSnb
  319. _equipScript.Mature = "有效期:" + this.equipmentList[i].effectiveDay + '天'
  320. _equipScript.Synopsis = this.equipmentList[i].itemDescribe;
  321. //设置一个生成点
  322. let _spawnScript = _equip.getComponent('Content_equip')
  323. _spawnScript.onSetStoreView(this.node);
  324. _spawnScript.myIndex = i
  325. _equipScript.NumLabel.string = this.equipmentList[i].amount
  326. _equipScript.NameLabel.string = this.equipmentList[i].name
  327. switch (this.equipmentList[i].picture) {
  328. case 'dog':
  329. _equipScript.bgSprite.spriteFrame = this.equipIconList[0];
  330. _equipScript.showConsumeType = 2;
  331. break
  332. case 'beatDogStick':
  333. _equipScript.bgSprite.spriteFrame = this.equipIconList[1];
  334. _equipScript.showConsumeType = 2;
  335. break
  336. case 'natural':
  337. _equipScript.bgSprite.spriteFrame = this.equipIconList[2];
  338. _equipScript.showConsumeType = 1;
  339. break
  340. case 'beast':
  341. _equipScript.bgSprite.spriteFrame = this.equipIconList[3];
  342. _equipScript.showConsumeType = 1;
  343. break
  344. default:
  345. break
  346. }
  347. this.equipmentList[i].bgSpriteFrame = _equipScript.bgSprite.spriteFrame;
  348. }
  349. //更新装备布局
  350. this.EquipmentCotainer.getComponent(cc.Layout).updateLayout();
  351. if (this.EquipmentCotainer.active) {
  352. this.Content.setContentSize(this.EquipmentCotainer.getContentSize());
  353. }
  354. })
  355. },
  356. //切换建筑的面板
  357. onSwitchBuildingContent(event, index) {
  358. this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Seed_Sprite
  359. this.ExchangeBtn.getComponent(cc.Sprite).spriteFrame =
  360. this.Normal_Exchange_Sprite
  361. this.EquipmentBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_EquipmentBtn_Sprite
  362. this.HiddenAll()
  363. //面板设置index
  364. //种子
  365. if ('0' == index) {
  366. this.SeedBtn.getComponent(cc.Sprite).spriteFrame =
  367. this.Selecteded_Seed_Sprite
  368. this.Seed.active = true
  369. this.Seed.getComponent(cc.Layout).updateLayout();
  370. this.Content.setContentSize(this.Seed.getContentSize());
  371. if (this.seedNodeArry.length != 0) {
  372. this.SelectedFrame.parent = this.seedNodeArry[0]
  373. }
  374. this.scrollViewNode.active = true
  375. this.seedBottomLabel.active = true
  376. this.seedsView.active = true
  377. this.Exchange.active = false
  378. }
  379. //兑换
  380. else if ('1' == index) {
  381. this.ExchangeBtn.getComponent(cc.Sprite).spriteFrame =
  382. this.Selecteded_Exchange_Sprite
  383. this.scrollViewNode.active = false
  384. this.seedBottomLabel.active = false
  385. this.seedsView.active = false
  386. this.Exchange.active = true
  387. }
  388. //装备
  389. else if ('2' == index) {
  390. this.EquipmentBtn.getComponent(cc.Sprite).spriteFrame =
  391. this.Selecteded_EquipmentBtn_Sprite
  392. this.EquipmentCotainer.active = true;
  393. this.EquipmentCotainer.getComponent(cc.Layout).updateLayout();
  394. this.Content.setContentSize(this.EquipmentCotainer.getContentSize());
  395. this.scrollViewNode.active = true
  396. this.seedBottomLabel.active = true
  397. this.seedsView.active = true
  398. this.Exchange.active = false
  399. }
  400. },
  401. switch: function () {
  402. var children = this.container.children
  403. var length = children.length
  404. if (length > 1) {
  405. var src = Math.floor(Math.random() * length)
  406. var node = children[src]
  407. var dst = src === length - 1 ? 0 : src + 1
  408. node.setSiblingIndex(dst)
  409. }
  410. },
  411. OpentSNBExchangeToCNT() {
  412. // GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "转换CNT通道关闭!", 1);
  413. // return;
  414. //限制相关人员交易
  415. if (1 === GlobalD.UserInfo.limitTran) {
  416. GlobalD.GameData.showToast(
  417. cc.find('Canvas/UICamera'),
  418. '转换CNT通道关闭,请联系相关管理人员!',
  419. 1
  420. )
  421. return
  422. }
  423. //更新数据
  424. this.snbAmountLabel.string = GlobalD.GameData.SNB
  425. this.ExchangePopView.active = true
  426. },
  427. SNBExchangeToCNT() {
  428. //限制相关人员交易
  429. if (1 === GlobalD.UserInfo.limitTran) {
  430. GlobalD.GameData.showToast(
  431. cc.find('Canvas/UICamera'),
  432. '转换CNT通道关闭,请联系相关管理人员!',
  433. 1
  434. )
  435. return
  436. }
  437. if (0 === Number(this.snbAmount) || 0 != Number(this.snbAmount) % 5) {
  438. GlobalD.GameData.showToast(
  439. cc.find('Canvas/UICamera'),
  440. '请输入5的倍数兑换!',
  441. 1
  442. )
  443. return
  444. }
  445. console.log('发起兑换:' + Number(this.snbAmount))
  446. GlobalD.GameData.onSnbToCnt(Number(this.snbAmount), (data) => {
  447. //更新数据
  448. this.snbAmountLabel.string = GlobalD.GameData.SNB
  449. this.ExchangePopView.active = false
  450. console.log('data=', data)
  451. // console.log('res=', res)
  452. })
  453. },
  454. /**
  455. * 提交申请
  456. */
  457. onApplyingTran() {
  458. //限制相关人员交易
  459. if (1 === GlobalD.UserInfo.limitTran) {
  460. GlobalD.GameData.showToast(
  461. cc.find('Canvas/UICamera'),
  462. '转换CNT通道关闭,请联系相关管理人员!',
  463. 1
  464. )
  465. return
  466. }
  467. if (0 === Number(this.snbAmount) || 0 != Number(this.snbAmount) % 5) {
  468. GlobalD.GameData.showToast(
  469. cc.find('Canvas/UICamera'),
  470. '请输入5的倍数兑换!',
  471. 1
  472. )
  473. return
  474. }
  475. console.log('申请兑换:' + Number(this.snbAmount))
  476. GlobalD.GameData.onPostApplySnbToCnt(Number(this.snbAmount), (value) => {
  477. console.log("兑换", value);
  478. if (0 === value.code) {
  479. this.ExchangePopView.active = false
  480. GlobalD.GameData.showToast(
  481. cc.find('Canvas/UICamera'),
  482. '已提交申请,详情见申请列表兑换CNT。',
  483. 2
  484. )
  485. } else {
  486. GlobalD.GameData.showToast(
  487. cc.find('Canvas/UICamera'),
  488. value.msg,
  489. 2
  490. )
  491. }
  492. });
  493. },
  494. /**
  495. * 幸运值转换snb
  496. * @returns
  497. */
  498. OpenLuckyExchangeToSNB() {
  499. //限制相关人员交易
  500. if (1 === GlobalD.UserInfo.limitTran) {
  501. GlobalD.GameData.showToast(
  502. cc.find('Canvas/UICamera'),
  503. '转换SNB通道关闭,请联系相关管理人员!',
  504. 1
  505. )
  506. return
  507. }
  508. //更新数据
  509. this.luckyAmountLabel.string = GlobalD.GameData.GetLucky();
  510. this.ExchangeLuckyPopView.active = true
  511. },
  512. LuckyExchangeToSNB() {
  513. //限制相关人员交易
  514. if (1 === GlobalD.UserInfo.limitTran) {
  515. GlobalD.GameData.showToast(
  516. cc.find('Canvas/UICamera'),
  517. '转换SNB通道关闭,请联系相关管理人员!',
  518. 1
  519. )
  520. return
  521. }
  522. if (0 >= Number(this.luckyAmount) || 0 != Number(this.luckyAmount) % 50) {
  523. GlobalD.GameData.showToast(
  524. cc.find('Canvas/UICamera'),
  525. '请输入50的倍数兑换!',
  526. 1
  527. )
  528. return
  529. }
  530. console.log('发起兑换:' + Number(this.luckyAmount))
  531. GlobalD.GameData.onPostLuckToSnb({ luckNum: Number(this.luckyAmount) }, (value) => {
  532. //更新数据
  533. this.luckyAmountLabel.string = GlobalD.GameData.GetLucky();
  534. console.log(GlobalD.GameData.GetLucky());
  535. this.ExchangeLuckyPopView.active = false;
  536. })
  537. },
  538. onTextChangedLucky: function (text, editbox, customEventData) {
  539. var numberTemp = new RegExp('^[A-Za-z0-9]+$')
  540. if (numberTemp.test(text)) {
  541. if (Number(text) >= 1) {
  542. this.luckyAmount = Number(text)
  543. } else {
  544. this.luckyAmount = 0
  545. editbox.string = this.luckyAmount
  546. }
  547. } else {
  548. this.luckyAmount = 0
  549. editbox.string = this.luckyAmount
  550. console.log('请输入50的倍数', this.luckyAmount)
  551. }
  552. },
  553. onPayCNTPopView(myIndex) {
  554. this.buySeedIndex = myIndex
  555. this.PayCNTPopView.active = true
  556. this._updatePrice()
  557. },
  558. onPaySNBPopView(myIndex) {
  559. this.buySeedIndex = myIndex
  560. this.PaySNBPopView.active = true
  561. // console.log('this.mySeedList[this.buySeedIndex] =',this.mySeedList[this.buySeedIndex])
  562. this.PaySNBPopView.getChildByName('BG')
  563. .getChildByName('BG1_sprite_splash')
  564. .getChildByName('NameLabel')
  565. .getChildByName('label')
  566. .getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].name
  567. this.PaySNBPopView.getChildByName('BG')
  568. .getChildByName('BG1_sprite_splash')
  569. .getChildByName('PriceLabel')
  570. .getChildByName('label')
  571. .getComponent(cc.Label).string =
  572. this.mySeedList[this.buySeedIndex].priceCnt + ' SNB'
  573. this.PaySNBPopView.getChildByName('BG')
  574. .getChildByName('BG1_sprite_splash')
  575. .getChildByName('MutureDurLabel')
  576. .getChildByName('label')
  577. .getComponent(cc.Label).string =
  578. this.mySeedList[this.buySeedIndex].maturity
  579. },
  580. PayCNT() {
  581. console.log('this.playAmount=', this.playAmount)
  582. console.log(
  583. 'this.playAmount price=',
  584. this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt)
  585. )
  586. //购买种子也要使用轮询
  587. let currentAmount = 0
  588. for (let i = 0; i < this.myWareHouseSeedList.length; i++) {
  589. if (
  590. this.myWareHouseSeedList[i].id == this.mySeedList[this.buySeedIndex].id
  591. ) {
  592. currentAmount = this.myWareHouseSeedList[i].amount
  593. }
  594. }
  595. //当前背包的数量
  596. console.log('currentAmount:', {
  597. seedId: this.mySeedList[this.buySeedIndex].id,
  598. currentAmount: currentAmount, //把当前背包的数据传进去
  599. })
  600. let playAmount =
  601. this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt)
  602. if (0 === playAmount) {
  603. GlobalD.GameData.showToast(
  604. cc.find('Canvas/UICamera'),
  605. '请输入购买数量',
  606. 1
  607. )
  608. return
  609. }
  610. // if (this.isPlaying) {
  611. // GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "购买过快!", 1);
  612. // return;
  613. // }
  614. // this.isPlaying = true;
  615. // GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "区块确认中,请耐心等待!", 120);
  616. GlobalD.GameData.payCNT(
  617. playAmount,
  618. 4,
  619. this.mySeedList[this.buySeedIndex].id + '',
  620. (data) => {
  621. const [err, tx] = data
  622. // this.isPlaying = false;
  623. if (err === null) {
  624. // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
  625. console.log(tx) // 交易hash,唯一标识符
  626. //todo 种子
  627. if (this.AutoGetSeedsData) {
  628. this.unschedule(this.AutoGetSeedsData)
  629. this.AutoGetSeedsData = null
  630. }
  631. this.AutoGetSeedsData = () => {
  632. // getSeedCount ++;
  633. GlobalD.GameData.onGetSeedState(
  634. {
  635. seedId: this.mySeedList[this.buySeedIndex].id,
  636. currentAmount: currentAmount, //把当前背包的数据传进去
  637. },
  638. (value) => {
  639. console.log('轮询种子:' + JSON.stringify(value))
  640. if (0 === value.code) {
  641. this.unschedule(this.AutoGetSeedsData)
  642. console.log('轮询种子购买成功')
  643. GlobalD.GameData.showToast(
  644. cc.find('Canvas/UICamera'),
  645. '种子购买成功!',
  646. 1
  647. )
  648. // this.PayCNTPopView.active = false;
  649. //直接重新初始化一下列表,
  650. this.buildingViewScript.onUpdateList()
  651. }
  652. }
  653. )
  654. }
  655. this.schedule(this.AutoGetSeedsData, 5)
  656. } else {
  657. console.log(err)
  658. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), err, 2)
  659. }
  660. }
  661. )
  662. },
  663. PaySNB() {
  664. console.log('this.playAmount=', this.playAmount)
  665. console.log('priceSnb price=', this.mySeedList[this.buySeedIndex].priceSnb)
  666. console.log(
  667. 'this.playAmount price=',
  668. this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb)
  669. )
  670. console.log(
  671. '支付价格:' +
  672. this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb)
  673. )
  674. let playAmount =
  675. this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb)
  676. if (0 === playAmount) {
  677. GlobalD.GameData.showToast(
  678. cc.find('Canvas/UICamera'),
  679. '请输入购买数量',
  680. 1
  681. )
  682. return
  683. }
  684. if (this.isPlaying) {
  685. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '购买过快!', 1)
  686. return
  687. }
  688. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '支付处理中...', 10)
  689. this.isPlaying = true
  690. GlobalD.GameData.onBuySeedsWithSNB(
  691. playAmount,
  692. this.mySeedList[this.buySeedIndex].id,
  693. (flag, value) => {
  694. // console.log("SNB购买后", value);
  695. this.isPlaying = false
  696. if (flag && 0 === value.code) {
  697. //todo 种子
  698. GlobalD.GameData.showToast(
  699. cc.find('Canvas/UICamera'),
  700. '种子购买成功!',
  701. 1
  702. )
  703. // this.PayCNTPopView.active = false;
  704. //重新获取一下snb,会自动更新到面板
  705. GlobalD.GameData.onGetUserSnb()
  706. //直接重新初始化一下列表,
  707. this.buildingViewScript.onUpdateList()
  708. //更新日志数据
  709. cc.find('GameNode/ManageDapp')
  710. .getComponent('ManageDapp')
  711. .onUpdateSnbList()
  712. } else {
  713. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 2)
  714. }
  715. }
  716. )
  717. },
  718. onTextChanged1: function (text, editbox, customEventData) {
  719. // 这里的 text 表示 修改完后的 EditBox 的文本内容
  720. // 这里 editbox 是一个 cc.EditBox 对象
  721. // 这里的 customEventData 参数就等于你之前设置的 "foobar"
  722. // this.playAmount = parseInt(text)
  723. var numberTemp = new RegExp('^[A-Za-z0-9]+$')
  724. if (numberTemp.test(text)) {
  725. if (Number(text) >= 1) {
  726. this.playAmount = Number(text)
  727. } else {
  728. this.playAmount = 0
  729. editbox.string = this.playAmount
  730. }
  731. } else {
  732. this.playAmount = 0
  733. editbox.string = this.playAmount
  734. // console.log('playAmount', this.snbAmount)
  735. }
  736. },
  737. // 假设这个回调是给 textChanged 事件的
  738. onTextChanged2: function (text, editbox, customEventData) {
  739. // 这里的 text 表示 修改完后的 EditBox 的文本内容
  740. // 这里 editbox 是一个 cc.EditBox 对象
  741. // 这里的 customEventData 参数就等于你之前设置的 "foobar"
  742. // this.snbAmount = parseInt(text);
  743. var numberTemp = new RegExp('^[A-Za-z0-9]+$')
  744. if (numberTemp.test(text)) {
  745. if (Number(text) >= 1) {
  746. this.snbAmount = Number(text)
  747. } else {
  748. this.snbAmount = 0
  749. editbox.string = this.snbAmount
  750. }
  751. } else {
  752. this.snbAmount = 0
  753. editbox.string = this.snbAmount
  754. console.log('请输入5的倍数', this.snbAmount)
  755. }
  756. },
  757. _updatePrice() {
  758. this.PayCNTPopViewNameLabel.string = this.mySeedList[this.buySeedIndex].name;
  759. this.PayCNTPopViewCNTLabel.string = this.mySeedList[this.buySeedIndex].priceCnt;
  760. this.PayCNTPopViewSNBLabel.string = this.mySeedList[this.buySeedIndex].priceSnb;
  761. this.PayCNTPopViewMutureDurLabel.string = this.mySeedList[this.buySeedIndex].maturity;
  762. this.PopViewSeed.spriteFrame = this.mySeedList[this.buySeedIndex].bgSpriteFrame;
  763. // switch (this.toggleInputValue) {
  764. // case '1':
  765. // this.PayCNTPopViewNameLabel.string =
  766. // this.mySeedList[this.buySeedIndex].name
  767. // this.PayCNTPopViewCNTLabel.string =
  768. // this.mySeedList[this.buySeedIndex].priceCnt + ' CNT'
  769. // this.PayCNTPopViewMutureDurLabel.string =
  770. // this.mySeedList[this.buySeedIndex].maturity
  771. // break
  772. // case '2':
  773. // this.PayCNTPopViewNameLabel.string =
  774. // this.mySeedList[this.buySeedIndex].name
  775. // this.PayCNTPopViewCNTLabel.string =
  776. // this.mySeedList[this.buySeedIndex].priceSnb + ' SNB'
  777. // this.PayCNTPopViewMutureDurLabel.string =
  778. // this.mySeedList[this.buySeedIndex].maturity
  779. // break
  780. // default:
  781. // console.error(
  782. // 'this.toggleInputValue 不是1 2 3!',
  783. // this.toggleInputValue
  784. // )
  785. // break
  786. // }
  787. },
  788. //根据状态吊起不同支付
  789. onSwitchPlayType() {
  790. switch (this.toggleInputValue) {
  791. case '1': //cnt 支付
  792. this.PayCNT()
  793. break
  794. case '2': //snb 支付
  795. this.PaySNB()
  796. break
  797. default:
  798. console.error('状态吊起错误', this.toggleInputValue)
  799. GlobalD.GameData.showToast(
  800. cc.find('Canvas/UICamera'),
  801. '请先选择支付方式',
  802. 1
  803. )
  804. break
  805. }
  806. },
  807. onToggleInput(value, evnentData) {
  808. this.toggleInputValue = evnentData
  809. this._updatePrice()
  810. },
  811. //购买装备
  812. onPayEquipPopView(myIndex) {
  813. this.buyEquipIndex = myIndex
  814. this.PayEquipPopView.active = true
  815. this.PayEquipPopView.getComponent("PayEquipPopView").setInfo(this.equipmentList[this.buyEquipIndex]);
  816. },
  817. PayEquipSNB() {
  818. console.log(
  819. '支付价格Snb:' + this.equipmentList[this.buyEquipIndex].priceSnb
  820. )
  821. if (this.isPlaying) {
  822. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '购买过快!', 1)
  823. return
  824. }
  825. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '支付处理中...', 10)
  826. this.isPlaying = true
  827. GlobalD.GameData.onGetAddEquipment(
  828. { mallOtherId: this.equipmentList[this.buyEquipIndex].id },
  829. (flag, value) => {
  830. console.log("SNB购买后", value);
  831. this.isPlaying = false
  832. if (flag && 0 === value.code) {
  833. let _equip = value.data.equip;
  834. //todo 装备
  835. GlobalD.GameData.showToast(
  836. cc.find('Canvas/UICamera'),
  837. '购买装备成功',
  838. 1
  839. )
  840. //重新获取一下snb,会自动更新到面板
  841. GlobalD.GameData.onGetUserSnb()
  842. if (0 === _equip.otherType) {
  843. GlobalD.Dog = _equip;
  844. this.ManageUI.getComponent('ManageUI').onSettingDogAlpha(255);
  845. //刷新狗状态
  846. let _dogContainerScript = cc.find("Canvas/DogContainer").getComponent("DogContainer")
  847. _dogContainerScript.onSetSelfDogState(_equip);
  848. } else if (1 === _equip.otherType) {
  849. GlobalD.Stick = _equip;
  850. this.ManageUI.getComponent('ManageUI').onSettingStickAlpha(255);
  851. }
  852. //更新日志数据
  853. cc.find('GameNode/ManageDapp')
  854. .getComponent('ManageDapp')
  855. .onUpdateSnbList()
  856. } else {
  857. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 2)
  858. }
  859. }
  860. )
  861. },
  862. //用cnt购买
  863. PayEquipCNT() {
  864. console.log(
  865. '支付价格Cnt:' + this.equipmentList[this.buyEquipIndex].priceCnt + ",购买类型:" + this.equipmentList[this.buyEquipIndex].otherType
  866. )
  867. if (!(this.equipmentList[this.buyEquipIndex].otherType == 2 || this.equipmentList[this.buyEquipIndex].otherType == 3)) return;
  868. if (this.isPlaying) {
  869. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '购买过快!', 1)
  870. return
  871. }
  872. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '支付处理中...', 10)
  873. this.isPlaying = true
  874. let playAmount = this.equipmentList[this.buyEquipIndex].priceCnt
  875. if (0 === playAmount) {
  876. GlobalD.GameData.showToast(
  877. cc.find('Canvas/UICamera'),
  878. 'CNT不能为0!',
  879. 1
  880. )
  881. return
  882. }
  883. GlobalD.GameData.payCNT(
  884. playAmount,
  885. this.equipmentList[this.buyEquipIndex].otherType,// payType
  886. this.equipmentList[this.buyEquipIndex].id + '',
  887. (data) => {
  888. const [err, tx] = data
  889. this.isPlaying = false;
  890. if (err === null) {
  891. // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
  892. console.log(tx) // 交易hash,唯一标识符
  893. //todo 轮询装备
  894. if (this.AutoGetEquipsData) {
  895. this.unschedule(this.AutoGetEquipsData)
  896. this.AutoGetEquipsData = null
  897. }
  898. this.AutoGetEquipsData = () => {
  899. GlobalD.GameData.onGetDisasterProtected((value) => {
  900. if (0 === value.code) {
  901. // console.log('轮询购买防护包:' + JSON.stringify(value))
  902. let data = value.data;
  903. if (this.equipmentList[this.buyEquipIndex].otherType == 2) {
  904. if (GlobalD.NaturalPack == null) {
  905. if (data.naturalProtected != null) {
  906. this.unschedule(this.AutoGetEquipsData)
  907. GlobalD.GameData.showToast(
  908. cc.find('Canvas/UICamera'),
  909. '购买自然防护包成功!',
  910. 1
  911. )
  912. this.ManageUI.getComponent('ManageUI').onRunProtected(value);
  913. }
  914. } else if (!date.datesIsEqual(data.naturalProtected.protectTime, GlobalD.NaturalPack.protectTime)) {
  915. this.unschedule(this.AutoGetEquipsData)
  916. GlobalD.GameData.showToast(
  917. cc.find('Canvas/UICamera'),
  918. '增加自然防护包成功!',
  919. 1
  920. )
  921. this.ManageUI.getComponent('ManageUI').onRunProtected(value);
  922. }
  923. } else if (this.equipmentList[this.buyEquipIndex].otherType == 3) {
  924. if (GlobalD.BeastPack == null) {
  925. if (data.beastProtected != null) {
  926. this.unschedule(this.AutoGetEquipsData)
  927. GlobalD.GameData.showToast(
  928. cc.find('Canvas/UICamera'),
  929. '购买野兽防护包成功!',
  930. 1
  931. )
  932. this.ManageUI.getComponent('ManageUI').onRunProtected(value);
  933. }
  934. } else if (!date.datesIsEqual(data.beastProtected.protectTime, GlobalD.BeastPack.protectTime)) {
  935. this.unschedule(this.AutoGetEquipsData)
  936. //如果时间不相等,叠加时间成功
  937. GlobalD.GameData.showToast(
  938. cc.find('Canvas/UICamera'),
  939. '增加野兽防护包成功!',
  940. 1
  941. )
  942. this.ManageUI.getComponent('ManageUI').onRunProtected(value);
  943. }
  944. } else {
  945. this.unschedule(this.AutoGetEquipsData)
  946. }
  947. }
  948. })
  949. }
  950. this.schedule(this.AutoGetEquipsData, 5)
  951. } else {
  952. console.log(err)
  953. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), err, 2)
  954. }
  955. }
  956. )
  957. },
  958. onDestory() {
  959. if (this.AutoGetSeedsData) {
  960. this.unschedule(this.AutoGetSeedsData)
  961. this.AutoGetSeedsData = null
  962. }
  963. },
  964. //申请列表
  965. OpenApplyList() {
  966. this.applySnbView.active = true;
  967. }
  968. })