StoreView.js 28 KB

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