Detail.cshtml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. @using MES.Production.Service;
  2. @using Central.Control.Domain;
  3. @using Ant.Service.Common;
  4. @using CommonToolHelper;
  5. @{
  6. ViewBag.Title = "添加/修改商品";
  7. Layout = "~/Views/Shared/_Layout.cshtml";
  8. }
  9. @model MES.Production.Entity.Entity.YW_Product
  10. <style>
  11. body {
  12. background-color: white;
  13. }
  14. .changeicon {
  15. float: right;
  16. margin-right: 22px;
  17. position: absolute;
  18. right: -7px;
  19. top: 0px;
  20. border: none;
  21. background-color: #18a689;
  22. color: #FFFFFF;
  23. line-height: 33px;
  24. height: 33px;
  25. }
  26. </style>
  27. <link href="~/Content/uploadone/CSS/webuploader.css" rel="stylesheet" />
  28. <link href="~/Content/uploadone/CSS/bootstrap.min.css" rel="stylesheet" />
  29. <link href="~/Content/uploadone/CSS/uploadstyle.css" rel="stylesheet" />
  30. <link href="~/Content/uploadone/CSS/font-awesome.css" rel="stylesheet" />
  31. <script src="~/Content/uploadone/Script/webuploader.js"></script>
  32. @using (Ajax.BeginForm("Save", null, new AjaxOptions()
  33. {
  34. HttpMethod = "Post",
  35. OnBegin = "SubAjax.Loading",
  36. OnComplete = "SubAjax.Complate",
  37. OnFailure = "SubAjax.Failure",
  38. OnSuccess = "SubAjax.Success"
  39. },
  40. new { @class = "form-horizontal dig-from", @role = "form" }))
  41. {
  42. <div class="wrapper-content">
  43. <div class="panel-body">
  44. <div class="tab-content">
  45. <div id="tab-1" class="tab-pane active">
  46. @Html.HiddenFor(p => p.Id)
  47. <div class="form-group">
  48. <label class="col-lg-3 control-label">商品名称:</label>
  49. <div class="col-lg-8">
  50. @Html.TextBoxFor(p => p.Name, new { @class = "form-control", @id = "Name", @placeholder = "请输入商品名称", @datatype = "*", @nullmsg = "请输入商品名称!", @errormsg = "请输入商品名称!" })
  51. </div>
  52. </div>
  53. <div class="form-group">
  54. <label class="col-lg-3 control-label">商品编号:</label>
  55. <div class="col-lg-8">
  56. @Html.TextBoxFor(p => p.Code, new { @class = "form-control", @id = "Code", @placeholder = "请输入商品编号", @datatype = "*", @nullmsg = "请输入商品编号!", @errormsg = "请输入商品编号!" })
  57. </div>
  58. </div>
  59. <div class="form-group fileUpload">
  60. @Html.Hidden("hidfilename", Model.Img, new { @class = "hidfilename" })
  61. @Html.Hidden("hidfileid", Model.Img, new { @class = "hidfileid" })
  62. <label class="col-lg-3 control-label">图片:</label>
  63. <div class="col-lg-8">
  64. <div class="fileNameList">
  65. </div>
  66. <div class="cp_img_jia fileNamePicker"></div>
  67. </div>
  68. </div>
  69. <div class="form-group">
  70. <label class="col-lg-3 control-label">进货价:</label>
  71. <div class="col-lg-8">
  72. @Html.TextBoxFor(p => p.BuyingPrice, new { @class = "form-control", @id = "BuyingPrice", @placeholder = "请输入进货价", @type = "number", @nullmsg = "请输入进货价!", @errormsg = "请输入进货价!" })
  73. </div>
  74. </div>
  75. <div class="form-group">
  76. <label class="col-lg-3 control-label">售卖价:</label>
  77. <div class="col-lg-8">
  78. @Html.TextBoxFor(p => p.Price, new { @class = "form-control", @id = "Price", @placeholder = "请输入售卖价", @type = "number", @nullmsg = "请输入售卖价!", @errormsg = "请输入售卖价!" })
  79. </div>
  80. </div>
  81. <div class="form-group">
  82. <label class="col-lg-3 control-label">库存:</label>
  83. <div class="col-lg-8">
  84. @Html.TextBoxFor(p => p.Stock, new { @class = "form-control", @id = "Stock", @placeholder = "请输入库存", @type = "number", @nullmsg = "请输入库存!", @errormsg = "请输入库存!" })
  85. </div>
  86. </div>
  87. <div class="form-group hidden-1024">
  88. <label class="col-lg-3 control-label">商品简介:</label>
  89. <div class="col-lg-8">
  90. @Html.TextAreaFor(p => p.Info, new { @class = "form-control", @id = "Info" })
  91. </div>
  92. </div>
  93. <div class="hr-line-dashed">
  94. <div class="form-group m20" style="text-align:center">
  95. <div class="col-sm-2 col-sm-offset-2">
  96. <button class="btn btn-primary btn-save" onclick="return verificationForm()" type="submit"><i class="fa fa-check"></i> <span>确定保存</span></button>
  97. <button class="btn btn-warning" id="btn-dig-close" type="button"><i class="im-undo2"></i> 取消返回</button>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. }
  106. @section scripts{
  107. <script type="text/javascript">
  108. $.fn.extend(
  109. {
  110. FileUpload: function (options) {
  111. $(this).each(function () {
  112. var filename = $(this).find(".hidfilename").val();
  113. if (filename != null && filename != "") {
  114. var headstr = "<div id=\"WU_FILE_0\" class=\"cpup_img upload-state-done\"><img src=\"";
  115. var footstr = "\"><div class=\"upcp_img_jian\"></div><p class=\"progress hide\"><span style=\"width: 100%;\"></span></p></div>";
  116. $(this).find(".fileNameList").html(headstr + filename + footstr);
  117. }
  118. options = options || {};
  119. var applicationPath = "http://" + window.location.host;
  120. var fileId;
  121. var $list = $(this).find('.fileNameList');
  122. var _this = this;
  123. var ratio = window.devicePixelRatio || 1;
  124. var defaultOptions = {
  125. thumbnailWidth: 90 * ratio,
  126. thumbnailHeight: 90 * ratio,
  127. auto: true,
  128. disableGlobalDnd: true,
  129. swf: applicationPath + '/Script/Uploader.swf',
  130. server: applicationPath + '/Sys/Home/UpLoadProcess',
  131. pick: $(_this).find(".fileNamePicker"),
  132. accept: {
  133. title: 'Images',
  134. extensions: 'gif,jpg,jpeg,bmp,png',
  135. mimeTypes: 'image/*'
  136. },
  137. fileNumLimit: 1
  138. };
  139. options = $.extend(options, defaultOptions);
  140. var uploader = WebUploader.create(options);
  141. // 当有文件添加进来的时候
  142. uploader.on('fileQueued', function (file) {
  143. debugger;
  144. var $li = $(
  145. '<div id="' + file.id + '" class="cpup_img">' +
  146. '<img class="jjgimg">' +
  147. '<div class="upcp_img_jian"></div></div>'
  148. );
  149. var $img = $li.find('img');
  150. $list.children().remove();//先清空元素内容
  151. if (fileId != file.id && fileId != null) {
  152. uploader.removeFile(uploader.getFile(fileId, true));
  153. }
  154. fileId = file.id;
  155. $list.append($li);
  156. // 创建缩略图
  157. // 如果为非图片文件,可以不用调用此方法。
  158. // thumbnailWidth x thumbnailHeight 为 100 x 100
  159. uploader.makeThumb(file, function (error, src) {
  160. if (error) {
  161. $img.replaceWith('<span>不能预览</span>');
  162. return;
  163. }
  164. $img.attr('src', src);
  165. }, options.thumbnailWidth, options.thumbnailHeight);
  166. });
  167. //上传压缩宽度
  168. uploader.option('compress', {
  169. width: 700
  170. });
  171. // 文件上传过程中创建进度条实时显示。
  172. uploader.on('uploadProgress', function (file, percentage) {
  173. var $li = $(_this).find('#' + file.id),
  174. $percent = $li.find('.progress span');
  175. // 避免重复创建
  176. if (!$percent.length) {
  177. $percent = $('<p class="progress"><span></span></p>')
  178. .appendTo($li)
  179. .find('span');
  180. }
  181. $percent.css('width', percentage * 100 + '%');
  182. });
  183. // 文件上传成功,给item添加成功class, 用样式标记上传成功。
  184. uploader.on('uploadSuccess', function (file, response) {
  185. debugger;
  186. var imgurl = response.filePath; //上传图片的路径
  187. var fileid = response.fileid; //上传图片的路径
  188. $(_this).find('#' + file.id).addClass('upload-state-done');
  189. $(_this).find(".hidfilename").val(imgurl);
  190. $(_this).find(".jjgimg").attr('src', imgurl);//季健国加为了解决保存一串字符串
  191. $(_this).find(".hidfileid").val(fileid);
  192. });
  193. // 文件上传失败,显示上传出错。
  194. uploader.on('uploadError', function (file) {
  195. var $li = $(_this).find('#' + file.id),
  196. $error = $li.find('div.error');
  197. // 避免重复创建
  198. if (!$error.length) {
  199. $error = $('<div class="error"></div>').appendTo($li);
  200. }
  201. $error.text('上传失败');
  202. });
  203. // 完成上传完了,成功或者失败,先删除进度条。
  204. uploader.on('uploadComplete', function (file) {
  205. $(_this).find('#' + file.id).find('.progress').remove();
  206. });
  207. //所有文件上传完毕
  208. uploader.on("uploadFinished", function () {
  209. //提交表单
  210. });
  211. //开始上传
  212. $(this).find("#ctlUpBtn").click(function () {
  213. uploader.upload();
  214. });
  215. //显示删除按钮
  216. $(this).find(".cpup_img").on("mouseover", function () {
  217. $(this).children(".upcp_img_jian").css('display', 'block');
  218. });
  219. //隐藏删除按钮
  220. $(this).find(".cpup_img").on("mouseout", function () {
  221. $(this).children(".upcp_img_jian").css('display', 'none');
  222. });
  223. //执行删除方法
  224. $list.on("click", ".upcp_img_jian", function () {
  225. debugger;
  226. var Id = $(this).parent().attr("id");
  227. try {
  228. $(_this).find(".hidfilename").val("");
  229. $(_this).find(".hidfileid").val("");
  230. uploader.removeFile(uploader.getFile(Id, true));
  231. }
  232. catch (ex) { }
  233. $(this).parent().remove();
  234. });
  235. });
  236. }
  237. }
  238. );
  239. $(function () {
  240. $(".fileUpload").FileUpload();
  241. $('.form-horizontal').initValidform();
  242. $('.select2').select2();
  243. });
  244. function verificationForm() {
  245. var buyingPrice = parseInt($("#BuyingPrice").val());
  246. var price = parseInt($("#Price").val());
  247. var stock = parseInt($("#Stock").val());
  248. if (buyingPrice <= 0 || price <= 0) {
  249. dig.alertError("提示", "进货价或售卖价不能小于0");
  250. return false;
  251. }
  252. if (stock < 0) {
  253. dig.alertError("提示", "库存不能小于0");
  254. return false;
  255. }
  256. if (price < buyingPrice) {
  257. dig.alertError("提示", "当前售卖价小于进货价,即将亏本!");
  258. return false;
  259. }
  260. return true;
  261. }
  262. function isCardNo() {
  263. // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
  264. //\d 匹配数字
  265. // |将两个匹配条件进行逻辑“或”(or)运算。
  266. //^匹配输入字符串的开始位置。
  267. //$匹配输入字符串的结束位置
  268. //()是为了提取匹配字符串的,表达式中有几个()就有几个相应的匹配字符串
  269. //{}一般是用来匹配的长度。比如\s{3}表示匹配三个空格,\s[1,3]表示匹配1到3个空格
  270. var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  271. var card = document.getElementById("IDCard").value;
  272. //console.log(card);
  273. if (reg.test(card) === false) {
  274. dig.alertError("提示", "对不起,身份证号输入不合法!");
  275. return false;
  276. } else {
  277. //alert("输入正确");
  278. return true;
  279. }
  280. }
  281. </script>
  282. }