"use strict"; cc._RF.push(module, 'b944dF1oGVDj42KYzgNrY2F', 'cmp.dispatch.item'); // Scripts/mod/home/dispatch/cmps/cmp.dispatch.item.js "use strict"; /****************************************************************** * * 派遣任务项 * ******************************************************************/ var SVCItem = require("nx.fx.sv.expand.item"); var ItemBase = require("cmp.item.base"); var DispatchConst = require("dispatch.const"); var DispatchMod = require("dispatch.mod"); // 订单状态 var DSOS = DispatchConst.Order_Status; cc.Class({ "extends": SVCItem, properties: { nodQA: { "default": null, type: cc.Node }, nodDesc: { "default": null, type: cc.Node }, nodCost: { "default": null, type: cc.Node }, nodOps: { "default": null, type: cc.Node }, icoReward: { "default": null, type: ItemBase } }, // 数据重置 rebind: function rebind(_idx, _data, _key) { this.unscheduleAllCallbacks(); // 订单监听解除 if (this.mdata && this.binder) { this.mdata.unbind(this.binder); this.binder = null; } this._super(_idx, _data, _key); if (nx.dt.objEmpty(_data)) { return; } // 刷新 this.freshBase(); this.freshStatus(); // 订单监听 this.binder = this.mdata.bind(DispatchConst.UpdateOrder, this.freshStatus.bind(this)); }, // 隐藏 onDisable: function onDisable() { // 订单监听解除 if (this.mdata && this.binder) { this.mdata.unbind(this.binder); this.binder = null; } }, // 刷新基本信息 freshBase: function freshBase() { var cfgs = this.mdata.config; // 名字 var key = nx.text.getKey(cfgs.name); nx.gui.setString(this.nodDesc, "", key); // 底板 var path = cc.path.join("prefab/home/dispatch/ui", "bg" + cfgs.quality); nx.gui.setSpriteFrame(this, "bg", path); // 图标底 path = cc.path.join("prefab/home/dispatch/ui", "box" + cfgs.quality); nx.gui.setSpriteFrame(this.nodQA, "", path); // 图标 path = cc.path.join("prefab/home/dispatch/ui", "qa" + cfgs.quality); nx.gui.setSpriteFrame(this.nodQA, "icon", path); // 奖励 var item = cfgs.award[0]; this.icoReward.setData(item); // 消耗 var cost = cfgs.expend[0]; var info = gitemdata(cost[0]); nx.bridge.setIconS(this.nodCost, "icon", info.icon); nx.gui.setString(this.nodCost, "txt", cost[1]); }, // 刷新状态 freshStatus: function freshStatus() { // 操作隐藏 nx.gui.hideAllChildren(this.nodOps, ""); this.unscheduleAllCallbacks(); switch (this.mdata.status) { // 已完成 case DSOS.Finish: { nx.gui.setActive(this.nodOps, "get", true); } break; // 进行中 case DSOS.Underway: { var btn = nx.gui.setActive(this.nodOps, "quick", true); // 剩余时间 this.left_time = this.mdata.end_time - client.socket.getTime(); if (this.left_time < 0) { this.left_time = 0; } var self = this; var tick = function tick() { var txt = ""; if (self.left_time > 0) { txt = nx.bridge.time.cdSeconds(self.left_time); self.left_time -= 1; } nx.gui.setString(btn, "cd", txt); }; this.schedule(tick, 1, cc.macro.REPEAT_FOREVER); tick(); // 花费 var DM = DispatchMod.getInstance().getModel(); var need = DM.getQuickFinishNeedGoldByTime(this.left_time); nx.bridge.setIconS(btn, "btn/cost/icon", gitemdata(3).icon); nx.gui.setString(btn, "btn/cost/txt", need); } break; // 未截取 default: { nx.gui.setActive(this.nodOps, "dispatch", true); } break; } }, // 点击派遣 onTouchDispatch: function onTouchDispatch() { nx.bridge.createPanel("WndDispatchPartnerSelector", this.mdata); }, // 点击领取 onTouchReward: function onTouchReward() { var DC = DispatchMod.getInstance(); DC.requestFinishOrder(this.mdata.order_id, 0, function (_ret, _data) { if (!_ret) { nx.tbox(_data); return; } }); }, // 点击快速完成 onTouchQuickDone: function onTouchQuickDone() { var DC = DispatchMod.getInstance(); DC.requestFinishOrder(this.mdata.order_id, 1, function (_ret, _data) { if (!_ret) { nx.tbox(_data); return; } }); } }); cc._RF.pop();