StoreView.js 23 KB

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