goods.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. $(function () {
  2. $("#jqGrid").Grid({
  3. url: '../goods/list',
  4. rownumWidth:60,
  5. colModel: [
  6. {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
  7. {label: '商品名称', name: 'name', index: 'name', width: 160},
  8. {label: '商品描述', name: 'goodsSimpleDesc', index: 'goodsSimpleDesc', width: 160},
  9. {label: '购买链接', name: 'realShopUrl', index: 'realShopUrl', width: 160},
  10. {label: '商品分类', name: 'categoryName', index: 'category_id', width: 80},
  11. {label: '店铺名称', name: 'brandName', index: 'brand_id', width: 120},
  12. {
  13. label: '录入日期', name: 'addTime', index: 'add_time', width: 80, formatter: function (value) {
  14. return transDate(value, 'yyyy-MM-dd');
  15. }
  16. },
  17. // {label: '属性类别', name: 'attributeCategoryName', index: 'attribute_category', width: 80},
  18. {label: '零售价格', name: 'retailPrice', index: 'retail_price', width: 80},
  19. {label: '商品库存', name: 'goodsNumber', index: 'goods_number', width: 80},
  20. {label: '销售量', name: 'sellVolume', index: 'sell_volume', width: 80, formatoptions: { defaultValue: '0' }},
  21. {label: '市场价', name: 'marketPrice', index: 'market_price', width: 80},
  22. {
  23. label: '上架', align:'center',name: 'isOnSale', index: 'is_on_sale', width: 50,
  24. formatter: function (value) {
  25. return transIsNot(value);
  26. }
  27. }
  28. // {
  29. // label: '热销', name: 'isHot', index: 'is_hot', width: 80, formatter: function (value) {
  30. // return transIsNot(value);
  31. // }
  32. // }
  33. ]
  34. });
  35. $('#goodsDesc').editable({
  36. inlineMode: false,
  37. alwaysBlank: true,
  38. minHeight: '200px',
  39. language: "zh_cn",
  40. spellcheck: false,
  41. plainPaste: true,
  42. enableScript: false,
  43. imageButtons: ["floatImageLeft", "floatImageNone", "floatImageRight", "linkImage", "replaceImage", "removeImage"],
  44. allowedImageTypes: ["jpeg", "jpg", "png", "gif"],
  45. imageUploadURL: '../sys/oss/upload',
  46. imageUploadParams: {id: "edit"},
  47. imagesLoadURL: '../sys/oss/queryAll'
  48. })
  49. });
  50. var ztree;
  51. var setting = {
  52. data: {
  53. simpleData: {
  54. enable: true,
  55. idKey: "id",
  56. pIdKey: "parentId",
  57. rootPId: -1
  58. },
  59. key: {
  60. url: "nourl"
  61. }
  62. }
  63. };
  64. var guigeDetailHeader = [
  65. {
  66. name:'库存',
  67. id:'goodsNumber'
  68. },
  69. {
  70. name:'规格编码',
  71. id:'goodsSn'
  72. },
  73. {
  74. name:'市场价',
  75. id:'marketPrice'
  76. },
  77. {
  78. name:'销售价',
  79. id:'retailPrice'
  80. },
  81. ]
  82. var val1 = [
  83. {
  84. val:'20码',
  85. id:'20m'
  86. },
  87. {
  88. val:'30码',
  89. id:'30m'
  90. }
  91. ]
  92. var val2 = [
  93. {
  94. val:'10寸',
  95. id:'10c'
  96. },
  97. {
  98. val:'20寸',
  99. id:'20c'
  100. },
  101. ]
  102. var val3 = [
  103. {
  104. val:'毛坯房',
  105. id:'mp'
  106. },
  107. {
  108. val:'精装房',
  109. id:'jz'
  110. }
  111. ]
  112. var isFrist = true
  113. var vm = new Vue({
  114. el: '#rrapp',
  115. data: function () {
  116. const validateBrandIdCheck =function (rule, value, callback) {
  117. if (value === '' || !value) {
  118. callback(new Error('店铺不能为空'));
  119. }else {
  120. callback();
  121. }
  122. };
  123. const validateCategoryNameCheck =function (rule, value, callback) {
  124. if (isFrist) {
  125. isFrist = false
  126. return
  127. }
  128. if (value === '' || !value || value==='一级分类') {
  129. callback(new Error('请选择商品类型'));
  130. } else {
  131. callback();
  132. }
  133. };
  134. const validateNameCheck =function (rule, value, callback) {
  135. if (value === '' || !value ) {
  136. callback(new Error('名称不能为空'));
  137. }
  138. else if(value.length>15){
  139. callback(new Error('商品名称不能超过15个字符'));
  140. }
  141. else {
  142. callback();
  143. }
  144. };
  145. const validaterealShopUrlCheck =function (rule, value, callback) {
  146. if (value === '' || !value ) {
  147. callback();
  148. }
  149. else if(value.length>500){
  150. callback(new Error('网站链接不能超过500个字符'));
  151. }
  152. else if(!(value.indexOf('item.jd')>-1||value.indexOf('item.m.jd')>-1)){
  153. callback(new Error('目前不支持添加其他网站链接'));
  154. }
  155. else {
  156. callback();
  157. }
  158. };
  159. const validateDescCheck =function (rule, value, callback) {
  160. if (value === '' || !value ) {
  161. callback(new Error('商品描述不能为空'));
  162. }
  163. else if(value.length>30){
  164. callback(new Error('商品描述不能超过30个字符'));
  165. }
  166. else {
  167. callback();
  168. }
  169. };
  170. return {
  171. ggheader:guigeDetailHeader,
  172. ggContent:'',
  173. showList: true,
  174. title: null,
  175. uploadList: [],
  176. imgName: '',
  177. visible: false,
  178. goods: {
  179. primaryPicUrl: '',
  180. listPicUrl: '',
  181. categoryId: '',
  182. isOnSale: 1,
  183. isNew: 1,
  184. realShopUrl:'',
  185. isAppExclusive: 0,
  186. isLimited: 0,
  187. isHot: 0,
  188. categoryName: '',
  189. guigeArr: []
  190. },
  191. ruleValidate: {
  192. categoryName: [
  193. {required: true, validator: validateCategoryNameCheck, trigger: 'change'}
  194. ],
  195. goodsSn: [
  196. {required: true, message: '商品序列号不能为空', trigger: 'blur'}
  197. ],
  198. name: [
  199. {required: true, validator: validateNameCheck, trigger: 'blur'}
  200. ],
  201. goodsSimpleDesc: [
  202. {required: true, validator: validateDescCheck, trigger: 'blur'}
  203. ],
  204. realShopUrl: [
  205. {validator: validaterealShopUrlCheck, trigger: 'blur'}
  206. ],
  207. brandId: [
  208. {required: true, validator: validateBrandIdCheck, trigger: 'change'}
  209. ],
  210. primaryPicUrl: [
  211. {required: true, message: '商品主图不能为空', trigger: 'change'}
  212. ],
  213. listPicUrl: [
  214. {required: true, message: '商品列表图不能为空', trigger: 'change'}
  215. ]
  216. },
  217. q: {
  218. name: '',
  219. brandId:''
  220. },
  221. brands: [],//品牌
  222. macros: [],//商品单位
  223. attributeCategories: [],//属性类别
  224. specifications: [],
  225. ggname:[],
  226. guigeArr:[{
  227. name:'',
  228. val:[
  229. {
  230. name:'',
  231. picUrl:''
  232. }
  233. ]
  234. }],
  235. currenIdx:'',
  236. currenI:'',
  237. inputArr:[],
  238. goodsSpecificationList:[]
  239. }
  240. },
  241. methods: {
  242. getInputArr:function(){
  243. let uuidLink = []
  244. var arr = []
  245. function pushArr (arr, uuidLink , inputVal) {
  246. let item = vm.inputArr.find(item => item.uuidLink === uuidLink)
  247. console.log(item)
  248. if (item) {
  249. arr.push(item)
  250. } else {
  251. arr.push(Object.assign(inputVal,{
  252. uuidLink
  253. }))
  254. }
  255. }
  256. this.ggContent.forEach(function (item){
  257. uuidLink = []
  258. uuidLink.push(item.uuid)
  259. if (item.subItems) {
  260. item.subItems.forEach(function(sub){
  261. uuidLink[1] = sub.uuid
  262. if (sub.subItems) {
  263. sub.subItems.forEach(function(last){
  264. uuidLink[2] = last.uuid
  265. if (!last.subItems) {
  266. pushArr(arr, uuidLink.join('_'), last.inputVal)
  267. uuidLink.pop()
  268. }
  269. })
  270. }
  271. else{
  272. pushArr(arr, uuidLink.join('_'), sub.inputVal)
  273. uuidLink.pop()
  274. }
  275. })
  276. }else{
  277. pushArr(arr, uuidLink.join('_'), item.inputVal)
  278. uuidLink.pop()
  279. }
  280. })
  281. this.inputArr = arr
  282. },
  283. showArrsds:function () {
  284. },
  285. transToGuigeArr:function (arr) {
  286. let temp = []
  287. let tepName = arr.map(function (item) {
  288. return item.specificationName
  289. })
  290. console.log(arr, 'arr')
  291. tepName = []
  292. arr.forEach(function (item) {
  293. if (!~tepName.indexOf(item.specificationName)) {
  294. tepName.push(item.specificationName)
  295. temp.push({
  296. name: item.specificationName,
  297. val:[
  298. {
  299. name:item.value,
  300. picUrl:item.picUrl,
  301. uuid:item.uuid,
  302. id:item.id
  303. }
  304. ]
  305. })
  306. }else{
  307. temp.forEach(function (sub) {
  308. if (sub.name === item.specificationName) {
  309. sub.val.push(
  310. {
  311. name:item.value,
  312. picUrl:item.picUrl,
  313. uuid:item.uuid,
  314. id:item.id
  315. }
  316. )
  317. }
  318. })
  319. }
  320. })
  321. this.guigeArr = temp
  322. this.showArr()
  323. },
  324. validateGuigeArr: function () {
  325. var pass = true
  326. if (this.guigeArr.length <= 0) {
  327. layer.alert("请先添加规格项目", {icon: 5});
  328. pass = false
  329. return pass
  330. }
  331. this.guigeArr.forEach(function(item) {
  332. item.val && item.val.forEach(function (i) {
  333. if (!i.name) {
  334. layer.alert("规格值请填写完整", {icon: 5});
  335. pass = false
  336. }
  337. })
  338. })
  339. return pass
  340. },
  341. showArr:function () {
  342. if (!this.validateGuigeArr()) {
  343. return
  344. }
  345. let tmp = []
  346. let itm = []
  347. let goodsSpecificationList = []
  348. this.ggname = []
  349. this.guigeArr.forEach(function(item,idx){
  350. itm = []
  351. item.val.forEach(function(sub,i){
  352. let tt= {
  353. value:sub.name,
  354. picUrl:sub.picUrl||'',
  355. uuid: sub.uuid||((idx+1)+'-'+(i+1)),
  356. specificationId: item.specificationId,
  357. inputVal:{
  358. goodsNumber:'',
  359. goodsSn:'',
  360. retailPrice:'',
  361. marketPrice:''
  362. }
  363. }
  364. sub.uuid = sub.uuid||((idx+1)+'-'+(i+1))
  365. itm.push(tt)
  366. goodsSpecificationList.push(tt)
  367. })
  368. vm.ggname.push({
  369. name:item.name
  370. })
  371. tmp.push(itm)
  372. })
  373. console.log(this.guigeArr)
  374. tmp[0].forEach(function (i1){
  375. if (tmp[1]) {
  376. i1['subItems'] = tmp[1]
  377. i1['subItems'].forEach(function (i2){
  378. if (tmp[2]) {
  379. i2['subItems'] = tmp[2]
  380. }
  381. })
  382. }
  383. })
  384. this.ggContent = tmp[0]
  385. this.goodsSpecificationList = goodsSpecificationList
  386. this.getInputArr()
  387. },
  388. handleItem: function (idx,sub) {
  389. this.$set(this.guigeArr[idx],'name',sub.name)
  390. this.$set(this.guigeArr[idx],'picUrl','')
  391. this.$set(this.guigeArr[idx],'specificationId',sub.id)
  392. this.$set(this.guigeArr[idx],'show',false)
  393. },
  394. handleBigItem:function (item) {
  395. this.guigeArr.splice(item,1)
  396. },
  397. handleCurrentIdx: function (i,idx) {
  398. vm.currenIdx = idx
  399. vm.currenI = i
  400. },
  401. handleItemPicUrl: function (res, file) {
  402. vm.$set(vm.guigeArr[vm.currenI]['val'][vm.currenIdx],'picUrl',file.response.url)
  403. this.guigeArr = vm.guigeArr
  404. },
  405. onfocus:function (idx) {
  406. this.$set(this.guigeArr[idx],'show',true)
  407. },
  408. onblur:function (idx) {
  409. this.$set(this.guigeArr[idx],'show',false)
  410. },
  411. delguige:function (item,parent) {
  412. parent.splice(item,1)
  413. },
  414. addguige:function (item) {
  415. item.val.push({
  416. name:'',
  417. picUrl:''
  418. })
  419. },
  420. addGoodsItem:function () {
  421. if (!this.guigeArr) {
  422. this.guigeArr = []
  423. }
  424. if (this.guigeArr.length >= 3) {
  425. window.alert('抱歉,最多只能添加三个规格')
  426. return
  427. }
  428. this.guigeArr.push({
  429. name:'',
  430. val:[
  431. {
  432. name:'',
  433. picUrl:''
  434. }
  435. ]
  436. })
  437. },
  438. query: function () {
  439. vm.reload();
  440. },
  441. getSpecification: function () {
  442. Ajax.request({
  443. url: "../specification/queryAll",
  444. async: true,
  445. successCallback: function (r) {
  446. vm.specifications = r.list;
  447. }
  448. });
  449. },
  450. add: function () {
  451. vm.showList = false;
  452. vm.title = "新增";
  453. vm.uploadList = [];
  454. vm.goods = {
  455. primaryPicUrl: '',
  456. listPicUrl: '',
  457. categoryId: '',
  458. isOnSale: 1,
  459. isNew: 1,
  460. isAppExclusive: 0,
  461. isLimited: 0,
  462. isHot: 0,
  463. goodsNumber:1,
  464. retailPrice: '',
  465. marketPrice: '',
  466. categoryName: ''
  467. };
  468. $('#goodsDesc').editable('setHTML', '');
  469. vm.getCategory();
  470. vm.brands = [];
  471. vm.macros = [];
  472. vm.attributeCategories = [];
  473. vm.ggname=[]
  474. vm.guigeArr=[{
  475. name:'',
  476. val:[
  477. {
  478. name:'',
  479. picUrl:''
  480. }
  481. ]
  482. }]
  483. vm.ggContent=''
  484. vm.currenIdx=''
  485. vm.currenI=''
  486. vm.inputArr=[]
  487. vm.goodsSpecificationList=[]
  488. // vm.attribute = [];
  489. vm.getBrands();
  490. vm.getMacro();
  491. vm.getAttributeCategories();
  492. vm.getSpecification();
  493. // vm.getAttributes('');
  494. },
  495. update: function (event) {
  496. var id = getSelectedRow("#jqGrid");
  497. if (id == null) {
  498. return;
  499. }
  500. vm.showList = false;
  501. vm.title = "修改";
  502. vm.uploadList = [];
  503. vm.getInfo(id);
  504. vm.getBrands();
  505. vm.getMacro();
  506. vm.getAttributeCategories();
  507. vm.getGoodsGallery(id);
  508. },
  509. /**
  510. * 获取品牌
  511. */
  512. getBrands: function () {
  513. Ajax.request({
  514. url: "../brand/queryAll",
  515. async: true,
  516. successCallback: function (r) {
  517. vm.brands = r.list;
  518. r.list.forEach(item=>{
  519. if (item.id == vm.goods.brandId) {
  520. vm.goods.brandName = item.name
  521. }
  522. })
  523. }
  524. });
  525. },
  526. /**
  527. * 获取单位
  528. */
  529. getMacro: function () {
  530. Ajax.request({
  531. url: "../sys/macro/queryMacrosByValue?value=goodsUnit",
  532. async: true,
  533. successCallback: function (r) {
  534. vm.macros = r.list;
  535. }
  536. });
  537. },
  538. getGoodsGallery: function (id) {//获取商品顶部轮播图
  539. Ajax.request({
  540. url: "../goodsgallery/queryAll?goodsId=" + id,
  541. async: true,
  542. successCallback: function (r) {
  543. vm.uploadList = r.list;
  544. }
  545. });
  546. },
  547. getAttributeCategories: function () {
  548. Ajax.request({
  549. url: "../attributecategory/queryAll",
  550. async: true,
  551. successCallback: function (r) {
  552. vm.attributeCategories = r.list;
  553. }
  554. });
  555. },
  556. saveOrUpdate: function (event) {
  557. var url = vm.goods.id == null ? "../goods/save" : "../goods/update";
  558. vm.goods.goodsDesc = $('#goodsDesc').editable('getHTML');
  559. vm.goods.goodsImgList = vm.uploadList;
  560. vm.goods['goodsSpecificationList'] = vm.goods.id == null ?vm.guigeArr: vm.goodsSpecificationList
  561. vm.goods['productList'] = vm.inputArr
  562. vm.goods['guigeArr'] = JSON.stringify(vm.guigeArr)
  563. vm.goods['ggContent'] = JSON.stringify(vm.ggContent)
  564. // 修改市场价和零售价,库存
  565. vm.goods.goodsNumber = 0
  566. vm.goods['productList'].forEach(function (item, index) {
  567. vm.goods.goodsNumber += Number(item.goodsNumber)
  568. if (index === 0) {
  569. vm.goods.retailPrice = item.retailPrice
  570. vm.goods.marketPrice = item.marketPrice
  571. } else {
  572. if (item.retailPrice < vm.goods.retailPrice) {
  573. vm.goods.retailPrice = Number(item.retailPrice)
  574. }
  575. if (item.marketPrice < vm.goods.marketPrice) {
  576. vm.goods.marketPrice = Number(item.marketPrice)
  577. }
  578. }
  579. })
  580. Ajax.request({
  581. type: "POST",
  582. url: url,
  583. contentType: "application/json",
  584. params: JSON.stringify(vm.goods),
  585. successCallback: function (r) {
  586. alert('操作成功', function (index) {
  587. vm.reload();
  588. });
  589. }
  590. });
  591. },
  592. enSale: function () {
  593. // var id = getSelectedRow("#jqGrid");
  594. var ids = getSelectedRows("#jqGrid");
  595. if (ids == null) {
  596. return;
  597. }
  598. confirm('确定要上架选中的商品?', function () {
  599. Ajax.request({
  600. type: "POST",
  601. url: "../goods/enSale",
  602. params: ids.join(','),
  603. contentType: "application/json",
  604. type: 'POST',
  605. successCallback: function () {
  606. alert('提交成功', function (index) {
  607. vm.reload();
  608. });
  609. }
  610. });
  611. });
  612. },
  613. openSpe: function () {
  614. var id = getSelectedRow("#jqGrid");
  615. if (id == null) {
  616. return;
  617. }
  618. openWindow({
  619. type: 2,
  620. title: '商品规格',
  621. content: '../shop/goodsspecification.html?goodsId=' + id
  622. })
  623. },
  624. openPro: function () {
  625. var id = getSelectedRow("#jqGrid");
  626. if (id == null) {
  627. return;
  628. }
  629. openWindow({
  630. type: 2,
  631. title: '产品设置',
  632. content: '../shop/product.html?goodsId=' + id
  633. });
  634. },
  635. unSale: function () {
  636. var ids = getSelectedRows("#jqGrid");
  637. if (ids == null) {
  638. return;
  639. }
  640. function filterUnsale (ids) {
  641. return ids.filter(function(id) {
  642. return $("#jqGrid").jqGrid('getRowData',id).isOnSale.indexOf('是') !== -1
  643. })
  644. }
  645. ids = filterUnsale(ids)
  646. if (ids.length === 0) {
  647. alert('商品已下架')
  648. return
  649. }
  650. confirm('确定要下架选中的商品?', function () {
  651. Ajax.request({
  652. type: "POST",
  653. url: "../goods/unSale",
  654. contentType: "application/json",
  655. params: ids.join(','),
  656. successCallback: function (r) {
  657. alert('操作成功', function (index) {
  658. vm.reload();;
  659. });
  660. }
  661. });
  662. });
  663. },
  664. del: function (event) {
  665. var ids = getSelectedRows("#jqGrid");
  666. if (ids == null) {
  667. return;
  668. }
  669. confirm('确定要删除选中的记录?', function () {
  670. Ajax.request({
  671. type: "POST",
  672. url: "../goods/delete",
  673. contentType: "application/json",
  674. params: JSON.stringify(ids),
  675. successCallback: function (r) {
  676. alert('操作成功', function (index) {
  677. vm.reload();;
  678. });
  679. }
  680. });
  681. });
  682. },
  683. countProductSort: function(uuidLink) {
  684. if (!uuidLink) {
  685. return
  686. }
  687. var sort = uuidLink.split('_')
  688. var length = sort.length
  689. var val = 0
  690. sort.forEach(function (item, index) {
  691. var arr = item.split('-')
  692. val += arr[1] * Math.pow(10, length - index)
  693. })
  694. return val
  695. },
  696. getInfo: function (id) {
  697. Ajax.request({
  698. url: "../goods/info/" + id,
  699. async: true,
  700. successCallback: function (r) {
  701. vm.goods = r.goods;
  702. var productList = r.goods.productList.sort(function(a, b) {
  703. var a_uuid_sort = vm.countProductSort(a.uuidLink)
  704. var b_uuid_sort = vm.countProductSort(b.uuidLink)
  705. return a_uuid_sort - b_uuid_sort
  706. })
  707. vm.inputArr = productList
  708. vm.goodsSpecificationList = r.goods.goodsSpecificationList
  709. vm.guigeArr = JSON.parse(r.goods.guigeArr) || []
  710. vm.ggContent = JSON.parse(r.goods.ggContent)
  711. vm.ggname = []
  712. vm.guigeArr.forEach(function (item){
  713. vm.ggname.push({
  714. name:item.name
  715. })
  716. })
  717. $('#goodsDesc').editable('setHTML', vm.goods.goodsDesc);
  718. vm.getCategory();
  719. vm.getSpecification();
  720. }
  721. });
  722. },
  723. reload: function (event) {
  724. this.getBrands();
  725. vm.showList = true;
  726. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  727. $("#jqGrid").jqGrid('setGridParam', {
  728. postData: {'name': vm.q.name,'brandId': vm.q.brandId},
  729. page: page
  730. }).trigger("reloadGrid");
  731. vm.handleReset('formValidate');
  732. },
  733. getCategory: function () {
  734. //加载分类树
  735. Ajax.request({
  736. url: "../category/queryAll",
  737. async: true,
  738. successCallback: function (r) {
  739. ztree = $.fn.zTree.init($("#categoryTree"), setting, r.list);
  740. if (vm.goods.categoryId) {
  741. var node = ztree.getNodeByParam("id", vm.goods.categoryId);
  742. if (node) {
  743. ztree.selectNode(node);
  744. vm.goods.categoryName = node.name;
  745. } else {
  746. node = ztree.getNodeByParam("id", 0);
  747. ztree.selectNode(node);
  748. vm.goods.categoryName = node.name;
  749. }
  750. }
  751. }
  752. });
  753. },
  754. categoryTree: function () {
  755. openWindow({
  756. title: "选择类型",
  757. area: ['300px', '450px'],
  758. content: jQuery("#categoryLayer"),
  759. btn: ['确定', '取消'],
  760. btn1: function (index) {
  761. var node = ztree.getSelectedNodes();
  762. //选择上级菜单
  763. if (node[0].children) {
  764. alert('请选择商品类型', function () {
  765. });
  766. }
  767. else{
  768. vm.goods.categoryId = node[0].id;
  769. vm.goods.categoryName = node[0].name;
  770. layer.close(index);
  771. }
  772. }
  773. });
  774. },
  775. handleView:function(name) {
  776. this.imgName = name;
  777. this.visible = true;
  778. },
  779. handleRemove:function(file) {
  780. // 从 upload 实例删除数据
  781. const fileList = this.uploadList;
  782. this.uploadList.splice(fileList.indexOf(file), 1);
  783. },
  784. handleSuccess:function(res, file) {
  785. // 因为上传过程为实例,这里模拟添加 url
  786. file.imgUrl = res.url;
  787. file.name = res.url;
  788. vm.uploadList.add(file);
  789. },
  790. handleBeforeUpload:function() {
  791. const check = this.uploadList.length < 5;
  792. if (!check) {
  793. this.$Notice.warning({
  794. title: '最多只能上传 5 张图片。'
  795. });
  796. }
  797. return check;
  798. },
  799. handleSubmit: function (name) {
  800. vm.validateData(name, vm.saveOrUpdate)
  801. },
  802. validateData: function (name, cb) {
  803. handleSubmitValidate(vm, name, function () {
  804. var pass = true
  805. var item = vm.guigeArr.find(function(item) {
  806. if (!item.name) {
  807. pass = false
  808. alert('商品规格请填写完整')
  809. }
  810. return !item.name
  811. })
  812. if (item) {
  813. return pass && cb()
  814. }
  815. vm.guigeArr.forEach(function (item) {
  816. item.val.forEach(function(i) {
  817. if (!i.name || !i.picUrl) {
  818. if (pass) {
  819. alert('商品规格请填写完整')
  820. pass = false
  821. }
  822. }
  823. })
  824. })
  825. pass && cb()
  826. });
  827. },
  828. handleFormatError: function (file) {
  829. this.$Notice.warning({
  830. title: '文件格式不正确',
  831. desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
  832. });
  833. },
  834. handleMaxSize: function (file) {
  835. this.$Notice.warning({
  836. title: '超出文件大小限制',
  837. desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
  838. });
  839. },
  840. handleReset: function (name) {
  841. handleResetForm(this, name);
  842. },
  843. handleSuccessPicUrl: function (res, file) {
  844. vm.goods.primaryPicUrl = file.response.url;
  845. },
  846. handleSuccessListPicUrl: function (res, file) {
  847. vm.goods.listPicUrl = file.response.url;
  848. },
  849. eyeImageItemPicUrl: function (url) {
  850. eyeImage(url);
  851. },
  852. eyeImagePicUrl: function () {
  853. var url = vm.goods.primaryPicUrl;
  854. eyeImage(url);
  855. },
  856. eyeImageListPicUrl: function () {
  857. var url = vm.goods.listPicUrl;
  858. eyeImage(url);
  859. },
  860. eyeImage: function (e) {
  861. eyeImage($(e.target).attr('src'));
  862. }
  863. },
  864. mounted:function() {
  865. // this.transToGuigeArr()
  866. this.uploadList = this.$refs.upload.fileList;
  867. this.getBrands()
  868. }
  869. });