/*
*资料导入
*/
import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE,UPCLOUD_RDC_TMS_BUSINESS_SERVICE,UPCLOUD_RDC_TMS_INTERFACE_SERVICE} from '@/config/serviceSettings.js';
import { getSelectGJ, querySysPicture } from '@/utils/prolog.ajax.js';
export default () => {

	var importUrl = "";
	var upload = layui.upload;
	//滑屏
	var carousel = layui.carousel;
	carousel.render({
		elem: "#importTemple_grid",
		autoplay: false,
		index: 0,
		arrow: "none",
		indicator: "none",
		anim: "fade",
		width: "100%", //设置容器宽度
		height: "100%"
	});

	function changePanel(name) {
		var dl = ["importTemplate_grid_import1", "importTemplate_grid_show", "importTemplate_grid_edit"];
		dl.forEach(function (item) { $("#" + item).removeClass("layui-this"); });
		$("#" + name).addClass("layui-this");
	}

	//定义页面及全局参数
	var import_form;
	var showgridIns;
	var edit_form;


	//主界面form
	var import_opt = {

		renderer: "importTemplate_grid_import",
		items: [

			{ type: "settings", position: "label-right", labelWidth: 50, inputWidth: "*", labelAlign: "left" },
			{
				type: "block", list: [
					{ type: "radio", name: "importtype", value: "cosigner", label: "货主" },
					{ type: "radio", name: "importtype", value: "company", label: "承运商" },
					{ type: "newcolumn", offset: 80 },
					{ type: "radio", name: "importtype", value: "branch", label: "仓资料" },
					{ type: "radio", name: "importtype", value: "orgrization", label: "门店" },
					{ type: "newcolumn", offset: 80 },
					{ type: "radio", name: "importtype", value: "item", label: "商品资料" },
					{ type: "radio", name: "importtype", value: "trad", label: "贸易伙伴" },
					{ type: "newcolumn", offset: 80 },
					{ type: "radio", name: "importtype", value: "area", label: "库区" },
					{ type: "radio", name: "importtype", value: "location", label: "货位" },
					{ type: "newcolumn", offset: 80 },
					{ type: "radio", name: "importtype", value: "workstation", label: "工作台" },
					{ type: "radio", name: "importtype", value: "container", label: "容器" },
					{ type: "newcolumn", offset: 80 },
					{ type: "radio", name: "importtype", value: "user", label: "用户" },
					{ type: "radio", name: "importtype", value: "sgs", label: "集货区" }
				]
			},
			{ type: "label", name: "line", width: "*", labelWidth: "*", label: "<hr style='background: #D8D8D8;height:1px;width:100%;margin:15px 0px;' />" },
			{ type: "block", list: [{ type: "button", className: "fileSelect", name: "caret", value: "<i class='layui-icon layui-icon-link'></i>选择文件" }] },
			{
				type: "block", list: [
					{ type: "button", className: "importUpload primary", name: "importUpload", value: "<i class='layui-icon layui-icon-upload-drag'></i>上传文件" },
					{ type: "newcolumn", offset: 10 },
					{ type: "button", className: "showImportData", name: "showImportData", value: "查看未保存数据" }
				]
			}
		]
	};

	import_form = new PlgForm(import_opt);

	// 初始化上传
	var upfile = upload.render({
		elem: ".fileSelect",
		auto: false,
		bindAction: ".importUpload",
		url: importUrl,
		accept: "file", //普通文件
		contentType: "application/x-www-form-urlencoded",
		done: function (res) {
			if (res.success) {
				PlgDialog.msg(res.message == null ? "接口调用失败" : res.message);
				//调用显示界面生成grid方法
				showGridInit();
				changePanel("importTemplate_grid_show");
			}
 else {
				setTimeout(() => { PlgDialog.alert(res.message == null ? "接口调用失败" : res.message); }, 300);
			}
		}
	});


	var importtype = "";
	var showUrl = "";
	var importSaveUrl = "";
	var delUrl = "";
	var editSaveUrl = "";
	var field = "";

	//调整字段顺序
	var urlList = [
		{
			"text": "cosigner",
			"impUrl": "/import/imp-consignors",
			"impSaveUrl": "/import/create-consigors",
			"showUrl": "/import/list-consignors",
			"delUrl": "/import/del-consignors",
			"editSaveUrl": "/import/update-company",
			"field": [
				{ "name": "companycode", "comments": "货主编码" }, { "name": "locname", "comments": "货主名称" },
				{ "name": "customergroupname", "comments": "货主类型" }, { "name": "provincename", "comments": "省" },
				{ "name": "cityname", "comments": "市" }, { "name": "areaname", "comments": "区" },
				{ "name": "groupno1", "comments": "所在区域" }, { "name": "contactman", "comments": "到货联系人" },
				{ "name": "address", "comments": "详细地址" }, { "name": "extattr2", "comments": "拓展预留" },
				{ "name": "errorMsg", "comments": "错误信息" }
			]
		},
		{
			"text": "company",
			"impUrl": "/import/imp-carriers",
			"impSaveUrl": "/import/create-carries",
			"showUrl": "/import/list-carriers",
			"delUrl": "/import/del-carriers",
			"editSaveUrl": "/import/update-company",
			"field": [
				{ "name": "companycode", "comments": "承运商编号" }, { "name": "locname", "comments": "承运商名称" },
				{ "name": "customergroupname", "comments": "承运商类型" }, { "name": "groupno1", "comments": "所在区域" },
				{ "name": "contactman", "comments": "联系人" }, { "name": "address", "comments": "地址" },
				{ "name": "provincename", "comments": "省" }, { "name": "cityname", "comments": "市" },
				{ "name": "areaname", "comments": "区" }, { "name": "errorMsg", "comments": "错误信息" }]
		},
		{
			"text": "branch",
			"impUrl": "/import/imp-branches",
			"impSaveUrl": "/import/create-branches",
			"showUrl": "/import/list-braches",
			"delUrl": "/import/del-branches",
			"editSaveUrl": "/import/update-company",
			"field": [
				{ "name": "companycode", "comments": "编码" }, { "name": "locname", "comments": "名称" },
				{ "name": "provincename", "comments": "省名称" }, { "name": "cityname", "comments": "市名称" },
				{ "name": "areaname", "comments": "区名称" }, { "name": "areaid", "comments": "分管区" },
				{ "name": "zjm", "comments": "助记码" }, { "name": "address", "comments": "地址" },
				{ "name": "contactman", "comments": "联系人" }, { "name": "tel", "comments": "电话" },
				{ "name": "status", "comments": "状态" }, { "name": "errorMsg", "comments": "错误信息" }]

		},
		{
			"text": "orgrization",
			"impUrl": "/import/imp-stores",
			"impSaveUrl": "/import/create-stores",
			"showUrl": "/import/list-stores",
			"delUrl": "/import/del-stores",
			"editSaveUrl": "/import/update-company",
			"field": [
				{ "name": "companycode", "comments": "店编号" }, { "name": "locname", "comments": "店名称" },
				{ "name": "areaid", "comments": "关联仓" }, { "name": "charger", "comments": "负责人" },
				{ "name": "errorMsg", "comments": "错误信息" }
			]
		},
		{
			"text": "item",
			"impUrl": "/import/imp-itms",
			"impSaveUrl": "/import/create-itm",
			"showUrl": "/import/list-itms",
			"delUrl": "/import/del-itms",
			"editSaveUrl": "/import/update-itm",
			"field": [
				{ "name": "uniteitemid", "comments": "统一商品ID" }, { "name": "itemcode", "comments": "商品编码" },
				{ "name": "locname", "comments": "商品名称" }, { "name": "consignor", "comments": "货主" },
				{ "name": "packtype", "comments": "包装单位" }, { "name": "capacity", "comments": "规格" },
				{ "name": "basepack", "comments": "包装数量" }, { "name": "orign", "comments": "产地" },
				{ "name": "status", "comments": "状态" }, { "name": "itembrand", "comments": "商品品牌" },
				{ "name": "keeptemperature", "comments": "存储条件" }, { "name": "abcgroup", "comments": "ABC分类" },
				{ "name": "stockunit", "comments": "库存单位" }, { "name": "inkeepdays", "comments": "入库预留保质期" },
				{ "name": "itemtype", "comments": "商品主类" }, { "name": "datetracklevel", "comments": "效期跟踪级别" },
				{ "name": "outkeepdays", "comments": "出库预留保质期" }, { "name": "qa_group", "comments": "质检分组" },
				{ "name": "alertshelfdays", "comments": "预警保质期" }, { "name": "palletpacks", "comments": "标准托盘量" },
				{ "name": "keeptype", "comments": "整散标识" }, { "name": "shelfdaytype", "comments": "保质期单位" },
				{ "name": "sf_fragile", "comments": "是否易碎" }, { "name": "is_specialty", "comments": "是否特殊品" },
				{ "name": "sf_shap", "comments": "是否异型" }, { "name": "isbatch", "comments": "是否批次管理" },
				{ "name": "islot", "comments": "是否批号管理" }, { "name": "isseries", "comments": "是否序列号管理" },
				{ "name": "sf_pcgl", "comments": "是否校期管理" }, { "name": "valuabletype", "comments": "是否贵重" },
				{ "name": "sf_wxp", "comments": "是否危险品" }, { "name": "ftypes", "comments": "剂型" },
				{ "name": "fsymbol", "comments": "批准文号" }, { "name": "normname", "comments": "通用名" },
				{ "name": "ffactory", "comments": "生产厂家" }, { "name": "shelfdays", "comments": "有效期" },
				{ "name": "buyer", "comments": "采购员" }, { "name": "exsattr8", "comments": "是否重点品种" },
				{ "name": "basemedicinetype", "comments": "是否基药" }, { "name": "sf_printdrutlist", "comments": "是否打印药监单" },
				{ "name": "exsattr10", "comments": "错误信息" }]

		},
		{
			"text": "trad",
			"impUrl": "/import/imp-customers",
			"impSaveUrl": "/import/create-customers",
			"showUrl": "/import/list-customers",
			"delUrl": "/import/del-customers",
			"editSaveUrl": "/import/update-customer",
			"field": [
				{ "name": "companycode", "comments": "单位编号" }, { "name": "provincename", "comments": "省" },
				{ "name": "cityname", "comments": "市" }, { "name": "areaname", "comments": "区" },
				{ "name": "consignorname", "comments": "货主名称" }, { "name": "locname", "comments": "单位名称" },
				{ "name": "taxcode", "comments": "税号" }, { "name": "companytype", "comments": "类型" },
				{ "name": "legalman", "comments": "法人代表" }, { "name": "status", "comments": "状态" },
				{ "name": "shortname", "comments": "简称" }, { "name": "address", "comments": "地址" },
				{ "name": "shiptoaddress", "comments": "配送地址" }, { "name": "zjm", "comments": "助记码" },
				{ "name": "contactman", "comments": "到货联系人" }, { "name": "comments", "comments": "备注" },
				{ "name": "customergroupname", "comments": "单位性质" }, { "name": "tel", "comments": "联系电话" },
				{ "name": "lineno", "comments": "线路" }, { "name": "groupno1", "comments": "分组属性1" },
				{ "name": "groupno2", "comments": "分组属性2" }, { "name": "businessnote", "comments": "经营范围" },
				{ "name": "lineseq", "comments": "装车顺序" }, { "name": "firstopstatus", "comments": "是否首营" },
				{ "name": "areaid", "comments": "所属片区" }, { "name": "print_ship_sendlist", "comments": "客户标签格式" },
				{ "name": "isprintdruglist", "comments": "是否打印药监单" }, { "name": "shipleadtime", "comments": "运输时效" },
				{ "name": "extattr1", "comments": "扩展预留1" }, { "name": "extattr2", "comments": "扩展预留2" },
				{ "name": "extattr3", "comments": "扩展预留3" }, { "name": "extattr4", "comments": "扩展预留4" },
				{ "name": "extattr5", "comments": "扩展预留5" }, { "name": "extattr6", "comments": "扩展预留6" },
				{ "name": "extattr7", "comments": "扩展预留7" }, { "name": "extattr8", "comments": "扩展预留8" },
				{ "name": "invoicetitle", "comments": "发票抬头" }, { "name": "taxregplace", "comments": "税务登记地" },
				{ "name": "alipay", "comments": "支付宝账号" }, { "name": "bankcode", "comments": "开户银行" },
				{ "name": "regaddress", "comments": "开户行所在地" }, { "name": "webchataccount", "comments": "微信账号" },
				{ "name": "bankaccoutno", "comments": "银行账号" }, { "name": "invoiceto", "comments": "开户名" },
				{ "name": "errMsg", "comments": "错误" }]
		},
		{
			"text": "area",
			"impUrl": "/import/imp-areas",
			"impSaveUrl": "/import/create-area",
			"showUrl": "/import/list-areas",
			"delUrl": "/import/del-areas",
			"editSaveUrl": "/import/update-area",
			"field": [
				{ "name": "branchid", "comments": "组织/仓" }, { "name": "areacode", "comments": "区域编码" },
				{ "name": "refstoreroom", "comments": "库别" }, { "name": "pickmode", "comments": "拣选方式" },
				{ "name": "areaname", "comments": "区域名称" }, { "name": "scattermark", "comments": "存储属性" },
				{ "name": "areatype", "comments": "区域类型" }, { "name": "message", "comments": "错误信息" }
			]
		},
		{
			"text": "location",
			"impUrl": "/import/import-locs",
			"impSaveUrl": "/import/create-loc",
			"showUrl": "/import/list-locs",
			"delUrl": "/import/del-locs",
			"editSaveUrl": "/import/update-loc",
			"field": [
				{ "name": "loctype", "comments": "库别" }, { "name": "locgroup", "comments": "货位类型" },
				{ "name": "storegroup", "comments": "逻辑区域" }, { "name": "itemgroup", "comments": "商品主类" },
				{ "name": "keeptemperature", "comments": "存储条件" }, { "name": "areano", "comments": "区域" },
				{ "name": "abcgroup", "comments": "ABC属性" }, { "name": "status", "comments": "状态" },
				{ "name": "stacktype", "comments": "码放类型" }, { "name": "capacitylimittype", "comments": "容器限制方式" },
				{ "name": "pickseqno", "comments": "拣货顺序号" }, { "name": "putawayseqno", "comments": "上架顺序号" },
				{ "name": "loccode", "comments": "货位编号" }, { "name": "locfloor", "comments": "层" },
				{ "name": "tunnelno", "comments": "巷道" }, { "name": "loccol", "comments": "列" },
				{ "name": "locrow", "comments": "排" }, { "name": "picktype1group", "comments": "拣选方式分组1" },
				{ "name": "containernum", "comments": "数量限制" }, { "name": "weightlimit", "comments": "重量限制" },
				{ "name": "floorno", "comments": "楼层号" }, { "name": "itemnum", "comments": "品种限制" },
				{ "name": "limitvalue", "comments": "体积限制" }, { "name": "lotnum", "comments": "品规限制" },
				{ "name": "loclength", "comments": "长" }, { "name": "locwidth", "comments": "宽" },
				{ "name": "locheight", "comments": "高" }, { "name": "branchid", "comments": "仓ID" },
				{ "name": "branchcode", "comments": "仓编码" },
				{ "name": "picktype5group", "comments": "错误信息" }]
		},
		{
			"text": "workstation",
			"impUrl": "/import/imp-wrkstas",
			"impSaveUrl": "/import/create-wrkstas",
			"showUrl": "/import/list-wrkstas",
			"delUrl": "/import/del-wrkstas",
			"editSaveUrl": "/import/update-wrksta",
			"field": [

				{ "name": "branchid", "comments": "仓/配送中心" }, { "name": "stationcode", "comments": "工作站编码" },
				{ "name": "groupcode", "comments": "分组号" }, { "name": "stationtype", "comments": "工作站类型" },
				{ "name": "stationname", "comments": "工作站名称" }, { "name": "ceilingtasknum", "comments": "任务上限" },
				{ "name": "stationattr1", "comments": "复核台类型" }, { "name": "status", "comments": "状态" },
				{ "name": "stationattr2", "comments": "复核台类别" }, { "name": "abnormalflag", "comments": "异常处理工作站标志" },
				{ "name": "message", "comments": "错误信息" }]
		},
		{
			"text": "container",
			"impUrl": "/import/imp-cntr",
			"impSaveUrl": "/import/create-cntr",
			"showUrl": "/import/list-cntr",
			"delUrl": "/import/del-cntrs",
			"editSaveUrl": "/import/update-cntr",
			"field": [
				{ "name": "branchid", "comments": "组织/仓" }, { "name": "containercode", "comments": "容器号" },
				{ "name": "containertype", "comments": "类型" }, { "name": "startContainercode", "comments": "起始号" },
				{ "name": "endContainercode", "comments": "终止号" }, { "name": "message", "comments": "错误信息" }]
		},
		{
			"text": "sgs",
			"impUrl": "/import/imp-wrkstages",
			"impSaveUrl": "/import/create-wrkstages",
			"showUrl": "/import/list-wrkstages",
			"delUrl": "/import/del-wrkstages",
			"editSaveUrl": "/import/update-wrkstage",
			"field": [
				{ "name": "stagecode", "comments": "集货区编号" }, { "name": "stagetype", "comments": "类型" },
				{ "name": "linecode", "comments": "配送方向" }, { "name": "deliverytype", "comments": "提货方式" },
				{ "name": "stageattr4", "comments": "单据类型" }, { "name": "stageattr3", "comments": "贸易伙伴" },
				{ "name": "stageattr1", "comments": "客户类型" }, { "name": "stageattr5", "comments": "订单信息" },
				{ "name": "stageattr2", "comments": "客户数限制" }, { "name": "numlimit", "comments": "订单数限制" },
				{ "name": "tunnelno", "comments": "巷道" }, { "name": "status", "comments": "状态" },
				{ "name": "branchid", "comments": "仓库ID" }, { "name": "message", "comments": "错误信息" }
			]
		},
		{
			"text": "user",
			"impUrl": "/import/imp-usrs",
			"impSaveUrl": "/import/create-usrs",
			"showUrl": "/import/list-usrs",
			"delUrl": "/import/del-usrs",
			"editSaveUrl": "/import/update-usr",
			"field": [
				{ "name": "p_username", "comments": "用户账号" }, { "name": "p_nickname", "comments": "用户姓名" },
				{ "name": "p_workernumber", "comments": "员工号" }, { "name": "p_companyid", "comments": "所属仓" },
				{ "name": "p_organizationid", "comments": "所属组织" }, { "name": "p_phone", "comments": "联系电话" },
				{ "name": "p_email", "comments": "Email" }, { "name": "p_frozen", "comments": "冻结状态" },
				{ "name": "message", "comments": "错误信息" }]
		}
	];

	//按钮点击事件
	import_form.attachEvent("onButtonClick", function (name) {
		if (name === "importUpload") {
			import_form_import();
		}
 else if (name === "showImportData") {
			showImportData();
		}
	});


	function showImportData() {

		importtype = import_form.getItemValue("importtype");

		if (importtype == null || importtype == "" || importtype == undefined) {
			PlgDialog.msg("请选择一个导入项！");
			return;
		}

		showGridInit();
		changePanel("importTemplate_grid_show");

	}

	//按钮点击事件
	import_form.attachEvent("onChange", function (name, value, state) {
		if (name === "importtype" && state) {

			importtype = value;

			for (var url in urlList) {
				if (urlList[url].text == importtype) {
					importUrl = urlList[url].impUrl;
					showUrl = urlList[url].showUrl;
					importSaveUrl = urlList[url].impSaveUrl;
					delUrl = urlList[url].delUrl;
					editSaveUrl = urlList[url].editSaveUrl;
					field = urlList[url].field;
				}
			}

			// 重写上传组件配置
			upfile.config.url = importUrl;
			upfile.config.elem.next()[0].value = "";
			$(upfile.config.elem.next()[0]).next().remove();
		}
	});

	//上传文件
	function import_form_import() {
		importtype = import_form.getItemValue("importtype");

		if (importtype == null || importtype == "" || importtype == undefined) {
			PlgDialog.msg("请选择一个导入项！");
			return;
		}
		let filename = $("#importTemplate_grid_import1 .layui-upload-choose").html();
		if (filename == undefined || filename == ""){
			PlgDialog.msg("请选择要导入的文件！");
			return;
		}
	}


	function showGridInit() {

		//生成grid1动态列参数
		var showGrid = field;
		var colData = [];

		colData.push({ id: "uuid", name: "ID", type: "ro", hidden: true });
		for (var i = 0; i < showGrid.length; i++) {

			colData.push({ id: showGrid[i].name, name: showGrid[i].comments, type: "ro", width: "100" });
		}
		colData.push({
			id: "op", name: "操作", type: "button", align: "center", width: 100, render: function () {
				return "删除^res_showdata_delClick,修改^res_showdata_editClick";
			}
		});

		//数据展示gird
		var show_opt = {
			skin: "terrace",
			rowId: "uuid",
			columns: colData,
			toolbar: [
				{ type: "input", name: "search", width: 320, label: "查询条件:", placeholder: "", offsetLeft: 10 }, { type: "newcolumn" },
				{ type: "button", name: "searchBtn", width: 50, value: "查询" }, { type: "newcolumn" }
			],
			pagebar: {
				buttons: [
					{ text: "删除", className: "layui-btn-normal", name: "deldata" }
				],
				type: "full"
			},
			imagePath: "/prologui/dist/images/PlgGrid",
			url: showUrl,//数据接口
			type: "post",//数据提交方式，默认为get
			contentType: "application/x-www-form-urlencoded",
			params: { pageSize: 10, pageNum: 1 },
			multiselect: true,//是否支持多选
			fixedLast: true,
			page: true, //是否启用分页
			totalCount: "totalCount" //总记录数字段，默认totalCount
		};

		showgridIns = new PlgGrid(show_opt);
		showgridIns.renderTo("importTemplate_show_sub");
		showgridIns.loadData();

		showgridIns.attachToolBarEvent("onButtonClick", function (name) {

			if (name == "searchBtn") {
				var fdata = showgridIns.getToolBarForm().getFormData();
				fdata.pageNum = 1;
				fdata.pageSize = 10;
				showgridIns.setParams(fdata);
				showgridIns.reload();
			}

		});


		showgridIns.attachPageBarEvent(function (name, ids) {

			if (name == "deldata") {

				if (ids == null || ids == "") {
					PlgDialog.msg("请选择一行数据");
					return;
				}

				var id = ids.split(",");
				var rdata;
				var dataList = [];

				for (var s = 0; s < id.length; s++) {
					rdata = showgridIns.getGrid().getUserData(id[s], "data");
					dataList.push(rdata);
				}

				Prolog.ajax({
					url: delUrl,
					type: "post",
					contentType: "application/json",
					data: JSON.stringify(dataList),
					success: function (data) {
						if (data.success) {
							setTimeout(()=>{PlgDialog.msg(data.message);},300);
							showgridIns.reload();
						}
						else {
							setTimeout(()=>{PlgDialog.alert(data.message == null ? "接口调用失败" : data.message);},300);
						}
					},
					error: function () { PlgDialog.msg("接口调用失败"); }
				});

			}

		});

	}

	//展示页面 点击返回按钮 返回主表
	$("#importTemplate_show_back").click(function () {
		changePanel("importTemplate_grid_import1");
		return false;
	});

	//展示页面 点击保存按钮
	$("#btn_save_importTemplate").click(function () {
		saveImportData();
		return false;
	});


	window.res_showdata_editClick = function (rid, rdata) {
		changePanel("importTemplate_grid_edit");
		showEditGrid(rdata);
		return false;
	};

	window.res_showdata_delClick = function (rid, rdata) {
		var params = rdata;
		var listParam = [];
		listParam.push(params);
		Prolog.ajax({
			url: delUrl,
			type: "post",
			contentType: "application/json",
			data: JSON.stringify(listParam),
			success: function (data) {
				if (data.success) {
					setTimeout(()=>{PlgDialog.msg(data.message);},300);
					showgridIns.reload();
				}
				else {
					setTimeout(()=>{PlgDialog.alert(data.message == null ? "接口调用失败" : data.message);},300);
				}
			},
			error: function () { PlgDialog.msg("接口调用失败"); }
		});

		return false;

	};


	function saveImportData() {

		Prolog.ajax({
			url: importSaveUrl,
			type: "post",
			contentType: "application/json",
			data: {},
			success: function (data) {
				setTimeout(()=>{PlgDialog.msg(data.message);},300);
				showgridIns.reload();
			},
			error: function () { PlgDialog.msg("接口调用失败"); }
		});

	}


	function showEditGrid(data) {

		var showForm = field;

		//生成form动态列参数
		var formData = [];
		formData.push({ type: "settings", inputWidth: 200, width: "*", labelWidth: 80, position: "label-left", labelAlign: "left" });

		for (var i = 0; i < showForm.length; i++) {
			formData.push({ type: "input", name: showForm[i].name, label: showForm[i].comments });

			if (i + 1 == Math.floor(showForm.length / 3) || i + 1 == Math.floor(showForm.length * 2 / 3)) {
				formData.push({ type: "newcolumn", offset: 40 });
			}
		}

		var edit_opt = {
			renderer: "importTemplate_edit_sub",
			items: formData
		};

		edit_form = new PlgForm(edit_opt);

		edit_form.setFormData(data);

	}

	//修改页面 点击返回按钮 返回主表
	$("#importTemplate_edit_back").click(function () {
		changePanel("importTemplate_grid_show");
		return false;
	});

	//修改页面 点击保存按钮
	$("#btn_editsave_importTemplate").click(function () {

		var params = edit_form.getFormData();

		Prolog.ajax({
			url: editSaveUrl,
			type: "post",
			contentType: "application/json",
			data: JSON.stringify(params),
			success: function (data) {
				if (data.success) {
					setTimeout(()=>{PlgDialog.msg(data.message);},300);
					changePanel("importTemplate_grid_show");
					showgridIns.reload();
				}
				else {
					setTimeout(()=>{PlgDialog.alert(data.message == null ? "接口调用失败" : data.message);},300);
				}
			},
			error: function () { PlgDialog.msg("接口调用失败"); }
		});


		return false;
	});


}