You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
387 lines
16 KiB
387 lines
16 KiB
|
|
import { ryw_Event } from "../../../FrameWork/Event/EventEnum";
|
|
import EventMgr from "../../../FrameWork/Event/EventMgr";
|
|
import GameReport from "../../../FrameWork/Report/ZyZyReport";
|
|
import User from "../../../FrameWork/User/User";
|
|
import AppPlatform from "../../../FrameWork/Util/AppPlatform";
|
|
import Common5 from "../../../Platform/th/Common5";
|
|
import TaskManager, { MainTaskIdEnum } from "../../JuQingChat/TaskManager";
|
|
import PrefabManage, { GameType } from "../../PrefabManager/PrefabManage";
|
|
import GameBase from "../../SCommon/GameBase";
|
|
import BuyStockBox from "./BuyStockBox"
|
|
import SaleStockBox from "./SaleStockBox"
|
|
import StockManager from "./StockManager";
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
enum StockMarketType {
|
|
StockMarket,
|
|
MyStocks,
|
|
TouTiao
|
|
}
|
|
enum StockRiskType {
|
|
LowRisk,
|
|
HighRisk
|
|
}
|
|
@ccclass
|
|
export default class Stock extends GameBase {
|
|
@property(cc.Node)
|
|
stockMarketNode: cc.Node = null
|
|
@property(cc.Node)
|
|
stockContent: cc.Node = null
|
|
@property(cc.Node)
|
|
stockItem: cc.Node = null
|
|
|
|
@property(cc.Node)
|
|
myStockNode: cc.Node = null
|
|
@property(cc.Node)
|
|
myStockContent: cc.Node = null
|
|
@property(cc.Node)
|
|
myStockItem: cc.Node = null
|
|
|
|
|
|
@property(cc.Node)
|
|
btn_buy: cc.Node = null
|
|
|
|
@property(cc.Prefab)
|
|
buyStockPrefab: cc.Prefab = null
|
|
@property(cc.Prefab)
|
|
saleStockPrefab: cc.Prefab = null
|
|
@property(cc.Prefab)
|
|
jinRongTouTiaoPrefab: cc.Prefab = null
|
|
|
|
@property(cc.Node)
|
|
btnADRefresh: cc.Node = null
|
|
|
|
@property(cc.Node)
|
|
btnRefresh: cc.Node = null
|
|
|
|
|
|
|
|
curStockRiskType: StockRiskType.HighRisk
|
|
curStockMarketType: StockMarketType.StockMarket
|
|
buyStockNode: cc.Node = null
|
|
saleStockNode: cc.Node = null
|
|
jinRongTouTiaoBox: cc.Node = null
|
|
|
|
|
|
onLoad() {
|
|
super.onLoad()
|
|
EventMgr.onEvent_custom(ryw_Event.updateStockView, () => {
|
|
this.setStockMarketContent(this.curStockRiskType)
|
|
this.setMyStockContent()
|
|
}, this)
|
|
}
|
|
|
|
onDestroy() {
|
|
super.onDestroy()
|
|
}
|
|
|
|
start() {
|
|
this.setStockMarketContent(StockRiskType.HighRisk)
|
|
this.showBtnRefresh()
|
|
}
|
|
showBtnRefresh() {
|
|
// let stockFreeNum = User.getStockFreeNum()
|
|
// if (stockFreeNum > 0) {
|
|
// this.btnADRefresh.active = false
|
|
// this.btnRefresh.active = true
|
|
// this.btnRefresh.getChildByName('str').getComponent(cc.Label).string = `刷新(${stockFreeNum}/4)`
|
|
// } else {
|
|
// this.btnADRefresh.active = true
|
|
// this.btnRefresh.active = false
|
|
// }
|
|
}
|
|
//初始化股票市场
|
|
setStockMarketContent(riskType) {
|
|
// console.log("初始化股票市场",riskType)
|
|
this.curStockRiskType = riskType
|
|
let riskStr = ""
|
|
if (riskType == StockRiskType.LowRisk) {
|
|
riskStr = "低"
|
|
this.reportKey(() => {
|
|
GameReport.BtnsReport('低风险')
|
|
})
|
|
} else if (riskType == StockRiskType.HighRisk) {
|
|
riskStr = "高"
|
|
|
|
this.reportKey(() => {
|
|
GameReport.BtnsReport('高风险')
|
|
})
|
|
}
|
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
|
let mainId = mainTaskInfo.Id
|
|
|
|
this.stockContent.removeAllChildren()
|
|
let stocksStorageConfig = User.getStocksData()
|
|
|
|
console.log(stocksStorageConfig, 'stocksStorageConfig++++')
|
|
for (var key in stocksStorageConfig) {
|
|
if (stocksStorageConfig[key].riskAttributes == riskStr) {
|
|
let childItem = cc.instantiate(this.stockItem)
|
|
if (key == '钱氏集团' && mainId == MainTaskIdEnum.MainTask_1106) {
|
|
childItem.getChildByName("感叹号").active = true
|
|
} else if (key == '傅氏医疗' && mainId == MainTaskIdEnum.MainTask_1404) {
|
|
childItem.getChildByName("感叹号").active = true
|
|
} else if (key == '傅氏股票' && mainId == MainTaskIdEnum.MainTask_1806) {
|
|
childItem.getChildByName("感叹号").active = true
|
|
} else if (key == '安氏集团' && mainId == MainTaskIdEnum.MainTask_2104) {
|
|
childItem.getChildByName("感叹号").active = true
|
|
// let singConfig = StockManager.getSingleCompanyConfig(stocksStorageConfig[key].stockName)
|
|
// stocksStorageConfig[key].curPrice = User.getMoney() / singConfig.stockSum
|
|
} else if (key == '龙氏集团' && mainId == MainTaskIdEnum.MainTask_2404) {
|
|
childItem.getChildByName("感叹号").active = true
|
|
// let singConfig = StockManager.getSingleCompanyConfig(stocksStorageConfig[key].stockName)
|
|
// stocksStorageConfig[key].curPrice = User.getMoney() / singConfig.stockSum
|
|
} else {
|
|
childItem.getChildByName("感叹号").active = false
|
|
}
|
|
childItem.getChildByName("stockName").getComponent(cc.Label).string = key
|
|
// childItem.getChildByName("price").getComponent(cc.Label).string = StockManager.handPrice(riskStr,stocksStorageConfig[key].curPrice)
|
|
childItem.getChildByName("price").getComponent(cc.Label).string = Common5.getNumberChangeHanzi(stocksStorageConfig[key].curPrice, '1', 1) + ""
|
|
childItem.getChildByName("rateOfRise").getComponent(cc.Label).string = stocksStorageConfig[key].curRate + "%"
|
|
//涨跌颜色区分
|
|
if (stocksStorageConfig[key].curRate < 0) {
|
|
childItem.getChildByName("stockName").color = new cc.Color().fromHEX("#1D8A89")
|
|
childItem.getChildByName("price").color = new cc.Color().fromHEX("#1D8A89")
|
|
childItem.getChildByName("rateOfRise").color = new cc.Color().fromHEX("#1D8A89")
|
|
} else {
|
|
childItem.getChildByName("stockName").color = new cc.Color().fromHEX("#FC4436")
|
|
childItem.getChildByName("price").color = new cc.Color().fromHEX("#FC4436")
|
|
childItem.getChildByName("rateOfRise").color = new cc.Color().fromHEX("#FC4436")
|
|
}
|
|
childItem.active = true
|
|
childItem.getChildByName("btn_buy").attr({ stockConfig: stocksStorageConfig[key] })
|
|
this.stockContent.addChild(childItem)
|
|
}
|
|
}
|
|
}
|
|
|
|
//股市-我的股票toggle
|
|
onSocketMarketTypeToggle(event, customData) {
|
|
// Common5.playEffect("CommonRes/sound/按键点击")
|
|
if (this.curStockMarketType == customData) {
|
|
return
|
|
}
|
|
this.changeMarketAndMyStock(customData)
|
|
}
|
|
//切换股市和我的股票
|
|
changeMarketAndMyStock(marketType) {
|
|
this.curStockMarketType = marketType
|
|
//股市
|
|
if (marketType == StockMarketType.StockMarket) {
|
|
// console.log("点击股市")
|
|
|
|
this.reportKey(() => {
|
|
GameReport.BtnsReport('股市')
|
|
})
|
|
this.stockMarketNode.active = true
|
|
this.myStockNode.active = false
|
|
|
|
// this.btn_buy.active = true
|
|
//我的股票
|
|
} else if (marketType == StockMarketType.MyStocks) {
|
|
// console.log("我的股票")
|
|
|
|
this.reportKey(() => {
|
|
GameReport.BtnsReport('我的股票')
|
|
})
|
|
this.stockMarketNode.active = false
|
|
this.myStockNode.active = true
|
|
|
|
// this.btn_buy.active = true
|
|
this.setMyStockContent()
|
|
//金融头条
|
|
} else if (marketType == StockMarketType.TouTiao) {
|
|
this.stockMarketNode.active = false
|
|
this.myStockNode.active = false
|
|
|
|
// this.btn_buy.active = false
|
|
}
|
|
}
|
|
//低风险-高风险toggle
|
|
onStockRiskTypeToggle(event, customData) {
|
|
// Common5.playEffect("CommonRes/sound/按键点击")
|
|
if (this.curStockRiskType == customData) {
|
|
return
|
|
}
|
|
this.setStockMarketContent(customData)
|
|
}
|
|
//初始化我的股票
|
|
setMyStockContent() {
|
|
this.myStockContent.removeAllChildren()
|
|
let stocksStorageConfig = User.getStocksData()
|
|
let myStockHistoryData = User.getMyStockData()
|
|
console.log("myStockHistoryData==", myStockHistoryData)
|
|
for (var key in myStockHistoryData) {
|
|
let singleStockData = stocksStorageConfig[key]
|
|
let nowPrice = singleStockData["curPrice"]
|
|
let buyPrice = myStockHistoryData[key].buyPrice
|
|
let riskAttributes = singleStockData["riskAttributes"]
|
|
let childItem = cc.instantiate(this.myStockItem)
|
|
if (riskAttributes == "高") {
|
|
childItem.getChildByName("icon_red").active = true
|
|
} else {
|
|
childItem.getChildByName("icon_green").active = true
|
|
}
|
|
|
|
let singConfig = StockManager.getSingleCompanyConfig(key)
|
|
|
|
|
|
childItem.getChildByName("stockName").getComponent(cc.Label).string = key
|
|
childItem.getChildByName("newPrice").getComponent(cc.Label).string = Common5.getNumberChangeHanzi(nowPrice, '1', 1) + ""
|
|
childItem.getChildByName("rateOfRise").getComponent(cc.Label).string = ((nowPrice / buyPrice - 1) * 100).toFixed(1) + "%"
|
|
childItem.getChildByName("buyPrice").getComponent(cc.Label).string = Common5.getNumberChangeHanzi(myStockHistoryData[key].buyPrice, '1', 1) + ""
|
|
|
|
|
|
let numindex = (myStockHistoryData[key].prossess / singConfig.stockSum) * 100
|
|
|
|
let baoliuNum = numindex.toFixed(2).slice(0, -1)
|
|
|
|
// if(numindex>1 && numindex<10){
|
|
// baoliuNum = numindex.toFixed(2).slice(0, -1)
|
|
// }else if(numindex>10 && numindex<100){
|
|
// baoliuNum = Math.floor(numindex)
|
|
// }else{
|
|
// baoliuNum = 100
|
|
// }
|
|
//console.log('(myStockHistoryData[key].prossess/singConfig.stockSum)*100',baoliuNum)
|
|
childItem.getChildByName("possess").getComponent(cc.Label).string = baoliuNum + '%'//myStockHistoryData[key].prossess//(myStockHistoryData[key].prossess/singConfig.stockSum)*100 + '%'
|
|
|
|
|
|
childItem.getChildByName("btn_buy").attr({ stockConfig: stocksStorageConfig[key] })
|
|
childItem.getChildByName("btn_sell").attr({ stockConfig: stocksStorageConfig[key] })
|
|
childItem.active = true
|
|
if (nowPrice >= buyPrice) {
|
|
childItem.getChildByName("stockName").color = new cc.Color().fromHEX("#FC4436")
|
|
childItem.getChildByName("newPrice").color = new cc.Color().fromHEX("#FC4436")
|
|
childItem.getChildByName("rateOfRise").color = new cc.Color().fromHEX("#FC4436")
|
|
childItem.getChildByName("buyPrice").color = new cc.Color().fromHEX("#FC4436")
|
|
childItem.getChildByName("possess").color = new cc.Color().fromHEX("#FC4436")
|
|
} else {
|
|
childItem.getChildByName("stockName").color = new cc.Color().fromHEX("#1D8A89")
|
|
childItem.getChildByName("newPrice").color = new cc.Color().fromHEX("#1D8A89")
|
|
childItem.getChildByName("rateOfRise").color = new cc.Color().fromHEX("#1D8A89")
|
|
childItem.getChildByName("buyPrice").color = new cc.Color().fromHEX("#1D8A89")
|
|
childItem.getChildByName("possess").color = new cc.Color().fromHEX("#1D8A89")
|
|
}
|
|
this.myStockContent.addChild(childItem)
|
|
}
|
|
}
|
|
//买入
|
|
onBtnBuy(event) {
|
|
// Common5.playEffect("CommonRes/sound/按键点击")
|
|
|
|
this.reportKey(() => {
|
|
GameReport.BtnsReport('买入点击')
|
|
})
|
|
if (this.buyStockNode) {
|
|
this.buyStockNode.removeFromParent()
|
|
}
|
|
this.buyStockNode = cc.instantiate(this.buyStockPrefab)
|
|
this.node.addChild(this.buyStockNode)
|
|
this.buyStockNode.getComponent(BuyStockBox).initBoxContent(event.target.stockConfig)
|
|
}
|
|
//卖出
|
|
onBtnSell(event) {
|
|
let config = event.target.stockConfig
|
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
|
let mainId = mainTaskInfo.Id
|
|
if (mainId > MainTaskIdEnum.MainTask_1106 && config.stockName == '钱氏集团') {
|
|
PrefabManage.showTextTips('钱氏集团不能卖出')
|
|
return
|
|
} else if (mainId > MainTaskIdEnum.MainTask_1404 && config.stockName == '傅氏医疗') {
|
|
PrefabManage.showTextTips('傅氏医疗不能卖出')
|
|
return
|
|
} else if (mainId > MainTaskIdEnum.MainTask_1806 && config.stockName == '傅氏股票') {
|
|
PrefabManage.showTextTips('傅氏股票不能卖出')
|
|
return
|
|
} else if (mainId > MainTaskIdEnum.MainTask_2104 && config.stockName == '安氏集团') {
|
|
PrefabManage.showTextTips('安氏集团不能卖出')
|
|
return
|
|
} else if (mainId > MainTaskIdEnum.MainTask_2404 && config.stockName == '龙氏集团') {
|
|
PrefabManage.showTextTips('龙氏集团不能卖出')
|
|
return
|
|
}
|
|
|
|
this.reportKey(() => {
|
|
GameReport.BtnsReport('卖出点击')
|
|
})
|
|
// Common5.playEffect("CommonRes/sound/按键点击")
|
|
if (this.saleStockNode) {
|
|
this.saleStockNode.removeFromParent()
|
|
}
|
|
this.saleStockNode = cc.instantiate(this.saleStockPrefab)
|
|
this.node.addChild(this.saleStockNode)
|
|
this.saleStockNode.getComponent(SaleStockBox).initBoxContent(config)
|
|
}
|
|
//刷新
|
|
onBtnADRefresh() {
|
|
// Common5.playEffect("CommonRes/sound/按键点击")
|
|
|
|
let tab = {
|
|
onClose: (finish) => {
|
|
if (finish) {
|
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
|
let mainId = mainTaskInfo.Id
|
|
Common5.ReportDY("inLevel", `任务${mainId}-AD-股票市场获取次数`);
|
|
|
|
// this.reportKey(()=>{
|
|
// GameReport.ADReport('证券中心股票刷新',1)
|
|
// })
|
|
User.setStockFreeNum(4)
|
|
// this.showBtnRefresh()
|
|
StockManager.refreshAllStocksData(User.getDay() + 1, true)
|
|
}
|
|
else {
|
|
// this.reportKey(()=>{
|
|
// GameReport.ADReport('证券中心股票刷新',0)
|
|
// })
|
|
Common5.showTips_custom("广告未观看完");
|
|
}
|
|
}, onFailed: () => {
|
|
|
|
}
|
|
}
|
|
AppPlatform.playVideo_custom(tab)
|
|
|
|
}
|
|
onBtnRefresh() {
|
|
User.setStockFreeNum(User.getStockFreeNum() - 1)
|
|
this.showBtnRefresh()
|
|
StockManager.refreshAllStocksData(User.getDay() + 1, true)
|
|
}
|
|
//查阅
|
|
onBtnView(event) {
|
|
// Common5.playEffect("CommonRes/sound/按键点击")
|
|
|
|
let tab = {
|
|
onClose: (finish) => {
|
|
if (finish) {
|
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
|
let mainId = mainTaskInfo.Id
|
|
Common5.ReportDY("inLevel", `任务${mainId}-AD-股票市场查阅`);
|
|
|
|
if (this.jinRongTouTiaoBox) {
|
|
this.jinRongTouTiaoBox.removeFromParent()
|
|
}
|
|
this.jinRongTouTiaoBox = cc.instantiate(this.jinRongTouTiaoPrefab)
|
|
this.node.addChild(this.jinRongTouTiaoBox)
|
|
// this.jinRongTouTiaoBox.getComponent(JinRongTouTiaoBox).initBoxContent()
|
|
}
|
|
else {
|
|
this.reportKey(() => {
|
|
GameReport.ADReport('证券中心查阅', 0)
|
|
})
|
|
Common5.showTips_custom("广告未观看完");
|
|
}
|
|
}, onFailed: () => {
|
|
|
|
}
|
|
}
|
|
AppPlatform.playVideo_custom(tab)
|
|
|
|
}
|
|
onBtnClichCaoPan() {
|
|
PrefabManage.loadPrefabByType(GameType.CaiShangLevel1)
|
|
}
|
|
}
|
|
|