StoreView.js 23 KB

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