1
0

goods.js 22 KB

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