edit.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. <?php
  2. use backend\widgets\TabWidget;
  3. echo TabWidget::widget(['list' => $this->context->menuList, 'currentMenu' => $this->context->id]);
  4. ?>
  5. <div class="panel panel-default">
  6. <?php
  7. use backend\widgets\SubTabWidget;
  8. echo SubTabWidget::widget(['list' => $this->context->subMenuList, 'currentMenu' => $this->context->action->id]);
  9. ?>
  10. <div class="panel-body">
  11. <form role="form" class="form-horizontal" id="goods-data-form">
  12. <input type="hidden" name="_csrf" value="<?= Yii::$app->request->csrfToken ?>"/>
  13. <input type="hidden" name="id" value="<?= $goods['id'] ?>"/>
  14. <div class="form-group">
  15. <label class="col-sm-2 control-label">*名称:</label>
  16. <div class="col-sm-10">
  17. <input type="text" class="form-control" name="goodsName" value="<?= $goods['goodsName'] ?>" placeholder="">
  18. <p></p>
  19. </div>
  20. </div>
  21. <div class="form-group">
  22. <label class="col-sm-2 control-label">编号:</label>
  23. <div class="col-sm-10">
  24. <span style="display:block;padding-top:6px;"><?= $goods['itemNumber'] ?></span>
  25. </div>
  26. </div>
  27. <div class="form-group">
  28. <label class="col-sm-2 control-label">*已售出:</label>
  29. <div class="col-sm-10">
  30. <input type="tel" class="form-control" name="sold" value="<?= $goods['sold'] ?>" placeholder="">
  31. <p></p>
  32. </div>
  33. </div>
  34. <div class="form-group">
  35. <label class="col-sm-2 control-label" for="field-1">花材:</label>
  36. <div class="col-sm-10">
  37. <input type="text" class="form-control" value="<?= $goods['material'] ?>" name="material" placeholder="">
  38. <p></p>
  39. </div>
  40. </div>
  41. <div class="form-group">
  42. <label class="col-sm-2 control-label" for="field-1">花语:</label>
  43. <div class="col-sm-10">
  44. <input type="text" class="form-control" name="representative" value="<?= $goods['representative'] ?>" placeholder="">
  45. <p></p>
  46. </div>
  47. </div>
  48. <div class="form-group-separator"></div>
  49. <div class="form-group">
  50. <label class="col-sm-2 control-label">*图片:</label>
  51. <div>
  52. <div style="margin-left:16px;width:113px;height:174px;float:left;display:inline-block">
  53. 封面[550x550]:
  54. <div style="width:97px;height:110px;display:inline-block;margin-bottom:3px;">
  55. <img src="<?= Yii::$app->params['imgUrl'] . $goods['cover'] ?>" name="cover" style="width:97px;height:110px;" onerror="javascript:this.src='/images/nopicture.png';" class="img-thumbnail"/>
  56. </div>
  57. <a href="javascript:;" class="a-upload">
  58. <input type="file" accept="image/*" id="cover" value=""/>选择图片 </a>
  59. <input type="hidden" name="cover" value="<?= $goods['cover'] ?>"/>
  60. </div>
  61. <?php $shopImg = json_decode($goods['shopImg'], true); ?>
  62. <div style="margin-left:16px;width:157px;height:174px;float:left;display:inline-block;float:left;">
  63. 图Ⅰ[800x800]:
  64. <div style="width:141px;height:110px;display:inline-block;margin-bottom:3px;">
  65. <img src="<?php if (isset($shopImg[0])) {
  66. echo Yii::$app->params['imgUrl'] . $shopImg[0];
  67. } else {
  68. echo '/images/nopicture.png';
  69. } ?>" name="shopImg1" style="width:128px;height:110px;" onerror="javascript:this.src='/images/nopicture.png';" class="img-thumbnail"/>
  70. </div>
  71. <a href="javascript:;" class="a-upload">
  72. <input type="file" accept="image/*" id="shopImg1" value=""/>选择图片 </a>
  73. <input type="hidden" name="shopImg1" value="<?php echo isset($shopImg[0]) ? $shopImg[0] : ''; ?>"/>
  74. </div>
  75. <div style="margin-left:16px;width:157px;height:174px;float:left;display:inline-block;float:left;">
  76. 图Ⅱ[800x800]:
  77. <div style="width:141px;height:110px;display:inline-block;margin-bottom:3px;">
  78. <img src="<?php if (isset($shopImg[1])) {
  79. echo Yii::$app->params['imgUrl'] . $shopImg[1];
  80. } else {
  81. echo '/images/nopicture.png';
  82. } ?>" name="shopImg2" style="width:128px;height:110px;" class="img-thumbnail"/>
  83. </div>
  84. <a href="javascript:;" class="a-upload">
  85. <input type="file" accept="image/*" id="shopImg2" value=""/>选择图片 </a>
  86. <input type="hidden" name="shopImg2" value="<?php echo isset($shopImg[1]) ? $shopImg[1] : ''; ?>"/>
  87. </div>
  88. <div style="margin-left:16px;width:157px;height:174px;float:left;display:inline-block;float:left;">
  89. 图Ⅲ[800x800]:
  90. <div style="width:141px;height:110px;display:inline-block;margin-bottom:3px;">
  91. <img src="<?php if (isset($shopImg[2])) {
  92. echo Yii::$app->params['imgUrl'] . $shopImg[2];
  93. } else {
  94. echo '/images/nopicture.png';
  95. } ?>" name="shopImg3" style="width:128px;height:110px;" onerror="javascript:this.src='/images/nopicture.png';" class="img-thumbnail"/>
  96. </div>
  97. <a href="javascript:;" class="a-upload">
  98. <input type="file" accept="image/*" id="shopImg3" value=""/>选择图片 </a>
  99. <input type="hidden" name="shopImg3" value="<?php echo isset($shopImg[2]) ? $shopImg[2] : ''; ?>"/>
  100. </div>
  101. <div style="clear:both;margin-left:228px;"><p></p></div>
  102. </div>
  103. </div>
  104. <div class="form-group-separator"></div>
  105. <div class="form-group price-area">
  106. <label class="col-sm-2 control-label">价格选项:</label>
  107. <div class="col-sm-10">
  108. <div class="col-sm-2 radio-inline">
  109. <label><input type="radio" name="priceType" data-type='single' value='single' <?php if ($goods['multiPrice'] == '') {
  110. echo 'checked="checked"';
  111. } ?> > 单价格</label>
  112. </div>
  113. <div class="col-sm-2 radio-inline">
  114. <label><input type="radio" name="priceType" data-type='multi' value='multi' <?php if ($goods['multiPrice'] != '') {
  115. echo 'checked="checked"';
  116. } ?> > 多价格</label>
  117. </div>
  118. </div>
  119. </div>
  120. <div class="form-group">
  121. <label class="col-sm-2 control-label">价格:</label>
  122. <div class="single-price-area" <?php if ($goods['multiPrice'] != '') {
  123. echo 'style="display:none;"';
  124. } ?> >
  125. <div class="col-sm-10" style="color:#555">
  126. <div class="form-group">
  127. <div class="col-sm-10">
  128. <input type="text" name="price" class="form-control" value="<?= $goods['price'] ?>">
  129. <p></p>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. <div class="multi-price-area" <?php if (!isset($goodsPriceArr)) {
  135. echo 'style="display:none;"';
  136. } ?> >
  137. <div class="col-sm-10" style="color:#555;">
  138. <?php
  139. if (isset($goodsPriceArr)) {
  140. foreach ($goodsPriceArr as $key => $item) {
  141. ?>
  142. <div class="form-group">
  143. <div class="col-sm-10 price-area">
  144. 名称:<input type="text" name="goodTitle[]" value="<?= $item['title'] ?>" class="form-control" style="width:150px;display:inline-block;">
  145. &nbsp;&nbsp;&nbsp;&nbsp;价格:<input type="text" name="multiPrice[]" value="<?= $item['price'] ?>" class="form-control" style="width:100px;display:inline-block;" placeholder="">
  146. <input type="hidden" name="priceId[]" value="<?= $item['id'] ?>"/>
  147. <!-- &nbsp;&nbsp;&nbsp;&nbsp;<img src="" alt="">
  148. &nbsp;&nbsp;<button type="button" class="btn btn-sm btn-white" style="display: none;margin:0;">上传图片</button>
  149. &nbsp;&nbsp;<button type="button" class="btn btn-sm btn-pink rm-price-btn" onclick="removePrice($(this))" style="display:none;margin:0;"><li class="fa-remove">删除</li></button>-->
  150. <?php
  151. if ($item['picture'] == '') {
  152. ?>
  153. &nbsp;&nbsp;&nbsp;&nbsp;
  154. <img src="/images/nopicture.png" style="width:50px;height:50px;" class="multi-price-img">
  155. <?php
  156. } else {
  157. ?>
  158. &nbsp;&nbsp;&nbsp;&nbsp;
  159. <img src="<?= Yii::$app->params['imgUrl']; ?><?= $item['picture'] ?>" style="width:50px;height:50px;" class="multi-price-img">
  160. <?php
  161. }
  162. ?>
  163. [210X150] <a href="javascript:;" class="a-upload">
  164. <input type="file" accept="image/*" class="img-upload-btn"/>上传图片 </a>
  165. <?php
  166. if ($item['picture'] == '') {
  167. ?>
  168. <input type="hidden" name="multiImg[]" value=""/>
  169. <?php
  170. } else {
  171. ?>
  172. <input type="hidden" name="multiImg[]" value="<?= $item['picture'] ?>"/>
  173. <?php
  174. }
  175. ?>
  176. </div>
  177. </div>
  178. <?php
  179. }
  180. } else {
  181. ?>
  182. <div class="form-group">
  183. <div class="col-sm-10">
  184. 名称:<input type="text" name="goodTitle[]" class="form-control" style="width:150px;display:inline-block;">
  185. &nbsp;&nbsp;&nbsp;&nbsp;价格:<input type="text" name="multiPrice[]" class="form-control" style="width:100px;display:inline-block;" placeholder="">
  186. <input type="hidden" name="priceId[]" value=""/>
  187. &nbsp;&nbsp;&nbsp;&nbsp;<img src="/images/nopicture.png" style="width:50px;height:50px;" class="multi-price-img">[210X150]
  188. <a href="javascript:;" class="a-upload">
  189. <input type="file" accept="image/*" class="img-upload-btn"/>上传图片 </a>
  190. <input type="hidden" name="multiImg[]" value=""/>
  191. </div>
  192. </div>
  193. <div class="form-group">
  194. <div class="col-sm-10">
  195. 名称:<input type="text" name="goodTitle[]" class="form-control" style="width:150px;display:inline-block;">
  196. &nbsp;&nbsp;&nbsp;&nbsp;价格:<input type="text" name="multiPrice[]" class="form-control" style="width:100px;display:inline-block;" placeholder="">
  197. <input type="hidden" name="priceId[]" value=""/>
  198. &nbsp;&nbsp;&nbsp;&nbsp;<img src="/images/nopicture.png" style="width:50px;height:50px;" class="multi-price-img">[210X150]
  199. <a href="javascript:;" class="a-upload">
  200. <input type="file" accept="image/*" class="img-upload-btn"/>上传图片 </a>
  201. <input type="hidden" name="multiImg[]" value=""/>
  202. </div>
  203. </div>
  204. <?php
  205. }
  206. ?>
  207. </div>
  208. <div class="col-sm-10">
  209. <label class="col-sm-2 control-label"></label>
  210. <div class="col-sm-8" style="margin-left: 35px;">
  211. <button type="button" class="btn btn-turquoise add-price-btn">
  212. <li class="fa-plus"></li>
  213. 增加价格
  214. </button>
  215. </div>
  216. </div>
  217. </div>
  218. </div>
  219. <div class="form-group price-area">
  220. <label class="col-sm-2 control-label">运费计算:</label>
  221. <div class="col-sm-10">
  222. <div class="col-sm-2 radio-inline">
  223. <label><input type="radio" name="isCharge" value='1' <?php if ($goods['isCharge'] == 1){ ?>checked="checked"<?php } ?> > 按距离收费</label>
  224. </div>
  225. <div class="col-sm-2 radio-inline">
  226. <label><input type="radio" name="isCharge" value='0' <?php if ($goods['isCharge'] == 0){ ?>checked="checked"<?php } ?> > 免运费</label>
  227. </div>
  228. </div>
  229. </div>
  230. <div class="form-group-separator"></div>
  231. <div class="form-group">
  232. <label class="col-sm-2 control-label" for="field-3">*商品简介:</label>
  233. <div class="col-sm-10">
  234. <?php use common\widgets\UeditorWidget; ?>
  235. <?= UeditorWidget::widget(['name' => 'content', 'content' => $goods['content']]); ?>
  236. <p></p>
  237. </div>
  238. </div>
  239. <div class="form-group-separator"></div>
  240. <div class="form-group">
  241. <label class="col-sm-2 control-label">*鲜花类型</label>
  242. <div class="col-sm-10 category-area">
  243. <div style="border:1px solid #CCC;padding-left:8px;border-radius:4px;">
  244. <?php
  245. if (!empty($categoryList)) {
  246. foreach ($categoryList as $clKey => $clVal) {
  247. if (!empty($clVal['child'])) {
  248. echo '<label class="checkbox-inline" style="padding-left:0px;">' . $clVal['name']. '</label><p>';
  249. foreach ($clVal['child'] as $ccKey => $ccVal) {
  250. echo '&nbsp;&nbsp;&nbsp;|-- <label class="checkbox-inline"><input name="categoryId[]"';
  251. if (in_array($ccVal['id'], $goodsCategory)) echo 'checked ';
  252. echo 'value="' . $ccVal['id'] . '" type="checkbox">' . $ccVal['name']. '</label>';
  253. }
  254. echo '</p>';
  255. } else {
  256. echo '<label class="checkbox-inline"><input name="categoryId[]"';
  257. if (in_array($clVal['id'], $goodsCategory)) echo 'checked ';
  258. echo 'value="' . $clVal['id'] . '" type="checkbox">' . $clVal['name'] . '</label><p></p>';
  259. }
  260. }
  261. }
  262. ?>
  263. </div>
  264. <p name="categoryIdMention"></p>
  265. </div>
  266. </div>
  267. <div class="form-group-separator"></div>
  268. <div class="form-group">
  269. <label class="col-sm-2 control-label">*用途</label>
  270. <div class="col-sm-10 usage-area">
  271. <div style="border:1px solid #CCC;padding-left:8px;border-radius:4px;">
  272. <?php
  273. if (!empty($usageList)) {
  274. foreach ($usageList as $usageKey => $usageVal) {
  275. echo '<label class="checkbox-inline"><input name="usageId[]"';
  276. if (in_array($usageVal['id'], $goodsUsageIdList)) echo 'checked ';
  277. echo 'value="' . $usageVal['id'] . '" type="checkbox">' . $usageVal['name'].'</label><p></p>';
  278. }
  279. }
  280. ?>
  281. </div>
  282. <p name="usageIdMention"></p>
  283. </div>
  284. </div>
  285. <div class="form-group">
  286. <label class="col-sm-2 control-label" for="field-4">*商品状态</label>
  287. <div class="col-sm-10">
  288. <div class="radio-inline">
  289. <label>
  290. <input type="radio" name="status" <?php if ($goods['status'] == 0){ ?>checked<?php } ?> checked value="0"> 上架
  291. </label>
  292. </div>
  293. <div class="radio-inline">
  294. <label>
  295. <input type="radio" name="status" <?php if ($goods['status'] == 1){ ?>checked<?php } ?> value="1"> 下架
  296. </label>
  297. </div>
  298. </div>
  299. </div>
  300. <div class="form-group-separator"></div>
  301. <div class="form-group" style="text-align:center;">
  302. <button type="button" onclick="editSubmit('click', this)" class="btn btn-info btn-single">确认</button>
  303. <button type="button" onclick="history.go(-1);" class="btn btn-info btn-single">返回</button>
  304. </div>
  305. </form>
  306. </div>
  307. </div>
  308. <!-- footer -->
  309. <?php
  310. use backend\widgets\FooterWidget;
  311. ?>
  312. <?= FooterWidget::widget() ?>
  313. <!-- footer -->
  314. <script src="/js/lrz/dist/lrz.bundle.js"></script>
  315. <script>
  316. //添加商品验证流程
  317. var goodsId = $("input[name=id]");
  318. var goodsName = $("input[name=goodsName]");
  319. var price = $("input[name=price]");
  320. var sold = $("input[name=sold]");
  321. var material = $("input[name=material]");
  322. var representative = $(":input[name=representative]");
  323. var cover = $(":input[name=cover]");
  324. var shopImg1 = $(":input[name=shopImg1]");
  325. var shopImg2 = $(":input[name=shopImg2]");
  326. var shopImg3 = $(":input[name=shopImg3]");
  327. var content = $("textarea[name=content]");
  328. Array.prototype.diff = function (a) {
  329. return this.filter(function (i) {
  330. return a.indexOf(i) < 0;
  331. });
  332. };
  333. var needValidate = [goodsName, price, sold, material, representative];
  334. //添加商品验证流程
  335. editSubmit();
  336. function editSubmit() {
  337. var verifyStatus = true;
  338. setStats(goodsName, '请填写商品名称', function (val, mess) {
  339. var info = [false, mess];
  340. if (val.length <= 0) {
  341. info[1] = '请填写商品名称';
  342. } else if (getLength(val) >= 0 && getLength(val) <= 40) {
  343. info[0] = true;
  344. info[1] = '填写正确';
  345. } else {
  346. info[0] = false;
  347. }
  348. return info;
  349. });
  350. var priceType = $('.price-area input:radio[name=priceType]:checked').attr('data-type');
  351. if (priceType == 'single') {
  352. setStats(price, '请填写价格', function (val, mess) {
  353. var info = [false, mess];
  354. if (isNotNull(val) == false || isNaN(val)) {
  355. info[1] = '请填写价格';
  356. } else {
  357. info[0] = true;
  358. }
  359. return info;
  360. });
  361. } else {
  362. var units = $('.multi-price-area .col-sm-10').find('.form-group');
  363. units.each(function (e) {
  364. var title = $(this).find('.form-control').eq(0).val();
  365. var price = $(this).find('.form-control').eq(1).val();
  366. if ($.trim(title) == '') {
  367. xhPopMsg('价格项: 名称不为空', 2500);
  368. verifyStatus = false;
  369. return;
  370. }
  371. if ($.trim(price) == '') {
  372. xhPopMsg('价格项: 有价格未填写', 2500);
  373. verifyStatus = false;
  374. return;
  375. }
  376. if (isNaN(price)) {
  377. xhPopMsg('价格项: 价格必须为数字', 2500);
  378. verifyStatus = false;
  379. return;
  380. }
  381. });
  382. var singlePriceObj = $('.single-price-area input[name=price]');
  383. singlePriceObj.attr('addStatus', 'yes');
  384. singlePriceObj.siblings('p').removeClass('help-error-mention').html('');
  385. }
  386. setStats(sold, '请填写售量', function (val, mess) {
  387. var info = [false, mess];
  388. if (isNotNull(val) == false || isNaN(val)) {
  389. info[1] = '请填写售量';
  390. } else {
  391. info[0] = true;
  392. }
  393. return info;
  394. });
  395. setStats(material, '请填写花材', function (val, mess) {
  396. var info = [false, mess];
  397. if (getLength(val) >= 0) {
  398. info[0] = true;
  399. info[1] = '填写正确';
  400. } else {
  401. info[1] = '请填写花材';
  402. }
  403. return info;
  404. });
  405. setStats(representative, '请填写花语', function (val, mess) {
  406. var info = [false, mess];
  407. if (getLength(val) >= 0) {
  408. info[0] = true;
  409. info[1] = '填写正确';
  410. } else {
  411. info[1] = '请填写花语';
  412. }
  413. return info;
  414. });
  415. setStats(shopImg1, '请填写上传图片', function (val, mess) {
  416. var info = [false, mess];
  417. if (getLength(val) >= 0) {
  418. info[0] = true;
  419. info[1] = '填写正确';
  420. } else {
  421. info[1] = '至少需要上传一张图片';
  422. }
  423. return info;
  424. });
  425. setStats(content, '请填写简介', function (val, mess) {
  426. var info = [false, mess];
  427. if (val.length > 0) {
  428. info[0] = true;
  429. info[1] = '填写正确';
  430. } else {
  431. info[1] = '请填写简介';
  432. }
  433. return info;
  434. });
  435. if (arguments[0] == 'click') {//用户点击提交
  436. var submitButton = arguments[1];//获取提交按钮对象
  437. var submitButtonObj = $(submitButton);
  438. if (submitButtonObj.attr('submitStatus') == 'yes') {
  439. alert('表单已经提交成功,不允许重复提交');
  440. return;//表单已经提交成功,不允许重复提交
  441. }
  442. for (var m = 0; m < needValidate.length; m++) {
  443. var singleObj = needValidate[m];
  444. if (singleObj.attr('addStatus') == undefined) {
  445. singleObj.blur();
  446. }
  447. if (singleObj.attr('addStatus') == 'no') {
  448. verifyStatus = false;
  449. continue;
  450. }
  451. }
  452. //封面 图片1判断
  453. if (isNotNull(shopImg1.val()) == false || isNotNull(cover.val()) == false) {
  454. shopImg1.parent().parent().find('p').addClass('help-error-mention').html('封面和图Ⅰ必须上传');
  455. verifyStatus = false;
  456. } else {
  457. shopImg1.parent().parent().find('p').removeClass('help-error-mention').html('');
  458. }
  459. //确认有没选择分类
  460. var checkNum = $(".form-group .category-area :checkbox:checked").length;
  461. if (parseInt(checkNum) < 1) {
  462. $("p[name=categoryIdMention]").addClass('help-error-mention').html('请选择分类');
  463. verifyStatus = false;
  464. } else {
  465. $("p[name=categoryIdMention]").removeClass('help-error-mention').html('');
  466. }
  467. var newGoodsCategory = [];
  468. $(":input[name=categoryId\\[\\]]:checked").each(function () {
  469. var thisCId = $(this).val();
  470. newGoodsCategory.push(thisCId);
  471. });
  472. var addCategoryId = newGoodsCategory;//并集,需要添加的
  473. //确认有没选择用途
  474. var checkNum = $(".form-group .usage-area :checkbox:checked").length;
  475. if (parseInt(checkNum) < 1) {
  476. $("p[name=usageIdMention]").addClass('help-error-mention').html('请选择分类');
  477. verifyStatus = false;
  478. } else {
  479. $("p[name=usageIdMention]").removeClass('help-error-mention').html('');
  480. }
  481. var newUsage = [];
  482. $(":input[name=usageId\\[\\]]:checked").each(function () {
  483. var thisCId = $(this).val();
  484. newUsage.push(thisCId);
  485. });
  486. var addUsageId = newUsage;//并集,需要添加的
  487. if (verifyStatus) {
  488. var data = $('#goods-data-form').serialize();
  489. data = data + "&addCategoryId=" + addCategoryId.join(',') + "&addUsageId="+addUsageId.join(',');
  490. $.ajax({
  491. type: "POST",
  492. url: '/goods/save-edit',
  493. data: data,
  494. dataType: 'json',
  495. async: false,
  496. success: function (data) {
  497. if (data.code == 'A0001') {
  498. submitButtonObj.attr('submitStatus', 'yes');
  499. xhPopMsg(data.msg, 1300);//调用定时浮层 XXX毫秒后消失
  500. setTimeout(function () {
  501. window.location.href = '/goods/list';
  502. }, 1400);
  503. } else {
  504. xhPopMsg(data.msg, 1500);
  505. }
  506. }
  507. });
  508. }
  509. }
  510. }
  511. function setStats(obj, mess, check) {
  512. obj.focus(function () {
  513. $(this).removeAttr('addStatus');
  514. $(this).siblings('p').removeClass('help-error-mention').html('');
  515. $(this).parent().parent().removeClass("has-success").removeClass('has-error');
  516. });
  517. obj.blur(function () {
  518. var objVal = obj.val();
  519. var info = check(objVal, mess);
  520. if (info[0]) {
  521. $(this).attr('addStatus', 'yes');
  522. $(this).siblings('p').removeClass('help-error-mention').html('');
  523. $(this).parent().parent().addClass("has-success").removeClass("has-error");
  524. } else {
  525. $(this).attr('addStatus', 'no');
  526. $(this).siblings('p').addClass('help-error-mention').html(info[1]);
  527. $(this).parent().parent().addClass("has-error").removeClass("has-success");
  528. }
  529. });
  530. }
  531. document.querySelector('#cover').addEventListener('change', function () {
  532. //参数说明 https://github.com/think2011/localResizeIMG/wiki/2.-%E5%8F%82%E6%95%B0%E6%96%87%E6%A1%A3
  533. lrz(this.files[0], {
  534. width: 800,// 图片最大不超过的宽度,默认为原图宽度,高度不设时会适应宽度。
  535. fieldName: 'Filedata',//文件名
  536. quality: 1,//图片质量 0.1 - 1
  537. })
  538. .then(function (rst) {
  539. // 处理成功会执行
  540. rst.formData.append('fileLen', rst.fileLen);
  541. rst.formData.append('_csrf', '<?= Yii::$app->request->csrfToken?>');
  542. $.ajax({
  543. //url: '/main/img', // 这个地址做了跨域处理,可以用于实际调试
  544. url: '/upload/upload-goods-img', // 这个地址做了跨域处理,可以用于实际调试
  545. data: rst.formData,
  546. processData: false,
  547. contentType: false,
  548. type: 'POST',
  549. dataType: 'json',
  550. success: function (data) {
  551. $("img[name=cover]").attr('src', '<?= Yii::$app->params['imgUrl']; ?>' + data.url);
  552. $("input[name='cover']").val(data.url);
  553. }
  554. });
  555. })
  556. .catch(function (err) {
  557. // 处理失败会执行
  558. })
  559. .always(function () {
  560. // 不管是成功失败,都会执行
  561. });
  562. });
  563. document.querySelector('#shopImg1').addEventListener('change', function () {
  564. //参数说明 https://github.com/think2011/localResizeIMG/wiki/2.-%E5%8F%82%E6%95%B0%E6%96%87%E6%A1%A3
  565. lrz(this.files[0], {
  566. width: 800,// 图片最大不超过的宽度,默认为原图宽度,高度不设时会适应宽度。
  567. fieldName: 'Filedata',//文件名
  568. quality: 1,//图片质量 0.1 - 1
  569. })
  570. .then(function (rst) {
  571. // 处理成功会执行
  572. rst.formData.append('fileLen', rst.fileLen);
  573. rst.formData.append('_csrf', '<?= Yii::$app->request->csrfToken?>');
  574. $.ajax({
  575. //url: '/main/img', // 这个地址做了跨域处理,可以用于实际调试
  576. url: '/upload/upload-goods-img', // 这个地址做了跨域处理,可以用于实际调试
  577. data: rst.formData,
  578. processData: false,
  579. contentType: false,
  580. type: 'POST',
  581. dataType: 'json',
  582. success: function (data) {
  583. $("img[name=shopImg1]").attr('src', '<?= Yii::$app->params['imgUrl']; ?>' + data.url);
  584. $("input[name='shopImg1']").val(data.url);
  585. }
  586. });
  587. })
  588. .catch(function (err) {
  589. // 处理失败会执行
  590. })
  591. .always(function () {
  592. // 不管是成功失败,都会执行
  593. });
  594. });
  595. document.querySelector('#shopImg2').addEventListener('change', function () {
  596. //参数说明 https://github.com/think2011/localResizeIMG/wiki/2.-%E5%8F%82%E6%95%B0%E6%96%87%E6%A1%A3
  597. lrz(this.files[0], {
  598. width: 800,// 图片最大不超过的宽度,默认为原图宽度,高度不设时会适应宽度。
  599. fieldName: 'Filedata',//文件名
  600. quality: 1,//图片质量 0.1 - 1
  601. })
  602. .then(function (rst) {
  603. // 处理成功会执行
  604. rst.formData.append('fileLen', rst.fileLen);
  605. rst.formData.append('_csrf', '<?= Yii::$app->request->csrfToken?>');
  606. $.ajax({
  607. //url: '/main/img', // 这个地址做了跨域处理,可以用于实际调试
  608. url: '/upload/upload-goods-img', // 这个地址做了跨域处理,可以用于实际调试
  609. data: rst.formData,
  610. processData: false,
  611. contentType: false,
  612. type: 'POST',
  613. dataType: 'json',
  614. success: function (data) {
  615. $("img[name=shopImg2]").attr('src', '<?= Yii::$app->params['imgUrl']; ?>' + data.url);
  616. $("input[name='shopImg2']").val(data.url);
  617. }
  618. });
  619. })
  620. .catch(function (err) {
  621. // 处理失败会执行
  622. })
  623. .always(function () {
  624. // 不管是成功失败,都会执行
  625. });
  626. });
  627. document.querySelector('#shopImg3').addEventListener('change', function () {
  628. //参数说明 https://github.com/think2011/localResizeIMG/wiki/2.-%E5%8F%82%E6%95%B0%E6%96%87%E6%A1%A3
  629. lrz(this.files[0], {
  630. width: 800,// 图片最大不超过的宽度,默认为原图宽度,高度不设时会适应宽度。
  631. fieldName: 'Filedata',//文件名
  632. quality: 1,//图片质量 0.1 - 1
  633. })
  634. .then(function (rst) {
  635. // 处理成功会执行
  636. rst.formData.append('fileLen', rst.fileLen);
  637. rst.formData.append('_csrf', '<?= Yii::$app->request->csrfToken?>');
  638. $.ajax({
  639. //url: '/main/img', // 这个地址做了跨域处理,可以用于实际调试
  640. url: '/upload/upload-goods-img', // 这个地址做了跨域处理,可以用于实际调试
  641. data: rst.formData,
  642. processData: false,
  643. contentType: false,
  644. type: 'POST',
  645. dataType: 'json',
  646. success: function (data) {
  647. $("img[name=shopImg3]").attr('src', '<?= Yii::$app->params['imgUrl']; ?>' + data.url);
  648. $("input[name='shopImg3']").val(data.url);
  649. }
  650. });
  651. })
  652. .catch(function (err) {
  653. // 处理失败会执行
  654. })
  655. .always(function () {
  656. // 不管是成功失败,都会执行
  657. });
  658. });
  659. $('.a-upload .img-upload-btn').on('change', function () {
  660. var obj = $(this);
  661. lrz(this.files[0], {
  662. width: 800,// 图片最大不超过的宽度,默认为原图宽度,高度不设时会适应宽度。
  663. fieldName: 'Filedata',//文件名
  664. quality: 1,//图片质量 0.1 - 1
  665. })
  666. .then(function (rst) {
  667. // 处理成功会执行
  668. rst.formData.append('fileLen', rst.fileLen);
  669. rst.formData.append('_csrf', '<?= Yii::$app->request->csrfToken?>');
  670. $.ajax({
  671. //url: '/main/img', // 这个地址做了跨域处理,可以用于实际调试
  672. url: '/upload/upload-goods-img', // 这个地址做了跨域处理,可以用于实际调试
  673. data: rst.formData,
  674. processData: false,
  675. contentType: false,
  676. type: 'POST',
  677. dataType: 'json',
  678. success: function (data) {
  679. obj.parent().prev().attr('src', '<?= Yii::$app->params['imgUrl']; ?>' + data.url);
  680. obj.parent().next().val(data.url);
  681. }
  682. });
  683. })
  684. .catch(function (err) {
  685. // 处理失败会执行
  686. })
  687. .always(function () {
  688. // 不管是成功失败,都会执行
  689. });
  690. });
  691. function delPrice(obj) {
  692. obj.closest('.form-group').remove();
  693. }
  694. function removePrice(obj) {
  695. var formGroupObj = obj.closest('.form-group').siblings();
  696. var length = formGroupObj.length;
  697. if (length < 2) {
  698. var content = '<div class="form-group"><div class="col-sm-10">名称:<input type="text" name="goodTitle[]" class="form-control" style="width:150px;display:inline-block;" >&nbsp;&nbsp;&nbsp;&nbsp;价格:<input type="text" name="multiPrice[]" class="form-control" style="width:100px;display:inline-block;" placeholder="">&nbsp;&nbsp;&nbsp;&nbsp;<img src="" alt="">[210X150]&nbsp;&nbsp;<button type="button" class="btn btn-sm btn-white" style="display: none;margin:0;">上传图片</button></div></div>';
  699. formGroupObj.last().after(content);
  700. }
  701. obj.closest('.form-group').remove();
  702. }
  703. $(function () {
  704. //增加价格按钮事件
  705. $('.add-price-btn').on('click', function () {
  706. var unitNum = $(this).closest('.form-group').find('.multi-price-area .col-sm-10').eq(0).find('.form-group').length;
  707. if (unitNum > 9) {
  708. xhPopMsg('价格最多只可设置10个', 2500);
  709. return;
  710. }
  711. var content = '<div class="form-group"><div class="col-sm-10">名称:<input type="text" name="goodTitle[]" class="form-control" style="width:150px;display:inline-block;" placeholder="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价格:<input type="text" name="multiPrice[]" class="form-control" style="width:100px;display:inline-block;" placeholder=""> &nbsp;&nbsp;&nbsp;&nbsp;<img src="/images/nopicture.png" alt="" style="width:50px;height:50px;">[210X150]&nbsp;&nbsp;<a href="javascript:;" class="a-upload"><input type="file" accept="image/*" class="img-upload-btn"/>上传图片</a><input type="hidden" name="multiImg[]" value="" />&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-sm btn-pink" onclick="delPrice(this)" style="margin:0;"><li class="fa-remove">删除</li></button></div></div>';
  712. $(this).closest('.form-group').find('.multi-price-area .col-sm-10').eq(0).find('.form-group').last().after(content);
  713. $(this).closest('.form-group').find('.multi-price-area .col-sm-10').eq(0).find('.form-group').last().find('.a-upload .img-upload-btn').on('change', function () {
  714. var obj = $(this);
  715. lrz(this.files[0], {
  716. width: 800,// 图片最大不超过的宽度,默认为原图宽度,高度不设时会适应宽度。
  717. fieldName: 'Filedata',//文件名
  718. quality: 1,//图片质量 0.1 - 1
  719. })
  720. .then(function (rst) {
  721. // 处理成功会执行
  722. rst.formData.append('fileLen', rst.fileLen);
  723. rst.formData.append('_csrf', '<?= Yii::$app->request->csrfToken?>');
  724. $.ajax({
  725. //url: '/main/img', // 这个地址做了跨域处理,可以用于实际调试
  726. url: '/upload/upload-goods-img', // 这个地址做了跨域处理,可以用于实际调试
  727. data: rst.formData,
  728. processData: false,
  729. contentType: false,
  730. type: 'POST',
  731. dataType: 'json',
  732. success: function (data) {
  733. obj.parent().prev().attr('src', '<?= Yii::$app->params['imgUrl']; ?>' + data.url);
  734. obj.parent().next().val(data.url);
  735. }
  736. });
  737. })
  738. .catch(function (err) {
  739. // 处理失败会执行
  740. })
  741. .always(function () {
  742. // 不管是成功失败,都会执行
  743. });
  744. })
  745. });
  746. //价格选项事件
  747. $('.price-area input:radio[name=priceType]').on('change', function () {
  748. var type = $(this).attr('data-type');
  749. if (type == 'single') {
  750. $('.single-price-area').show();
  751. $('.multi-price-area').hide();
  752. } else {
  753. $('.multi-price-area').show();
  754. $('.single-price-area').hide();
  755. var singlePriceObj = $('.single-price-area input[name=price]');
  756. singlePriceObj.attr('addStatus', 'yes');
  757. singlePriceObj.siblings('p').removeClass('help-error-mention').html('');
  758. }
  759. });
  760. //显示删除按钮
  761. $('.form-group .price-area').hover(function () {
  762. $(this).find('.rm-price-btn').show();
  763. }, function () {
  764. $(this).find('.rm-price-btn').hide();
  765. });
  766. });
  767. </script>