goods.js 27 KB

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