goods.js 22 KB

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