edit.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. {extend name="common/base"/}
  2. {block name="style"}
  3. <style>
  4. .upload-img {
  5. width: 120px;
  6. height: 90px;
  7. overflow: hidden;
  8. position: relative;
  9. border: 1px solid #eee;
  10. padding: 1px;
  11. margin: 5px;
  12. float: left;
  13. }
  14. .upload-close {
  15. position: absolute;
  16. top: 1px;
  17. right: 1px;
  18. }
  19. </style>
  20. {/block}
  21. <!-- 主体 -->
  22. {block name="body"}
  23. <form class="layui-form p-3">
  24. <h3 class="pb-3">编辑商品</h3>
  25. <table class="layui-table layui-table-form">
  26. <tr>
  27. <td class="layui-td-gray">商品标题<font>*</font></td>
  28. <td colspan="5"><input type="text" name="title" lay-verify="required" lay-reqText="请输入商品标题" placeholder="请输入商品标题" class="layui-input" value="{$detail.title}"></td>
  29. <td class="layui-td-gray">商品分类<font>*</font></td>
  30. <td>
  31. <select name="cate_id" lay-verify="required" lay-reqText="请选择商品分类">
  32. <option value="">请选择商品分类</option>
  33. {volist name=":set_recursion(get_goods_cate())" id="v"}
  34. <option value="{$v.id}" {eq name="$detail.cate_id" value="$v.id" }selected{/eq}>{$v.title}</option>
  35. {/volist}
  36. </select>
  37. </td>
  38. </tr>
  39. <tr>
  40. <td class="layui-td-gray">关键字<font>*</font></td>
  41. <td colspan="5">
  42. <input type="text" id="keyword_name" name="keyword_names" lay-verify="required" lay-reqText="请选择关键字"
  43. placeholder="请选择关键字" class="layui-input" value="{$detail.keyword_names}" readonly>
  44. <input type="hidden" id="keyword_id" name="keyword_ids" value="{$detail.keyword_ids}">
  45. </td>
  46. <td class="layui-td-gray" rowspan="3">缩略图<font>*</font></td>
  47. <td rowspan="3" style="vertical-align:top">
  48. <div class="layui-upload" style="text-align:center;">
  49. <button type="button" class="layui-btn layui-btn-sm" id="upload_btn_thumb">上传商品封面图(尺寸:750x560)</button>
  50. <div class="layui-upload-list" id="upload_box_thumb">
  51. <img src="{$detail.thumb|get_file}" style="width:200px;max-width:200px" />
  52. <input type="hidden" name="thumb" value="{$detail.thumb}">
  53. </div>
  54. </div>
  55. </td>
  56. </tr>
  57. <tr>
  58. <td class="layui-td-gray">商品卖点<font>*</font></td>
  59. <td colspan="5">
  60. <input type="text" name="tips" lay-verify="required" lay-reqText="请输入商品卖点" placeholder="一句话描述商品卖点,30字以内" value="{$detail.tips}" class="layui-input">
  61. </td>
  62. </tr>
  63. <tr>
  64. <td class="layui-td-gray" style="vertical-align:top;">商品简介</td>
  65. <td colspan="5">
  66. <textarea name="desc" placeholder="请输入商品简介,200字以内" class="layui-textarea">{$detail.desc}</textarea>
  67. </td>
  68. </tr>
  69. <tr>
  70. <td class="layui-td-gray">商品标签<font>*</font></td>
  71. <td colspan="8">
  72. <input type="checkbox" name="tag_values[]" title="正品保证" lay-skin="primary" value="1" {eq
  73. name="$detail.tag1" value="1" }checked{/eq} />
  74. <input type="checkbox" name="tag_values[]" title="一年保修" lay-skin="primary" value="2" {eq
  75. name="$detail.tag2" value="1" }checked{/eq} />
  76. <input type="checkbox" name="tag_values[]" title="七天退换(拆封后不支持)" lay-skin="primary" value="3" {eq
  77. name="$detail.tag3" value="1" }checked{/eq} />
  78. <input type="checkbox" name="tag_values[]" title="赠运费险" lay-skin="primary" value="4" {eq
  79. name="$detail.tag4" value="1" }checked{/eq} />
  80. <input type="checkbox" name="tag_values[]" title="闪电发货" lay-skin="primary" value="5" {eq
  81. name="$detail.tag5" value="1" }checked{/eq} />
  82. <input type="checkbox" name="tag_values[]" title="售后无忧" lay-skin="primary" value="6" {eq
  83. name="$detail.tag6" value="1" }checked{/eq} />
  84. </td>
  85. </tr>
  86. <tr>
  87. <td class="layui-td-gray">市场价格<font>*</font></td>
  88. <td>
  89. <input type="text" name="base_price" lay-verify="required|number" lay-reqText="请输入市场价格"
  90. placeholder="请输入市场价格" class="layui-input" value="{$detail.base_price}">
  91. </td>
  92. <td class="layui-td-gray">实际价格<font>*</font></td>
  93. <td>
  94. <input type="text" name="price" lay-verify="required|number" lay-reqText="请输入实际价格" placeholder="请输入实际价格"
  95. class="layui-input" value="{$detail.price}">
  96. </td>
  97. <td class="layui-td-gray">商品库存<font>*</font></td>
  98. <td>
  99. <input type="text" name="stocks" value="{$detail.stocks}" lay-verify="required|number" lay-reqText="请输入商品库存" placeholder="请输入商品库存" class="layui-input">
  100. </td>
  101. <td class="layui-td-gray">是否包邮<font>*</font></td>
  102. <td>
  103. <input type="radio" name="is_mail" value="1" title="是" {eq name="$detail.is_mail" value="1"
  104. }checked{/eq}>
  105. <input type="radio" name="is_mail" value="0" title="否" {eq name="$detail.is_mail" value="0"
  106. }checked{/eq}>
  107. </td>
  108. </tr>
  109. <tr>
  110. <td class="layui-td-gray">商品属性</td>
  111. <td>
  112. <select name="type">
  113. <option value="">请选择属性</option>
  114. <option value="1" {eq name="$detail.type" value="1" }selected{/eq}>精华</option>
  115. <option value="2" {eq name="$detail.type" value="2" }selected{/eq}>热门</option>
  116. <option value="3" {eq name="$detail.type" value="3" }selected{/eq}>推荐</option>
  117. </select>
  118. </td>
  119. <td class="layui-td-gray">首页显示</td>
  120. <td>
  121. <input type="radio" name="is_home" value="1" title="是" {eq name="$detail.is_home" value="1"
  122. }checked{/eq}>
  123. <input type="radio" name="is_home" value="0" title="否" {eq name="$detail.is_home" value="0"
  124. }checked{/eq}>
  125. </td>
  126. <td class="layui-td-gray">排序</td>
  127. <td>
  128. <input type="text" name="sort" placeholder="请输入排序,数字" lay-verify="number" class="layui-input" value="{$detail.sort}">
  129. </td>
  130. <td class="layui-td-gray">状态<font>*</font></td>
  131. <td>
  132. <input type="radio" name="status" value="1" title="正常" {eq name="$detail.status" value="1" }checked{/eq}>
  133. <input type="radio" name="status" value="0" title="下架" {eq name="$detail.status" value="0" }checked{/eq}>
  134. </td>
  135. </tr>
  136. <tr>
  137. <td class="layui-td-gray">商品图集</td>
  138. <td colspan="7">
  139. <div class="layui-upload">
  140. <button type="button" class="layui-btn layui-btn-sm" id="uploadBtn2">上传轮播图</button>
  141. <div class="layui-upload-list" id="demo2">
  142. <input type="hidden" name="banner" value="{$detail.banner}">
  143. {notempty name="detail.banner"}
  144. {volist name="detail.banner_array" id="vo"}
  145. <div class="upload-img img-cover" id="uploadImg{$vo}"><div class="gg-img-cover cover-4-3"><img src="{$vo|get_file}"><div class="upload-close"><a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delimg" data-id="{$vo}">删除</a></div></div></div>
  146. {/volist}
  147. {/notempty}
  148. </div>
  149. </div>
  150. </td>
  151. </tr>
  152. <tr>
  153. <td colspan="8" class="layui-td-gray" style="text-align:left">商品介绍<font>*</font></td>
  154. </tr>
  155. <tr>
  156. <td colspan="8">
  157. <textarea class="layui-textarea" id="container_content">{$detail.content}</textarea>
  158. </td>
  159. </tr>
  160. </table>
  161. <div class="pt-3">
  162. <input type="hidden" name="id" value="{$detail.id}">
  163. <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
  164. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  165. <button lay-event="back" class="layui-btn layui-btn-primary">关闭</button>
  166. </div>
  167. </form>
  168. {/block}
  169. <!-- /主体 -->
  170. <!-- 脚本 -->
  171. {block name="script"}
  172. <script>
  173. // 查找指定的元素在数组中的位置
  174. Array.prototype.indexOf = function (val) {
  175. for (var i = 0; i < this.length; i++) {
  176. if (this[i] == val) {
  177. return i;
  178. }
  179. }
  180. return -1;
  181. };
  182. // 通过索引删除数组元素
  183. Array.prototype.remove = function (val) {
  184. var index = this.indexOf(val);
  185. if (index > -1) {
  186. this.splice(index, 1);
  187. }
  188. };
  189. var moduleInit = ['tool','tagpicker','tinymce'];
  190. function gouguInit() {
  191. var form = layui.form, tool = layui.tool,tagpicker = layui.tagpicker;
  192. //上传缩略图
  193. var upload_thumb = layui.upload.render({
  194. elem: '#upload_btn_thumb',
  195. url: '/admin/api/upload',
  196. done: function (res) {
  197. //如果上传失败
  198. if (res.code == 1) {
  199. return layer.msg('上传失败');
  200. }
  201. //上传成功
  202. $('#upload_box_thumb input').attr('value', res.data.id);
  203. $('#upload_box_thumb img').attr('src', res.data.filepath);
  204. }
  205. });
  206. //banner图上传
  207. var uploadInst2 = layui.upload.render({
  208. elem: '#uploadBtn2'
  209. , url: '/admin/api/upload'
  210. , done: function (res) {
  211. //如果上传失败
  212. if (res.code == 1) {
  213. return layer.msg('上传失败');
  214. }
  215. //上传成功
  216. var idsStr = $('#demo2 input').val();
  217. var idsArray = [];
  218. if (idsStr != '') {
  219. idsArray = idsStr.split(",");
  220. }
  221. idsArray.push(res.data.id);
  222. $('#demo2 input').attr('value', idsArray.join(','));
  223. $('#demo2').append('<div class="upload-img img-cover" id="uploadImg' + res.data.id + '"><div class="gg-img-cover cover-4-3"><img src="' + res.data.filepath + '"><div class="upload-close"><a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delimg" data-id="' + res.data.id + '">删除</a></div></div>');
  224. }
  225. });
  226. $('#demo2').on('click', '[lay-event="delimg"]', function () {
  227. var _id = $(this).data('id');
  228. var idsStr = $('#demo2 input').val();
  229. var idsArray = [];
  230. if (idsStr != '') {
  231. idsArray = idsStr.split(",");
  232. }
  233. idsArray.remove(_id);
  234. $('#demo2 input').attr('value', idsArray.join(','));
  235. $('#uploadImg' + _id).remove();
  236. })
  237. var tags = new tagpicker({
  238. 'url': '/admin/api/get_keyword_cate',
  239. 'target': 'keyword_name',
  240. 'tag_ids': 'keyword_id',
  241. 'tag_tags': 'keyword_name',
  242. 'height': 500,
  243. 'isDiy': 1
  244. });
  245. //商品描述富文本编辑器
  246. var edit = layui.tinymce.render({
  247. selector: '#container_content',
  248. height: 500
  249. });
  250. //自定义验证规则
  251. form.verify({
  252. otherReq: function (value, item) {
  253. var verifyName = $(item).attr('name')
  254. , verifyType = $(item).attr('type')
  255. , formElem = $(item).parents('.layui-form')//获取当前所在的form元素,如果存在的话
  256. , verifyElem = formElem.find('input[name=' + verifyName + ']')//获取需要校验的元素
  257. , isTrue = verifyElem.is(':checked')//是否命中校验
  258. , focusElem = verifyElem.next().find('i.layui-icon');//焦点元素
  259. if (!isTrue || !value) {
  260. //定位焦点
  261. focusElem.css(verifyType == 'radio' ? { "color": "#FF5722" } : { "border-color": "#FF5722" });
  262. //对非输入框设置焦点
  263. focusElem.first().attr("tabIndex", "1").css("outline", "0").blur(function () {
  264. focusElem.css(verifyType == 'radio' ? { "color": "" } : { "border-color": "" });
  265. }).focus();
  266. var reqText = verifyElem.attr('lay-reqText');
  267. if (reqText && reqText != '') {
  268. return reqText;
  269. }
  270. else {
  271. return '必填项不能为空';
  272. }
  273. }
  274. }
  275. });
  276. //监听提交
  277. form.on('submit(webform)', function (data) {
  278. data.field.content = tinyMCE.editors['container_content'].getContent();
  279. if (data.field.content == '') {
  280. layer.msg('请先完善商品描述内容');
  281. return false;
  282. }
  283. let callback = function (e) {
  284. layer.msg(e.msg);
  285. if (e.code == 0) {
  286. tool.sideClose(1000);
  287. }
  288. }
  289. tool.post("/admin/goods/edit", data.field, callback);
  290. return false;
  291. });
  292. }
  293. </script>
  294. {/block}
  295. <!-- /脚本 -->