goods.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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: 'merchName', index: 'merchName', width: 100, align: 'center'},
  8. {label: '第三方商户编号', name: 'thirdPartyMerchCode', index: 'thirdPartyMerchCode', width: 60, align: 'center'},
  9. {label: '商品编码', name: 'goodsSn', index: 'goods_Sn', width: 60, align: 'center'},
  10. {label: 'SKU', name: 'sku', index: 'sku', width: 80, align: 'center'},
  11. {label: '商品类型', name: 'categoryName', index: 'category_id', width: 40, align: 'center'},
  12. {label: '名称', name: 'name', index: 'name', width: 160, align: 'center'},
  13. {
  14. label: '货品业务类型', name: 'goodsBizType', index: 'goods_biz_type', width: 70, align: 'center',
  15. formatter: function (value) {
  16. if (value == '00') {
  17. return '保税备货';
  18. } else if (value == '02') {
  19. return '保税展示补货';
  20. } else if (value == '10') {
  21. return '保税展示跨境';
  22. }
  23. return '普通货物';
  24. }
  25. },
  26. // {label: '零售价格', name: 'retailPrice', index: 'retail_price', width: 80, align: 'center'},
  27. // {label: '市场价', name: 'marketPrice', index: 'market_price', width: 80, align: 'center'},
  28. {
  29. label: '上架', name: 'isOnSale', index: 'is_on_sale', width: 40, align: 'center',
  30. formatter: function (value) {
  31. return transIsNot(value);
  32. }
  33. },
  34. /*{
  35. label: '热销', name: 'isHot', index: 'is_hot', width: 80, formatter: function (value) {
  36. return transIsNot(value);
  37. }
  38. },
  39. {
  40. label: '活动', name: 'goodsType', index: 'goodsType', width: 80,
  41. formatter: function (value) {
  42. if (value == 2) {
  43. return '<span class="label label-warning">团购</span>';
  44. } else {
  45. return '<span class="label label-success">无活动</span>';
  46. }
  47. }
  48. },*/
  49. {
  50. label: '录入日期', name: 'addTime', index: 'add_time', width: 80, align: 'center',
  51. formatter: function (value) {
  52. return transDate(value, 'yyyy-MM-dd hh:mm:ss');
  53. }
  54. }
  55. ],
  56. viewrecords: true,
  57. height: 575,
  58. rowNum: 10,
  59. rowList: [10, 30, 50],
  60. rownumbers: true,
  61. rownumWidth: 25,
  62. autowidth: true,
  63. multiselect: true,
  64. pager: "#jqGridPager",
  65. jsonReader: {
  66. root: "page.list",
  67. page: "page.currPage",
  68. total: "page.totalPage",
  69. records: "page.totalCount"
  70. },
  71. prmNames: {
  72. page: "page",
  73. rows: "limit",
  74. order: "order"
  75. },
  76. gridComplete: function () {
  77. $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
  78. }
  79. });
  80. $('#goodsDesc').editable({
  81. inlineMode: false,
  82. alwaysBlank: true,
  83. height: '500px', //高度
  84. minHeight: '200px',
  85. language: "zh_cn",
  86. spellcheck: false,
  87. plainPaste: true,
  88. enableScript: false,
  89. imageButtons: ["floatImageLeft", "floatImageNone", "floatImageRight", "linkImage", "replaceImage", "removeImage"],
  90. allowedImageTypes: ["jpeg", "jpg", "png", "gif"],
  91. imageUploadURL: '../sys/oss/upload',
  92. imageUploadParams: {id: "edit"},
  93. imagesLoadURL: '../sys/oss/queryAll'
  94. })
  95. });
  96. var ztree;
  97. var setting = {
  98. data: {
  99. simpleData: {
  100. enable: true,
  101. idKey: "id",
  102. pIdKey: "parentId",
  103. rootPId: -1
  104. },
  105. key: {
  106. url: "nourl"
  107. }
  108. }
  109. };
  110. var vm = new Vue({
  111. el: '#rrapp',
  112. data: {
  113. showList: true,
  114. fileList: true,
  115. title: null,
  116. uploadList: [],
  117. imgName: '',
  118. visible: false,
  119. goods: {primaryPicUrl: '', listPicUrl: '',videoUrl:'', categoryId: '', isOnSale: 1, isAppExclusive: 0, isLimited: 0, isHot: 0, categoryName: '', retailPrice: '', marketPrice: '', goodsRate: '', sortOrder: '' },
  120. ruleValidate: {
  121. /*name: [
  122. {required: true, message: '名称不能为空', trigger: 'blur'}
  123. ]*/
  124. },
  125. q: {name: '', goodsSn: '', category: '', categoryTwo: '', merchSn: ''},
  126. attributes: [],
  127. attributeEntityList: [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}],
  128. productEntityList: [{'id': '', 'goodsId': '', 'goodsSpecificationIds': '', 'goodsSpecificationNameValue': '', 'goodsSn': '', 'goodsNumber': '', 'isDelete': 0, 'goodsDefault': 0}],
  129. queryCategories: [],//一级分类
  130. queryCategoriesTwo: [],
  131. queryMerch: [],
  132. categories: [],//一级分类
  133. categoriesTwo: [],
  134. macros: [],//商品单位
  135. attributeCategories: [],//属性类别
  136. specifications: [],
  137. brands: [],
  138. freights: [],
  139. showInput: true,
  140. categoryId: '',
  141. cusUnitCodeList: [],
  142. cusNationCodeList: [],
  143. merchList: [],
  144. suppliers: [],
  145. thirdMerchantBizList: []
  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. merchSn: ''
  183. }
  184. },
  185. query: function () {
  186. vm.reload(1);
  187. },
  188. add: function () {
  189. vm.showList = false;
  190. vm.title = "新增";
  191. vm.uploadList = [];
  192. vm.goods = {primaryPicUrl: '', listPicUrl: '',videoUrl:'', categoryId: '', isOnSale: 1, isAppExclusive: 0, isLimited: 0, isHot: 0, categoryName: '', retailPrice: '', marketPrice: '', goodsRate: '', sortOrder: '' };
  193. $('#goodsDesc').editable('setHTML', '');
  194. vm.getCategory();
  195. vm.macros = [];
  196. vm.brands = [];
  197. vm.freights = [];
  198. vm.cusUnitCodeList = [];
  199. vm.cusNationCodeList = [];
  200. vm.attributeEntityList = [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}];
  201. vm.getMacro();
  202. vm.getCusUnitCodeList();
  203. vm.getCusNationCode();
  204. vm.getMerchList();
  205. vm.showInput = true;
  206. },
  207. update: function (event) {
  208. var id = getSelectedRow();
  209. if (id == null) {
  210. return;
  211. }
  212. vm.showList = false;
  213. vm.title = "修改";
  214. vm.uploadList = [];
  215. vm.getInfo(id);
  216. var opt = {};
  217. opt.value = vm.goods.categoryId;
  218. opt.flag = 1;
  219. vm.thirdMerchantBizList = [];
  220. vm.getAttributes(opt);
  221. vm.getMacro();
  222. vm.getCusUnitCodeList();
  223. vm.getCusNationCode();
  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 (merchSn) {
  238. $.get("../brand/queryAll?merchSn=" + merchSn, function (r) {
  239. vm.brands = r.list;
  240. });
  241. },
  242. getSuppliers: function (merchSn) {
  243. $.get("../supplier/queryAll?merchSn=" + merchSn, 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(merchSn) {
  258. $.get("../freight/queryAll?merchSn=" + merchSn, 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. getThirdMerchantBizList: function(merchSn) {
  273. $.get("../thirdmerchantbiz/queryAll?merchSn=" + merchSn, function (r) {
  274. vm.thirdMerchantBizList = r.list;
  275. });
  276. },
  277. saveOrUpdate: function (event) {
  278. var url = vm.goods.id == null ? "../goods/save" : "../goods/update";
  279. vm.goods.goodsDesc = $('#goodsDesc').editable('getHTML');
  280. vm.goods.goodsImgList = vm.uploadList;
  281. vm.goods.attributeEntityList = vm.attributeEntityList;
  282. vm.goods.productEntityList = vm.productEntityList;
  283. $.ajax({
  284. type: "POST",
  285. url: url,
  286. dataType: "json",
  287. contentType: "application/json",
  288. data: JSON.stringify(vm.goods),
  289. success: function (r) {
  290. if (r.code === 0) {
  291. alert('操作成功', function (index) {
  292. vm.reload();
  293. });
  294. } else {
  295. alert(r.msg);
  296. }
  297. }
  298. });
  299. },
  300. enSale: function () {
  301. var ids = getSelectedRows();
  302. if (ids == null) {
  303. return;
  304. }
  305. confirm('确定要上架选中的商品?', function () {
  306. $.ajax({
  307. type: "POST",
  308. url: "../goods/enSaleBatch",
  309. contentType: "application/json",
  310. data: JSON.stringify(ids),
  311. success: function (r) {
  312. if (r.code == 0) {
  313. alert('操作成功', function (index) {
  314. $("#jqGrid").trigger("reloadGrid");
  315. });
  316. } else {
  317. alert(r.msg);
  318. }
  319. }
  320. });
  321. });
  322. },
  323. openSpe: function () {
  324. var id = getSelectedRow();
  325. if (id == null) {
  326. return;
  327. }
  328. openWindow({
  329. type: 2,
  330. title: '商品规格',
  331. content: '../shop/goodsspecification.html?goodsId=' + id
  332. })
  333. },
  334. openPro: function () {
  335. var id = getSelectedRow();
  336. if (id == null) {
  337. return;
  338. }
  339. openWindow({
  340. type: 2,
  341. title: '产品设置',
  342. content: '../shop/product.html?goodsId=' + id
  343. });
  344. },
  345. unSale: function () {
  346. var ids = getSelectedRows();
  347. if (ids == null) {
  348. return;
  349. }
  350. confirm('确定要下架选中的商品?', function () {
  351. $.ajax({
  352. type: "POST",
  353. url: "../goods/unSaleBatch",
  354. contentType: "application/json",
  355. data: JSON.stringify(ids),
  356. success: function (r) {
  357. if (r.code == 0) {
  358. alert('操作成功', function (index) {
  359. $("#jqGrid").trigger("reloadGrid");
  360. });
  361. } else {
  362. alert(r.msg);
  363. }
  364. }
  365. });
  366. });
  367. },
  368. del: function (event) {
  369. var ids = getSelectedRows();
  370. if (ids == null) {
  371. return;
  372. }
  373. confirm('确定要删除选中的记录?', function () {
  374. $.ajax({
  375. type: "POST",
  376. url: "../goods/delete",
  377. contentType: "application/json",
  378. data: JSON.stringify(ids),
  379. success: function (r) {
  380. if (r.code == 0) {
  381. alert('操作成功', function (index) {
  382. $("#jqGrid").trigger("reloadGrid");
  383. });
  384. } else {
  385. alert(r.msg);
  386. }
  387. }
  388. });
  389. });
  390. },
  391. getInfo: function (id) {
  392. $.get("../goods/info/" + id, function (r) {
  393. vm.goods = r.goods;
  394. vm.categoryId = r.goods.categoryId;
  395. // vm.getCategory();
  396. var opt = {};
  397. opt.value = vm.goods.attributeCategory;
  398. vm.changeCategories(opt);
  399. if (r.goods.attributeEntityList.length > 0) {
  400. vm.attributeEntityList = r.goods.attributeEntityList;
  401. } else {
  402. vm.attributeEntityList = [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}];
  403. }
  404. if (r.goods.productEntityList.length > 0) {
  405. vm.productEntityList = r.goods.productEntityList;
  406. } else {
  407. vm.productEntityList = [{'id': '', 'goodsId': '', 'goodsSpecificationIds': '', 'goodsSpecificationNameValue': '', 'goodsSn': '', 'goodsNumber': '', 'isDelete': 0, 'goodsDefault': 0}];
  408. }
  409. $('#goodsDesc').editable('setHTML', vm.goods.goodsDesc);
  410. });
  411. },
  412. reload: function (event) {
  413. vm.showList = true;
  414. let page = event;
  415. if (event != 1) {
  416. page = $("#jqGrid").jqGrid('getGridParam', 'page');
  417. }
  418. $("#jqGrid").jqGrid('setGridParam', {
  419. postData: {
  420. 'name': vm.q.name,
  421. 'goodsSn': vm.q.goodsSn,
  422. 'category': vm.q.category,
  423. 'categoryTwo': vm.q.categoryTwo,
  424. 'merchSn': vm.q.merchSn
  425. },
  426. page: page
  427. }).trigger("reloadGrid");
  428. vm.handleReset('formValidate');
  429. },
  430. getCategory: function () {
  431. //加载分类树
  432. $.get("../category/query", function (r) {
  433. ztree = $.fn.zTree.init($("#categoryTree"), setting, r.list);
  434. var node = ztree.getNodeByParam("id", vm.goods.categoryId);
  435. if (node) {
  436. ztree.selectNode(node);
  437. vm.goods.categoryName = node.name;
  438. } else {
  439. node = ztree.getNodeByParam("id", 0);
  440. ztree.selectNode(node);
  441. vm.goods.categoryName = node.name;
  442. }
  443. })
  444. },
  445. categoryTree: function () {
  446. openWindow({
  447. title: "选择类型",
  448. area: ['300px', '450px'],
  449. content: jQuery("#categoryLayer"),
  450. btn: ['确定', '取消'],
  451. btn1: function (index) {
  452. var node = ztree.getSelectedNodes();
  453. if (node[0].isParent) {
  454. alert("只能选择");
  455. return;
  456. }
  457. //选择上级菜单
  458. vm.goods.categoryId = node[0].id;
  459. vm.goods.categoryName = node[0].name;
  460. layer.close(index);
  461. }
  462. });
  463. },
  464. changeGoodsBizType: function(opt) {
  465. var goodsBizType = opt.value;
  466. if (vm.goods.goodsBizType == '10' || vm.goods.goodsBizType == '02') {
  467. vm.showInput = false;
  468. } else {
  469. vm.showInput = true;
  470. }
  471. },
  472. handleView(name) {
  473. this.imgName = name;
  474. this.visible = true;
  475. },
  476. changeQueryCategories: function (opt) {
  477. var value = opt.value;
  478. $.get("../category/getCategorySelectByParent?parentId=" + value, function (r) {
  479. vm.queryCategoriesTwo = r.list;
  480. });
  481. },
  482. getAttributes: function (opt) {
  483. var value = opt.value;
  484. $.get("../attribute/query?attributeCategoryId=" + value, function (r) {
  485. vm.attributes = r.list;
  486. });
  487. if (opt.flag != 1 && !(value === vm.categoryId)) {
  488. if (vm.attributeEntityList.length > 0 && vm.attributeEntityList[0].attributeId != '') {
  489. for (var i = 0; i < vm.attributeEntityList.length; i++) {
  490. if (!(vm.attributeEntityList[0].attributeId === '')) {
  491. vm.attributeEntityList[i].isDelete = 1;
  492. }
  493. }
  494. var goodsId = '';
  495. if (vm.goods) {
  496. goodsId = vm.goods.id;
  497. }
  498. vm.attributeEntityList.unshift({'id': '', 'goodsId': goodsId, 'attributeId': '', 'value': '', 'isDelete': 0});
  499. }
  500. }
  501. },
  502. changeCategories: function (opt) {
  503. var value = opt.value;
  504. $.get("../category/getCategorySelectByParent?isShow=1&parentId=" + value, function (r) {
  505. vm.categoriesTwo = r.list;
  506. });
  507. },
  508. uploadExcelSuccess: function (data) {
  509. console.log(data);
  510. if(data.code==0){
  511. alert('导入成功', function (index) {
  512. $("#jqGrid").trigger("reloadGrid");
  513. });
  514. }else{
  515. alert(data.msg);
  516. }
  517. },
  518. uploadExcelError: function () {
  519. alert('上传出现异常,请重试!');
  520. },
  521. uploadExcelFormatError: function (file) {
  522. this.$Notice.warning({
  523. title: '文件格式不正确',
  524. desc: '文件 ' + file.name + ' 格式不正确,请上传 xls 或 xlsx 格式的文件。'
  525. });
  526. },
  527. handleRemove(file) {
  528. // 从 upload 实例删除数据
  529. const fileList = vm.uploadList;
  530. vm.uploadList.splice(fileList.indexOf(file), 1);
  531. },
  532. handleSuccess(res, file) {
  533. // 因为上传过程为实例,这里模拟添加 url
  534. file.imgUrl = res.url;
  535. file.name = res.url;
  536. vm.uploadList.add(file);
  537. },
  538. handleBeforeUpload() {
  539. const check = vm.uploadList.length < 5;
  540. if (!check) {
  541. this.$Notice.warning({
  542. title: '最多只能上传 5 张图片。'
  543. });
  544. }
  545. return check;
  546. },
  547. handleSubmit: function (name) {
  548. // handleSubmitValidate(this, name, function () {
  549. vm.saveOrUpdate()
  550. // });
  551. },
  552. handleFormatError: function (file) {
  553. this.$Notice.warning({
  554. title: '文件格式不正确',
  555. desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
  556. });
  557. },
  558. handleMaxSize: function (file) {
  559. this.$Notice.warning({
  560. title: '超出文件大小限制',
  561. desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
  562. });
  563. },
  564. handleReset: function (name) {
  565. handleResetForm(this, name);
  566. },
  567. handleSuccessPicUrl: function (res, file) {
  568. vm.goods.primaryPicUrl = file.response.url;
  569. },
  570. handleSuccessListPicUrl: function (res, file) {
  571. vm.goods.listPicUrl = file.response.url;
  572. },
  573. eyeImagePicUrl: function () {
  574. var url = vm.goods.primaryPicUrl;
  575. eyeImage(url);
  576. },
  577. eyeImageListPicUrl: function () {
  578. var url = vm.goods.listPicUrl;
  579. eyeImage(url);
  580. },
  581. eyeImage: function (e) {
  582. eyeImage($(e.target).attr('src'));
  583. },
  584. eyeImageListVideoUrl: function (e) {
  585. var url = vm.goods.videoUrl;
  586. eyeVideo(url);
  587. },
  588. handleVideoFormatError: function (file) {
  589. this.$Notice.warning({
  590. title: '文件格式不正确',
  591. desc: '文件 ' + file.name + ' 格式不正确,请上传 mp4 格式的图片。'
  592. });
  593. },
  594. handleVideoMaxSize: function (file) {
  595. this.$Notice.warning({
  596. title: '超出文件大小限制',
  597. desc: '文件 ' + file.name + ' 太大,不能超过 10M。'
  598. });
  599. },
  600. handleSuccessListVideoUrl: function (res, file) {
  601. vm.goods.videoUrl = file.response.url;
  602. },
  603. goodsExport: function () {
  604. vm.fileList = false;
  605. },
  606. showMerchInfo:function(opt){
  607. var merchSn = opt.value;
  608. vm.getCategories(merchSn);
  609. vm.getFreights(merchSn);
  610. vm.getBrand(merchSn);
  611. vm.getSuppliers(merchSn);
  612. vm.getThirdMerchantBizList(merchSn);
  613. },
  614. getCategories: function (merchSn) {
  615. $.get("../category/getCategorySelect?isShow=1&merchSn=" + merchSn, function (r) {
  616. vm.categories = r.list;
  617. });
  618. },
  619. },
  620. mounted() {
  621. // this.uploadList = this.$refs.upload.fileList;
  622. $.get("../category/getCategorySelect", function (r) {
  623. vm.queryCategories = r.list;
  624. });
  625. $.get("../merch/queryAll", function (r) {
  626. vm.queryMerch = r.list;
  627. });
  628. }
  629. });