goods.js 22 KB

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