goods.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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: '',videoUrl:'', 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. cusUnitCodeList: [],
  138. cusNationCodeList: []
  139. },
  140. methods: {
  141. delSpeRow: function (index) {
  142. //最后一行时禁止删除
  143. if (vm.productEntityList.length == 1) {
  144. return;
  145. }
  146. vm.productEntityList[index].isDelete = 1;
  147. },
  148. addSpeRow: function () {
  149. let goodsId = '';
  150. if (vm.goods) {
  151. goodsId = vm.goods.id;
  152. }
  153. vm.productEntityList.push({'id': '', 'goodsId': '', 'goodsSpecificationIds': '', 'goodsSpecificationNameValue': '', 'goodsSn': '', 'goodsNumber': '', 'isDelete': 0, 'goodsDefault': 0});
  154. },
  155. delAttrRow: function (index) {
  156. //最后一行时禁止删除
  157. if (vm.attributeEntityList.length == 1) {
  158. return;
  159. }
  160. vm.attributeEntityList[index].isDelete = 1;
  161. },
  162. addAttrRow: function () {
  163. let goodsId = '';
  164. if (vm.goods) {
  165. goodsId = vm.goods.id;
  166. }
  167. vm.attributeEntityList.push({'id': '', 'goodsId': goodsId, 'attributeId': '', 'value': '', 'isDelete': 0});
  168. },
  169. reloadSearch: function () {
  170. vm.q = {
  171. name: '',
  172. goodsSn: '',
  173. category: '',
  174. categoryTwo: ''
  175. }
  176. },
  177. query: function () {
  178. vm.reload(1);
  179. },
  180. add: function () {
  181. vm.showList = false;
  182. vm.title = "新增";
  183. vm.uploadList = [];
  184. vm.goods = {primaryPicUrl: '', listPicUrl: '',videoUrl:'', categoryId: '', isOnSale: 1, isAppExclusive: 0, isLimited: 0, isHot: 0, categoryName: '', retailPrice: '', marketPrice: '', goodsRate: '', sortOrder: '' };
  185. $('#goodsDesc').editable('setHTML', '');
  186. vm.getCategory();
  187. vm.macros = [];
  188. vm.brands = [];
  189. vm.freights = [];
  190. vm.cusUnitCodeList = [];
  191. vm.cusNationCodeList = [];
  192. vm.attributeEntityList = [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}];
  193. vm.getMacro();
  194. vm.getBrand();
  195. vm.getFreights();
  196. vm.getCusUnitCodeList();
  197. vm.getCusNationCode();
  198. vm.showInput = true;
  199. },
  200. update: function (event) {
  201. var id = getSelectedRow();
  202. if (id == null) {
  203. return;
  204. }
  205. vm.showList = false;
  206. vm.title = "修改";
  207. vm.uploadList = [];
  208. vm.getInfo(id);
  209. var opt = {};
  210. opt.value = vm.goods.categoryId;
  211. opt.flag = 1;
  212. vm.getAttributes(opt);
  213. vm.getMacro();
  214. vm.getBrand();
  215. vm.getCusUnitCodeList();
  216. vm.getCusNationCode();
  217. vm.getFreights();
  218. vm.getGoodsGallery(id);
  219. vm.showInput = true;
  220. if (vm.goods.goodsBizType == '10' || vm.goods.goodsBizType == '02') {
  221. vm.showInput = false;
  222. }
  223. },
  224. getMacro: function () {
  225. // 获取货品业务类型
  226. $.get("../sys/macro/queryMacrosByValue?value=goodsBizType", function (r) {
  227. vm.macros = r.list;
  228. });
  229. },
  230. getBrand: function () {
  231. $.get("../brand/queryAll", function (r) {
  232. vm.brands = r.list;
  233. });
  234. },
  235. getCusUnitCodeList: function () {
  236. $.get("../syscusunitcode/queryAll", function (r) {
  237. vm.cusUnitCodeList = r.list;
  238. });
  239. },
  240. getCusNationCode: function () {
  241. $.get("../syscusnationcode/queryAll", function (r) {
  242. vm.cusNationCodeList = r.list;
  243. });
  244. },
  245. getFreights: function() {
  246. $.get("../freight/queryAll", function (r) {
  247. vm.freights = r.list;
  248. });
  249. },
  250. getGoodsGallery: function (id) {//获取商品顶部轮播图
  251. $.get("../goodsgallery/queryAll?goodsId=" + id, function (r) {
  252. vm.uploadList = r.list;
  253. });
  254. },
  255. saveOrUpdate: function (event) {
  256. var url = vm.goods.id == null ? "../goods/save" : "../goods/update";
  257. vm.goods.goodsDesc = $('#goodsDesc').editable('getHTML');
  258. vm.goods.goodsImgList = vm.uploadList;
  259. vm.goods.attributeEntityList = vm.attributeEntityList;
  260. vm.goods.productEntityList = vm.productEntityList;
  261. $.ajax({
  262. type: "POST",
  263. url: url,
  264. dataType: "json",
  265. contentType: "application/json",
  266. data: JSON.stringify(vm.goods),
  267. success: function (r) {
  268. if (r.code === 0) {
  269. alert('操作成功', function (index) {
  270. vm.reload();
  271. });
  272. } else {
  273. alert(r.msg);
  274. }
  275. }
  276. });
  277. },
  278. enSale: function () {
  279. var ids = getSelectedRows();
  280. if (ids == null) {
  281. return;
  282. }
  283. confirm('确定要上架选中的商品?', function () {
  284. $.ajax({
  285. type: "POST",
  286. url: "../goods/enSaleBatch",
  287. contentType: "application/json",
  288. data: JSON.stringify(ids),
  289. success: function (r) {
  290. if (r.code == 0) {
  291. alert('操作成功', function (index) {
  292. $("#jqGrid").trigger("reloadGrid");
  293. });
  294. } else {
  295. alert(r.msg);
  296. }
  297. }
  298. });
  299. });
  300. },
  301. openSpe: function () {
  302. var id = getSelectedRow();
  303. if (id == null) {
  304. return;
  305. }
  306. openWindow({
  307. type: 2,
  308. title: '商品规格',
  309. content: '../shop/goodsspecification.html?goodsId=' + id
  310. })
  311. },
  312. openPro: function () {
  313. var id = getSelectedRow();
  314. if (id == null) {
  315. return;
  316. }
  317. openWindow({
  318. type: 2,
  319. title: '产品设置',
  320. content: '../shop/product.html?goodsId=' + id
  321. });
  322. },
  323. unSale: function () {
  324. var ids = getSelectedRows();
  325. if (ids == null) {
  326. return;
  327. }
  328. confirm('确定要下架选中的商品?', function () {
  329. $.ajax({
  330. type: "POST",
  331. url: "../goods/unSaleBatch",
  332. contentType: "application/json",
  333. data: JSON.stringify(ids),
  334. success: function (r) {
  335. if (r.code == 0) {
  336. alert('操作成功', function (index) {
  337. $("#jqGrid").trigger("reloadGrid");
  338. });
  339. } else {
  340. alert(r.msg);
  341. }
  342. }
  343. });
  344. });
  345. },
  346. del: function (event) {
  347. var ids = getSelectedRows();
  348. if (ids == null) {
  349. return;
  350. }
  351. confirm('确定要删除选中的记录?', function () {
  352. $.ajax({
  353. type: "POST",
  354. url: "../goods/delete",
  355. contentType: "application/json",
  356. data: JSON.stringify(ids),
  357. success: function (r) {
  358. if (r.code == 0) {
  359. alert('操作成功', function (index) {
  360. $("#jqGrid").trigger("reloadGrid");
  361. });
  362. } else {
  363. alert(r.msg);
  364. }
  365. }
  366. });
  367. });
  368. },
  369. getInfo: function (id) {
  370. $.get("../goods/info/" + id, function (r) {
  371. vm.goods = r.goods;
  372. vm.categoryId = r.goods.categoryId;
  373. // vm.getCategory();
  374. var opt = {};
  375. opt.value = vm.goods.attributeCategory;
  376. vm.changeCategories(opt);
  377. if (r.goods.attributeEntityList.length > 0) {
  378. vm.attributeEntityList = r.goods.attributeEntityList;
  379. } else {
  380. vm.attributeEntityList = [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}];
  381. }
  382. if (r.goods.productEntityList.length > 0) {
  383. vm.productEntityList = r.goods.productEntityList;
  384. } else {
  385. vm.productEntityList = [{'id': '', 'goodsId': '', 'goodsSpecificationIds': '', 'goodsSpecificationNameValue': '', 'goodsSn': '', 'goodsNumber': '', 'isDelete': 0, 'goodsDefault': 0}];
  386. }
  387. $('#goodsDesc').editable('setHTML', vm.goods.goodsDesc);
  388. });
  389. },
  390. reload: function (event) {
  391. vm.showList = true;
  392. let page = event;
  393. if (event != 1) {
  394. page = $("#jqGrid").jqGrid('getGridParam', 'page');
  395. }
  396. $("#jqGrid").jqGrid('setGridParam', {
  397. postData: {
  398. 'name': vm.q.name,
  399. 'goodsSn': vm.q.goodsSn,
  400. 'category': vm.q.category,
  401. 'categoryTwo': vm.q.categoryTwo
  402. },
  403. page: page
  404. }).trigger("reloadGrid");
  405. vm.handleReset('formValidate');
  406. },
  407. getCategory: function () {
  408. //加载分类树
  409. $.get("../category/query", function (r) {
  410. ztree = $.fn.zTree.init($("#categoryTree"), setting, r.list);
  411. var node = ztree.getNodeByParam("id", vm.goods.categoryId);
  412. if (node) {
  413. ztree.selectNode(node);
  414. vm.goods.categoryName = node.name;
  415. } else {
  416. node = ztree.getNodeByParam("id", 0);
  417. ztree.selectNode(node);
  418. vm.goods.categoryName = node.name;
  419. }
  420. })
  421. },
  422. categoryTree: function () {
  423. openWindow({
  424. title: "选择类型",
  425. area: ['300px', '450px'],
  426. content: jQuery("#categoryLayer"),
  427. btn: ['确定', '取消'],
  428. btn1: function (index) {
  429. var node = ztree.getSelectedNodes();
  430. if (node[0].isParent) {
  431. alert("只能选择");
  432. return;
  433. }
  434. //选择上级菜单
  435. vm.goods.categoryId = node[0].id;
  436. vm.goods.categoryName = node[0].name;
  437. layer.close(index);
  438. }
  439. });
  440. },
  441. changeGoodsBizType: function(opt) {
  442. var goodsBizType = opt.value;
  443. if (vm.goods.goodsBizType == '10' || vm.goods.goodsBizType == '02') {
  444. vm.showInput = false;
  445. } else {
  446. vm.showInput = true;
  447. }
  448. },
  449. handleView(name) {
  450. this.imgName = name;
  451. this.visible = true;
  452. },
  453. changeQueryCategories: function (opt) {
  454. var value = opt.value;
  455. $.get("../category/getCategorySelectByParent?parentId=" + value, function (r) {
  456. vm.queryCategoriesTwo = r.list;
  457. });
  458. },
  459. getAttributes: function (opt) {
  460. var value = opt.value;
  461. $.get("../attribute/query?attributeCategoryId=" + value, function (r) {
  462. vm.attributes = r.list;
  463. });
  464. if (opt.flag != 1 && !(value === vm.categoryId)) {
  465. if (vm.attributeEntityList.length > 0 && vm.attributeEntityList[0].attributeId != '') {
  466. for (var i = 0; i < vm.attributeEntityList.length; i++) {
  467. if (!(vm.attributeEntityList[0].attributeId === '')) {
  468. vm.attributeEntityList[i].isDelete = 1;
  469. }
  470. }
  471. var goodsId = '';
  472. if (vm.goods) {
  473. goodsId = vm.goods.id;
  474. }
  475. vm.attributeEntityList.unshift({'id': '', 'goodsId': goodsId, 'attributeId': '', 'value': '', 'isDelete': 0});
  476. }
  477. }
  478. },
  479. changeCategories: function (opt) {
  480. var value = opt.value;
  481. $.get("../category/getCategorySelectByParent?isShow=1&parentId=" + value, function (r) {
  482. vm.categoriesTwo = r.list;
  483. });
  484. },
  485. handleRemove(file) {
  486. // 从 upload 实例删除数据
  487. const fileList = vm.uploadList;
  488. vm.uploadList.splice(fileList.indexOf(file), 1);
  489. },
  490. handleSuccess(res, file) {
  491. // 因为上传过程为实例,这里模拟添加 url
  492. file.imgUrl = res.url;
  493. file.name = res.url;
  494. vm.uploadList.add(file);
  495. },
  496. handleBeforeUpload() {
  497. const check = vm.uploadList.length < 5;
  498. if (!check) {
  499. this.$Notice.warning({
  500. title: '最多只能上传 5 张图片。'
  501. });
  502. }
  503. return check;
  504. },
  505. handleSubmit: function (name) {
  506. // handleSubmitValidate(this, name, function () {
  507. vm.saveOrUpdate()
  508. // });
  509. },
  510. handleFormatError: function (file) {
  511. this.$Notice.warning({
  512. title: '文件格式不正确',
  513. desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
  514. });
  515. },
  516. handleMaxSize: function (file) {
  517. this.$Notice.warning({
  518. title: '超出文件大小限制',
  519. desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
  520. });
  521. },
  522. handleReset: function (name) {
  523. handleResetForm(this, name);
  524. },
  525. handleSuccessPicUrl: function (res, file) {
  526. vm.goods.primaryPicUrl = file.response.url;
  527. },
  528. handleSuccessListPicUrl: function (res, file) {
  529. vm.goods.listPicUrl = file.response.url;
  530. },
  531. eyeImagePicUrl: function () {
  532. var url = vm.goods.primaryPicUrl;
  533. eyeImage(url);
  534. },
  535. eyeImageListPicUrl: function () {
  536. var url = vm.goods.listPicUrl;
  537. eyeImage(url);
  538. },
  539. eyeImage: function (e) {
  540. eyeImage($(e.target).attr('src'));
  541. },
  542. eyeImageListVideoUrl: function (e) {
  543. var url = vm.goods.videoUrl;
  544. eyeVideo(url);
  545. },
  546. handleVideoFormatError: function (file) {
  547. this.$Notice.warning({
  548. title: '文件格式不正确',
  549. desc: '文件 ' + file.name + ' 格式不正确,请上传 mp4 格式的图片。'
  550. });
  551. },
  552. handleVideoMaxSize: function (file) {
  553. this.$Notice.warning({
  554. title: '超出文件大小限制',
  555. desc: '文件 ' + file.name + ' 太大,不能超过 10M。'
  556. });
  557. },
  558. handleSuccessListVideoUrl: function (res, file) {
  559. vm.goods.videoUrl = file.response.url;
  560. }
  561. },
  562. mounted() {
  563. // this.uploadList = this.$refs.upload.fileList;
  564. $.get("../category/getCategorySelect", function (r) {
  565. vm.queryCategories = r.list;
  566. });
  567. $.get("../category/getCategorySelect?isShow=1", function (r) {
  568. vm.categories = r.list;
  569. });
  570. }
  571. });