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.com')>-1||value.indexOf('item.m.jd.com')>-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. tepName = []
  291. arr.forEach(function (item) {
  292. if (!~tepName.indexOf(item.specificationName)) {
  293. tepName.push(item.specificationName)
  294. temp.push({
  295. name: item.specificationName,
  296. val:[
  297. {
  298. name:item.value,
  299. picUrl:item.picUrl,
  300. uuid:item.uuid,
  301. id:item.id
  302. }
  303. ]
  304. })
  305. }else{
  306. temp.forEach(function (sub) {
  307. if (sub.name === item.specificationName) {
  308. sub.val.push(
  309. {
  310. name:item.value,
  311. picUrl:item.picUrl,
  312. uuid:item.uuid,
  313. id:item.id
  314. }
  315. )
  316. }
  317. })
  318. }
  319. })
  320. this.guigeArr = temp
  321. this.showArr()
  322. },
  323. validateGuigeArr: function () {
  324. var pass = true
  325. if (this.guigeArr.length <= 0) {
  326. layer.alert("请先添加规格项目", {icon: 5});
  327. pass = false
  328. return pass
  329. }
  330. this.guigeArr.forEach(function(item) {
  331. item.val && item.val.forEach(function (i) {
  332. if (!i.name) {
  333. layer.alert("规格值请填写完整", {icon: 5});
  334. pass = false
  335. }
  336. })
  337. })
  338. return pass
  339. },
  340. showArr:function () {
  341. if (!this.validateGuigeArr()) {
  342. return
  343. }
  344. let tmp = []
  345. let itm = []
  346. let goodsSpecificationList = []
  347. this.ggname = []
  348. this.guigeArr.forEach(function(item,idx){
  349. itm = []
  350. item.val.forEach(function(sub,i){
  351. let tt= {
  352. value:sub.name,
  353. picUrl:sub.picUrl||'',
  354. uuid: sub.uuid||((idx+1)+'-'+(i+1)),
  355. specificationId: item.specificationId,
  356. inputVal:{
  357. goodsNumber:'',
  358. goodsSn:'',
  359. retailPrice:'',
  360. marketPrice:''
  361. }
  362. }
  363. sub.uuid = sub.uuid||((idx+1)+'-'+(i+1))
  364. itm.push(tt)
  365. goodsSpecificationList.push(tt)
  366. })
  367. vm.ggname.push({
  368. name:item.name
  369. })
  370. tmp.push(itm)
  371. })
  372. console.log(this.guigeArr)
  373. tmp[0].forEach(function (i1){
  374. if (tmp[1]) {
  375. i1['subItems'] = tmp[1]
  376. i1['subItems'].forEach(function (i2){
  377. if (tmp[2]) {
  378. i2['subItems'] = tmp[2]
  379. }
  380. })
  381. }
  382. })
  383. this.ggContent = tmp[0]
  384. this.goodsSpecificationList = goodsSpecificationList
  385. this.getInputArr()
  386. },
  387. handleItem: function (idx,sub) {
  388. this.$set(this.guigeArr[idx],'name',sub.name)
  389. this.$set(this.guigeArr[idx],'picUrl','')
  390. this.$set(this.guigeArr[idx],'specificationId',sub.id)
  391. this.$set(this.guigeArr[idx],'show',false)
  392. },
  393. handleBigItem:function (item) {
  394. this.guigeArr.splice(item,1)
  395. },
  396. handleCurrentIdx: function (i,idx) {
  397. vm.currenIdx = idx
  398. vm.currenI = i
  399. },
  400. handleItemPicUrl: function (res, file) {
  401. vm.$set(vm.guigeArr[vm.currenI]['val'][vm.currenIdx],'picUrl',file.response.url)
  402. this.guigeArr = vm.guigeArr
  403. },
  404. onfocus:function (idx) {
  405. this.$set(this.guigeArr[idx],'show',true)
  406. },
  407. onblur:function (idx) {
  408. this.$set(this.guigeArr[idx],'show',false)
  409. },
  410. delguige:function (item,parent) {
  411. parent.splice(item,1)
  412. },
  413. addguige:function (item) {
  414. item.val.push({
  415. name:'',
  416. picUrl:''
  417. })
  418. },
  419. addGoodsItem:function () {
  420. if (!this.guigeArr) {
  421. this.guigeArr = []
  422. }
  423. if (this.guigeArr.length >= 3) {
  424. window.alert('抱歉,最多只能添加三个规格')
  425. return
  426. }
  427. this.guigeArr.push({
  428. name:'',
  429. val:[
  430. {
  431. name:'',
  432. picUrl:''
  433. }
  434. ]
  435. })
  436. },
  437. query: function () {
  438. vm.reload();
  439. },
  440. getSpecification: function () {
  441. Ajax.request({
  442. url: "../specification/queryAll",
  443. async: true,
  444. successCallback: function (r) {
  445. vm.specifications = r.list;
  446. }
  447. });
  448. },
  449. add: function () {
  450. vm.showList = false;
  451. vm.title = "新增";
  452. vm.uploadList = [];
  453. vm.goods = {
  454. primaryPicUrl: '',
  455. listPicUrl: '',
  456. categoryId: '',
  457. isOnSale: 1,
  458. isNew: 1,
  459. isAppExclusive: 0,
  460. isLimited: 0,
  461. isHot: 0,
  462. goodsNumber:1,
  463. retailPrice:1,
  464. marketPrice:1,
  465. categoryName: ''
  466. };
  467. $('#goodsDesc').editable('setHTML', '');
  468. vm.getCategory();
  469. vm.brands = [];
  470. vm.macros = [];
  471. vm.attributeCategories = [];
  472. vm.ggname=[]
  473. vm.guigeArr=[{
  474. name:'',
  475. val:[
  476. {
  477. name:'',
  478. picUrl:''
  479. }
  480. ]
  481. }]
  482. vm.ggContent=''
  483. vm.currenIdx=''
  484. vm.currenI=''
  485. vm.inputArr=[]
  486. vm.goodsSpecificationList=[]
  487. // vm.attribute = [];
  488. vm.getBrands();
  489. vm.getMacro();
  490. vm.getAttributeCategories();
  491. vm.getSpecification();
  492. // vm.getAttributes('');
  493. },
  494. update: function (event) {
  495. var id = getSelectedRow("#jqGrid");
  496. if (id == null) {
  497. return;
  498. }
  499. vm.showList = false;
  500. vm.title = "修改";
  501. vm.uploadList = [];
  502. vm.getInfo(id);
  503. vm.getBrands();
  504. vm.getMacro();
  505. vm.getAttributeCategories();
  506. vm.getGoodsGallery(id);
  507. },
  508. /**
  509. * 获取品牌
  510. */
  511. getBrands: function () {
  512. Ajax.request({
  513. url: "../brand/queryAll",
  514. async: true,
  515. successCallback: function (r) {
  516. vm.brands = r.list;
  517. r.list.forEach(item=>{
  518. if (item.id == vm.goods.brandId) {
  519. vm.goods.brandName = item.name
  520. }
  521. })
  522. }
  523. });
  524. },
  525. /**
  526. * 获取单位
  527. */
  528. getMacro: function () {
  529. Ajax.request({
  530. url: "../sys/macro/queryMacrosByValue?value=goodsUnit",
  531. async: true,
  532. successCallback: function (r) {
  533. vm.macros = r.list;
  534. }
  535. });
  536. },
  537. getGoodsGallery: function (id) {//获取商品顶部轮播图
  538. Ajax.request({
  539. url: "../goodsgallery/queryAll?goodsId=" + id,
  540. async: true,
  541. successCallback: function (r) {
  542. vm.uploadList = r.list;
  543. }
  544. });
  545. },
  546. getAttributeCategories: function () {
  547. Ajax.request({
  548. url: "../attributecategory/queryAll",
  549. async: true,
  550. successCallback: function (r) {
  551. vm.attributeCategories = r.list;
  552. }
  553. });
  554. },
  555. saveOrUpdate: function (event) {
  556. var url = vm.goods.id == null ? "../goods/save" : "../goods/update";
  557. vm.goods.goodsDesc = $('#goodsDesc').editable('getHTML');
  558. vm.goods.goodsImgList = vm.uploadList;
  559. vm.goods['goodsSpecificationList'] = vm.goods.id == null ?vm.guigeArr: vm.goodsSpecificationList
  560. vm.goods['productList'] = vm.inputArr
  561. vm.goods['guigeArr'] = JSON.stringify(vm.guigeArr)
  562. vm.goods['ggContent'] = JSON.stringify(vm.ggContent)
  563. // 修改市场价和零售价,库存
  564. vm.goods.goodsNumber = 0
  565. vm.goods['productList'].forEach(function (item, index) {
  566. vm.goods.goodsNumber += Number(item.goodsNumber)
  567. if (index === 0) {
  568. vm.goods.retailPrice = item.retailPrice
  569. vm.goods.marketPrice = item.marketPrice
  570. } else {
  571. if (item.retailPrice < vm.goods.retailPrice) {
  572. vm.goods.retailPrice = Number(item.retailPrice)
  573. }
  574. if (item.marketPrice < vm.goods.marketPrice) {
  575. vm.goods.marketPrice = Number(item.marketPrice)
  576. }
  577. }
  578. })
  579. Ajax.request({
  580. type: "POST",
  581. url: url,
  582. contentType: "application/json",
  583. params: JSON.stringify(vm.goods),
  584. successCallback: function (r) {
  585. alert('操作成功', function (index) {
  586. vm.reload();
  587. });
  588. }
  589. });
  590. },
  591. enSale: function () {
  592. // var id = getSelectedRow("#jqGrid");
  593. var ids = getSelectedRows("#jqGrid");
  594. if (ids == null) {
  595. return;
  596. }
  597. confirm('确定要上架选中的商品?', function () {
  598. Ajax.request({
  599. type: "POST",
  600. url: "../goods/enSale",
  601. params: ids.join(','),
  602. contentType: "application/json",
  603. type: 'POST',
  604. successCallback: function () {
  605. alert('提交成功', function (index) {
  606. vm.reload();
  607. });
  608. }
  609. });
  610. });
  611. },
  612. openSpe: function () {
  613. var id = getSelectedRow("#jqGrid");
  614. if (id == null) {
  615. return;
  616. }
  617. openWindow({
  618. type: 2,
  619. title: '商品规格',
  620. content: '../shop/goodsspecification.html?goodsId=' + id
  621. })
  622. },
  623. openPro: function () {
  624. var id = getSelectedRow("#jqGrid");
  625. if (id == null) {
  626. return;
  627. }
  628. openWindow({
  629. type: 2,
  630. title: '产品设置',
  631. content: '../shop/product.html?goodsId=' + id
  632. });
  633. },
  634. unSale: function () {
  635. var ids = getSelectedRows("#jqGrid");
  636. if (ids == null) {
  637. return;
  638. }
  639. function filterUnsale (ids) {
  640. return ids.filter(function(id) {
  641. return $("#jqGrid").jqGrid('getRowData',id).isOnSale.indexOf('是') !== -1
  642. })
  643. }
  644. ids = filterUnsale(ids)
  645. if (ids.length === 0) {
  646. alert('商品已下架')
  647. return
  648. }
  649. confirm('确定要下架选中的商品?', function () {
  650. Ajax.request({
  651. type: "POST",
  652. url: "../goods/unSale",
  653. contentType: "application/json",
  654. params: ids.join(','),
  655. successCallback: function (r) {
  656. alert('操作成功', function (index) {
  657. vm.reload();;
  658. });
  659. }
  660. });
  661. });
  662. },
  663. del: function (event) {
  664. var ids = getSelectedRows("#jqGrid");
  665. if (ids == null) {
  666. return;
  667. }
  668. confirm('确定要删除选中的记录?', function () {
  669. Ajax.request({
  670. type: "POST",
  671. url: "../goods/delete",
  672. contentType: "application/json",
  673. params: JSON.stringify(ids),
  674. successCallback: function (r) {
  675. alert('操作成功', function (index) {
  676. vm.reload();;
  677. });
  678. }
  679. });
  680. });
  681. },
  682. countProductSort: function(uuidLink) {
  683. if (!uuidLink) {
  684. return
  685. }
  686. var sort = uuidLink.split('_')
  687. var length = sort.length
  688. var val = 0
  689. sort.forEach(function (item, index) {
  690. var arr = item.split('-')
  691. val += arr[1] * Math.pow(10, length - index)
  692. })
  693. return val
  694. },
  695. getInfo: function (id) {
  696. Ajax.request({
  697. url: "../goods/info/" + id,
  698. async: true,
  699. successCallback: function (r) {
  700. vm.goods = r.goods;
  701. var productList = r.goods.productList.sort(function(a, b) {
  702. var a_uuid_sort = vm.countProductSort(a.uuidLink)
  703. var b_uuid_sort = vm.countProductSort(b.uuidLink)
  704. return a_uuid_sort - b_uuid_sort
  705. })
  706. vm.inputArr = productList
  707. vm.goodsSpecificationList = r.goods.goodsSpecificationList
  708. vm.guigeArr = JSON.parse(r.goods.guigeArr) || []
  709. vm.ggContent = JSON.parse(r.goods.ggContent)
  710. vm.ggname = []
  711. vm.guigeArr.forEach(function (item){
  712. vm.ggname.push({
  713. name:item.name
  714. })
  715. })
  716. $('#goodsDesc').editable('setHTML', vm.goods.goodsDesc);
  717. vm.getCategory();
  718. vm.getSpecification();
  719. }
  720. });
  721. },
  722. reload: function (event) {
  723. this.getBrands();
  724. vm.showList = true;
  725. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  726. $("#jqGrid").jqGrid('setGridParam', {
  727. postData: {'name': vm.q.name,'brandId': vm.q.brandId},
  728. page: page
  729. }).trigger("reloadGrid");
  730. vm.handleReset('formValidate');
  731. },
  732. getCategory: function () {
  733. //加载分类树
  734. Ajax.request({
  735. url: "../category/queryAll",
  736. async: true,
  737. successCallback: function (r) {
  738. ztree = $.fn.zTree.init($("#categoryTree"), setting, r.list);
  739. if (vm.goods.categoryId) {
  740. var node = ztree.getNodeByParam("id", vm.goods.categoryId);
  741. if (node) {
  742. ztree.selectNode(node);
  743. vm.goods.categoryName = node.name;
  744. } else {
  745. node = ztree.getNodeByParam("id", 0);
  746. ztree.selectNode(node);
  747. vm.goods.categoryName = node.name;
  748. }
  749. }
  750. }
  751. });
  752. },
  753. categoryTree: function () {
  754. openWindow({
  755. title: "选择类型",
  756. area: ['300px', '450px'],
  757. content: jQuery("#categoryLayer"),
  758. btn: ['确定', '取消'],
  759. btn1: function (index) {
  760. var node = ztree.getSelectedNodes();
  761. //选择上级菜单
  762. if (node[0].children) {
  763. alert('请选择商品类型', function () {
  764. });
  765. }
  766. else{
  767. vm.goods.categoryId = node[0].id;
  768. vm.goods.categoryName = node[0].name;
  769. layer.close(index);
  770. }
  771. }
  772. });
  773. },
  774. handleView:function(name) {
  775. this.imgName = name;
  776. this.visible = true;
  777. },
  778. handleRemove:function(file) {
  779. // 从 upload 实例删除数据
  780. const fileList = this.uploadList;
  781. this.uploadList.splice(fileList.indexOf(file), 1);
  782. },
  783. handleSuccess:function(res, file) {
  784. // 因为上传过程为实例,这里模拟添加 url
  785. file.imgUrl = res.url;
  786. file.name = res.url;
  787. vm.uploadList.add(file);
  788. },
  789. handleBeforeUpload:function() {
  790. const check = this.uploadList.length < 5;
  791. if (!check) {
  792. this.$Notice.warning({
  793. title: '最多只能上传 5 张图片。'
  794. });
  795. }
  796. return check;
  797. },
  798. handleSubmit: function (name) {
  799. vm.validateData(name, vm.saveOrUpdate)
  800. },
  801. validateData: function (name, cb) {
  802. handleSubmitValidate(vm, name, function () {
  803. var pass = true
  804. var item = vm.guigeArr.find(function(item) {
  805. if (!item.name) {
  806. pass = false
  807. alert('商品规格请填写完整')
  808. }
  809. return !item.name
  810. })
  811. if (item) {
  812. return pass && cb()
  813. }
  814. vm.guigeArr.forEach(function (item) {
  815. item.val.forEach(function(i) {
  816. if (!i.name || !i.picUrl) {
  817. if (pass) {
  818. alert('商品规格请填写完整')
  819. pass = false
  820. }
  821. }
  822. })
  823. })
  824. pass && cb()
  825. });
  826. },
  827. handleFormatError: function (file) {
  828. this.$Notice.warning({
  829. title: '文件格式不正确',
  830. desc: '文件 ' + file.name + ' 格式不正确,请上传 jpg 或 png 格式的图片。'
  831. });
  832. },
  833. handleMaxSize: function (file) {
  834. this.$Notice.warning({
  835. title: '超出文件大小限制',
  836. desc: '文件 ' + file.name + ' 太大,不能超过 2M。'
  837. });
  838. },
  839. handleReset: function (name) {
  840. handleResetForm(this, name);
  841. },
  842. handleSuccessPicUrl: function (res, file) {
  843. vm.goods.primaryPicUrl = file.response.url;
  844. },
  845. handleSuccessListPicUrl: function (res, file) {
  846. vm.goods.listPicUrl = file.response.url;
  847. },
  848. eyeImageItemPicUrl: function (url) {
  849. eyeImage(url);
  850. },
  851. eyeImagePicUrl: function () {
  852. var url = vm.goods.primaryPicUrl;
  853. eyeImage(url);
  854. },
  855. eyeImageListPicUrl: function () {
  856. var url = vm.goods.listPicUrl;
  857. eyeImage(url);
  858. },
  859. eyeImage: function (e) {
  860. eyeImage($(e.target).attr('src'));
  861. }
  862. },
  863. mounted:function() {
  864. // this.transToGuigeArr()
  865. this.uploadList = this.$refs.upload.fileList;
  866. this.getBrands()
  867. }
  868. });