"use strict";
|
cc._RF.push(module, '68669Ad5XpC4Lw+4ffTXOFr', 'sureveyquest_window');
|
// Scripts/mod/welfare/view/sureveyquest_window.js
|
|
"use strict";
|
|
// --------------------------------------------------------------------
|
// @author: xxx@syg.com(必填, 创建模块的人员)
|
// @description:
|
// 这里是描述这个窗体的作用的
|
// <br/>Create: 2019-08-12 15:43:29
|
// --------------------------------------------------------------------
|
var PathTool = require("pathtool");
|
|
var WelfareEvent = require("welfare_event");
|
|
var WelfareConst = require("welfare_const");
|
|
var SureveyquestWindow = cc.Class({
|
"extends": BaseView,
|
ctor: function ctor() {
|
this.prefabPath = PathTool.getPrefabPath("welfare", "surveyquest_window");
|
this.viewTag = SCENE_TAG.dialogue; //该窗体所属ui层级,全屏ui需要在ui层,非全屏ui在dialogue层,这个要注意
|
|
this.win_type = WinType.Big; //是否是全屏窗体 WinType.Full, WinType.Big, WinType.Mini, WinType.Tips
|
|
this.ctrl = arguments[0];
|
},
|
// 初始化一些配置数据,可以用于声明一些变量之类的
|
initConfig: function initConfig() {
|
this.topic_length = 10; //题目数
|
|
this.index_count = -1; //做题数量
|
|
this.answer_ret_temp = null;
|
this.topic_layout = {}; //点击区域
|
|
this.answer_list = []; //答案
|
},
|
// 预制体加载完成之后的回调,可以在这里捕获相关节点或者组件
|
openCallBack: function openCallBack() {
|
this.background = this.root_wnd.getChildByName("background");
|
this.main_container = this.root_wnd.getChildByName("main_container");
|
this.btn_start = this.main_container.getChildByName("btn_start");
|
this.btn_start.label = this.btn_start.getChildByName("Text_9").getComponent(cc.Label);
|
this.btn_close = this.main_container.getChildByName("btn_close");
|
this.answer_content = this.main_container.getChildByName("answer_content");
|
this.answer_content.active = false;
|
this.titleTopic = this.main_container.getChildByName("titleTopic").getComponent(cc.Label);
|
this.topic_layout_nd = this.answer_content.getChildByName("topic_layout");
|
this.scroll = this.answer_content.getChildByName("answer_scroll");
|
this.content = this.answer_content.getChildByName("answer_scroll").getChildByName("content");
|
this.main_container.getChildByName("Text_10").getComponent(cc.Label).string = Utils.TI18N("小助手的冒险调查"); // --调查开始的框
|
|
this.text_prompt = this.main_container.getChildByName("text_prompt");
|
this.start_title = this.text_prompt.getChildByName("Text_8").getComponent(cc.Label);
|
this.start_title.string = "";
|
this.start_memo = this.text_prompt.getChildByName("Text_8_0").getComponent(cc.Label);
|
this.start_memo.string = ""; // --填空框
|
|
this.suggest_panel = this.main_container.getChildByName("suggest_panel");
|
this.text_field_eb = this.suggest_panel.getChildByName("text_Field").getComponent(cc.EditBox);
|
this.suggest_panel.active = false; // --奖励框
|
|
this.reward_panel = this.main_container.getChildByName("reward_panel");
|
this.reward_panel.active = false;
|
},
|
// 注册事件监听的接口,不需要手动调用,如果是使用gcore.GlobalEvent监听,可以直接调用addGlobalEvent
|
registerEvent: function registerEvent() {
|
this.btn_start.on('click', function () {
|
Utils.playButtonSound(1);
|
var open_data = this.ctrl.getModel().getQuestOpenData();
|
|
if (open_data && open_data.flag != 0) {
|
this.ctrl.sender24604();
|
return;
|
}
|
|
if (this.index_count > this.topic_length) return;
|
|
if (this.questNaire_list) {
|
var last_data = this.questNaire_list[this.index_count]; //有题目
|
|
var tab = {};
|
tab.id = last_data.id;
|
tab.topic_type = last_data.topic_type;
|
|
if (last_data.specific_type != WelfareConst.QuestConst.fill_blank) {
|
var status_return = false;
|
|
for (var i in this.topic_layout) {
|
if (this.topic_layout[i].active && this.topic_layout[i].getChildByName("checkmark").active) {
|
status_return = true;
|
break;
|
}
|
}
|
|
if (!status_return && last_data.must == 1) {
|
message(Utils.TI18N("必须选择一个答案"));
|
return;
|
} // [{id:"题目ID",topic_type:"类型",ret:"ret"},{id:"题目ID",topic_type:"类型",ret:"ret"},{id:"题目ID",topic_type:"类型",ret:"ret"}]
|
|
|
var str = "";
|
|
for (var _i in this.topic_layout) {
|
if (this.topic_layout[_i].active && this.topic_layout[_i].getChildByName("checkmark").active) {
|
str += _i;
|
}
|
}
|
|
tab.ret = str;
|
} else {
|
//意见
|
if (last_data.must == 1 && this.text_field_eb.string == "") {
|
message(Utils.TI18N("当前题必填"));
|
return;
|
}
|
|
tab.ret = this.text_field_eb.string;
|
}
|
|
this.answer_list.push(tab);
|
}
|
|
this.index_count = this.index_count + 1;
|
|
if (this.index_count == 0) {
|
this.ctrl.sender24602();
|
}
|
|
if (this.questNaire_list) {
|
if (this.index_count == this.questNaire_list.length) {
|
this.ctrl.sender24603(this.answer_list);
|
} else {
|
this.startTopicAnswer(this.questNaire_list);
|
}
|
}
|
}, this);
|
this.btn_close.on('click', function () {
|
Utils.playButtonSound(2);
|
this.ctrl.openSureveyQuestView(false);
|
}, this);
|
this.addGlobalEvent(WelfareEvent.Get_SureveyQuest_Basic, function (data) {
|
if (!data || Utils.next(data) == null) return;
|
var open = this.ctrl.getModel().getQuestOpenData();
|
|
if (open && open.status == 0) {
|
return;
|
}
|
|
this.answer_reward_list = data.rewards;
|
var open_data = this.ctrl.getModel().getQuestOpenData();
|
|
if (open_data) {
|
if (open_data.flag == 0) {
|
this.start_title.string = Utils.TI18N("亲爱的冒险者大人:");
|
this.start_memo.string = Utils.TI18N("辛苦您参加小助手的冒险调查,小助手为大人\n\n准备了小小谢礼,放在了问卷的最后哦~");
|
} else {
|
this.getRewardList(open_data.flag);
|
}
|
}
|
}.bind(this));
|
this.addGlobalEvent(WelfareEvent.Get_SureveyQuest_Topic_Content, function (data) {
|
if (!data || Utils.next(data) == null) return;
|
var open = this.ctrl.getModel().getQuestOpenData();
|
|
if (open && open.status == 0) {
|
return;
|
}
|
|
this.topic_length = data.questionnaire_list.length;
|
data.questionnaire_list.sort(function (a, b) {
|
return a.sort - b.sort;
|
});
|
this.questNaire_list = data.questionnaire_list;
|
this.startTopicAnswer(this.questNaire_list);
|
}.bind(this));
|
this.addGlobalEvent(WelfareEvent.SureveyQuest_Submit, function () {
|
this.answer_content.active = false;
|
this.suggest_panel.active = false;
|
this.titleTopic.node.active = false;
|
this.getRewardList();
|
}, this);
|
this.addGlobalEvent(WelfareEvent.Get_SureveyQuest_Get_Reward, function (data) {
|
if (!data || Utils.next(data) == null) return;
|
var open = this.ctrl.getModel().getQuestOpenData();
|
|
if (open && open.status == 0) {
|
return;
|
}
|
|
this.btn_start.label.string = Utils.TI18N("已完成");
|
this.btn_start.label.node.getComponent(cc.LabelOutline).enabled = false;
|
this.btn_start.getComponent(cc.Button).interactable = false;
|
this.btn_start.getComponent(cc.Button).enableAutoGrayEffect = true;
|
}, this);
|
},
|
// 预制体加载完成之后,添加到对应主节点之后的回调,也就是一个窗体的正式入口,可以设置一些数据了
|
openRootWnd: function openRootWnd(params) {
|
var open_data = this.ctrl.getModel().getQuestOpenData();
|
|
if (open_data.flag == 1) {
|
this.ctrl.setWelfareStatus(WelfareConst.WelfareIcon.quest, true);
|
} else {
|
this.ctrl.setWelfareStatus(WelfareConst.WelfareIcon.quest, false);
|
}
|
|
this.ctrl.sender24601();
|
},
|
//题目
|
startTopicAnswer: function startTopicAnswer(data) {
|
var _this = this;
|
|
this.scroll.getComponent(cc.ScrollView).scrollToTop(0);
|
this.text_prompt.active = false;
|
if (!data || Utils.next(data) == null) return;
|
|
if (!data[this.index_count]) {
|
return;
|
}
|
|
var answer = data[this.index_count].specific_type;
|
|
if (answer == WelfareConst.QuestConst.single) {
|
this.selectNum = WelfareConst.QuestConst.single;
|
} else if (answer == WelfareConst.QuestConst.multiple) {
|
this.selectNum = WelfareConst.QuestConst.multiple;
|
}
|
|
this.titleTopic.string = data[this.index_count].title;
|
|
if (answer == WelfareConst.QuestConst.fill_blank) {
|
this.answer_content.active = false;
|
this.suggest_panel.active = true;
|
this.text_field_eb.string = "";
|
return;
|
} else {
|
this.answer_content.active = true;
|
this.suggest_panel.active = false;
|
}
|
|
var str = data[this.index_count].option.replace(/\\r/g, "");
|
var strArr = [];
|
|
for (var i = 0; i < str.length; ++i) {
|
if (str[i] == '"') {
|
strArr.push(i);
|
}
|
}
|
|
var topic = {};
|
|
for (var _i2 = 0; _i2 < strArr.length / 4; ++_i2) {
|
var index = _i2 * 4;
|
var p = /[a-z]/i;
|
var string = str.slice(strArr[index] + 1, strArr[index + 1]);
|
var string1 = str.slice(strArr[index + 2] + 1, strArr[index + 3]);
|
var b = p.test(string);
|
|
if (b) {
|
topic[string] = string1;
|
}
|
}
|
|
for (var _i3 in this.topic_layout) {
|
if (this.topic_layout[_i3]) {
|
this.topic_layout[_i3].active = false;
|
this.topic_layout[_i3].getChildByName("checkmark").active = false;
|
}
|
}
|
|
var spacingY = 30;
|
var count = 0;
|
var itemHeight = 40;
|
var height = 5;
|
|
var _loop = function _loop(_i4) {
|
var node = _this.topic_layout[_i4];
|
|
if (node == null) {
|
node = cc.instantiate(_this.topic_layout_nd);
|
|
_this.content.addChild(node);
|
|
node.background_sp = node.getChildByName("Background").getComponent(cc.Sprite);
|
node.label = node.getChildByName("Background").getChildByName("label").getComponent("cc.Label");
|
node.getChildByName("checkmark").active = false;
|
_this.topic_layout[_i4] = node;
|
node.on('touchend', function (event) {
|
this.setButtonState(_i4);
|
}, _this);
|
}
|
|
node.active = true;
|
count++;
|
var path = void 0;
|
|
if (answer == WelfareConst.QuestConst.single) {
|
path = PathTool.getUIIconPath("common", "common_1030");
|
} else {
|
path = PathTool.getUIIconPath("common", "common_1044");
|
}
|
|
node.label.string = topic[_i4];
|
|
node.label._updateRenderData(true);
|
|
40 + 30 * (2 - 1);
|
var y = height;
|
|
if (node.label.node.height > itemHeight) {
|
height = y + node.label.node.height + spacingY;
|
} else {
|
height = y + itemHeight + spacingY;
|
}
|
|
node.setPosition(-243, -y);
|
|
_this.loadRes(path, function (res) {
|
node.background_sp.spriteFrame = res;
|
}.bind(_this));
|
};
|
|
for (var _i4 in topic) {
|
_loop(_i4);
|
}
|
|
this.content.height = height - spacingY;
|
|
if (this.index_count != this.topic_length) {
|
this.btn_start.label.string = Utils.TI18N("下一页");
|
}
|
},
|
setButtonState: function setButtonState(index) {
|
if (this.selectNum == WelfareConst.QuestConst.single) {
|
for (var i in this.topic_layout) {
|
if (this.topic_layout[i].active) {
|
this.topic_layout[i].getChildByName("checkmark").active = false;
|
}
|
}
|
|
this.topic_layout[index].getChildByName("checkmark").active = true;
|
} else if (this.selectNum == WelfareConst.QuestConst.multiple) {
|
this.topic_layout[index].getChildByName("checkmark").active = !this.topic_layout[index].getChildByName("checkmark").active;
|
var count = 0;
|
|
for (var _i5 in this.topic_layout) {
|
if (this.topic_layout[_i5].active && this.topic_layout[_i5].getChildByName("checkmark").active) {
|
count++;
|
}
|
}
|
|
if (count > this.selectNum) {
|
if (count == this.selectNum + 1) {
|
this.topic_layout[index].getChildByName("checkmark").active = false;
|
}
|
|
message(Utils.TI18N("最多选择三个选项"));
|
}
|
}
|
},
|
getRewardList: function getRewardList(flag) {
|
flag = flag || 1;
|
this.reward_panel.active = true;
|
this.end_memo = this.reward_panel.getChildByName("Text_1").getComponent(cc.Label);
|
this.end_memo.string = Utils.TI18N("亲爱的冒险者大人~\n\n请收下小助手的一点心意");
|
|
if (flag == 2) {
|
this.btn_start.label.string = Utils.TI18N("已完成");
|
this.btn_start.label.node.getComponent(cc.LabelOutline).enabled = false;
|
this.btn_start.getComponent(cc.Button).interactable = false;
|
this.btn_start.getComponent(cc.Button).enableAutoGrayEffect = true;
|
} else {
|
this.btn_start.label.string = Utils.TI18N("领取奖励");
|
}
|
|
if (this.answer_reward_list) {
|
var content = this.reward_panel.getChildByName("good_cons").getChildByName("content");
|
var space_x = 10;
|
this.award_item = [];
|
|
for (var i = 0; i < this.answer_reward_list.length; ++i) {
|
var bid = this.answer_reward_list[i].bid;
|
var num = this.answer_reward_list[i].num;
|
var item = ItemsPool.getInstance().getItem("backpack_item");
|
item.setParent(content);
|
var x = 60 + i * 120 + i * space_x;
|
item.setPosition(x, 60);
|
item.show();
|
item.setData({
|
bid: bid,
|
num: num
|
});
|
this.award_item.push(item);
|
}
|
|
content.width = this.answer_reward_list.length * 120 + (this.answer_reward_list.length - 1) * space_x;
|
}
|
},
|
// 关闭窗体回调,需要在这里调用该窗体所属controller的close方法没用于置空该窗体实例对象
|
closeCallBack: function closeCallBack() {
|
if (this.award_item) {
|
for (var i = 0; i < this.award_item.length; ++i) {
|
if (this.award_item[i]) {
|
this.award_item[i].deleteMe();
|
this.award_item[i] = null;
|
}
|
}
|
|
this.award_item = null;
|
}
|
|
this.ctrl.openSureveyQuestView(false);
|
}
|
});
|
|
cc._RF.pop();
|