var GRAYLAYER = {
  create: function (className) {
    var _grayLayer = document.createElement("div");
    _grayLayer.className = className;
    _grayLayer.style.cssText = "display:block;position: absolute;top: 0px;left: 0px;background: #000;opacity: 0.3;filter: alpha(opacity=50);z-index: 999;";
    _grayLayer.style.width = $(document).width() + 'px';
    _grayLayer.style.height = $(document).height() + 'px';
    document.body.appendChild(_grayLayer);
    //         this.resize(className);  
    setTimeout("GRAYLAYER.del('grayLayer-div');", 20000);
  },
  del: function (className) {
    $("." + className).remove();
  },
  resize: function (className) {
    //         $(window).resize(function() {  
    //             $("." + className).css({  
    //                 "width" : $(document).width(),  
    //                 "height" : $(document).height()  
    //             });  
    //         });  
  }
};

var taskMsgForms = {};
var curTaskMsgInput = null;

/**
 * 弹出窗口类
 */
function TaskMsgDialog() {
  this.curDialogCallBack = null; //当前弹出窗口的回调函数

  /**
   * 显示弹出窗口
   * @param  {[type]} title      [description]
   * @param  {[type]} content    [description]
   * @param  {[type]} height     [description]
   * @param  {[type]} showOkButton [description]
   * @param  {[type]} afterShow  [description]
   * @param  {[type]} clickOk    [description]
   * @return {[type]}            [description]
   */
  this.showScreenDialog = function (title, content, height, showOkButton, afterShow, clickOk) {
    this.curDialogCallBack = clickOk;
    tmClient.disableTitleButton();
    $(".TaskMsgForm").hide();

    $("body").append("<div class=\"TaskMsgMaskDiv\"></div>");
    $("body").append("<div class=\"TaskMsgScreenDialog\"></div>");
    $(".TaskMsgScreenDialog").css("top", "30%");
    $(".TaskMsgScreenDialog").css("width", "80%");
    $(".TaskMsgScreenDialog").css("height", height);
    $(".TaskMsgScreenDialog").append("<div class=\"TaskMsgScreenDialogHeader\">" + title + "</div>");
    $(".TaskMsgScreenDialog").append("<div class=\"TaskMsgScreenDialogBody\">" + content + "</div>");
    $(".TaskMsgScreenDialog").append("<div class=\"TaskMsgScreenDialogFooter\"></div>");

    var str = "";
    if (showOkButton) {
      str += "<span class=\"tmdfb cancelButton\">取消</span>" +
        "<span class=\"tmdfb okButton\">确定</span>";
    } else {
      str += "<span class=\"tmdfb cancelButton\">取消</span>";
    }
    $(".TaskMsgScreenDialogFooter").append(str);
    $(".TaskMsgScreenDialogFooter").find(".tmdfb").each(function () {
      if ($(this).html() == "确定") {
        $(this).bind("click", function () {
          if (!clickOk) {
            alert("未提供点击确定后的回调函数！");
            return;
          }
          tmClient.enableTitleButton();
          clickOk();
          event.stopPropagation();
          return;
        });
      } else {
        $(this).bind("click", function () {
          tmDialog.hideScreenDialog();
          tmClient.enableTitleButton();
          event.stopPropagation();
          return;
        });
      }
    });
    if (afterShow) afterShow();
  };

  /**
   * 显示全屏弹出窗口
   * @param  {[type]} content    [description]
   * @param  {[type]} showOkButton [description]
   * @param  {[type]} cbOk       [description]
   * @return {[type]}            [description]
   */
  this.showFullScreenDialog = function (content, showOkButton, cbOk) {
    this.curDialogCallBack = cbOk;
    tmClient.disableTitleButton();
    $(".TaskMsgForm").hide();
    $("body").append("<div class=\"TaskMsgMaskDiv\"></div>");
    $("body").append("<div class=\"TaskMsgDialog\">" + content + "</div>");

    $(".TaskMsgDialog").css("bottom", "60px");
    var str = "<div class=\"TaskMsgDialogFooter\">";
    if (showOkButton) {
      str += "<div class=\"okButton\">确定</div>" +
        "<div class=\"cancelButton\">取消</div></div>";
    } else {
      str += "<div class=\"cancelButton\" style=\"width:100%; " +
        "background-color: #3399FF; color:#FFF;\">取消</div></div>";
    }
    $("body").append(str);
    $(".TaskMsgDialogFooter").find("div").each(function () {
      if ($(this).html() == "确定") {
        $(this).bind("click", function (event) {
          if (!cbOk) {
            alert("未提供点击确定后的回调函数！");
            return;
          }
          tmClient.enableTitleButton();
          cbOk();
          event.stopPropagation();
          return;
        });
      } else {
        $(this).bind("click", function (event) {
          tmDialog.hide();
          tmClient.enableTitleButton();
          event.stopPropagation();
          return;
        });
      }
    });
  };

  /**
   * 隐藏弹出窗口
   * @return {[type]} [description]
   */
  this.hideScreenDialog = function () {
    //        $(".TaskMsgScreenDialogHeader").remove();
    //        $(".TaskMsgScreenDialogBody").remove();
    //        $(".TaskMsgScreenDialogFooter").remove();
    $(".TaskMsgScreenDialog").remove();
    $(".TaskMsgMaskDiv").remove();
    $(".TaskMsgForm").show();
    this.curDialogCallBack = null;
  };

  /**
   * 隐藏弹出窗口
   * @return {[type]} [description]
   */
  this.hide = function () {
    $(".TaskMsgDialog").remove();
    $(".TaskMsgDialogFooter").remove();
    $(".TaskMsgMaskDiv").remove();
    $(".TaskMsgForm").show();
    this.curDialogCallBack = null;
  };
}

var tmDialog = new TaskMsgDialog();

/**
 * 表单类
 */
function TaskMsgForm() {
  this.id = null; //表单编号
  this.appCode = null; //表单对应的应用代码
  this.appDataId = null; //表单对应的应用数据编号
  this.getDataService = null; //获得数据的服务
  this.submitService = null; //提交数据的服务
  this.jQueryObj = null; //jQuery对象
  this.inputs = {}; //输入项
  this.inputIds = []; //输入项编号数组，排序用
  this.dataMember = null; //表单对应的数据源对象名
  this.dataSource = null; //数据源对象
  this.onSubmit = null; //提交完成之后需要执行的回调函数名称
  this.onInitFinish = null; //表单初始化之后调用的回调函数
  this.onLoadData = null; //加载数据前执行的回调函数
  this.onAfterLoadData = null; //加载数据后执行的回调函数
  this.isIniting = true; //是否正在初始化

  var thisForm = this;

  /**
   * 初始化表单
   * @param  {[type]} obj 表单的jQuery对象
   */
  this.init = function (obj) {
    this.jQueryObj = obj;
    if (obj.attr("appCode")) this.appCode = obj.attr("appCode");
    if (obj.attr("appDataId")) this.appDataId = obj.attr("appDataId");
    if (obj.attr("getDataService")) this.getDataService = obj.attr("getDataService");
    if (obj.attr("submitService")) this.submitService = obj.attr("submitService");
    if (obj.attr("dataMember")) this.dataMember = obj.attr("dataMember");
    if (obj.attr("onSubmit")) this.onSubmit = obj.attr("onSubmit");
    if (obj.attr("onInitFinish")) this.onInitFinish = obj.attr("onInitFinish");
    if (obj.attr("onLoadData")) this.onLoadData = obj.attr("onLoadData");
    if (obj.attr("onAfterLoadData")) this.onAfterLoadData = obj.attr("onAfterLoadData");

    var haveInput = false;
    obj.find("input").each(function () {
      var ipt = new TaskMsgInput();
      ipt.parseFromTag(thisForm, $(this));
      haveInput = true;
    });

    if (haveInput) this.render();

    if (this.getDataService) {
      var service = new TaskMsgService(this.getDataService);
      service.request(null, function (req, res) {
        thisForm.dataBind(req, res);
        thisForm.isIniting = false;
      });
    } else {
      this.isIniting = false;
    }

    if (this.onInitFinish) eval(this.onInitFinish + "(this)");
  };

  /**
   * 渲染表单，生成表单html代码
   */
  this.render = function () {
    this.jQueryObj.replaceWith("<ul id=\"" + this.id + "\" class=\"TaskMsgForm\">" +
      this.jQueryObj.html() + "</ul>");
    this.jQueryObj = $("#" + this.id);

    for (var i = 0; i < this.inputIds.length; i++) {
      var ipt = this.inputs[this.inputIds[i]];
      if (this.jQueryObj.find("#" + ipt.id).length > 0) {
        this.jQueryObj.find("#" + ipt.id).replaceWith("<li id=\"inputLi_" + ipt.id + "\"></li>");
      } else {
        this.jQueryObj.append("<li id=\"inputLi_" + ipt.id + "\"></li>");
      }
      ipt.jQueryObj = this.jQueryObj.find("#inputLi_" + ipt.id);
      if (ipt.topSpacing) $("<div class=\"inputRowSeparate\"></div>").insertBefore(ipt.jQueryObj);
      if (ipt.bottomSpacing) $("<div class=\"inputRowSeparate\"></div>").insertAfter(ipt.jQueryObj);
      ipt.render();
    }
  };

  /**
   * 添加新控件
   * @param  {[type]} ipt    新控件对象
   */
  this.addInput = function (ipt) {
    ipt.form = this;
    if (!this.inputIds.contains(ipt.id)) this.inputIds.push(ipt.id);
    this.inputs[ipt.id] = ipt;
    if (this.jQueryObj.find("#" + ipt.id).length > 0) {
      this.jQueryObj.find("#" + ipt.id).replaceWith("<li id=\"inputLi_" + ipt.id + "\"></li>");
    } else {
      this.jQueryObj.append("<li id=\"inputLi_" + ipt.id + "\"></li>");
    }
    ipt.jQueryObj = this.jQueryObj.find("#inputLi_" + ipt.id);
    if (ipt.topSpacing) $("<div class=\"inputRowSeparate\"></div>").insertBefore(ipt.jQueryObj);
    if (ipt.bottomSpacing) $("<div class=\"inputRowSeparate\"></div>").insertAfter(ipt.jQueryObj);
    ipt.render();
  };

  /**
   * 在指定控件之前插入新控件
   * @param  {[type]} ipt    新控件对象
   * @param  {[type]} bIptId 指定控件的id
   */
  this.insertInputBefore = function (ipt, bIptId) {
    if ($("#inputLi_" + bIptId).length == 0) {
      alert("输入项[" + bIptId + "]不存在！");
      return;
    }
    ipt.form = this;
    if (!this.inputIds.contains(ipt.id)) this.inputIds.push(ipt.id);
    this.inputs[ipt.id] = ipt;
    if (this.jQueryObj.find("#" + ipt.id).length > 0) {
      this.jQueryObj.find("#" + ipt.id).replaceWith("<li id=\"inputLi_" + ipt.id + "\"></li>");
    } else {
      $("<li id=\"inputLi_" + ipt.id + "\"></li>").insertBefore("#inputLi_" + bIptId);
    }
    ipt.jQueryObj = this.jQueryObj.find("#inputLi_" + ipt.id);
    if (ipt.topSpacing) $("<div class=\"inputRowSeparate\"></div>").insertBefore(ipt.jQueryObj);
    if (ipt.bottomSpacing) $("<div class=\"inputRowSeparate\"></div>").insertAfter(ipt.jQueryObj);
    ipt.render();
  };

  /**
   * 在指定控件之后插入新控件
   * @param  {[type]} ipt    新控件对象
   * @param  {[type]} bIptId 指定控件的id
   */
  this.insertInputAfter = function (ipt, aIptId) {
    if ($("#inputLi_" + aIptId).length == 0) {
      alert("输入项[" + aIptId + "]不存在！");
      return;
    }
    ipt.form = this;
    if (!this.inputIds.contains(ipt.id)) this.inputIds.push(ipt.id);
    this.inputs[ipt.id] = ipt;
    if (this.jQueryObj.find("#" + ipt.id).length > 0) {
      this.jQueryObj.find("#" + ipt.id).replaceWith("<li id=\"inputLi_" + ipt.id + "\"></li>");
    } else {
      $("<li id=\"inputLi_" + ipt.id + "\"></li>").insertAfter("#inputLi_" + aIptId);
    }
    ipt.jQueryObj = this.jQueryObj.find("#inputLi_" + ipt.id);
    if (ipt.topSpacing) $("<div class=\"inputRowSeparate\"></div>").insertBefore(ipt.jQueryObj);
    if (ipt.bottomSpacing) $("<div class=\"inputRowSeparate\"></div>").insertAfter(ipt.jQueryObj);
    ipt.render();
  };

  /**
   * 绑定表单数据
   * @param  {[type]} res [description]
   */
  this.dataBind = function (req, res) {
    if (this.onLoadData) eval(this.onLoadData + "(req, res)");
    if (this.dataMember && res[this.dataMember]) {
      this.dataSource = res[this.dataMember];
    }
    for (var iptId in this.inputs) {
      var ipt = this.inputs[iptId];
      ipt.dataBind(res);
    }
    if (this.onAfterLoadData) eval(this.onAfterLoadData + "(req, res)");
  };

  /**
   * 解析表单数据
   * @return {[type]} [description]
   */
  this.parseData = function () {
    var args = {};
    for (var iptId in this.inputs) {
      var ipt = this.inputs[iptId];
      if (ipt.type == "submit") continue;
      var val = ipt.getValue();
      if (ipt.notNull && !ipt.hidden && (!val || val == "") && val != 0) {
        tmClient.alert(ipt.label + "不能为空！");
        if (ipt.canFocus) {
          if (ipt.type == "textarea") {
            ipt.jQueryObj.find("textarea").addClass("invalidInput");
            ipt.jQueryObj.find("textarea").focus();
          } else {
            ipt.jQueryObj.find("input").addClass("invalidInput");
            ipt.jQueryObj.find("input").focus();
          }
        }
        return null;
      }
      if ((val || val == 0) && val != "" && !ipt.isValid()) {
        tmClient.alert(ipt.label + "的格式不正确！");
        if (ipt.canFocus) {
          ipt.jQueryObj.find("input").addClass("invalidInput");
          ipt.jQueryObj.find("input").focus();
        }
        return null;
      }
      args[ipt.id] = val;
    }
    return args;
  };

  this.requestArgs = null;
  this.uploadFiles = [];

  this.uploadFile = function () {
    tmClient.uploadAttachs("taskMsgForms['" + this.id + "'].onUploadFiles",
      this.uploadFiles, true);
  };

  this.onUploadFiles = function (filesInfo) {
    for (var j = 0; j < filesInfo.length; j++) {
      var file1 = filesInfo[j];
      for (var i = 0; i < this.uploadFiles.length; i++) {
        var file2 = this.uploadFiles[i];
        if (file1.path == file2.path) {
          var ipt = this.inputs[file2.iptId];
          if (!ipt.multi) {
            ipt.value.code = file1.code;
            this.requestArgs[ipt.id].code = file1.code;
            delete this.requestArgs[ipt.id].path;
          } else {
            ipt.value[file2.index].code = file1.code;
            this.requestArgs[ipt.id][file2.index].code = file1.code;
            delete this.requestArgs[ipt.id][file2.index].path;
          }
          break;
        }
      }
    }
    var service = new TaskMsgService(this.submitService);
    service.request(this.requestArgs, function (req, res) {
      GRAYLAYER.del("grayLayer-div");
      if (thisForm.onSubmit) eval(thisForm.onSubmit + "(req, res)");
    });
  };

  /**
   * 提交数据
   */
  this.submit = function () {
    GRAYLAYER.create("grayLayer-div");
    if (!this.submitService) {
      alert("未设置处理提交请求的后台服务！");
      GRAYLAYER.del("grayLayer-div");
      return;
    }
    var args = this.parseData();
    if (args == null) return;
    this.uploadFiles = [];
    this.uploadIndex = 0;
    for (var iptId in this.inputs) {
      var ipt = this.inputs[iptId];
      if (ipt.value && (ipt.type == "file" || ipt.type == "photo" || ipt.type == "voice")) {
        if (!ipt.multi) {
          if (ipt.value.code) continue;
          var file = {};
          file.type = ipt.type;
          file.iptId = iptId;
          file.index = 0;
          file.path = ipt.value.path;
          file.appCode = this.appCode + "." + file.type;
          file.retainExt = ipt.retainExt;
          this.uploadFiles.push(file);
        } else {
          for (var i = 0; i < ipt.value.length; i++) {
            if (ipt.value[i].code) continue;
            var file = {};
            file.type = ipt.type;
            file.iptId = iptId;
            file.index = i;
            file.path = ipt.value[i].path;
            file.appCode = this.appCode + "." + file.type;
            file.retainExt = ipt.retainExt;
            this.uploadFiles.push(file);
          }
        }
      }
    }
    if (this.uploadFiles.length == 0) {
      var service = new TaskMsgService(this.submitService);
      service.onError = function (msg) {
        GRAYLAYER.del("grayLayer-div");
      };
      service.request(args, function (req, res) {
        GRAYLAYER.del("grayLayer-div");
        if (thisForm.onSubmit) eval(thisForm.onSubmit + "(req, res)");
      });
    } else {
      this.requestArgs = args;
      this.uploadFile();
    }
  };
}

/**
 * 输入项类
 */
function TaskMsgInput() {
  this.id = null; //控件编号
  this.type = null; //控件类型
  this.label = null; //控件的标签文本
  this.jQueryObj = null; //控件对应的jQuery对象
  this.value = null; //控件值
  this.text = null; //控件值
  this.notNull = false; //不能为空
  this.multi = false; //是否可以多选
  this.cascade = false; //是否可以级联
  this.values = null; //值集合
  this.texts = null; //文本集合
  this.nodes = null; //节点集合
  this.leafs = null; //叶子集合
  this.form = null; //当前表单
  this.sign = null; //签章数据//
  this.signs = null; //签章数据集合//
  this.tmp = null; //临时数据//
  this.tmps = null; //临时数据//
  this.defaultvalue = null; //默认值//
  this.parameter = null; //参数//
  this.maxlength = null; //最多可以输入的数量
  this.controlType = null; //控件类型//
  this.decimalPlaces = null; //小数位数//
  this.dataSheetName = null; //数据表名//
  this.useKeyboard = false; //是否使用键盘输入
  this.topSpacing = false; //控件上部间距
  this.bottomSpacing = false; //控件下部间距
  this.onFocus = null; //控件获取焦点时执行的函数
  this.onChange = null; //控件值改变后执行的函数
  this.onClick = null; //控件点击后执行的函数
  this.onBlur = null; //控件失去焦点时执行的函数
  this.canFocus = false; //控件是否可以获得焦点
  this.showIcon = true; //是否显示图标
  this.showLabel = true; //是否显示控件标签
  this.icon = null; //自定义图标url路径
  this.dataField = null; //输入项对应的数据源字段名称
  this.dataListMember = null; //数据列表对应的数据源成员
  this.valueField = null; //数据列表对应的数据源成员变量的值字段名
  this.textField = null; //数据列表对应的数据源成员变量的文本字段名
  this.readonly = false; //是否只读
  this.getDataListService = null; //获得数据列表的服务名称
  this.isRendered = false; //控件事否已渲染
  this.hidden = false; //控件是否隐藏
  this.retainExt = false; //保留扩展名
  this.submitObjectValue = false; //提交对象型值，某些控件在选择完值后，值的类型是对象，默认仅提交编号或路径，不会提交整个对象，例如用户、部门、文件等

  var thisInput = this;

  /**
   * 解析控件属性
   * @param  {[type]} tform [description]
   * @param  {[type]} obj   [description]
   * @return {[type]}       [description]
   */
  this.parseFromTag = function (tform, obj) {
    if (!obj.attr("type") || !obj.attr("id")) {
      tmClient.debug("控件类型或编号为空！");
      return;
    }
    this.form = tform;
    this.id = obj.attr("id");
    this.type = obj.attr("type");
    if (obj.attr("label")) this.label = obj.attr("label");
    if (obj.attr("value")) {
      if (this.type == "user" || this.type == "dep" || this.type == "group" ||
        this.type == "tree" || this.type == "sign" || this.type == "countersign" ||
        this.type == "file" || this.type == "photo" || this.type == "location" ||
        this.type == "voice" || this.type == "camera") {
        this.value = JSON.parse(obj.attr("value").replace(/'/g, "\""));
      } else {
        this.value = exeExpress(obj.attr("value"));
      }
    }
    if (obj.attr("topSpacing") == "true") this.topSpacing = true;
    if (obj.attr("bottomSpacing") == "true") this.bottomSpacing = true;
    if (obj.attr("notNull") == "true") this.notNull = true;
    if (obj.attr("multi") == "true") this.multi = true;
    if (obj.attr("cascade") == "true") this.cascade = true;
    if (obj.attr("showIcon") == "false") this.showIcon = false;
    if (obj.attr("showLabel") == "false") this.showLabel = false;
    if (obj.attr("icon")) this.icon = obj.attr("icon");
    if (obj.attr("onFocus")) this.onFocus = obj.attr("onFocus");
    if (obj.attr("onChange")) this.onChange = obj.attr("onChange");
    if (obj.attr("onClick")) this.onClick = obj.attr("onClick");
    if (obj.attr("onBlur")) this.onBlur = obj.attr("onBlur");
    if (obj.attr("maxlength")) this.maxlength = obj.attr("maxlength");
    if (obj.attr("submitObjectValue") == "true") this.submitObjectValue = true;
    if (obj.attr("readonly")) this.readonly = true;
    if (obj.attr("hidden")) this.hidden = true;
    if (obj.attr("getWaterMarkFunc")) this.getWaterMarkFunc = obj.attr("getWaterMarkFunc");
    if (obj.attr("compress") == "false") this.compress = false;
    if (obj.attr("getDataListService")) this.getDataListService = obj.attr("getDataListService");
    if (!this.maxlength) {
      if (this.type == "password") this.maxlength = 30;
      if (this.type == "email") this.maxlength = 50;
      if (this.type == "mobile") this.maxlength = 11;
      if (this.type == "tel") this.maxlength = 13;
      if (this.type == "idCard") this.maxlength = 18;
      if (this.type == "number") this.maxlength = 15;
      if (this.type == "int") this.maxlength = 15;
      if (this.type == "money") this.maxlength = 15;
      if (this.type == "postCode") this.maxlength = 6;
      if (this.type == "varCode") this.maxlength = 6;
      if (this.type == "file") this.maxlength = 10;
      if (this.type == "photo") this.maxlength = 9;
    }
    if ((this.type == "file" || this.type == "photo") && obj.attr("retainExt") == "true") this.retainExt = true;
    if (obj.attr("dataField")) this.dataField = obj.attr("dataField");
    if (obj.attr("values")) this.values = (obj.attr("values") + "").split(",");
    if (obj.attr("texts")) this.texts = (obj.attr("texts") + "").split(",");
    if (obj.attr("nodes")) this.values = (obj.attr("nodes") + "").split(",");
    if (obj.attr("leafs")) this.texts = (obj.attr("leafs") + "").split(",");
    if (obj.attr("dataListMember")) this.dataListMember = obj.attr("dataListMember");
    if (obj.attr("valueField")) this.valueField = obj.attr("valueField");
    if (obj.attr("textField")) this.textField = obj.attr("textField");
    if (this.values && !this.texts) this.texts = this.values;
    if (this.type == "date" || this.type == "time" || this.type == "datetime") {
      /*if(!this.value) {
        if(this.type=="date") this.value = (new Date()).format("yyyy-MM-dd");
        if(this.type=="time") this.value = (new Date()).format("hh:mm");
        if(this.type=="datetime") this.value = (new Date()).format("yyyy-MM-dd hh:mm");
      }*/
    } else if (this.type == "user") {
      this.selectSelf = false;
      if (obj.attr("selectSelf") == "true") this.selectSelf = true;
    } else if (this.type == "photo") {
      this.onlyCamera = false;
      if (obj.attr("onlyCamera") == "true") this.onlyCamera = true;
    } else if (this.type == "text" || this.type == "password" || this.type == "email" ||
      this.type == "tel" || this.type == "postCode" || this.type == "idCard" || this.type == "varCode" ||
      this.type == "number" || this.type == "money" || this.type == "int" ||
      this.type == "mobile") {
      this.canFocus = true;
    }

    tform.inputs[this.id] = this;
    tform.inputIds.push(this.id);
  };

  /**
   * 渲染控件
   */
  this.render = function () {
    //生成控件dom元素
    var iptHtml = "";
    if (this.type != "submit" && this.type != "label" && this.type != "button") {
      iptHtml += "<div class=\"notNullHint";
      if (this.notNull) {
        iptHtml += " notNullHintShow";
      }
      iptHtml += "\"></div>";
    }
    if (this.type == "text" || this.type == "password" || this.type == "email" ||
      this.type == "mobile" || this.type == "tel" || this.type == "idCard" ||
      this.type == "number" || this.type == "int" || this.type == "money" ||
      this.type == "postCode" || this.type == "varCode" || this.type == "macro") {
      if (this.type == "text" && !this.showLabel && this.readonly) {
        this.jQueryObj.addClass("flexBox");
        iptHtml += "<pre class=\"flexContent\">" + this.value + "</pre>";
      } else {
        if (this.showIcon && this.icon)
          iptHtml += "<img class=\"inputIcon\" src=\"" + this.icon + "\" />";
        if (this.label && this.showLabel) iptHtml += "<label>" + this.label + "</label>";
        var iptType = "text";
        if (this.type == "password" || this.type == "email") {
          iptType = this.type;
        } else if (this.type == "int" || this.type == "mobile" ||
          this.type == "idCard" || this.type == "postCode" || this.type == "varCode") {
          iptType = "tel";
        }
        if (this.type == "text" && !this.showLabel) iptHtml += "<div class=\"flexContent\">";
        iptHtml += "<input type=\"" + iptType + "\" ctype=\"" + this.type + "\"";
        if (this.maxlength) iptHtml += " maxlength=" + this.maxlength;
        if (this.readonly) {
          iptHtml += " readonly";
        } else {
          this.useKeyboard = true;
        }
        if (this.onClick) iptHtml += " onclick=\"" + this.onClick + "\"";
        if (this.onFocus) iptHtml += " onfocus=\"" + this.onFocus + "\"";
        if (this.onBlur) iptHtml += " onblur=\"" + this.onBlur + "\"";
        if (this.controlType) iptHtml += " controlType=\"" + this.controlType + "\"";
        if (this.decimalPlaces) iptHtml += " decimalPlaces=\"" + this.decimalPlaces + "\"";
        if (this.dataSheetName) iptHtml += " dataSheetName=\"" + this.dataSheetName + "\"";

        if (this.type == "text") {
          if (!this.showLabel) {
            this.jQueryObj.css("height", "50px");
            this.jQueryObj.addClass("flexBox");
            iptHtml += " style=\"text-align:left; width:100%;\"";
            //text-align:left; margin-top:0;padding:0;float:left;
          }
          if (!this.readonly && this.label) iptHtml += " value=\"请输入" + this.label + "\" onfocus=\"" +
            "if(this.value=='请输入" + this.label + "') {this.value='';}\"";
        }


        iptHtml += " />";
        if (this.type == "text" && !this.showLabel) iptHtml += "</div>";
      }
    } else if (this.type == "sign") { //
      //this.jQueryObj.addClass("flexBox");
      if (this.showIcon && this.icon)
        iptHtml += "<img class=\"inputIcon\" src=\"" + this.icon + "\" />";
      if (this.label && this.showLabel) iptHtml += "<label>" + this.label + "</label>";

      iptHtml += "<input type=\"hidden\" ctype=\"hidden\"/>";
      iptHtml += "<span class=\"signButton taskmsgSign\" style=\"display:none;\">签章</span>";
      iptHtml += "<span class=\"signButton taskmsgCancelSign\" style=\"display:none;\">取消签章</span>";
      iptHtml += "<img style=\"float:right;margin:6px 0px;width:90px;height:60px;display:none;\" />";
      iptHtml += "<input type=\"text\" ctype=\"text\" readonly style=\"display:none;\" />";
    } else if (this.type == "countersign") { //
      //this.jQueryObj.addClass("flexBox");
      if (this.showIcon && this.icon)
        iptHtml += "<img class=\"inputIcon\" src=\"" + this.icon + "\" />";
      if (this.label && this.showLabel) {
        iptHtml += "<div style=\"width:100%;height:50px;\"><label>" + this.label + "</label></div>";
      }
      iptHtml += "<span mtype=\"sign\" style=\"color: #666; display: block;\">";
      var selfsign = ""; //当前人
      if (this.tmps) {
        var vss = this.tmps.split("|"); //
        var nr = "";
        //显示已签章数据
        for (var i = 0; i < vss.length; i++) {
          var vs0 = vss[i].split("~");
          var vs = vs0[0].split(",");
          if (!this.readonly) {
            if (vs[0] == this.sign.split(",")[0]) {
              selfsign = vss[i];
              continue;
            }
          }
          if (nr) nr += "<br />";
          if (this.parameter.countersigntype.indexOf("意见") >= 0)
            nr += vs0[1] + "<br />";
          if (this.parameter.countersigntype.indexOf("当前时间") >= 0)
            nr += "<span style=\"float: right; height: 30px; display: inline-block; font-size: 16px;\">" + vs[5] + "&nbsp;</span>";
          if (this.parameter.countersigntype.indexOf("当前日期") >= 0)
            nr += "<span style=\"float: right; height: 30px; display: inline-block; font-size: 16px;\">" + vs[4] + "&nbsp;</span>";
          if (this.parameter.countersigntype.indexOf("当前用户部门") >= 0)
            nr += "<span style=\"float: right; height: 30px; display: inline-block; font-size: 16px;\">" + vs[6] + "&nbsp;</span>";
          if (this.parameter.countersigntype.indexOf("当前用户姓名") >= 0)
            nr += "<span style=\"float: right; height: 30px; display: inline-block; font-size: 16px;\">" + vs[1] + "&nbsp;</span>";
          if (this.parameter.countersigntype.indexOf("当前用户签章") >= 0) {
            if (vs[2]) {
              var strsigns = eval("this.signs.V" + vs[0] + "V" + vs[3]).split(",");
              nr += "<img style=\"float: right;margin:6px 0px;width:90px;height:60px;\" src=\"" + strsigns[3] + "\"/>";
            } else {
              nr += "<span style=\"float: right;\">" + vs[3] + "&nbsp;</span>";
            }
          }

          //nr += "<br />";
        }
        iptHtml += nr;
        this.value = selfsign;
      }

      iptHtml += "</span>";
      iptHtml += "<input type=\"hidden\" ctype=\"hidden\"/>";
      if (this.parameter.countersigntype.indexOf("意见") >= 0)
        iptHtml += "<textarea ctype=\"textarea\" style=\"display:none;\"></textarea>";
      //iptHtml += "<br />";
      if (this.parameter.countersigntype.indexOf("当前时间") >= 0)
        iptHtml += "<input type=\"text\" ctype=\"text\" mtype=\"time\" readonly style=\"float:right;margin:0;width:90px;display:none;\" />";
      if (this.parameter.countersigntype.indexOf("当前日期") >= 0)
        iptHtml += "<input type=\"text\" ctype=\"text\" mtype=\"date\" readonly style=\"float:right;margin:0;width:90px;display:none;\" />";
      if (this.parameter.countersigntype.indexOf("当前用户部门") >= 0)
        iptHtml += "<input type=\"text\" ctype=\"text\" mtype=\"dep\" readonly style=\"float:right;margin:0;width:90px;display:none;\" />";
      //iptHtml += "<input type=\"text\" ctype=\"text\" mtype=\"post\" readonly style=\"float:left;margin:0;width:90px;display:none;\" />";
      if (this.parameter.countersigntype.indexOf("当前用户姓名") >= 0)
        iptHtml += "<input type=\"text\" ctype=\"text\" mtype=\"user\" readonly style=\"float:right;margin:0;width:90px;display:none;\" />";

      if (this.parameter.countersigntype.indexOf("当前用户签章") >= 0) {
        iptHtml += "<img style=\"float:right;margin:6px 0px;width:90px;height:60px;display:none;\" />";
        iptHtml += "<input type=\"text\" ctype=\"text\" mtype=\"name\" readonly style=\"float:right;margin:0;width:90px;display:none;\" />";
        iptHtml += "<span class=\"signButton taskmsgSign\" style=\"float:right;display:none;\">签章</span>";
        iptHtml += "<span class=\"signButton taskmsgCancelSign\" style=\"float:right;display:none;\">取消签章</span>";
      }
    } else if (this.type == "switch" || this.type == "switchs") {
      if (this.showIcon && this.icon)
        iptHtml += "<img class=\"inputIcon\" src=\"" + this.icon + "\" />";
      if (this.label) iptHtml += "<label>" + this.label + "</label>";
      if (this.readonly) {
        var text = "";
        if (this.value && this.values) {
          if (!this.texts) this.texts = this.values;
          text = this.texts[0];
          if (this.value == this.values[1]) text = this.texts[1];
        }
        iptHtml += "<input type=\"text\" ctype=\"" + this.type +
          "\" value=\"" + text + "\" readonly />";
      } else {
        this.status = [this.type + "On", this.type + "Off"];
        if (this.values) {
          if (!this.value) this.value = this.values[0];
          if (this.value == this.values[1]) {
            this.status = [this.type + "Off", this.type + "On"];
          }
          iptHtml += "<div ctype=\"" + this.type + "\">" +
            "<div class=\"" + this.status[0] + "\">" + this.texts[0] + "</div>" +
            "<div class=\"" + this.status[1] + "\">" + this.texts[1] + "</div></div>";
        }
      }
    } else if (this.type == "file") {
      iptHtml += "<div style=\"height:50px; width:100%;\">";
      if (this.showIcon) {
        if (this.icon) {
          iptHtml += "<img class=\"inputIcon\" src=\"" + this.icon + "\" />";
        } else {
          iptHtml += "<img class=\"inputIcon\" src=\"" + TaskMsgClientAPIDir + "images/attach.png\" />";
        }
      }
      if (this.label) iptHtml += "<label>" + this.label + "</label>";
      if (this.multi && !this.readonly) {
        iptHtml += "<img src=\"" + TaskMsgClientAPIDir + "images/plus.png\" " +
          "class=\"inputRightIcon\" ";
      } else {
        iptHtml += "<span class=\"inputGt\">&gt;</span>";
        iptHtml += "<input type=\"text\" ctype=\"" + this.type + "\" readonly ";
      }
      iptHtml += " onClick=\"TaskMsg_Input_OnClick('" + this.form.id +
        "','" + this.id + "')\"/></div>";
    } else if (this.type == "voice") {
      if (this.showIcon) {
        if (this.icon) {
          iptHtml += "<img class=\"inputIcon\" src=\"" + this.icon + "\" />";
        } else {
          iptHtml += "<img class=\"inputIcon\" src=\"" + TaskMsgClientAPIDir +
            "images/audioRecorder.png\" />";
        }
      }
      if (this.label) iptHtml += "<label>" + this.label + "</label>";
      iptHtml += "<span class=\"inputGt\">&gt;</span><input " +
        "type=\"text\" ctype=\"" + this.type + "\" readonly";
      if (!this.readonly) iptHtml += " onClick=\"TaskMsg_Input_OnClick('" +
        this.form.id + "','" + this.id + "')\"";
      iptHtml += "/>";
    } else if (this.type == "barcode") {
      iptHtml += "<div  style=\"width:100%;height:50px;\" onClick=\"" +
        "TaskMsg_Input_OnClick('" + this.form.id + "','" + this.id + "')\">";
      if (this.showIcon) {
        if (this.icon) {
          iptHtml += "<img class=\"inputIcon\" src=\"" + this.icon + "\" />";
        } else {
          iptHtml += "<img class=\"inputIcon\" src=\"" + TaskMsgClientAPIDir + "images/qrcode.png\" />";
        }
      }
      if (this.label) iptHtml += "<label>" + this.label + "</label>";
      iptHtml += "<span class=\"inputGt\">&gt;</span></div>";
    } else if (this.type == "photo") {
      if (this.label && this.showLabel) {
        this.jQueryObj.css("height", "160px");
      } else {
        this.jQueryObj.css("height", "110px");
      }
      this.jQueryObj.addClass("flexBox");
      iptHtml += "<div class=\"flexContent\">";
      if (this.label && this.showLabel) {
        iptHtml += "<div style=\"width:100%;height:50px;\">";
        if (this.showIcon) {
          if (this.icon) {
            iptHtml += "<img class=\"inputIcon\" src=\"" + this.icon + "\" />";
          } else {
            if (this.onlyCamera) {
              iptHtml += "<img class=\"inputIcon\" src=\"" + TaskMsgClientAPIDir + "images/camera.png\" />";
            } else {
              iptHtml += "<img class=\"inputIcon\" src=\"" + TaskMsgClientAPIDir + "images/photo.png\" />";
            }
          }
        }
        iptHtml += "<label>" + this.label + "</label></div>";
      }
      if (!this.readonly) iptHtml += "<img class=\"photo_addBtn\" src=\"" +
        TaskMsgClientAPIDir + "images/plus90.png\" onClick=\"TaskMsg_Input_OnClick('" +
        this.form.id + "','" + this.id + "')\" />";
      iptHtml += "</div>";
    } else if (this.type == "textarea") {
      this.jQueryObj.addClass("flexBox");
      if (this.readonly) {
        iptHtml += "<div class=\"flexContent\">";
        if (this.label && this.showLabel) {
          iptHtml += "<div style=\"width:100%;height:50px;\">";
          iptHtml += "<label>" + this.label + "</label></div>";
        }
        if (this.value) {
          iptHtml += "<pre>" + this.value + "</pre>";
        } else {
          iptHtml += "<pre></pre>";
        }
        iptHtml += "</div>";
      } else {
        iptHtml += "<div class=\"flexContent\">";
        if (this.label && this.showLabel) {
          this.jQueryObj.css("height", "215px");
          iptHtml += "<div style=\"width:100%;height:50px;\">";
          iptHtml += "<label>" + this.label + "</label></div>";
        } else {
          this.jQueryObj.css("height", "165px");
        }
        iptHtml += "<textarea ctype=\"" + this.type + "\" ";
        if (this.label) {
          iptHtml += " onfocus=\"if(this.value=='请输入" + this.label + "') " +
            "{this.value='';}\" onblur=\"if(this.value=='')" +
            "{this.value='请输入" + this.label + "';}\">请输入" + this.label + "";
        } else {
          iptHtml += ">";
        }
        iptHtml += "</textarea>";
        iptHtml += "</div>";
      }
    } else if (this.type == "label") { //
      iptHtml += "<div>";
      if (this.label && this.showLabel) {
        this.jQueryObj.css("height", "36px");
        this.jQueryObj.css("background-color", "#EEE");
        iptHtml += "&nbsp;<span style=\"font-size:14px;line-height:36px;\">" + this.label + "</span>";
      }
      iptHtml += "<input id=\"" + this.id + "\" type=\"hidden\" ctype=\"" + this.type + "\" />";
      if (!this.readonly) {
        if (this.onClick) {
          iptHtml += "<span style=\"font-size:14px;line-height:36px;color:#63BFFF;float:right;\" " +
            "onclick=\"" + this.onClick + "\">" + this.text + "</span>";
        }
      }
      iptHtml += "</div>";
    } else if (this.type == "button") { //
      iptHtml += "<div style=\"text-align:center;\">";
      if (!this.readonly) {
        if (!this.hidden) {
          if (this.label && this.showLabel) {
            iptHtml += "&nbsp;<span style=\"line-height:40px;color:#63BFFF;font-size:16px;font-weight:bolder;\" onclick=\"";
            if (this.onClick) {
              iptHtml += this.onClick;
            }
            iptHtml += "\">" + this.label + "</span>";
          }
        }
      }
      iptHtml += "<input id=\"" + this.id + "\" type=\"hidden\" ctype=\"" + this.type + "\" value=\"" + this.value + "\" />";
      iptHtml += "</div>";
    } else if (this.type == "span") { //
      if (this.showIcon && this.icon)
        iptHtml += "<img class=\"inputIcon\" src=\"" + this.icon + "\" />";
      if (this.label && this.showLabel) iptHtml += "<label>" + this.label + "</label>";

      if (!this.showLabel) iptHtml += "<div class=\"flexContent\">";
      iptHtml += "<pre>" + this.value + "</pre>";
      if (!this.showLabel) iptHtml += "</div>";

      //iptHtml += "<span style=\"font-size:14px;line-height:36px;color:#63BFFF;float:right;\">" + this.text + "</span>";
    } else if (this.type == "submit") {
      this.readonly = true;
      this.jQueryObj.css("background-color", "#EEE");
      this.jQueryObj.css("border", "0");
      this.jQueryObj.css("height", "80px");
      var width = ($(window.document).width() - 40) + "px";
      iptHtml += "<input style=\"width:" + width + ";\" type=\"button\" ctype=\"" +
        this.type + "\" value=\"" + this.label + "\" onclick=\"";
      if (this.onClick) {
        iptHtml += this.onClick;
      } else {
        iptHtml += "taskMsgForms['" + this.form.id + "'].submit()";
      }
      iptHtml += "\" />";
    } else {
      if (this.showIcon) {
        if (this.icon) {
          iptHtml += "<img class=\"inputIcon\" src=\"" + this.icon + "\" />";
        } else {
          if (this.type == "user") {
            iptHtml += "<img class=\"inputIcon\" src=\"" + TaskMsgClientAPIDir + "images/men.png\" />";
          } else if (this.type == "location") {
            iptHtml += "<img class=\"inputIcon\" src=\"" + TaskMsgClientAPIDir + "images/location.png\" />";
          } else if (this.type == "chat") {
            iptHtml += "<img class=\"inputIcon\" src=\"" + TaskMsgClientAPIDir + "images/talk.png\" />";
          } else if (this.type == "dep") {
            iptHtml += "<img class=\"inputIcon\" src=\"" + TaskMsgClientAPIDir + "images/dep.png\" />";
          } else if (this.type == "group") {
            iptHtml += "<img class=\"inputIcon\" src=\"" + TaskMsgClientAPIDir + "images/users.png\" />";
          } else if (this.type == "tree") {
            iptHtml += "<img class=\"inputIcon\" src=\"" + TaskMsgClientAPIDir + "images/tree.png\" />";
          }
        }
      }
      if (this.label) iptHtml += "<label>" + this.label + "</label>";
      if (!this.readonly || this.onClick) iptHtml += "<span class=\"inputGt\">&gt;</span>";
      iptHtml += "<input type=\"text\" ctype=\"" + this.type + "\" readonly />";
      this.jQueryObj.click(function () {
        if (thisInput.onClick) {
          eval(thisInput.onClick + "('" + thisInput.form.id + "','" + thisInput.id + "')");
          return;
        }
        if (thisInput.readonly) return;
        TaskMsg_Input_OnClick(thisInput.form.id, thisInput.id);
      });
    }
    this.jQueryObj.append(iptHtml);
    if (this.type == "textarea" || this.type == "photo" ||
      (this.type == "text" && !this.showLabel && !this.readonly)) {
      this.jQueryObj.find(".notNullHint").css("float", "none");
    }

    //设置控件默认值
    if (this.value) this.setValue(this.value);

    if (this.getDataListService) this.loadData();

    //绑定控件事件
    if (this.type == "switch" || this.type == "switchs") {
      this.jQueryObj.children("div").click(function () {
        if (thisInput.onClick) {
          eval(thisInput.onClick + "('" + thisInput.form.id + "','" + thisInput.id + "')");
          return;
        }
        if (!thisInput.values || thisInput.readonly) return;
        if (thisInput.value == thisInput.values[0]) {
          thisInput.value = thisInput.values[1];
        } else {
          thisInput.value = thisInput.values[0];
        }
        $(this).find("div").each(function () {
          if ($(this).attr("class") == thisInput.type + "On") {
            $(this).attr("class", thisInput.type + "Off");
          } else {
            $(this).attr("class", thisInput.type + "On");
          }
        });
        if (thisInput.onChange) {
          eval(thisInput.onChange);
          return;
        }
      });
    } else if (this.type == "sign") { //
      //非只读无值
      if (!this.readonly && !this.value) {
        var strsigns = thisInput.sign.split(",");
        //                if (strsigns[2]) {
        this.jQueryObj.children(".taskmsgSign").show();
        //                }
        //                else {
        //                    $("#inputLi_" + thisInput.id).children("input[type=hidden]").val(strsigns[0]);
        //                    $("#inputLi_" + thisInput.id).children("input[type=text]").val(strsigns[1]);
        //                    $("#inputLi_" + thisInput.id).children("img").attr("src", strsigns[3]).show();
        //                    $("#inputLi_" + thisInput.id).children(".taskmsgSign").hide();
        //                    thisInput.value = strsigns[0] + "," + strsigns[1];
        //                }
      }

      this.jQueryObj.children(".taskmsgSign").click(function () {
        var strsigns = thisInput.sign.split(",");
        if (!strsigns[2]) {
          $("#inputLi_" + thisInput.id).children("input[type=hidden]").val(strsigns[0]);
          if (!strsigns[3]) {
            $("#inputLi_" + thisInput.id).children("input[type=text]").val(strsigns[1]).show();
          } else {
            $("#inputLi_" + thisInput.id).children("img").attr("src", strsigns[3]).show();
          }
          $("#inputLi_" + thisInput.id).children(".taskmsgSign").hide();
          $("#inputLi_" + thisInput.id).children(".taskmsgCancelSign").show();
          thisInput.value = strsigns[0] + "," + strsigns[1];
          return;
        }
        var content = "<div style=\"margin:20px 0px;text-align:center;\">";
        content += "请输入签章密码";
        content += "<br />";
        content += "<br />";
        content += "<input type=\"password\" class=\"TaskMsgInput\" style=\"width:185px;\" />";
        content += "</div>";
        tmDialog.showFullScreenDialog(content, true, function () {
          var strsigns = thisInput.sign.split(","); //bh,mc,mm,lj
          var mm = $(".TaskMsgDialog").find("input[type=password]").val();
          if (strsigns[2] == mm) {
            $("#inputLi_" + thisInput.id).children("input[type=hidden]").val(strsigns[0]);
            if (!strsigns[3]) {
              $("#inputLi_" + thisInput.id).children("input[type=text]").val(strsigns[1]).show();
            } else {
              $("#inputLi_" + thisInput.id).children("img").attr("src", strsigns[3]).show();
            }
            $("#inputLi_" + thisInput.id).children(".taskmsgSign").hide();
            $("#inputLi_" + thisInput.id).children(".taskmsgCancelSign").show();
            thisInput.value = strsigns[0] + "," + strsigns[1];
            tmDialog.hide();
          } else {
            alert("密码不正确");
          }
        });
      });
      this.jQueryObj.children(".taskmsgCancelSign").click(function () {
        var strsigns = thisInput.sign.split(",");
        if (!strsigns[2]) {
          $("#inputLi_" + thisInput.id).children("input[type=hidden]").val("");
          $("#inputLi_" + thisInput.id).children("input[type=text]").val("").hide();
          $("#inputLi_" + thisInput.id).children("img").attr("src", "").hide();
          $("#inputLi_" + thisInput.id).children(".taskmsgSign").show();
          $("#inputLi_" + thisInput.id).children(".taskmsgCancelSign").hide();
          thisInput.value = "";
          return;
        }
        var content = "<div style=\"margin:20px 0px;text-align:center;\">";
        content += "请输入签章密码";
        content += "<br />";
        content += "<br />";
        content += "<input type=\"password\" class=\"TaskMsgInput\" style=\"width:185px;\" />";
        content += "</div>";
        tmDialog.showFullScreenDialog(content, true, function () {
          var strsigns = thisInput.sign.split(",");
          var mm = $(".TaskMsgDialog").find("input[type=password]").val();
          if (strsigns[2] == mm) {
            $("#inputLi_" + thisInput.id).children("input[type=hidden]").val("");
            $("#inputLi_" + thisInput.id).children("input[type=text]").val("");
            $("#inputLi_" + thisInput.id).children("img").attr("src", "").hide();
            $("#inputLi_" + thisInput.id).children(".taskmsgSign").show();
            $("#inputLi_" + thisInput.id).children(".taskmsgCancelSign").hide();
            thisInput.value = "";
            tmDialog.hide();
          } else {
            alert("密码不正确");
          }
        });
      });
    } else if (this.type == "countersign") {
      //非只读无值
      if (!this.readonly && !this.value) {
        //                if (thisInput.sign.split(",")[2]) {
        this.jQueryObj.children(".taskmsgSign").show();
        //                } else {
        //                    var strsigns = thisInput.sign.split(","); //bh,mc,mm,lj
        //                    var dv0 = thisInput.defaultvalue.split("~");
        //                    var dv = dv0[0].split(",");
        //                    $("#inputLi_" + thisInput.id).children("input[type=hidden]").val(strsigns[0]);
        //                    $("#inputLi_" + thisInput.id).children("input[mtype=name]").val(strsigns[1]);
        //                    $("#inputLi_" + thisInput.id).children("img").attr("src", strsigns[3]).show();
        //                    $("#inputLi_" + thisInput.id).children(".taskmsgSign").hide();
        //                    $("#inputLi_" + thisInput.id).children("textarea").html(dv0[1]).show();
        //                    $("#inputLi_" + thisInput.id).children("input[mtype=user]").val(dv[1]).show();
        //                    $("#inputLi_" + thisInput.id).children("input[mtype=dep]").val(dv[6]).show();
        //                    $("#inputLi_" + thisInput.id).children("input[mtype=date]").val(dv[4]).show();
        //                    $("#inputLi_" + thisInput.id).children("input[mtype=time]").val(dv[5]).show();
        //                    thisInput.value = strsigns[0] + "," + dv[1] + ",Sign," + strsigns[1] + "," + dv[4] + "," + dv[5] + "," + dv[6] + "~" + dv0[1];
        //                }
      }

      this.jQueryObj.children(".taskmsgSign").click(function () {
        var strsigns = thisInput.sign.split(",");
        if (!strsigns[2]) {
          var dv0 = thisInput.defaultvalue.split("~");
          var dv = dv0[0].split(",");
          $("#inputLi_" + thisInput.id).children("input[type=hidden]").val(strsigns[0]);
          if (!strsigns[3]) {
            $("#inputLi_" + thisInput.id).children("input[mtype=name]").val(strsigns[1]).show();
          } else {
            $("#inputLi_" + thisInput.id).children("img").attr("src", strsigns[3]).show();
          }
          $("#inputLi_" + thisInput.id).children(".taskmsgSign").hide();
          $("#inputLi_" + thisInput.id).children(".taskmsgCancelSign").show();
          $("#inputLi_" + thisInput.id).children("textarea").html(dv0[1]).show();
          $("#inputLi_" + thisInput.id).children("input[mtype=user]").val(dv[1]).show();
          $("#inputLi_" + thisInput.id).children("input[mtype=dep]").val(dv[6]).show();
          $("#inputLi_" + thisInput.id).children("input[mtype=date]").val(dv[4]).show();
          $("#inputLi_" + thisInput.id).children("input[mtype=time]").val(dv[5]).show();
          thisInput.value = strsigns[0] + "," + dv[1] + ",," + strsigns[1] + "," + dv[4] + "," + dv[5] + "," + dv[6] + "~" + dv0[1];
          return;
        }
        var content = "<div style=\"margin:20px 0px;text-align:center;\">";
        content += "请输入签章密码";
        content += "<br />";
        content += "<br />";
        content += "<input type=\"password\" class=\"TaskMsgInput\" style=\"width:185px;\" />";
        content += "</div>";
        tmDialog.showFullScreenDialog(content, true, function () {
          var strsigns = thisInput.sign.split(","); //bh,mc,mm,lj
          var mm = $(".TaskMsgDialog").find("input[type=password]").val();
          if (strsigns[2] == mm) {
            var dv0 = thisInput.defaultvalue.split("~");
            var dv = dv0[0].split(",");
            $("#inputLi_" + thisInput.id).children("input[type=hidden]").val(strsigns[0]);
            if (!strsigns[3]) {
              $("#inputLi_" + thisInput.id).children("input[mtype=name]").val(strsigns[1]).show();
            } else {
              $("#inputLi_" + thisInput.id).children("img").attr("src", strsigns[3]).show();
            }
            $("#inputLi_" + thisInput.id).children(".taskmsgSign").hide();
            $("#inputLi_" + thisInput.id).children(".taskmsgCancelSign").show();
            $("#inputLi_" + thisInput.id).children("textarea").html(dv0[1]).show();
            $("#inputLi_" + thisInput.id).children("input[mtype=user]").val(dv[1]).show();
            $("#inputLi_" + thisInput.id).children("input[mtype=dep]").val(dv[6]).show();
            $("#inputLi_" + thisInput.id).children("input[mtype=date]").val(dv[4]).show();
            $("#inputLi_" + thisInput.id).children("input[mtype=time]").val(dv[5]).show();
            thisInput.value = strsigns[0] + "," + dv[1] + ",Sign," + strsigns[1] + "," + dv[4] + "," + dv[5] + "," + dv[6] + "~" + dv0[1];
            tmDialog.hide();
          } else {
            alert("密码不正确");
          }
        });
      });
      this.jQueryObj.children(".taskmsgCancelSign").click(function () {
        var strsigns = thisInput.sign.split(",");
        if (!strsigns[2]) {
          $("#inputLi_" + thisInput.id).children("input[type=hidden]").val("");
          $("#inputLi_" + thisInput.id).children("input[mtype=name]").val("").hide();
          $("#inputLi_" + thisInput.id).children("img").attr("src", "").hide();
          $("#inputLi_" + thisInput.id).children(".taskmsgSign").show();
          $("#inputLi_" + thisInput.id).children(".taskmsgCancelSign").hide();
          $("#inputLi_" + thisInput.id).children("textarea").hide();
          $("#inputLi_" + thisInput.id).children("input[mtype=user]").hide();
          $("#inputLi_" + thisInput.id).children("input[mtype=dep]").hide();
          $("#inputLi_" + thisInput.id).children("input[mtype=date]").hide();
          $("#inputLi_" + thisInput.id).children("input[mtype=time]").hide();
          thisInput.value = "";
          return;
        }
        var content = "<div style=\"margin:20px 0px;text-align:center;\">";
        content += "请输入签章密码";
        content += "<br />";
        content += "<br />";
        content += "<input type=\"password\" class=\"TaskMsgInput\" style=\"width:185px;\" />";
        content += "</div>";
        tmDialog.showFullScreenDialog(content, true, function () {
          var strsigns = thisInput.sign.split(",");
          var mm = $(".TaskMsgDialog").find("input[type=password]").val();
          if (strsigns[2] == mm) {
            $("#inputLi_" + thisInput.id).children("input[type=hidden]").val("");
            $("#inputLi_" + thisInput.id).children("input[mtype=name]").val("").hide();
            $("#inputLi_" + thisInput.id).children("img").attr("src", "").hide();
            $("#inputLi_" + thisInput.id).children(".taskmsgSign").show();
            $("#inputLi_" + thisInput.id).children(".taskmsgCancelSign").hide();
            $("#inputLi_" + thisInput.id).children("textarea").hide();
            $("#inputLi_" + thisInput.id).children("input[mtype=user]").hide();
            $("#inputLi_" + thisInput.id).children("input[mtype=dep]").hide();
            $("#inputLi_" + thisInput.id).children("input[mtype=date]").hide();
            $("#inputLi_" + thisInput.id).children("input[mtype=time]").hide();
            thisInput.value = "";
            tmDialog.hide();
          } else {
            alert("密码不正确");
          }
        });
      });
    } else if (this.type == "list") {
      this.jQueryObj.click(function () {
        if (thisInput.onClick) {
          eval(thisInput.onClick + "('" + thisInput.form.id + "','" + thisInput.id + "')");
          return;
        }
        if (!thisInput.values || thisInput.readonly) return;
        var vals = [];
        if (thisInput.value) vals = (thisInput.value + "").split(",");
        var content = "<ul>";
        for (var i = 0; i < thisInput.values.length; i++) {
          content += "<li onClick=\"TaskMsg_ListInput_ItemOnClick('" +
            thisInput.form.id + "','" + thisInput.id + "'," + i + ")\">";
          if (thisInput.multi) {
            content += "<input type=\"checkbox\" value=\"" + i + "\"";
            for (var j = 0; j < vals.length; j++) {
              if (vals[j] == thisInput.values[i]) {
                content += " checked";
              }
            }
            content += ">";
          }
          content += "<label>" + thisInput.texts[i] + "</label></li>";
        }
        content += "</ul>";
        tmDialog.showFullScreenDialog(content, thisInput.multi, function () {
          var vals = "";
          var texts = "";
          $(".TaskMsgDialog").find("input").each(function () {
            if ($(this).get(0).checked) {
              if (vals != "") {
                vals += ",";
                texts += "、";
              }
              var index = parseInt($(this).val());
              vals += thisInput.values[index];
              texts += thisInput.texts[index];
            }
          });
          thisInput.value = vals;
          thisInput.jQueryObj.find("input").val(texts);
          tmDialog.hide();
          return;
        });
      });
    } else if (this.useKeyboard && !this.readonly) {
      this.initNotReadOnlyInput();
    }
    if (this.hidden) this.jQueryObj.hide();

    this.isRendered = true;
  };

  /**
   * 重新加载控件数据
   */
  this.reload = function () {
    this.setValue(null);
    this.loadData();
  };

  /**
   * 加载控件数据
   */
  this.loadData = function () {
    if (!this.getDataListService) return;
    var service = new TaskMsgService(this.getDataListService);
    service.request(null, function (req, res) {
      thisInput.dataBindList(res);
    });
  };

  /**
   * 绑定控件数据
   * @param  {[type]} res [description]
   */
  this.dataBind = function (res) {
    /*
    if(this.dataListMember) {
      if(this.type=="list") {
        this.values = [];
        this.texts = [];
        var dataList = res[this.dataListMember];
        if(dataList) {
          if(dataList instanceof Array) {
            for(var i=0;i<dataList.length;i++) {
              this.values.push(dataList[i][this.valueField]);
              this.texts.push(dataList[i][this.textField]);
            }
          } else {
            for(objId in dataList) {
              this.values.push(dataList[objId][this.valueField]);
              this.texts.push(dataList[objId][this.textField]);
            }
          }
        }
      }
    }
    if(this.id=="target_type") console.log(this.id+":"+this.value);

    if(!this.form.dataSource) return;
    if(this.value || this.value==0) {
      this.setValue(this.value);
      return;
    }
    if(this.dataField) {
      var val = this.form.dataSource[this.dataField];
      this.setValue(val);
    } else if(this.id in this.form.dataSource) {
      var val = this.form.dataSource[this.id];
      if(this.id=="target_type") console.log("target_type:"+val);
      if(val||val==0) this.setValue(val);
    }
    */

    if (this.id == "target_type") console.log(this.id + ":" + this.value);

    var val;
    if (this.value || this.value === 0) val = this.value;
    if (!this.form.dataSource) return;
    if (this.dataField) {
      val = this.form.dataSource[this.dataField];
    } else if (this.id in this.form.dataSource) {
      val = this.form.dataSource[this.id];
    }

    if (val) {
      if (this.type == "date") val = (new Date(val)).format("yyyy-MM-dd");
      if (this.type == "time") val = (new Date()).format("hh:mm");
      if (this.type == "datetime") val = (new Date()).format("yyyy-MM-dd hh:mm");
    }
    this.setValue(val);
  };

  /**
   * 绑定控件数据
   * @param  {[type]} res [description]
   */
  this.dataBindList = function (res) {
    if (this.dataListMember) {
      if (this.type == "list") {
        this.values = [];
        this.texts = [];
        var dataList = res[this.dataListMember];
        if (dataList) {
          if (dataList instanceof Array) {
            for (var i = 0; i < dataList.length; i++) {
              this.values.push(dataList[i][this.valueField]);
              this.texts.push(dataList[i][this.textField]);
            }
          } else {
            for (objId in dataList) {
              this.values.push(dataList[objId][this.valueField]);
              this.texts.push(dataList[objId][this.textField]);
            }
          }
        }
      }
    }
  };

  /**
   * 设置控件值
   * @param {[type]} value [description]
   */
  this.setValue = function (value) {
    this.value = value;
    if (this.type == "sign") { //
      var strsigns = eval("this.signs.V" + this.value.replace(",", "V")).split(",");
      this.jQueryObj.children("input[type=hidden]").val(strsigns[0]);
      if (strsigns[3]) {
        this.jQueryObj.children("img").attr("src", strsigns[3]).show();
        this.jQueryObj.children("input[type=text]").val(strsigns[1]);
      } else {
        this.jQueryObj.children("input[type=text]").val(strsigns[1]).show();
      }
      //编辑时显示取消按钮
      if (!this.readonly) {
        if (strsigns[0] == this.value.split(",")[0])
          this.jQueryObj.children(".taskmsgCancelSign").show();
      }
    } else if (this.type == "countersign") { //
      var vtmps0 = this.value.split("~");
      var vtmps = vtmps0[0].split(",");

      this.jQueryObj.children("input[type=hidden]").val(vtmps[0]);
      this.jQueryObj.children("textarea").html(vtmps0[1]).show();
      this.jQueryObj.children("input[mtype=user]").val(vtmps[1]).show();
      this.jQueryObj.children("input[mtype=dep]").val(vtmps[6]).show();
      this.jQueryObj.children("input[mtype=date]").val(vtmps[4]).show();
      this.jQueryObj.children("input[mtype=time]").val(vtmps[5]).show();

      var strsigns = this.sign.split(",");
      if (strsigns[3]) {
        this.jQueryObj.children("img").attr("src", strsigns[3]).show();
        this.jQueryObj.children("input[mtype=name]").val(strsigns[1]);
      } else {
        this.jQueryObj.children("input[mtype=name]").val(strsigns[1]).show();
      }

      if (!this.readonly) {
        this.jQueryObj.children(".taskmsgCancelSign").show();
      }
    } else if (this.type == "switch" || this.type == "switchs") {
      if (!this.values) return;
      if ((this.value + "") == (this.values[0] + "")) {
        this.status = [this.type + "On", this.type + "Off"];
      } else {
        this.status = [this.type + "Off", this.type + "On"];
      }
      this.jQueryObj.children("div").children("div").each(function (index) {
        $(this).attr("class", thisInput.status[index]);
      });
    } else if (this.type == "list") {
      if (!this.values || !this.texts) return;
      if (!this.value || this.value == "") {
        this.jQueryObj.find("input").val("");
        return;
      }
      if (this.multi) {
        var vals = (this.value + "").split(",");
        var txts = "";
        for (var i = 0; i < this.values.length; i++) {
          for (var j = 0; j < vals.length; j++) {
            if (vals[j] == this.values[i]) {
              if (txts !== "") txts += "、";
              txts += this.texts[i];
              break;
            }
          }
        }
        this.jQueryObj.find("input").val(txts);
      } else {
        for (var i = 0; i < this.values.length; i++) {
          if (this.value == this.values[i]) {
            this.jQueryObj.find("input").val(this.texts[i]);
            break;
          }
        }
      }
    } else if (this.type == "user" || this.type == "dep" || this.type == "group" || this.type == "tree") {
      if (this.multi) {
        if (!this.value) this.value = [];
        var txts = "";
        for (var i = 0; i < this.value.length; i++) {
          if (txts !== "") txts += "、";
          txts += this.value[i].name;
        }
        this.jQueryObj.find("input").val(txts);
      } else {
        if (this.value) {
          this.jQueryObj.find("input").val(this.value.name);
        } else {
          this.jQueryObj.find("input").val("");
        }
      }
    } else if (this.type == "file") {
      if (!this.value) return;
      curTaskMsgInput = this;
      TaskMsg_OnSelectFiles(this.value);
      curTaskMsgInput = null;
    } else if (this.type == "photo") {
      if (!this.value) return;
      curTaskMsgInput = this;
      TaskMsg_OnSelectPhotos(this.value);
      curTaskMsgInput = null;
    } else if (this.type == "camera") {
      if (!this.value) return;
      curTaskMsgInput = this;
      TaskMsg_OnTakePhoto(this.value);
      curTaskMsgInput = null;
    } else if (this.type == "voice") {
      if (!this.value) return;
      curTaskMsgInput = this;
      TaskMsg_OnAudioRecord(this.value);
      curTaskMsgInput = null;
    } else if (this.type == "location") {
      if (!this.value) return;
      curTaskMsgInput = this;
      TaskMsg_OnGetLocation(this.value);
      curTaskMsgInput = null;
    } else if (this.type == "textarea") {
      if (!this.value) this.value = "";
      if (this.readonly) {
        this.jQueryObj.find("pre").html(this.value);
      } else {
        this.jQueryObj.find("textarea").val(this.value);
      }
    } else if (this.type == "barcode") {
      if (this.value) {
        curTaskMsgInput = this;
        TaskMsg_OnCodeScaned(this.value);
        curTaskMsgInput = null;
      }
    } else if (this.type == "money") {
      if (!this.value) {
        this.value = "";
      } else {
        this.value = formatMoney(this.value, 2);
      }
      this.jQueryObj.find("input").val(this.value);
    } else if (this.type == "submit") {} else {
      if (!this.value) this.value = "";
      if (this.type == "text" && !this.showLabel && this.readonly) {
        this.jQueryObj.find("pre").html(this.value);
      } else {
        this.jQueryObj.find("input").val(this.value);
      }
    }
  };

  /**
   * 获得控件值
   * @return {[type]} [description]
   */
  this.getValue = function () {
    if (this.type == "switch" || this.type == "switchs" || this.type == "list" || this.type == "user" ||
      this.type == "dep" || this.type == "group" || this.type == "tree" ||
      this.type == "file" || this.type == "photo" || this.type == "voice" ||
      this.type == "location" || this.type == "sign") {} else if (this.type == "textarea" || this.type == "barcode") {
      this.value = this.jQueryObj.find("textarea").val();
      if (this.value) this.value = this.value.replace("请输入" + this.label, "");
      // } else if (this.type == "sign") {
      //   var v = this.jQueryObj.find("input[type=hidden]").val();
      //   var t = this.jQueryObj.find("input[type=text]").val();
      //   if (v || t) this.value = v + "," + t;
    } else if (this.type == "countersign") { //
      var v = this.jQueryObj.find("input[type=hidden]").val();
      if (v) {
        var v2 = "";
        if (this.jQueryObj.find("img").is(':visible')) v2 = "Sign";
        var v0 = this.jQueryObj.find("input[type=hidden]").val();
        if (!v0) v0 = "";
        var v1 = this.jQueryObj.find("input[mtype=user]").val();
        if (!v1) v1 = "";
        var v3 = this.jQueryObj.find("input[mtype=name]").val();
        if (!v3) v3 = "";
        var v4 = this.jQueryObj.find("input[mtype=date]").val();
        if (!v4) v4 = "";
        var v5 = this.jQueryObj.find("input[mtype=time]").val();
        if (!v5) v5 = "";
        var v6 = this.jQueryObj.find("input[mtype=dep]").val();
        if (!v6) v6 = "";
        var v7 = this.jQueryObj.find("textarea").val();
        if (!v7) v7 = "";
        this.value = v0 + "," + v1 + "," + v2 + "," + v3 + "," + v4 + "," + v5 + "," + v6 + "~" + v7;
      }
    } else {
      this.value = this.jQueryObj.find("input").val();
      if (this.value) this.value = this.value.replace("请输入" + this.label, "");
      if (this.value && this.type == "money") this.value = this.value.replace(/,/g, "");
    }
    if (!this.value) this.value = "";
    return this.value;
  };

  /**
   * 判断输入项的值是否有效
   * @return {Boolean} [description]
   */
  this.isValid = function () {
    if (!(this.value || this.value == 0) && this.notNull) return false;
    if (this.value) {
      if (this.type == "email") return isEmail(this.value);
      if (this.type == "mobile") return isMobile(this.value);
      if (this.type == "tel") return isTel(this.value);
      if (this.type == "postCode") return isPostCode(this.value);
      //if(this.type=="varCode") return true;
      if (this.type == "idCard") return isIdCard(this.value);
      if (this.type == "number" || this.type == "money")
        return !isNaN(this.value.replace(/,/g, ""));
      if (this.type == "int") return isInt(this.value);
    }
    return true;
  };

  /**
   * 初始化非只读输入项
   */
  this.initNotReadOnlyInput = function () {
    this.jQueryObj.find("input").blur(function () {
      if (!(!thisInput.value && $(this).val() == "") &&
        thisInput.value + "" != $(this).val() + "" &&
        thisInput.onChange)
        eval(thisInput.onChange);
      thisInput.value = $(this).val();
      if (!thisInput.isValid()) {
        $(this).addClass("invalidInput");
        $(this).focus();
        return;
      }
      $(this).removeClass("invalidInput");
      if (thisInput.value && thisInput.type == "money")
        $(this).val(formatMoney(thisInput.value, 2));
      if (thisInput.value && thisInput.type == "int")
        $(this).val(parseInt(thisInput.value));
      if (thisInput.type == "text" && !thisInput.showLabel &&
        (!thisInput.value || thisInput.value == "")) {
        $(this).get(0).value = "请输入" + thisInput.label;
      }
    });
    this.jQueryObj.click(function () {
      thisInput.jQueryObj.find("input").focus();
    });
  };

  this.show = function () {
    this.jQueryObj.show();
    this.hidden = false;
  };

  this.hide = function () {
    this.jQueryObj.hide();
    this.hidden = true;
  };
}

/**
 * 点击列表控件数据项时
 * @param {[type]} formId [description]
 * @param {[type]} inputId   [description]
 * @param {[type]} itemIndex [description]
 */
function TaskMsg_ListInput_ItemOnClick(formId, inputId, itemIndex) {
  var form = taskMsgForms[formId];
  if (!form) return;
  var list = form.inputs[inputId];
  if (!list) return;
  if (list.multi) {
    if (window.event.srcElement.tagName == "INPUT") return;
    var cbk = $(".TaskMsgDialog").find("input").get(itemIndex);
    if (cbk.checked) {
      cbk.checked = false;
    } else {
      cbk.checked = true;
    }
  } else {
    tmDialog.hide();
    tmClient.enableTitleButton();
    list.value = list.values[itemIndex];
    list.jQueryObj.find("input").val(list.texts[itemIndex]);
  }
  if (curTaskMsgInput.onChange) eval(curTaskMsgInput.onChange);
}

/**
 * 添加图片
 * @param {[type]} formId [description]
 * @param {[type]} inputId   [description]
 */
function TaskMsg_Input_OnClick(formId, inputId) {
  var form = taskMsgForms[formId];
  if (!form) return;
  var ipt = form.inputs[inputId];
  if (!ipt) return;
  curTaskMsgInput = ipt;
  if (ipt.type == "file") {
    if (ipt.readonly) {
      tmClient.showAttachList(form.appCode + ".file", form.appDataId);
    } else {
      if (ipt.maxlength && ipt.value && ipt.value.length >= ipt.maxlength) {
        alert("最多只能选择" + ipt.maxlength + "个文件！");
        return;
      }
      tmClient.showFilePicker("TaskMsg_OnSelectFiles", ipt.multi);
    }
  } else if (ipt.type == "photo") {
    if (ipt.maxlength && ipt.value && ipt.value.length >= ipt.maxlength) {
      alert("最多只能选择" + ipt.maxlength + "张图片！");
      return;
    }
    if (ipt.onlyCamera) {
      if (ipt.getWaterMarkFunc) {
        eval(ipt.getWaterMarkFunc + "('" + formId + "','" + inputId + "')");
      } else {
        tmClient.takePhoto("TaskMsg_OnTakePhoto", ipt.compress);
      }
    } else {
      tmClient.showImagePicker("TaskMsg_OnSelectPhotos", ipt.multi);
    }
  } else if (ipt.type == "user") {
    tmClient.showUserPicker("TaskMsg_OnSelectOrgObjs", ipt.multi, ipt.selectSelf);
  } else if (ipt.type == "dep") {
    tmClient.showDepPicker("TaskMsg_OnSelectOrgObjs", ipt.multi);
  } else if (ipt.type == "group") {
    //tmClient.showGroupPicker();
  } else if (ipt.type == "tree") {
    tmClient.showTreePicker("TaskMsg_OnSelectOrgObjs", ipt.multi, ipt.cascade, ipt.label, ipt.tmp, ipt.nodes, ipt.leafs);
  } else if (ipt.type == "voice") {
    tmClient.showAudioRecorder("TaskMsg_OnAudioRecord");
  } else if (ipt.type == "barcode") {
    tmClient.showCodeScanner("TaskMsg_OnCodeScaned");
  } else if (ipt.type == "location") {
    tmClient.showLocation(null, null, "TaskMsg_OnGetLocation");
  } else if (ipt.type == "date" || ipt.type == "time" || ipt.type == "datetime") {
    tmClient.showDateTimePicker("TaskMsg_OnSelectDateTime", ipt.type, ipt.value);
  }
}

/**
 * 删除图片
 * @param {[type]} formId [description]
 * @param {[type]} inputId   [description]
 */
function TaskMsg_ImagePicker_Del(formId, inputId) {
  var form = taskMsgForms[formId];
  if (!form) return;
  var ipt = form.inputs[inputId];
  if (!ipt) return;
  curTaskMsgInput = ipt;
  if (curTaskMsgInput.onChange) eval(curTaskMsgInput.onChange);
}

/**
 * 使用浏览器扩展选择完日期后
 * @param {[type]} val [description]
 */
function TaskMsg_OnSelectDateTime(val) {
  curTaskMsgInput.value = val;
  curTaskMsgInput.jQueryObj.find("input").val(val);
  if (curTaskMsgInput.onChange) eval(curTaskMsgInput.onChange);
}

/**
 * 任信客户端扩展选择完组织结构数据后
 * @param  {[type]} objs [description]
 * @return {[type]}      [description]
 */
function TaskMsg_OnSelectOrgObjs(objs) {
  var names = "";
  var values = "";
  for (var i = 0; i < objs.length; i++) {
    if (names != "") {
      names += "、";
    }
    if (values != "") {
      values += ",";
    }
    var obj = objs[i];
    names += obj.name;
    values += obj.id;
  }
  if (curTaskMsgInput.multi) {
    curTaskMsgInput.value = objs;
    curTaskMsgInput.tmp = values;
  } else {
    curTaskMsgInput.value = objs[0];
    curTaskMsgInput.tmp = values;
  }
  curTaskMsgInput.jQueryObj.find("input").val(names);
  if (curTaskMsgInput.onChange) eval(curTaskMsgInput.onChange);
}

/**
 * 任信客户端扩展选择完文件
 * @param  {[type]} objs [description]
 * @return {[type]}      [description]
 */
function TaskMsg_OnSelectFiles(files) {
  if (curTaskMsgInput.readonly) {
    if (Object.prototype.toString.call(files) === "[object Array]") {
      curTaskMsgInput.jQueryObj.find("input").val(files.length + "个");
    } else {
      curTaskMsgInput.jQueryObj.find("input").val("1个");
    }
    return;
  }
  if (curTaskMsgInput.multi) {
    if (!curTaskMsgInput.value) curTaskMsgInput.value = [];
    if (curTaskMsgInput.maxlength && curTaskMsgInput.value.length >= curTaskMsgInput.maxlength) {
      alert("最多只能选择" + curTaskMsgInput.maxlength + "个文件！");
      return;
    }
    var fileIptWidth = ($(window.document).width() - 95) + "px";
    for (var i = 0; i < files.length; i++) {
      if (curTaskMsgInput.maxlength && curTaskMsgInput.value.length >= curTaskMsgInput.maxlength) {
        break;
      }
      var file = files[i];
      if (!curTaskMsgInput.form.isIniting && curTaskMsgInput.isRendered) {
        var isExist = false;
        for (var j = 0; j < curTaskMsgInput.value.length; j++) {
          if ((file.path && file.path == curTaskMsgInput.value[j].path) ||
            (file.code && file.code == curTaskMsgInput.value[j].code)) {
            isExist = true;
            break;
          }
        }
        if (isExist) continue;
      }
      if (!file.path) file.path = "";
      if (!file.code) file.code = "";
      var ext = "";
      if (file.name.lastIndexOf(".") > 0) ext = file.name.substr(file.name.lastIndexOf(".")) + " ";
      curTaskMsgInput.jQueryObj.append("<div class=\"fileInfo\">" +
        "<img class=\"fileInfo_icon\" src=\"" + TaskMsgClientAPIDir + "images/file.png\">" +
        "<div class=\"fileInfo_right\"><input class=\"fileInfo_name\" style=\"width:" +
        fileIptWidth + "\" type=\"text\" value=\"" + file.name + "\" readonly />" +
        "<div class=\"fileInfo_bottom\" style=\"width:" + fileIptWidth + "\">" +
        "<div class=\"fileInfo_size\">" + ext + formatFileSize(file.size) + "</div>" +
        "<div class=\"fileInfo_del\" onClick=\"TaskMsg_FilePicker_Del('" +
        curTaskMsgInput.form.id + "','" + curTaskMsgInput.id + "',this,'" + file.path +
        "','" + file.code + "')\">删除</div></div></div>");
      if (!curTaskMsgInput.form.isIniting && curTaskMsgInput.isRendered) curTaskMsgInput.value.push(file);
    }
  } else {
    if (Object.prototype.toString.call(files) === "[object Array]") {
      curTaskMsgInput.value = files[0];
    } else {
      curTaskMsgInput.value = files;
    }
    curTaskMsgInput.jQueryObj.find("input").val(curTaskMsgInput.value.name);
  }
  if (curTaskMsgInput.onChange) eval(curTaskMsgInput.onChange);
}

/**
 * 删除文件时
 * @param {[type]} formId [description]
 * @param {[type]} delLink   [description]
 * @param {[type]} path      [description]
 */
function TaskMsg_FilePicker_Del(formId, inputId, delLink, path, code) {
  var form = taskMsgForms[formId];
  if (!form) return;
  var ipt = form.inputs[inputId];
  if (!ipt) return;
  for (var j = 0; j < ipt.value.length; j++) {
    var file = ipt.value[j];
    if ((path != "" && path == file.path) ||
      (code != "" && code == file.code)) {
      ipt.value.deleteMember(file);
      break;
    }
  }
  $(delLink).parent().parent().parent().remove();
  if (curTaskMsgInput.onChange) eval(curTaskMsgInput.onChange);
}

/**
 * 拍照后
 * @param {[type]} path [description]
 * @param {[type]} size [description]
 */
function TaskMsg_OnTakePhoto(path, size) {
  if (typeof (path) == "String") {
    TaskMsg_OnSelectPhotos([{
      "path": path,
      "size": size
    }]);
  } else if (Object.prototype.toString.call(path) === "[object Array]") {
    TaskMsg_OnSelectPhotos(path);
  } else {
    TaskMsg_OnSelectPhotos([path]);
  }
}

/**
 * 选择完图片后
 * @param {[type]} images [description]
 */
function TaskMsg_OnSelectPhotos(images) {
  if (curTaskMsgInput.multi) {
    if (!curTaskMsgInput.value) curTaskMsgInput.value = [];
    if (curTaskMsgInput.maxlength && curTaskMsgInput.value.length >= curTaskMsgInput.maxlength) {
      alert("最多只能选择" + curTaskMsgInput.maxlength + "张图片！");
      return;
    }
    for (var i = 0; i < images.length; i++) {
      if (curTaskMsgInput.maxlength && curTaskMsgInput.value.length >= curTaskMsgInput.maxlength) {
        if (!curTaskMsgInput.readonly) break;
      }
      var image = images[i];
      var src = "";
      if (image.path) {
        src = tmClient.getLocalImageBase64Str(image.path);
      } else {
        src = "/TaskMsgDownload?fileCode=" + image.code + "&thumbnail=true&sessionId=" + tmClient.sessionId;
      }
      if (!image.path)
        image.path = '';
      if (!image.code)
        image.code = '';
      var str = "<img class=\"photoThumbnail\" src=\"" + src + "\" onclick=\"tmClient.showImage('" +
        image.path + "','" + image.code + "')\" />";
      if (curTaskMsgInput.readonly) {
        curTaskMsgInput.jQueryObj.find(".flexContent").append(str);
      } else {
        $(str).insertBefore(curTaskMsgInput.jQueryObj.find(".photo_addBtn"));
      }
      if (!curTaskMsgInput.form.isIniting && curTaskMsgInput.isRendered) curTaskMsgInput.value.push(image);
    }
    if (curTaskMsgInput.showLabel) {
      if (curTaskMsgInput.readonly) {
        curTaskMsgInput.jQueryObj.css("height", ((Math.floor((curTaskMsgInput.value.length - 1) / 3) + 1) * 100 + 60) + "px");
      } else {
        curTaskMsgInput.jQueryObj.css("height", ((Math.floor(curTaskMsgInput.value.length / 3) + 1) * 100 + 60) + "px");
      }
    } else {
      if (curTaskMsgInput.readonly) {
        curTaskMsgInput.jQueryObj.css("height", ((Math.floor((curTaskMsgInput.value.length - 1) / 3) + 1) * 100 + 10) + "px");
      } else {
        curTaskMsgInput.jQueryObj.css("height", ((Math.floor(curTaskMsgInput.value.length / 3) + 1) * 100 + 10) + "px");
      }
    }
  } else {
    if (Object.prototype.toString.call(images) === "[object Array]") {
      curTaskMsgInput.value = images[0];
    } else {
      curTaskMsgInput.value = images;
    }
    var src = "";
    if (curTaskMsgInput.value.path) {
      src = tmClient.getLocalImageBase64Str(curTaskMsgInput.value.path);
    } else {
      src = "/TaskMsgDownload?fileCode=" + curTaskMsgInput.value.code +
        "&thumbnail=true&sessionId=" + tmClient.sessionId;
    }
    if (!curTaskMsgInput.value.path)
      curTaskMsgInput.value.path = '';
    if (!curTaskMsgInput.value.code)
      curTaskMsgInput.value.code = '';
    curTaskMsgInput.jQueryObj.find(".photoThumbnail").remove();
    var str = "<img class=\"photoThumbnail\" src=\"" +
      src + "\" onclick=\"tmClient.showImage('" +
      curTaskMsgInput.value.path + "','" + curTaskMsgInput.value.code +
      "')\" />";
    if (curTaskMsgInput.readonly) {
      curTaskMsgInput.jQueryObj.find(".flexContent").append(str);
    } else {
      $(str).insertBefore(curTaskMsgInput.jQueryObj.find(".photo_addBtn"));
    }
  }
  if (curTaskMsgInput.value && !curTaskMsgInput.readonly &&
    curTaskMsgInput.jQueryObj.find(".photo_delBtn").length == 0) {
    $("<img class=\"photo_delBtn\" src=\"" + TaskMsgClientAPIDir +
      "images/minus90.png\" onClick=\"TaskMsg_ImagePicker_Del('" +
      curTaskMsgInput.form.id + "','" + curTaskMsgInput.id + "')\" />").insertAfter(
      curTaskMsgInput.jQueryObj.find(".photo_addBtn"));
  }
  if (curTaskMsgInput.onChange) eval(curTaskMsgInput.onChange);
}

/**
 * 删除图片
 * @param {[type]} formId [description]
 * @param {[type]} inputId   [description]
 */
function TaskMsg_ImagePicker_Del(formId, inputId) {
  var form = taskMsgForms[formId];
  if (!form) return;
  var ipt = form.inputs[inputId];
  if (!ipt) return;
  ipt.jQueryObj.find(".photoThumbnail").last().remove();
  if (ipt.multi) {
    ipt.value.deleteMember(ipt.value[ipt.value.length - 1]);
    if (ipt.showLabel) {
      if (ipt.readonly) {
        ipt.jQueryObj.css("height", ((Math.floor((ipt.value.length - 1) / 3) + 1) * 100 + 60) + "px");
      } else {
        ipt.jQueryObj.css("height", ((Math.floor(ipt.value.length / 3) + 1) * 100 + 60) + "px");
      }
    } else {
      if (ipt.readonly) {
        ipt.jQueryObj.css("height", ((Math.floor((ipt.value.length - 1) / 3) + 1) * 100 + 10) + "px");
      } else {
        ipt.jQueryObj.css("height", ((Math.floor(ipt.value.length / 3) + 1) * 100 + 10) + "px");
      }
    }
  } else {
    ipt.value = null;
  }
  if (!ipt.value || (ipt.multi && ipt.value.length == 0)) {
    ipt.jQueryObj.find(".photo_delBtn").remove();
  }
  if (ipt.onChange) eval(ipt.onChange);
}

/**
 * 获得位置后
 * @param {[type]} locInfo [description]
 */
function TaskMsg_OnGetLocation(locInfo) {
  curTaskMsgInput.value = locInfo;
  curTaskMsgInput.jQueryObj.find("input").val(locInfo.addrStr);
  if (curTaskMsgInput.onChange) eval(curTaskMsgInput.onChange);
}

/**
 * 播放录音
 * @param {[type]} formId [description]
 * @param {[type]} inputId   [description]
 */
function TaskMsg_AudioRecord_Play(formId, inputId) {
  var form = taskMsgForms[formId];
  if (!form) return;
  var ipt = form.inputs[inputId];
  if (!ipt) return;
  if (!ipt.value) {
    curTaskMsgInput = ipt;
    tmClient.showAudioRecorder("TaskMsg_OnAudioRecord");
  } else {
    if (ipt.value.code && (ipt.readonly || !ipt.value.path)) {
      tmClient.playAudio(null, ipt.value.code);
    } else {
      tmClient.playAudio(ipt.value.path);
    }
  }
}

/**
 * 删除录音
 * @param {[type]} formId [description]
 * @param {[type]} inputId   [description]
 */
function TaskMsg_AudioRecord_Del(formId, inputId) {
  var form = taskMsgForms[formId];
  if (!form) return;
  var ipt = form.inputs[inputId];
  if (!ipt) return;
  ipt.value = null;
  ipt.jQueryObj.find(".inputRightIcon").remove();
  ipt.jQueryObj.find(".voicePlayer").remove();
  ipt.jQueryObj.append("<span class=\"inputGt\">" +
    "&gt;</span><input type=\"text\" ctype=\"" + ipt.type +
    "\" readonly onClick=\"TaskMsg_Input_OnClick('" +
    ipt.form.id + "','" + ipt.id + "')\" />");
  if (ipt.onChange) eval(ipt.onChange);
}

/**
 * 录音结束后
 * @param {[type]} audioObj [description]
 */
function TaskMsg_OnAudioRecord(audioObj) {
  curTaskMsgInput.value = audioObj;
  var width = audioObj.seconds * 2 + 66;
  if (audioObj.seconds > 60) width = 60 * 2 + 66;
  curTaskMsgInput.jQueryObj.find("input").remove();
  curTaskMsgInput.jQueryObj.find(".inputGt").remove();
  var str = "";
  if (!curTaskMsgInput.readonly) {
    str += "<img src=\"" + TaskMsgClientAPIDir +
      "images/minus.png\" class=\"inputRightIcon\" onClick=\"" +
      "TaskMsg_AudioRecord_Del('" + curTaskMsgInput.form.id + "','" +
      curTaskMsgInput.id + "')\" />";
  }
  str += "<div class=\"voicePlayer\" onclick=\"TaskMsg_AudioRecord_Play('" +
    curTaskMsgInput.form.id + "','" + curTaskMsgInput.id +
    "')\" style=\"width:" + width + "px;";
  if (curTaskMsgInput.readonly) str += "margin-right:5px;";
  str += "\"><img src=\"" + TaskMsgClientAPIDir + "images/voice.png\" />" +
    "<label>" + audioObj.seconds + "\"</label></div>";
  curTaskMsgInput.jQueryObj.append(str);
  if (curTaskMsgInput.onChange) eval(curTaskMsgInput.onChange);
}

/**
 * 扫一扫完成后
 * @param {[type]} code [description]
 */
function TaskMsg_OnCodeScaned(code) {
  curTaskMsgInput.value = code;
  if (curTaskMsgInput.jQueryObj.find("textarea").length == 0) {
    //curTaskMsgInput.jQueryObj.css("height", "170px");
    var str = "<div style=\"width:100%; height:80px;margin-top:0px;" +
      "padding-left:5px;padding-right:5px;\"><textarea " +
      "class=\"barcodeResult\" readonly>" + code + "</textarea></div>";
    str += "<div style=\"width:100%; height:40px;margin-top:0px;\">" +
      "<span style=\"float:left;height:40px;line-height:40px;font-size:16px;" +
      "color: #0099FF; margin-left:5px;\" onclick=\"tmClient.copyToClipBoard(" +
      "$(this).parent().parent().find('textarea').val())\">复制</span>";
    if (code.indexOf("http://") === 0 || code.indexOf("https://") === 0) {
      str += "<span style=\"float:left;height:40px;line-height:40px;font-size:16px;" +
        "color: #0099FF; margin-left:20px;\" onclick=\"tmClient.openWebPage('" +
        code + "',true,true)\">打开</span>";
    }
    if (!curTaskMsgInput.readonly) {
      str += "<span style=\"float:left;height:40px;line-height:40px;font-size:16px;" +
        "color: #0099FF; margin-left:20px;\" onclick=\"TaskMsg_CodeScanner_Del('" +
        curTaskMsgInput.form.id + "','" + curTaskMsgInput.id + "')\">删除</span>";
    }
    str += "</div>";
    curTaskMsgInput.jQueryObj.append(str);
  } else {
    curTaskMsgInput.jQueryObj.find("textarea").val(code);
  }
  if (curTaskMsgInput.onChange) eval(curTaskMsgInput.onChange);
}

/**
 * 删除条码或二维码
 * @param {[type]} formId [description]
 * @param {[type]} inputId   [description]
 */
function TaskMsg_CodeScanner_Del(formId, inputId) {
  var form = taskMsgForms[formId];
  if (!form) return;
  var ipt = form.inputs[inputId];
  if (!ipt) return;
  ipt.value = null;
  ipt.jQueryObj.find("div").each(function () {
    if ($(this).find("textarea").length > 0 || $(this).find("span").length > 1) {
      $(this).remove();
    }
  });
  //ipt.jQueryObj.css("height", "50px");
  if (ipt.onChange) eval(ipt.onChange);
}

$(function () {
  $(".TaskMsgForm").each(function (index) {
    var form = new TaskMsgForm();
    if ($(this).attr("id")) {
      form.id = $(this).attr("id");
    } else {
      form.id = "TaskMsgForm_" + index;
    }
    taskMsgForms[form.id] = form;
    form.init($(this));
  });
});