goodshotspot.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. let linkHotData = {
  2. }
  3. $(function () {
  4. $("#jqGrid").Grid({
  5. url: '../brand/queryAllHot',
  6. rownumWidth:60,
  7. colModel: [
  8. {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
  9. {label: '店铺名称', align:'center', name: 'brandName', index: 'brand_id', width: 100,sortable:false},
  10. // {label: '场景名称', name: 'sceneName', index: 'scene_name', width: 120,sortable:false},
  11. {label: '热点ID', name: 'sid', index: 'sid', width: 120,sortable:false},
  12. {label: '热点分页内容', name: 'pageName', index: 'page_name', width: 120,sortable:false},
  13. {label: '热点内容', align:'center', name: 'hotData', index: 'hot_data', width: 250,sortable:false, formatter: function (value) {
  14. return transMedia(value,150,'auto');
  15. }},
  16. // {label: '商品名称', name: 'goodsNames', index: 'goods_names', width: 120,sortable:false},
  17. {
  18. label: '关联商品', width: 200, align: 'center', sortable: false,sortable:false, formatter: function (value, col, row) {
  19. linkHotData[col.rowId] = row
  20. return '<div style="margin-bottom:10px;">'+row.goodsNames+'</div> <button class="btn btn-outline btn-info" onclick="vm.linkHotspot(' + col.rowId + ')"><i></i>&nbsp;'+(row.goodsNames?'修改':'关联')+'</button>';
  21. }
  22. }
  23. // {label: '名称', name: 'name', index: 'name', width: 160},
  24. // {
  25. // label: '上架', name: 'isOnSale', index: 'is_on_sale', width: 50,
  26. // formatter: function (value) {
  27. // return transIsNot(value);
  28. // }
  29. // },
  30. // {
  31. // label: '录入日期', name: 'addTime', index: 'add_time', width: 80, formatter: function (value) {
  32. // return transDate(value, 'yyyy-MM-dd');
  33. // }
  34. // },
  35. // {label: '属性类别', name: 'attributeCategoryName', index: 'attribute_category', width: 80},
  36. // {label: '零售价格', name: 'retailPrice', index: 'retail_price', width: 80},
  37. // {label: '商品库存', name: 'goodsNumber', index: 'goods_number', width: 80},
  38. // {label: '销售量', name: 'sellVolume', index: 'sell_volume', width: 80},
  39. // {label: '市场价', name: 'marketPrice', index: 'market_price', width: 80},
  40. // {
  41. // label: '热销', name: 'isHot', index: 'is_hot', width: 80, formatter: function (value) {
  42. // return transIsNot(value);
  43. // }
  44. // }
  45. ]
  46. });
  47. $('#goodsDesc').editable({
  48. inlineMode: false,
  49. alwaysBlank: true,
  50. minHeight: '200px',
  51. language: "zh_cn",
  52. spellcheck: false,
  53. plainPaste: true,
  54. enableScript: false,
  55. imageButtons: ["floatImageLeft", "floatImageNone", "floatImageRight", "linkImage", "replaceImage", "removeImage"],
  56. allowedImageTypes: ["jpeg", "jpg", "png", "gif"],
  57. imageUploadURL: '../sys/oss/upload',
  58. imageUploadParams: {id: "edit"},
  59. imagesLoadURL: '../sys/oss/queryAll'
  60. })
  61. });
  62. var ztree;
  63. var setting = {
  64. data: {
  65. simpleData: {
  66. enable: true,
  67. idKey: "id",
  68. pIdKey: "parentId",
  69. rootPId: -1
  70. },
  71. key: {
  72. url: "nourl"
  73. }
  74. }
  75. };
  76. var vm = new Vue({
  77. el: '#rrapp',
  78. data: {
  79. showList: true,
  80. title: null,
  81. uploadList: [],
  82. imgName: '',
  83. visible: false,
  84. goods: {
  85. primaryPicUrl: '',
  86. listPicUrl: '',
  87. categoryId: '',
  88. isOnSale: 1,
  89. isNew: 1,
  90. isAppExclusive: 0,
  91. isLimited: 0,
  92. isHot: 0,
  93. categoryName: ''
  94. },
  95. ruleValidate: {
  96. name: [
  97. {required: true, message: '名称不能为空', trigger: 'blur'}
  98. ]
  99. },
  100. q: {
  101. name: ''
  102. },
  103. brands: [],//品牌
  104. macros: [],//商品单位
  105. attributeCategories: []//属性类别
  106. },
  107. methods: {
  108. query: function () {
  109. vm.reload();
  110. },
  111. linkHotspot: function (id) {
  112. var sid = linkHotData[id].sid,sceneNum=linkHotData[id].sceneNum,pageSid=linkHotData[id].pageSid
  113. openWindow({
  114. type: 2,
  115. title: '关联商品',
  116. content: '../shop/linkhotspot.html?sid='+sid+'&sceneNum='+sceneNum+'&pageSid='+pageSid,
  117. end:function () {
  118. vm.reload();
  119. }
  120. })
  121. },
  122. add: function () {
  123. vm.showList = false;
  124. vm.title = "新增";
  125. vm.uploadList = [];
  126. vm.goods = {
  127. primaryPicUrl: '',
  128. listPicUrl: '',
  129. categoryId: '',
  130. isOnSale: 1,
  131. isNew: 1,
  132. isAppExclusive: 0,
  133. isLimited: 0,
  134. isHot: 0,
  135. categoryName: ''
  136. };
  137. $('#goodsDesc').editable('setHTML', '');
  138. vm.getCategory();
  139. vm.brands = [];
  140. vm.macros = [];
  141. vm.attributeCategories = [];
  142. // vm.attribute = [];
  143. vm.getBrands();
  144. vm.getMacro();
  145. vm.getAttributeCategories();
  146. // vm.getAttributes('');
  147. },
  148. update: function (event) {
  149. var id = getSelectedRow("#jqGrid");
  150. if (id == null) {
  151. return;
  152. }
  153. vm.showList = false;
  154. vm.title = "修改";
  155. vm.uploadList = [];
  156. vm.getInfo(id);
  157. vm.getBrands();
  158. vm.getMacro();
  159. vm.getAttributeCategories();
  160. vm.getGoodsGallery(id);
  161. },
  162. /**
  163. * 获取品牌
  164. */
  165. getBrands: function () {
  166. Ajax.request({
  167. url: "../brand/queryAllHot",
  168. async: true,
  169. successCallback: function (r) {
  170. vm.brands = r.list;
  171. }
  172. });
  173. },
  174. /**
  175. * 获取单位
  176. */
  177. getMacro: function () {
  178. Ajax.request({
  179. url: "../sys/macro/queryMacrosByValue?value=goodsUnit",
  180. async: true,
  181. successCallback: function (r) {
  182. vm.macros = r.list;
  183. }
  184. });
  185. },
  186. getGoodsGallery: function (id) {//获取商品顶部轮播图
  187. Ajax.request({
  188. url: "../goodsgallery/queryAll?goodsId=" + id,
  189. async: true,
  190. successCallback: function (r) {
  191. vm.uploadList = r.list;
  192. }
  193. });
  194. },
  195. getAttributeCategories: function () {
  196. Ajax.request({
  197. url: "../attributecategory/queryAll",
  198. async: true,
  199. successCallback: function (r) {
  200. vm.attributeCategories = r.list;
  201. }
  202. });
  203. },
  204. saveOrUpdate: function (event) {
  205. var url = vm.goods.id == null ? "../goods/save" : "../goods/update";
  206. vm.goods.goodsDesc = $('#goodsDesc').editable('getHTML');
  207. vm.goods.goodsImgList = vm.uploadList;
  208. Ajax.request({
  209. type: "POST",
  210. url: url,
  211. contentType: "application/json",
  212. params: JSON.stringify(vm.goods),
  213. successCallback: function (r) {
  214. alert('操作成功', function (index) {
  215. vm.reload();
  216. });
  217. }
  218. });
  219. },
  220. enSale: function () {
  221. var id = getSelectedRow("#jqGrid");
  222. if (id == null) {
  223. return;
  224. }
  225. confirm('确定要上架选中的商品?', function () {
  226. Ajax.request({
  227. type: "POST",
  228. url: "../goods/enSale",
  229. params: JSON.stringify(id),
  230. contentType: "application/json",
  231. type: 'POST',
  232. successCallback: function () {
  233. alert('提交成功', function (index) {
  234. vm.reload();
  235. });
  236. }
  237. });
  238. });
  239. },
  240. openSpe: function () {
  241. var id = getSelectedRow("#jqGrid");
  242. if (id == null) {
  243. return;
  244. }
  245. openWindow({
  246. type: 2,
  247. title: '商品规格',
  248. content: '../shop/goodsspecification.html?goodsId=' + id
  249. })
  250. },
  251. openPro: function () {
  252. var id = getSelectedRow("#jqGrid");
  253. if (id == null) {
  254. return;
  255. }
  256. openWindow({
  257. type: 2,
  258. title: '产品设置',
  259. content: '../shop/product.html?goodsId=' + id
  260. });
  261. },
  262. unSale: function () {
  263. var id = getSelectedRow("#jqGrid");
  264. if (id == null) {
  265. return;
  266. }
  267. confirm('确定要下架选中的商品?', function () {
  268. Ajax.request({
  269. type: "POST",
  270. url: "../goods/unSale",
  271. contentType: "application/json",
  272. params: JSON.stringify(id),
  273. successCallback: function (r) {
  274. alert('操作成功', function (index) {
  275. vm.reload();;
  276. });
  277. }
  278. });
  279. });
  280. },
  281. del: function (event) {
  282. var id = getSelectedRow("#jqGrid");
  283. let row = linkHotData[id]
  284. if (id == null) {
  285. return;
  286. }
  287. confirm('确定要删除选中的记录?', function () {
  288. Ajax.request({
  289. type: "POST",
  290. url: "../brand/deleteGoodsHot",
  291. params: {
  292. sid: row.sid,
  293. pageSid:row.pageSid
  294. },
  295. successCallback: function (r) {
  296. alert('操作成功', function (index) {
  297. vm.reload();;
  298. });
  299. }
  300. });
  301. });
  302. },
  303. getInfo: function (id) {
  304. Ajax.request({
  305. url: "../goods/info/" + id,
  306. async: true,
  307. successCallback: function (r) {
  308. vm.goods = r.goods;
  309. $('#goodsDesc').editable('setHTML', vm.goods.goodsDesc);
  310. vm.getCategory();
  311. }
  312. });
  313. },
  314. reload: function (event) {
  315. vm.showList = true;
  316. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  317. $("#jqGrid").jqGrid('setGridParam', {
  318. postData: {'name': vm.q.name},
  319. page: page
  320. }).trigger("reloadGrid");
  321. vm.handleReset('formValidate');
  322. },
  323. getCategory: function () {
  324. //加载分类树
  325. Ajax.request({
  326. url: "../category/queryAll",
  327. async: true,
  328. successCallback: function (r) {
  329. ztree = $.fn.zTree.init($("#categoryTree"), setting, r.list);
  330. var node = ztree.getNodeByParam("id", vm.goods.categoryId);
  331. if (node) {
  332. ztree.selectNode(node);
  333. vm.goods.categoryName = node.name;
  334. } else {
  335. node = ztree.getNodeByParam("id", 0);
  336. ztree.selectNode(node);
  337. vm.goods.categoryName = node.name;
  338. }
  339. }
  340. });
  341. },
  342. categoryTree: function () {
  343. openWindow({
  344. title: "选择类型",
  345. area: ['300px', '450px'],
  346. content: jQuery("#categoryLayer"),
  347. btn: ['确定', '取消'],
  348. btn1: function (index) {
  349. var node = ztree.getSelectedNodes();
  350. //选择上级菜单
  351. vm.goods.categoryId = node[0].id;
  352. vm.goods.categoryName = node[0].name;
  353. layer.close(index);
  354. }
  355. });
  356. },
  357. handleView: function(name) {
  358. this.imgName = name;
  359. this.visible = true;
  360. },
  361. handleRemove: function(file) {
  362. // 从 upload 实例删除数据
  363. const fileList = this.uploadList;
  364. this.uploadList.splice(fileList.indexOf(file), 1);
  365. },
  366. handleSuccess: function(res, file) {
  367. // 因为上传过程为实例,这里模拟添加 url
  368. file.imgUrl = res.url;
  369. file.name = res.url;
  370. vm.uploadList.add(file);
  371. },
  372. handleBeforeUpload: function() {
  373. const check = this.uploadList.length < 5;
  374. if (!check) {
  375. this.$Notice.warning({
  376. title: '最多只能上传 5 张图片。'
  377. });
  378. }
  379. return check;
  380. },
  381. handleSubmit: function (name) {
  382. handleSubmitValidate(this, name, function () {
  383. vm.saveOrUpdate()
  384. });
  385. },
  386. handleFormatError: function (file) {
  387. this.$Notice.warning({
  388. title: '文件格式不正确',
  389. desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
  390. });
  391. },
  392. handleMaxSize: function (file) {
  393. this.$Notice.warning({
  394. title: '超出文件大小限制',
  395. desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
  396. });
  397. },
  398. handleReset: function (name) {
  399. handleResetForm(this, name);
  400. },
  401. handleSuccessPicUrl: function (res, file) {
  402. vm.goods.primaryPicUrl = file.response.url;
  403. },
  404. handleSuccessListPicUrl: function (res, file) {
  405. vm.goods.listPicUrl = file.response.url;
  406. },
  407. eyeImagePicUrl: function () {
  408. var url = vm.goods.primaryPicUrl;
  409. eyeImage(url);
  410. },
  411. eyeImageListPicUrl: function () {
  412. var url = vm.goods.listPicUrl;
  413. eyeImage(url);
  414. },
  415. eyeImage: function (e) {
  416. eyeImage($(e.target).attr('src'));
  417. }
  418. },
  419. mounted:function() {
  420. this.uploadList = this.$refs.upload.fileList;
  421. }
  422. });