1
0

goods.js 23 KB

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