goods.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. $(function () {
  2. $("#jqGrid").jqGrid({
  3. url: '../goods/list',
  4. datatype: "json",
  5. colModel: [
  6. {label: 'ID', name: 'id', index: 'id', hidden: true, key: true},
  7. {label: '商品编码', name: 'goodsSn', index: 'goods_Sn', width: 60},
  8. {label: 'SKU', name: 'sku', index: 'sku', width: 80},
  9. {label: '商品类型', name: 'categoryName', index: 'category_id', width: 40},
  10. {label: '名称', name: 'name', index: 'name', width: 160},
  11. {
  12. label: '货品业务类型', name: 'goodsBizType', index: 'goods_biz_type', width: 70,
  13. formatter: function (value) {
  14. if (value == '00') {
  15. return '保税备货';
  16. } else if (value == '02') {
  17. return '保税展示补货';
  18. } else if (value == '10') {
  19. return '保税展示跨境';
  20. }
  21. return '普通货物';
  22. }
  23. },
  24. {label: '零售价格', name: 'retailPrice', index: 'retail_price', width: 80},
  25. {label: '市场价', name: 'marketPrice', index: 'market_price', width: 80},
  26. {
  27. label: '上架', name: 'isOnSale', index: 'is_on_sale', width: 40, align: 'center',
  28. formatter: function (value) {
  29. return transIsNot(value);
  30. }
  31. },
  32. /*{
  33. label: '热销', name: 'isHot', index: 'is_hot', width: 80, formatter: function (value) {
  34. return transIsNot(value);
  35. }
  36. },
  37. {
  38. label: '活动', name: 'goodsType', index: 'goodsType', width: 80,
  39. formatter: function (value) {
  40. if (value == 2) {
  41. return '<span class="label label-warning">团购</span>';
  42. } else {
  43. return '<span class="label label-success">无活动</span>';
  44. }
  45. }
  46. },*/
  47. {
  48. label: '录入日期', name: 'addTime', index: 'add_time', width: 80,
  49. formatter: function (value) {
  50. return transDate(value, 'yyyy-MM-dd hh:mm:ss');
  51. }
  52. }
  53. ],
  54. viewrecords: true,
  55. height: 675,
  56. rowNum: 15,
  57. rowList: [15, 30, 50],
  58. rownumbers: true,
  59. rownumWidth: 25,
  60. autowidth: true,
  61. multiselect: true,
  62. pager: "#jqGridPager",
  63. jsonReader: {
  64. root: "page.list",
  65. page: "page.currPage",
  66. total: "page.totalPage",
  67. records: "page.totalCount"
  68. },
  69. prmNames: {
  70. page: "page",
  71. rows: "limit",
  72. order: "order"
  73. },
  74. gridComplete: function () {
  75. $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
  76. }
  77. });
  78. $('#goodsDesc').editable({
  79. inlineMode: false,
  80. alwaysBlank: true,
  81. height: '500px', //高度
  82. minHeight: '200px',
  83. language: "zh_cn",
  84. spellcheck: false,
  85. plainPaste: true,
  86. enableScript: false,
  87. imageButtons: ["floatImageLeft", "floatImageNone", "floatImageRight", "linkImage", "replaceImage", "removeImage"],
  88. allowedImageTypes: ["jpeg", "jpg", "png", "gif"],
  89. imageUploadURL: '../sys/oss/upload',
  90. imageUploadParams: {id: "edit"},
  91. imagesLoadURL: '../sys/oss/queryAll'
  92. })
  93. });
  94. var ztree;
  95. var setting = {
  96. data: {
  97. simpleData: {
  98. enable: true,
  99. idKey: "id",
  100. pIdKey: "parentId",
  101. rootPId: -1
  102. },
  103. key: {
  104. url: "nourl"
  105. }
  106. }
  107. };
  108. var vm = new Vue({
  109. el: '#rrapp',
  110. data: {
  111. showList: true,
  112. title: null,
  113. uploadList: [],
  114. imgName: '',
  115. visible: false,
  116. goods: {primaryPicUrl: '', listPicUrl: '', categoryId: '', isOnSale: 1, isAppExclusive: 0, isLimited: 0, isHot: 0, categoryName: '', retailPrice: '', marketPrice: '', goodsRate: '', sortOrder: '' },
  117. ruleValidate: {
  118. /*name: [
  119. {required: true, message: '名称不能为空', trigger: 'blur'}
  120. ]*/
  121. },
  122. q: {name: '', goodsSn: '', category: '', categoryTwo: ''},
  123. attributes: [],
  124. attributeEntityList: [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}],
  125. productEntityList: [{'id': '', 'goodsId': '', 'goodsSpecificationIds': '', 'goodsSpecificationNameValue': '', 'goodsSn': '', 'goodsNumber': '', 'isDelete': 0, 'goodsDefault': 0}],
  126. queryCategories: [],//一级分类
  127. queryCategoriesTwo: [],
  128. categories: [],//一级分类
  129. categoriesTwo: [],
  130. macros: [],//商品单位
  131. attributeCategories: [],//属性类别
  132. specifications: [],
  133. brands: [],
  134. freights: [],
  135. showInput: true,
  136. categoryId: ''
  137. },
  138. methods: {
  139. delSpeRow: function (index) {
  140. //最后一行时禁止删除
  141. if (vm.productEntityList.length == 1) {
  142. return;
  143. }
  144. vm.productEntityList[index].isDelete = 1;
  145. },
  146. addSpeRow: function () {
  147. let goodsId = '';
  148. if (vm.goods) {
  149. goodsId = vm.goods.id;
  150. }
  151. vm.productEntityList.push({'id': '', 'goodsId': '', 'goodsSpecificationIds': '', 'goodsSpecificationNameValue': '', 'goodsSn': '', 'goodsNumber': '', 'isDelete': 0, 'goodsDefault': 0});
  152. },
  153. delAttrRow: function (index) {
  154. //最后一行时禁止删除
  155. if (vm.attributeEntityList.length == 1) {
  156. return;
  157. }
  158. vm.attributeEntityList[index].isDelete = 1;
  159. },
  160. addAttrRow: function () {
  161. let goodsId = '';
  162. if (vm.goods) {
  163. goodsId = vm.goods.id;
  164. }
  165. vm.attributeEntityList.push({'id': '', 'goodsId': goodsId, 'attributeId': '', 'value': '', 'isDelete': 0});
  166. },
  167. reloadSearch: function () {
  168. vm.q = {
  169. name: '',
  170. goodsSn: '',
  171. category: '',
  172. categoryTwo: ''
  173. }
  174. },
  175. query: function () {
  176. vm.reload(1);
  177. },
  178. add: function () {
  179. vm.showList = false;
  180. vm.title = "新增";
  181. vm.uploadList = [];
  182. vm.goods = {primaryPicUrl: '', listPicUrl: '', categoryId: '', isOnSale: 1, isAppExclusive: 0, isLimited: 0, isHot: 0, categoryName: '', retailPrice: '', marketPrice: '', goodsRate: '', sortOrder: '' };
  183. $('#goodsDesc').editable('setHTML', '');
  184. vm.getCategory();
  185. vm.macros = [];
  186. vm.brands = [];
  187. vm.freights = [];
  188. vm.attributeEntityList = [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}];
  189. vm.getMacro();
  190. vm.getBrand();
  191. vm.getFreights();
  192. vm.showInput = true;
  193. },
  194. update: function (event) {
  195. var id = getSelectedRow();
  196. if (id == null) {
  197. return;
  198. }
  199. vm.showList = false;
  200. vm.title = "修改";
  201. vm.uploadList = [];
  202. vm.getInfo(id);
  203. var opt = {};
  204. opt.value = vm.goods.categoryId;
  205. opt.flag = 1;
  206. vm.getAttributes(opt);
  207. vm.getMacro();
  208. vm.getBrand();
  209. vm.getFreights();
  210. vm.getGoodsGallery(id);
  211. vm.showInput = true;
  212. if (vm.goods.goodsBizType == '10' || vm.goods.goodsBizType == '02') {
  213. vm.showInput = false;
  214. }
  215. },
  216. getMacro: function () {
  217. // 获取货品业务类型
  218. $.get("../sys/macro/queryMacrosByValue?value=goodsBizType", function (r) {
  219. vm.macros = r.list;
  220. });
  221. },
  222. getBrand: function () {
  223. $.get("../brand/queryAll", function (r) {
  224. vm.brands = r.list;
  225. });
  226. },
  227. getFreights: function() {
  228. $.get("../freight/queryAll", function (r) {
  229. vm.freights = r.list;
  230. });
  231. },
  232. getGoodsGallery: function (id) {//获取商品顶部轮播图
  233. $.get("../goodsgallery/queryAll?goodsId=" + id, function (r) {
  234. vm.uploadList = r.list;
  235. });
  236. },
  237. saveOrUpdate: function (event) {
  238. var url = vm.goods.id == null ? "../goods/save" : "../goods/update";
  239. vm.goods.goodsDesc = $('#goodsDesc').editable('getHTML');
  240. vm.goods.goodsImgList = vm.uploadList;
  241. vm.goods.attributeEntityList = vm.attributeEntityList;
  242. vm.goods.productEntityList = vm.productEntityList;
  243. $.ajax({
  244. type: "POST",
  245. url: url,
  246. dataType: "json",
  247. contentType: "application/json",
  248. data: JSON.stringify(vm.goods),
  249. success: function (r) {
  250. if (r.code === 0) {
  251. alert('操作成功', function (index) {
  252. vm.reload();
  253. });
  254. } else {
  255. alert(r.msg);
  256. }
  257. }
  258. });
  259. },
  260. enSale: function () {
  261. var ids = getSelectedRows();
  262. if (ids == null) {
  263. return;
  264. }
  265. confirm('确定要上架选中的商品?', function () {
  266. $.ajax({
  267. type: "POST",
  268. url: "../goods/enSaleBatch",
  269. contentType: "application/json",
  270. data: JSON.stringify(ids),
  271. success: function (r) {
  272. if (r.code == 0) {
  273. alert('操作成功', function (index) {
  274. $("#jqGrid").trigger("reloadGrid");
  275. });
  276. } else {
  277. alert(r.msg);
  278. }
  279. }
  280. });
  281. });
  282. },
  283. openSpe: function () {
  284. var id = getSelectedRow();
  285. if (id == null) {
  286. return;
  287. }
  288. openWindow({
  289. type: 2,
  290. title: '商品规格',
  291. content: '../shop/goodsspecification.html?goodsId=' + id
  292. })
  293. },
  294. openPro: function () {
  295. var id = getSelectedRow();
  296. if (id == null) {
  297. return;
  298. }
  299. openWindow({
  300. type: 2,
  301. title: '产品设置',
  302. content: '../shop/product.html?goodsId=' + id
  303. });
  304. },
  305. unSale: function () {
  306. var ids = getSelectedRows();
  307. if (ids == null) {
  308. return;
  309. }
  310. confirm('确定要下架选中的商品?', function () {
  311. $.ajax({
  312. type: "POST",
  313. url: "../goods/unSaleBatch",
  314. contentType: "application/json",
  315. data: JSON.stringify(ids),
  316. success: function (r) {
  317. if (r.code == 0) {
  318. alert('操作成功', function (index) {
  319. $("#jqGrid").trigger("reloadGrid");
  320. });
  321. } else {
  322. alert(r.msg);
  323. }
  324. }
  325. });
  326. });
  327. },
  328. del: function (event) {
  329. var ids = getSelectedRows();
  330. if (ids == null) {
  331. return;
  332. }
  333. confirm('确定要删除选中的记录?', function () {
  334. $.ajax({
  335. type: "POST",
  336. url: "../goods/delete",
  337. contentType: "application/json",
  338. data: JSON.stringify(ids),
  339. success: function (r) {
  340. if (r.code == 0) {
  341. alert('操作成功', function (index) {
  342. $("#jqGrid").trigger("reloadGrid");
  343. });
  344. } else {
  345. alert(r.msg);
  346. }
  347. }
  348. });
  349. });
  350. },
  351. getInfo: function (id) {
  352. $.get("../goods/info/" + id, function (r) {
  353. vm.goods = r.goods;
  354. vm.categoryId = r.goods.categoryId;
  355. // vm.getCategory();
  356. var opt = {};
  357. opt.value = vm.goods.attributeCategory;
  358. vm.changeCategories(opt);
  359. if (r.goods.attributeEntityList.length > 0) {
  360. vm.attributeEntityList = r.goods.attributeEntityList;
  361. } else {
  362. vm.attributeEntityList = [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}];
  363. }
  364. if (r.goods.productEntityList.length > 0) {
  365. vm.productEntityList = r.goods.productEntityList;
  366. } else {
  367. vm.productEntityList = [{'id': '', 'goodsId': '', 'goodsSpecificationIds': '', 'goodsSpecificationNameValue': '', 'goodsSn': '', 'goodsNumber': '', 'isDelete': 0, 'goodsDefault': 0}];
  368. }
  369. $('#goodsDesc').editable('setHTML', vm.goods.goodsDesc);
  370. });
  371. },
  372. reload: function (event) {
  373. vm.showList = true;
  374. let page = event;
  375. if (event != 1) {
  376. page = $("#jqGrid").jqGrid('getGridParam', 'page');
  377. }
  378. $("#jqGrid").jqGrid('setGridParam', {
  379. postData: {
  380. 'name': vm.q.name,
  381. 'goodsSn': vm.q.goodsSn,
  382. 'category': vm.q.category,
  383. 'categoryTwo': vm.q.categoryTwo
  384. },
  385. page: page
  386. }).trigger("reloadGrid");
  387. vm.handleReset('formValidate');
  388. },
  389. getCategory: function () {
  390. //加载分类树
  391. $.get("../category/query", function (r) {
  392. ztree = $.fn.zTree.init($("#categoryTree"), setting, r.list);
  393. var node = ztree.getNodeByParam("id", vm.goods.categoryId);
  394. if (node) {
  395. ztree.selectNode(node);
  396. vm.goods.categoryName = node.name;
  397. } else {
  398. node = ztree.getNodeByParam("id", 0);
  399. ztree.selectNode(node);
  400. vm.goods.categoryName = node.name;
  401. }
  402. })
  403. },
  404. categoryTree: function () {
  405. openWindow({
  406. title: "选择类型",
  407. area: ['300px', '450px'],
  408. content: jQuery("#categoryLayer"),
  409. btn: ['确定', '取消'],
  410. btn1: function (index) {
  411. var node = ztree.getSelectedNodes();
  412. if (node[0].isParent) {
  413. alert("只能选择");
  414. return;
  415. }
  416. //选择上级菜单
  417. vm.goods.categoryId = node[0].id;
  418. vm.goods.categoryName = node[0].name;
  419. layer.close(index);
  420. }
  421. });
  422. },
  423. changeGoodsBizType: function(opt) {
  424. var goodsBizType = opt.value;
  425. if (vm.goods.goodsBizType == '10' || vm.goods.goodsBizType == '02') {
  426. vm.showInput = false;
  427. } else {
  428. vm.showInput = true;
  429. }
  430. },
  431. handleView(name) {
  432. this.imgName = name;
  433. this.visible = true;
  434. },
  435. changeQueryCategories: function (opt) {
  436. var value = opt.value;
  437. $.get("../category/getCategorySelectByParent?parentId=" + value, function (r) {
  438. vm.queryCategoriesTwo = r.list;
  439. });
  440. },
  441. getAttributes: function (opt) {
  442. var value = opt.value;
  443. $.get("../attribute/query?attributeCategoryId=" + value, function (r) {
  444. vm.attributes = r.list;
  445. });
  446. if (opt.flag != 1 && !(value === vm.categoryId)) {
  447. if (vm.attributeEntityList.length > 0 && vm.attributeEntityList[0].attributeId != '') {
  448. for (var i = 0; i < vm.attributeEntityList.length; i++) {
  449. if (!(vm.attributeEntityList[0].attributeId === '')) {
  450. vm.attributeEntityList[i].isDelete = 1;
  451. }
  452. }
  453. var goodsId = '';
  454. if (vm.goods) {
  455. goodsId = vm.goods.id;
  456. }
  457. vm.attributeEntityList.unshift({'id': '', 'goodsId': goodsId, 'attributeId': '', 'value': '', 'isDelete': 0});
  458. }
  459. }
  460. },
  461. changeCategories: function (opt) {
  462. var value = opt.value;
  463. $.get("../category/getCategorySelectByParent?isShow=1&parentId=" + value, function (r) {
  464. vm.categoriesTwo = r.list;
  465. });
  466. },
  467. handleRemove(file) {
  468. // 从 upload 实例删除数据
  469. const fileList = vm.uploadList;
  470. vm.uploadList.splice(fileList.indexOf(file), 1);
  471. },
  472. handleSuccess(res, file) {
  473. // 因为上传过程为实例,这里模拟添加 url
  474. file.imgUrl = res.url;
  475. file.name = res.url;
  476. vm.uploadList.add(file);
  477. },
  478. handleBeforeUpload() {
  479. const check = vm.uploadList.length < 5;
  480. if (!check) {
  481. this.$Notice.warning({
  482. title: '最多只能上传 5 张图片。'
  483. });
  484. }
  485. return check;
  486. },
  487. handleSubmit: function (name) {
  488. // handleSubmitValidate(this, name, function () {
  489. vm.saveOrUpdate()
  490. // });
  491. },
  492. handleFormatError: function (file) {
  493. this.$Notice.warning({
  494. title: '文件格式不正确',
  495. desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
  496. });
  497. },
  498. handleMaxSize: function (file) {
  499. this.$Notice.warning({
  500. title: '超出文件大小限制',
  501. desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
  502. });
  503. },
  504. handleReset: function (name) {
  505. handleResetForm(this, name);
  506. },
  507. handleSuccessPicUrl: function (res, file) {
  508. vm.goods.primaryPicUrl = file.response.url;
  509. },
  510. handleSuccessListPicUrl: function (res, file) {
  511. vm.goods.listPicUrl = file.response.url;
  512. },
  513. eyeImagePicUrl: function () {
  514. var url = vm.goods.primaryPicUrl;
  515. eyeImage(url);
  516. },
  517. eyeImageListPicUrl: function () {
  518. var url = vm.goods.listPicUrl;
  519. eyeImage(url);
  520. },
  521. eyeImage: function (e) {
  522. eyeImage($(e.target).attr('src'));
  523. }
  524. },
  525. mounted() {
  526. // this.uploadList = this.$refs.upload.fileList;
  527. $.get("../category/getCategorySelect", function (r) {
  528. vm.queryCategories = r.list;
  529. });
  530. $.get("../category/getCategorySelect?isShow=1", function (r) {
  531. vm.categories = r.list;
  532. });
  533. }
  534. });