StoreView.js 22 KB

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