| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- /**
- * 回访试题 增加或编辑
- * */
- $(function() {
- autosize($('textarea'));
- var lid = helper.request.queryString("lid");
- var edit_id = helper.request.queryString("edit_id");
- getQCategoryAlllist()
- .then(function() {
- if(lid != "undefined") {
- $('#pro_classify').val(lid);
- }
- if(edit_id) { //修改
- getProject(edit_id);
- }
- });
- //添加编辑保存按钮点击
- $('#pro_save').on('click', saveProject);
- });
- //获取单个项目
- function getProject(ids) {
- $.getJSON(huayi.config.callcenter_url + "QuestionAnswer/GetInfo", {
- id: ids,
- token: $.cookie("token")
- }, function(data) {
- if(data.state == "success") {
- var res = data.data;
- if(res) {
- $('#pro_title').val(res.Title); // 是 string 名称
- $('#pro_classify').val(res.ParendId); // 是 int 父级id
- $('#pro_score').val(res.Score); // 是 int 分数
- $('#pro_sort').val(res.OrderBy); // 是 int 排序
- $('#pro_remark').val(res.Remark); // 是 string 备注
- }
- }
- });
- }
- //保存项目
- function saveProject() {
- var edit_id = helper.request.queryString("edit_id");
- var wUrl;
- if(!$.trim($('#pro_classify').val())) {
- layer.confirm('试题分类不能为空', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if(!$.trim($('#pro_title').val())) {
- layer.confirm('试题名称不能为空', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if(!regexs.nums.test($.trim($('#pro_score').val()))) {
- layer.confirm('分数只能输入0或正整数', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if(!regexs.phoneNum.test($.trim($('#pro_sort').val()))) {
- layer.confirm('排序只能输入正整数', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if(edit_id) {
- wURL = "QuestionAnswer/Update";
- } else {
- wURL = "QuestionAnswer/Add";
- }
- $.post(huayi.config.callcenter_url + wURL, {
- Id: edit_id, // 是 string id
- Title: $('#pro_title').val(), // 是 string 名称
- ParendId: $('#pro_classify').val(), // 是 int 父级id
- Score: $('#pro_score').val(), // 是 int 分数
- OrderBy: $('#pro_sort').val(), // 是 int 排序
- Remark: $('#pro_remark').val(), // 是 string 备注
- token: $.cookie("token")
- }, function(data) {
- data = JSON.parse(data);
- if(data.state == "success") {
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- parent.$('#tbr').bootstrapTable('refresh');
- parent.layer.msg("保存成功");
- }
- });
- }
- //获取试题分类
- function getQCategoryAlllist() {
- var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
- $.ajax({
- type: "get",
- url: huayi.config.callcenter_url + "QuestionAnswer/GetList",
- dataType: 'json',
- async: true,
- data: {
- // title 是 string 名称
- // parentid 是 int 父级id
- // page 是 int 当前页
- // pagesize 是 int 每页数
- token: $.cookie("token")
- },
- success: function(data) {
- /*验证请求*/
- if(data.state == "success") {
- data = data.rows;
- if(data && data.length > 0) {
- for(var i = 0; i < data.length; i++) {
- $('<option value="' + data[i].Id + '">' + data[i].Title + '</option>').appendTo("#pro_classify");
- }
- }
- dtd.resolve(); // 改变Deferred对象的执行状态
- }
- }
- });
- return dtd.promise(); // 返回promise对象
- }
|