goods.js 21 KB

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