StoreView.js 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  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. GlobalD.GameData.payCNT(
  611. playAmount,
  612. 4,
  613. this.mySeedList[this.buySeedIndex].id + '',
  614. (data) => {
  615. const [err, tx] = data
  616. // this.isPlaying = false;
  617. if (err === null) {
  618. // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
  619. // console.log(tx) // 交易hash,唯一标识符
  620. //todo 种子
  621. if (this.AutoGetSeedsData) {
  622. this.unschedule(this.AutoGetSeedsData)
  623. this.AutoGetSeedsData = null
  624. }
  625. this.AutoGetSeedsData = () => {
  626. // getSeedCount ++;
  627. GlobalD.GameData.onGetSeedState(
  628. {
  629. seedId: this.mySeedList[this.buySeedIndex].id,
  630. currentAmount: currentAmount, //把当前背包的数据传进去
  631. },
  632. (value) => {
  633. console.log('轮询种子:' + JSON.stringify(value))
  634. if (0 === value.code) {
  635. this.unschedule(this.AutoGetSeedsData)
  636. // console.log('轮询种子购买成功')
  637. GlobalD.GameData.showToast(
  638. cc.find('Canvas/UICamera'),
  639. '种子购买成功!',
  640. 1
  641. )
  642. //直接重新初始化一下列表,
  643. this.buildingViewScript.onUpdateList()
  644. }
  645. }
  646. )
  647. }
  648. this.schedule(this.AutoGetSeedsData, 5)
  649. } else {
  650. console.log(err)
  651. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), err, 2)
  652. }
  653. }
  654. )
  655. },
  656. PaySNB() {
  657. console.log('this.playAmount=', this.playAmount)
  658. console.log('priceSnb price=', this.mySeedList[this.buySeedIndex].priceSnb)
  659. console.log(
  660. 'this.playAmount price=',
  661. this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb)
  662. )
  663. console.log(
  664. '支付价格:' +
  665. this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb)
  666. )
  667. let playAmount =
  668. this.playAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb)
  669. if (0 === playAmount) {
  670. GlobalD.GameData.showToast(
  671. cc.find('Canvas/UICamera'),
  672. '请输入购买数量',
  673. 1
  674. )
  675. return
  676. }
  677. if (this.isPlaying) {
  678. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '购买过快!', 1)
  679. return
  680. }
  681. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '支付处理中...', 10)
  682. this.isPlaying = true
  683. GlobalD.GameData.onBuySeedsWithSNB(
  684. playAmount,
  685. this.mySeedList[this.buySeedIndex].id,
  686. (flag, value) => {
  687. // console.log("SNB购买后", value);
  688. this.isPlaying = false
  689. if (flag && 0 === value.code) {
  690. //todo 种子
  691. GlobalD.GameData.showToast(
  692. cc.find('Canvas/UICamera'),
  693. '种子购买成功!',
  694. 1
  695. )
  696. // this.PayCNTPopView.active = false;
  697. //重新获取一下snb,会自动更新到面板
  698. GlobalD.GameData.onGetUserSnb()
  699. //直接重新初始化一下列表,
  700. this.buildingViewScript.onUpdateList()
  701. //更新日志数据
  702. cc.find('GameNode/ManageDapp')
  703. .getComponent('ManageDapp')
  704. .onUpdateSnbList()
  705. } else {
  706. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 2)
  707. }
  708. }
  709. )
  710. },
  711. onTextChanged1: function (text, editbox, customEventData) {
  712. // 这里的 text 表示 修改完后的 EditBox 的文本内容
  713. // 这里 editbox 是一个 cc.EditBox 对象
  714. // 这里的 customEventData 参数就等于你之前设置的 "foobar"
  715. // this.playAmount = parseInt(text)
  716. var numberTemp = new RegExp('^[A-Za-z0-9]+$')
  717. if (numberTemp.test(text)) {
  718. if (Number(text) >= 1) {
  719. this.playAmount = Number(text)
  720. } else {
  721. this.playAmount = 0
  722. editbox.string = this.playAmount
  723. }
  724. } else {
  725. this.playAmount = 0
  726. editbox.string = this.playAmount
  727. // console.log('playAmount', this.snbAmount)
  728. }
  729. },
  730. // 假设这个回调是给 textChanged 事件的
  731. onTextChanged2: function (text, editbox, customEventData) {
  732. // 这里的 text 表示 修改完后的 EditBox 的文本内容
  733. // 这里 editbox 是一个 cc.EditBox 对象
  734. // 这里的 customEventData 参数就等于你之前设置的 "foobar"
  735. // this.snbAmount = parseInt(text);
  736. var numberTemp = new RegExp('^[A-Za-z0-9]+$')
  737. if (numberTemp.test(text)) {
  738. if (Number(text) >= 1) {
  739. this.snbAmount = Number(text)
  740. } else {
  741. this.snbAmount = 0
  742. editbox.string = this.snbAmount
  743. }
  744. } else {
  745. this.snbAmount = 0
  746. editbox.string = this.snbAmount
  747. console.log('请输入5的倍数', this.snbAmount)
  748. }
  749. },
  750. _updatePrice() {
  751. this.PayCNTPopViewNameLabel.string = this.mySeedList[this.buySeedIndex].name;
  752. //隐藏非植物的cnt购买按钮
  753. this.PayCNTPopViewCNTLabel.node.parent.active = 0 === this.mySeedList[this.buySeedIndex].mallType?true:false;
  754. this.PayCNTPopViewCNTLabel.string = this.mySeedList[this.buySeedIndex].priceCnt;
  755. this.PayCNTPopViewSNBLabel.string = this.mySeedList[this.buySeedIndex].priceSnb;
  756. this.PayCNTPopViewMutureDurLabel.string = this.mySeedList[this.buySeedIndex].maturity;
  757. this.PopViewSeed.spriteFrame = this.mySeedList[this.buySeedIndex].bgSpriteFrame;
  758. // switch (this.toggleInputValue) {
  759. // case '1':
  760. // this.PayCNTPopViewNameLabel.string =
  761. // this.mySeedList[this.buySeedIndex].name
  762. // this.PayCNTPopViewCNTLabel.string =
  763. // this.mySeedList[this.buySeedIndex].priceCnt + ' CNT'
  764. // this.PayCNTPopViewMutureDurLabel.string =
  765. // this.mySeedList[this.buySeedIndex].maturity
  766. // break
  767. // case '2':
  768. // this.PayCNTPopViewNameLabel.string =
  769. // this.mySeedList[this.buySeedIndex].name
  770. // this.PayCNTPopViewCNTLabel.string =
  771. // this.mySeedList[this.buySeedIndex].priceSnb + ' SNB'
  772. // this.PayCNTPopViewMutureDurLabel.string =
  773. // this.mySeedList[this.buySeedIndex].maturity
  774. // break
  775. // default:
  776. // console.error(
  777. // 'this.toggleInputValue 不是1 2 3!',
  778. // this.toggleInputValue
  779. // )
  780. // break
  781. // }
  782. },
  783. //根据状态吊起不同支付
  784. onSwitchPlayType() {
  785. switch (this.toggleInputValue) {
  786. case '1': //cnt 支付
  787. this.PayCNT()
  788. break
  789. case '2': //snb 支付
  790. this.PaySNB()
  791. break
  792. default:
  793. console.error('状态吊起错误', this.toggleInputValue)
  794. GlobalD.GameData.showToast(
  795. cc.find('Canvas/UICamera'),
  796. '请先选择支付方式',
  797. 1
  798. )
  799. break
  800. }
  801. },
  802. onToggleInput(value, evnentData) {
  803. this.toggleInputValue = evnentData
  804. this._updatePrice()
  805. },
  806. //购买装备
  807. onPayEquipPopView(myIndex) {
  808. this.buyEquipIndex = myIndex
  809. this.PayEquipPopView.active = true
  810. this.PayEquipPopView.getComponent("PayEquipPopView").setInfo(this.equipmentList[this.buyEquipIndex]);
  811. },
  812. PayEquipSNB() {
  813. console.log(
  814. '支付价格Snb:' + this.equipmentList[this.buyEquipIndex].priceSnb
  815. )
  816. if (this.isPlaying) {
  817. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '购买过快!', 1)
  818. return
  819. }
  820. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '支付处理中...', 10)
  821. this.isPlaying = true
  822. GlobalD.GameData.onGetAddEquipment(
  823. { mallOtherId: this.equipmentList[this.buyEquipIndex].id },
  824. (flag, value) => {
  825. console.log("SNB购买后", value);
  826. this.isPlaying = false
  827. if (flag && 0 === value.code) {
  828. let _equip = value.data.equip;
  829. //todo 装备
  830. GlobalD.GameData.showToast(
  831. cc.find('Canvas/UICamera'),
  832. '购买装备成功',
  833. 1
  834. )
  835. //重新获取一下snb,会自动更新到面板
  836. GlobalD.GameData.onGetUserSnb()
  837. if (0 === _equip.otherType) {
  838. GlobalD.Dog = _equip;
  839. this.ManageUI.getComponent('ManageUI').onSettingDogAlpha(255);
  840. //刷新狗状态
  841. let _dogContainerScript = cc.find("Canvas/DogContainer").getComponent("DogContainer")
  842. _dogContainerScript.onSetSelfDogState(_equip);
  843. } else if (1 === _equip.otherType) {
  844. GlobalD.Stick = _equip;
  845. this.ManageUI.getComponent('ManageUI').onSettingStickAlpha(255);
  846. }
  847. //更新日志数据
  848. cc.find('GameNode/ManageDapp')
  849. .getComponent('ManageDapp')
  850. .onUpdateSnbList()
  851. } else {
  852. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), value.msg, 2)
  853. }
  854. }
  855. )
  856. },
  857. //用cnt购买
  858. PayEquipCNT() {
  859. console.log(
  860. '支付价格Cnt:' + this.equipmentList[this.buyEquipIndex].priceCnt + ",购买类型:" + this.equipmentList[this.buyEquipIndex].otherType
  861. )
  862. if (!(this.equipmentList[this.buyEquipIndex].otherType == 2 || this.equipmentList[this.buyEquipIndex].otherType == 3)) return;
  863. if (this.isPlaying) {
  864. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '购买过快!', 1)
  865. return
  866. }
  867. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), '支付处理中...', 10)
  868. this.isPlaying = true
  869. let playAmount = this.equipmentList[this.buyEquipIndex].priceCnt
  870. if (0 === playAmount) {
  871. GlobalD.GameData.showToast(
  872. cc.find('Canvas/UICamera'),
  873. 'CNT不能为0!',
  874. 1
  875. )
  876. return
  877. }
  878. GlobalD.GameData.payCNT(
  879. playAmount,
  880. this.equipmentList[this.buyEquipIndex].otherType,// payType
  881. this.equipmentList[this.buyEquipIndex].id + '',
  882. (data) => {
  883. const [err, tx] = data
  884. this.isPlaying = false;
  885. if (err === null) {
  886. // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
  887. console.log(tx) // 交易hash,唯一标识符
  888. //todo 轮询装备
  889. if (this.AutoGetEquipsData) {
  890. this.unschedule(this.AutoGetEquipsData)
  891. this.AutoGetEquipsData = null
  892. }
  893. this.AutoGetEquipsData = () => {
  894. GlobalD.GameData.onGetDisasterProtected((value) => {
  895. if (0 === value.code) {
  896. // console.log('轮询购买防护包:' + JSON.stringify(value))
  897. let data = value.data;
  898. if (this.equipmentList[this.buyEquipIndex].otherType == 2) {
  899. if (GlobalD.NaturalPack == null) {
  900. if (data.naturalProtected != null) {
  901. this.unschedule(this.AutoGetEquipsData)
  902. GlobalD.GameData.showToast(
  903. cc.find('Canvas/UICamera'),
  904. '购买自然防护包成功!',
  905. 1
  906. )
  907. this.ManageUI.getComponent('ManageUI').onRunProtected(value);
  908. }
  909. } else if (!date.datesIsEqual(data.naturalProtected.protectTime, GlobalD.NaturalPack.protectTime)) {
  910. this.unschedule(this.AutoGetEquipsData)
  911. GlobalD.GameData.showToast(
  912. cc.find('Canvas/UICamera'),
  913. '增加自然防护包成功!',
  914. 1
  915. )
  916. this.ManageUI.getComponent('ManageUI').onRunProtected(value);
  917. }
  918. } else if (this.equipmentList[this.buyEquipIndex].otherType == 3) {
  919. if (GlobalD.BeastPack == null) {
  920. if (data.beastProtected != null) {
  921. this.unschedule(this.AutoGetEquipsData)
  922. GlobalD.GameData.showToast(
  923. cc.find('Canvas/UICamera'),
  924. '购买野兽防护包成功!',
  925. 1
  926. )
  927. this.ManageUI.getComponent('ManageUI').onRunProtected(value);
  928. }
  929. } else if (!date.datesIsEqual(data.beastProtected.protectTime, GlobalD.BeastPack.protectTime)) {
  930. this.unschedule(this.AutoGetEquipsData)
  931. //如果时间不相等,叠加时间成功
  932. GlobalD.GameData.showToast(
  933. cc.find('Canvas/UICamera'),
  934. '增加野兽防护包成功!',
  935. 1
  936. )
  937. this.ManageUI.getComponent('ManageUI').onRunProtected(value);
  938. }
  939. } else {
  940. this.unschedule(this.AutoGetEquipsData)
  941. }
  942. }
  943. })
  944. }
  945. this.schedule(this.AutoGetEquipsData, 5)
  946. } else {
  947. console.log(err)
  948. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), err, 2)
  949. }
  950. }
  951. )
  952. },
  953. onDestory() {
  954. if (this.AutoGetSeedsData) {
  955. this.unschedule(this.AutoGetSeedsData)
  956. this.AutoGetSeedsData = null
  957. }
  958. },
  959. //申请列表
  960. OpenApplyList() {
  961. this.applySnbView.active = true;
  962. }
  963. })