goods.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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. label: '操作', width: 60, align: 'center', sortable: false, formatter: function (value, col, row) {
  55. let htmlStr = '';
  56. if (row.goodsBizType == '02' || row.goodsBizType == '10') {
  57. htmlStr = '<button class="btn btn-outline btn-primary" onclick="vm.qrcodeCanvas(' + row.id + ')"><i class="fa fa-qrcode"></i>二维码</button>';
  58. }
  59. return htmlStr;
  60. }
  61. }
  62. ],
  63. viewrecords: true,
  64. height: 675,
  65. rowNum: 15,
  66. rowList: [15, 30, 50],
  67. rownumbers: true,
  68. rownumWidth: 25,
  69. autowidth: true,
  70. multiselect: true,
  71. pager: "#jqGridPager",
  72. jsonReader: {
  73. root: "page.list",
  74. page: "page.currPage",
  75. total: "page.totalPage",
  76. records: "page.totalCount"
  77. },
  78. prmNames: {
  79. page: "page",
  80. rows: "limit",
  81. order: "order"
  82. },
  83. gridComplete: function () {
  84. $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
  85. }
  86. });
  87. $('#goodsDesc').editable({
  88. inlineMode: false,
  89. alwaysBlank: true,
  90. height: '500px', //高度
  91. minHeight: '200px',
  92. language: "zh_cn",
  93. spellcheck: false,
  94. plainPaste: true,
  95. enableScript: false,
  96. imageButtons: ["floatImageLeft", "floatImageNone", "floatImageRight", "linkImage", "replaceImage", "removeImage"],
  97. allowedImageTypes: ["jpeg", "jpg", "png", "gif"],
  98. imageUploadURL: '../sys/oss/upload',
  99. imageUploadParams: {id: "edit"},
  100. imagesLoadURL: '../sys/oss/queryAll'
  101. })
  102. });
  103. var ztree;
  104. var setting = {
  105. data: {
  106. simpleData: {
  107. enable: true,
  108. idKey: "id",
  109. pIdKey: "parentId",
  110. rootPId: -1
  111. },
  112. key: {
  113. url: "nourl"
  114. }
  115. }
  116. };
  117. var vm = new Vue({
  118. el: '#rrapp',
  119. data: {
  120. showList: true,
  121. title: null,
  122. uploadList: [],
  123. imgName: '',
  124. visible: false,
  125. goods: {primaryPicUrl: '', listPicUrl: '', categoryId: '', isOnSale: 1, isAppExclusive: 0, isLimited: 0, isHot: 0, categoryName: '', retailPrice: '', marketPrice: '', goodsRate: '', sortOrder: '' },
  126. ruleValidate: {
  127. /*name: [
  128. {required: true, message: '名称不能为空', trigger: 'blur'}
  129. ]*/
  130. },
  131. q: {name: '', goodsSn: '', category: '', categoryTwo: ''},
  132. attributes: [],
  133. attributeEntityList: [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}],
  134. productEntityList: [{'id': '', 'goodsId': '', 'goodsSpecificationIds': '', 'goodsSpecificationNameValue': '', 'goodsSn': '', 'goodsNumber': '', 'isDelete': 0, 'goodsDefault': 0}],
  135. queryCategories: [],//一级分类
  136. queryCategoriesTwo: [],
  137. categories: [],//一级分类
  138. categoriesTwo: [],
  139. macros: [],//商品单位
  140. attributeCategories: [],//属性类别
  141. specifications: [],
  142. brands: [],
  143. freights: [],
  144. showInput: true,
  145. categoryId: ''
  146. },
  147. methods: {
  148. delSpeRow: function (index) {
  149. //最后一行时禁止删除
  150. if (vm.productEntityList.length == 1) {
  151. return;
  152. }
  153. vm.productEntityList[index].isDelete = 1;
  154. },
  155. addSpeRow: function () {
  156. let goodsId = '';
  157. if (vm.goods) {
  158. goodsId = vm.goods.id;
  159. }
  160. vm.productEntityList.push({'id': '', 'goodsId': '', 'goodsSpecificationIds': '', 'goodsSpecificationNameValue': '', 'goodsSn': '', 'goodsNumber': '', 'isDelete': 0, 'goodsDefault': 0});
  161. },
  162. delAttrRow: function (index) {
  163. //最后一行时禁止删除
  164. if (vm.attributeEntityList.length == 1) {
  165. return;
  166. }
  167. vm.attributeEntityList[index].isDelete = 1;
  168. },
  169. addAttrRow: function () {
  170. let goodsId = '';
  171. if (vm.goods) {
  172. goodsId = vm.goods.id;
  173. }
  174. vm.attributeEntityList.push({'id': '', 'goodsId': goodsId, 'attributeId': '', 'value': '', 'isDelete': 0});
  175. },
  176. reloadSearch: function () {
  177. vm.q = {
  178. name: '',
  179. goodsSn: '',
  180. category: '',
  181. categoryTwo: ''
  182. }
  183. },
  184. query: function () {
  185. vm.reload(1);
  186. },
  187. add: function () {
  188. vm.showList = false;
  189. vm.title = "新增";
  190. vm.uploadList = [];
  191. vm.goods = {primaryPicUrl: '', listPicUrl: '', categoryId: '', isOnSale: 1, isAppExclusive: 0, isLimited: 0, isHot: 0, categoryName: '', retailPrice: '', marketPrice: '', goodsRate: '', sortOrder: '' };
  192. $('#goodsDesc').editable('setHTML', '');
  193. vm.getCategory();
  194. vm.macros = [];
  195. vm.brands = [];
  196. vm.freights = [];
  197. vm.attributeEntityList = [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}];
  198. vm.getMacro();
  199. vm.getBrand();
  200. vm.getFreights();
  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.getFreights();
  219. vm.getGoodsGallery(id);
  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 () {
  232. $.get("../brand/queryAll", function (r) {
  233. vm.brands = r.list;
  234. });
  235. },
  236. getFreights: function() {
  237. $.get("../freight/queryAll", function (r) {
  238. vm.freights = r.list;
  239. });
  240. },
  241. getGoodsGallery: function (id) {//获取商品顶部轮播图
  242. $.get("../goodsgallery/queryAll?goodsId=" + id, function (r) {
  243. vm.uploadList = r.list;
  244. });
  245. },
  246. saveOrUpdate: function (event) {
  247. var url = vm.goods.id == null ? "../goods/save" : "../goods/update";
  248. vm.goods.goodsDesc = $('#goodsDesc').editable('getHTML');
  249. vm.goods.goodsImgList = vm.uploadList;
  250. vm.goods.attributeEntityList = vm.attributeEntityList;
  251. vm.goods.productEntityList = vm.productEntityList;
  252. $.ajax({
  253. type: "POST",
  254. url: url,
  255. dataType: "json",
  256. contentType: "application/json",
  257. data: JSON.stringify(vm.goods),
  258. success: function (r) {
  259. if (r.code === 0) {
  260. alert('操作成功', function (index) {
  261. vm.reload();
  262. });
  263. } else {
  264. alert(r.msg);
  265. }
  266. }
  267. });
  268. },
  269. enSale: function () {
  270. var ids = getSelectedRows();
  271. if (ids == null) {
  272. return;
  273. }
  274. confirm('确定要上架选中的商品?', function () {
  275. $.ajax({
  276. type: "POST",
  277. url: "../goods/enSaleBatch",
  278. contentType: "application/json",
  279. data: JSON.stringify(ids),
  280. success: function (r) {
  281. if (r.code == 0) {
  282. alert('操作成功', function (index) {
  283. $("#jqGrid").trigger("reloadGrid");
  284. });
  285. } else {
  286. alert(r.msg);
  287. }
  288. }
  289. });
  290. });
  291. },
  292. openSpe: function () {
  293. var id = getSelectedRow();
  294. if (id == null) {
  295. return;
  296. }
  297. openWindow({
  298. type: 2,
  299. title: '商品规格',
  300. content: '../shop/goodsspecification.html?goodsId=' + id
  301. })
  302. },
  303. openPro: function () {
  304. var id = getSelectedRow();
  305. if (id == null) {
  306. return;
  307. }
  308. openWindow({
  309. type: 2,
  310. title: '产品设置',
  311. content: '../shop/product.html?goodsId=' + id
  312. });
  313. },
  314. unSale: function () {
  315. var ids = getSelectedRows();
  316. if (ids == null) {
  317. return;
  318. }
  319. confirm('确定要下架选中的商品?', function () {
  320. $.ajax({
  321. type: "POST",
  322. url: "../goods/unSaleBatch",
  323. contentType: "application/json",
  324. data: JSON.stringify(ids),
  325. success: function (r) {
  326. if (r.code == 0) {
  327. alert('操作成功', function (index) {
  328. $("#jqGrid").trigger("reloadGrid");
  329. });
  330. } else {
  331. alert(r.msg);
  332. }
  333. }
  334. });
  335. });
  336. },
  337. del: function (event) {
  338. var ids = getSelectedRows();
  339. if (ids == null) {
  340. return;
  341. }
  342. confirm('确定要删除选中的记录?', function () {
  343. $.ajax({
  344. type: "POST",
  345. url: "../goods/delete",
  346. contentType: "application/json",
  347. data: JSON.stringify(ids),
  348. success: function (r) {
  349. if (r.code == 0) {
  350. alert('操作成功', function (index) {
  351. $("#jqGrid").trigger("reloadGrid");
  352. });
  353. } else {
  354. alert(r.msg);
  355. }
  356. }
  357. });
  358. });
  359. },
  360. getInfo: function (id) {
  361. $.get("../goods/info/" + id, function (r) {
  362. vm.goods = r.goods;
  363. vm.categoryId = r.goods.categoryId;
  364. // vm.getCategory();
  365. var opt = {};
  366. opt.value = vm.goods.attributeCategory;
  367. vm.changeCategories(opt);
  368. if (r.goods.attributeEntityList.length > 0) {
  369. vm.attributeEntityList = r.goods.attributeEntityList;
  370. } else {
  371. vm.attributeEntityList = [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}];
  372. }
  373. if (r.goods.productEntityList.length > 0) {
  374. vm.productEntityList = r.goods.productEntityList;
  375. } else {
  376. vm.productEntityList = [{'id': '', 'goodsId': '', 'goodsSpecificationIds': '', 'goodsSpecificationNameValue': '', 'goodsSn': '', 'goodsNumber': '', 'isDelete': 0, 'goodsDefault': 0}];
  377. }
  378. $('#goodsDesc').editable('setHTML', vm.goods.goodsDesc);
  379. });
  380. },
  381. reload: function (event) {
  382. vm.showList = true;
  383. let page = event;
  384. if (event != 1) {
  385. page = $("#jqGrid").jqGrid('getGridParam', 'page');
  386. }
  387. $("#jqGrid").jqGrid('setGridParam', {
  388. postData: {
  389. 'name': vm.q.name,
  390. 'goodsSn': vm.q.goodsSn,
  391. 'category': vm.q.category,
  392. 'categoryTwo': vm.q.categoryTwo
  393. },
  394. page: page
  395. }).trigger("reloadGrid");
  396. vm.handleReset('formValidate');
  397. },
  398. getCategory: function () {
  399. //加载分类树
  400. $.get("../category/query", function (r) {
  401. ztree = $.fn.zTree.init($("#categoryTree"), setting, r.list);
  402. var node = ztree.getNodeByParam("id", vm.goods.categoryId);
  403. if (node) {
  404. ztree.selectNode(node);
  405. vm.goods.categoryName = node.name;
  406. } else {
  407. node = ztree.getNodeByParam("id", 0);
  408. ztree.selectNode(node);
  409. vm.goods.categoryName = node.name;
  410. }
  411. })
  412. },
  413. categoryTree: function () {
  414. openWindow({
  415. title: "选择类型",
  416. area: ['300px', '450px'],
  417. content: jQuery("#categoryLayer"),
  418. btn: ['确定', '取消'],
  419. btn1: function (index) {
  420. var node = ztree.getSelectedNodes();
  421. if (node[0].isParent) {
  422. alert("只能选择");
  423. return;
  424. }
  425. //选择上级菜单
  426. vm.goods.categoryId = node[0].id;
  427. vm.goods.categoryName = node[0].name;
  428. layer.close(index);
  429. }
  430. });
  431. },
  432. changeGoodsBizType: function(opt) {
  433. var goodsBizType = opt.value;
  434. if (vm.goods.goodsBizType == '10' || vm.goods.goodsBizType == '02') {
  435. vm.showInput = false;
  436. } else {
  437. vm.showInput = true;
  438. }
  439. },
  440. handleView(name) {
  441. this.imgName = name;
  442. this.visible = true;
  443. },
  444. changeQueryCategories: function (opt) {
  445. var value = opt.value;
  446. $.get("../category/getCategorySelectByParent?parentId=" + value, function (r) {
  447. vm.queryCategoriesTwo = r.list;
  448. });
  449. },
  450. getAttributes: function (opt) {
  451. var value = opt.value;
  452. $.get("../attribute/query?attributeCategoryId=" + value, function (r) {
  453. vm.attributes = r.list;
  454. });
  455. if (opt.flag != 1 && !(value === vm.categoryId)) {
  456. if (vm.attributeEntityList.length > 0 && vm.attributeEntityList[0].attributeId != '') {
  457. for (var i = 0; i < vm.attributeEntityList.length; i++) {
  458. if (!(vm.attributeEntityList[0].attributeId === '')) {
  459. vm.attributeEntityList[i].isDelete = 1;
  460. }
  461. }
  462. var goodsId = '';
  463. if (vm.goods) {
  464. goodsId = vm.goods.id;
  465. }
  466. vm.attributeEntityList.unshift({'id': '', 'goodsId': goodsId, 'attributeId': '', 'value': '', 'isDelete': 0});
  467. }
  468. }
  469. },
  470. changeCategories: function (opt) {
  471. var value = opt.value;
  472. $.get("../category/getCategorySelectByParent?isShow=1&parentId=" + value, function (r) {
  473. vm.categoriesTwo = r.list;
  474. });
  475. },
  476. handleRemove(file) {
  477. // 从 upload 实例删除数据
  478. const fileList = vm.uploadList;
  479. vm.uploadList.splice(fileList.indexOf(file), 1);
  480. },
  481. handleSuccess(res, file) {
  482. // 因为上传过程为实例,这里模拟添加 url
  483. file.imgUrl = res.url;
  484. file.name = res.url;
  485. vm.uploadList.add(file);
  486. },
  487. handleBeforeUpload() {
  488. const check = vm.uploadList.length < 5;
  489. if (!check) {
  490. this.$Notice.warning({
  491. title: '最多只能上传 5 张图片。'
  492. });
  493. }
  494. return check;
  495. },
  496. handleSubmit: function (name) {
  497. // handleSubmitValidate(this, name, function () {
  498. vm.saveOrUpdate()
  499. // });
  500. },
  501. handleFormatError: function (file) {
  502. this.$Notice.warning({
  503. title: '文件格式不正确',
  504. desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
  505. });
  506. },
  507. handleMaxSize: function (file) {
  508. this.$Notice.warning({
  509. title: '超出文件大小限制',
  510. desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
  511. });
  512. },
  513. handleReset: function (name) {
  514. handleResetForm(this, name);
  515. },
  516. handleSuccessPicUrl: function (res, file) {
  517. vm.goods.primaryPicUrl = file.response.url;
  518. },
  519. handleSuccessListPicUrl: function (res, file) {
  520. vm.goods.listPicUrl = file.response.url;
  521. },
  522. eyeImagePicUrl: function () {
  523. var url = vm.goods.primaryPicUrl;
  524. eyeImage(url);
  525. },
  526. eyeImageListPicUrl: function () {
  527. var url = vm.goods.listPicUrl;
  528. eyeImage(url);
  529. },
  530. eyeImage: function (e) {
  531. eyeImage($(e.target).attr('src'));
  532. },
  533. qrcodeCanvas: function(id) {
  534. $("#qrcodeCanvas").html("");
  535. $("#qrcodeCanvas").qrcode({
  536. render : "canvas", //设置渲染方式,有table和canvas,使用canvas方式渲染性能相对来说比较好
  537. text : "emato../goods/goods?id=" + id, //扫描二维码后显示的内容,可以直接填一个网址,扫描二维码后自动跳向该链接
  538. width : "100", //二维码的宽度
  539. height : "100", //二维码的高度
  540. background : "#ffffff", //二维码的后景色
  541. foreground : "#000000", //二维码的前景色
  542. src: '../../statics/img/logo.jpg' //二维码中间的图片
  543. });
  544. var qrcSrc = $("canvas")[0].toDataURL();
  545. $("#qrcImg .qrcImg").attr("src", qrcSrc);
  546. var upLogSrc = "../../statics/img/logo.jpg";
  547. $("#qrcImg .upLogo").attr("src", upLogSrc);
  548. $("#qrcImg").show();//隐藏canvas部分
  549. openWindow({
  550. title: "二维码",
  551. area: ['400px', '400px'],
  552. content: jQuery("#qrcode"),
  553. btn: ["打印"],
  554. btn1: function (index) {
  555. $("#qrcImg").show();
  556. $("#qrcImg").print({});
  557. $("#qrcImg").hide();
  558. layer.close(index);
  559. }
  560. });
  561. $("#qrcImg").hide();
  562. }
  563. },
  564. mounted() {
  565. // this.uploadList = this.$refs.upload.fileList;
  566. $.get("../category/getCategorySelect", function (r) {
  567. vm.queryCategories = r.list;
  568. });
  569. $.get("../category/getCategorySelect?isShow=1", function (r) {
  570. vm.categories = r.list;
  571. });
  572. }
  573. });