1 |
- (global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["pages/app_admin/add-goods/add-goods"],{"07ea":function(e,t,i){"use strict";var o=i("7c7b"),a=i.n(o);a.a},"0a7a":function(e,t,i){"use strict";var o,a=function(){var e=this,t=e.$createElement;e._self._c;e._isMounted||(e.e0=function(t){e.set_attr=!e.set_attr},e.e1=function(t){e.confine=!e.confine})},r=[];i.d(t,"b",(function(){return a})),i.d(t,"c",(function(){return r})),i.d(t,"a",(function(){return o}))},"17ef":function(e,t,i){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var o=i("2f62");function a(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,o)}return i}function r(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?a(Object(i),!0).forEach((function(t){n(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):a(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function n(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var s={data:function(){return n({postageIndex:-1,height:0,give_integral:0,forehead_integral:0,beSubmit:!1,inputName:!0,form:{cats:[],name:"",cost_price:"",price:"",original_price:""},cats:[],forehead:-1,unit:"件",iphone_x:!1,set_attr:!1,modal:!1,error:!1,set_cat:!1,set_postage:!1,set_service:!1,confine:!1,is_service:!1,goods_card:[],img:[],card:[],goods_detail:[],beMove:!1,service:[],postage:[],bePostage:"",beService:[],default_service:[],newIndex:"0",index:"0",attr:!1,have_children:!1,disabled:!0,imgHidden:!0,flag:!1,x:0,y:0,id:0,first_service:!0,choose_list:[],elements:[],img_src:"",loading:!1,dialog:!1},"loading",!1)},computed:r({},(0,o.mapState)({theme:function(e){return e.mallConfig.theme},userInfo:function(e){return e.user.info},adminImg:function(e){return e.mallConfig.__wxapp_img.app_admin}})),methods:{money:function(e){var t=e.toString();return 0==t.indexOf(".")&&(t="0"+t),t=t.replace(/[^\d.]/g,""),t=t.replace(/\.{2,}/g,"."),t=t.replace(".","$#$").replace(/\./g,"").replace("$#$","."),t=t.replace(/^(\-)*(\d+)\.(\d\d).*$/,"$1$2.$3"),t.indexOf(".")<0&&""!=t&&(t=parseFloat(t)),+t},costChange:function(e){this.form.cost_price=this.money(e.detail.value)},originalChange:function(e){this.form.original_price=this.money(e.detail.value)},priceChange:function(e){this.form.price=this.money(e.detail.value)},nameBlur:function(){this.inputName=!this.inputName},catchTouchMove:function(){return!1},toSubmit:function(){var t=this;if(t.loading)return!1;e.showLoading({title:"提交中..."}),t.loading=!0,t.beSubmit=!1,t.$request({url:t.$api.app_admin.edit,data:{form:JSON.stringify(t.form)},method:"post"}).then((function(i){t.loading=!1,t.$hideLoading(),e.hideLoading(),t.loading=!1,0==i.code&&0==i.code?(e.showToast({title:i.msg,duration:1e3}),e.setStorage({key:"goods_status",data:"保存成功"}),setTimeout((function(){e.navigateBack()}),500)):e.showToast({title:i.msg,icon:"none",duration:1e3})})).catch((function(i){t.loading=!1,t.$hideLoading(),e.hideLoading()}))},submit:function(e){var t=!1,i=this,o=i.form,a=[];if(!(i.img.length>0))return i.error="请上传商品图片",!1;if(o.pic_url=i.img,!o.name)return i.error="请设置商品名称",!1;if(0==i.cats.length)return i.error="请设置商品分类",!1;for(var r in i.cats)a.push(i.cats[r].value);if(!i.unit)return i.error="请设置商品单位",!1;if(o.unit||(o.unit=i.unit),!o.cost_price)return i.error="请设置商品成本价",!1;if(o.cost_price<0)return i.error="成本价不得小于零",!1;if(!o.original_price)return i.error="请设置商品原价",!1;if(o.original_price<0)return i.error="商品原价不得小于零",!1;if(!o.price)return i.error="请设置商品售价",!1;if(o.price<.01)return i.error="商品售价不得小于零",!1;if(i.set_attr){if(o.use_attr=1,o.goods_num=0,!o.attr_groups||0==o.attr_groups.length)return i.error="请设置商品规格",!1;t=!0}else{if(o.use_attr=0,o.attr=[],!o.goods_num)return i.error="商品库存不得为空",!1;if(o.goods_num<0)return i.error="商品库存不得小于零",!1;t=!0}o.cards=i.goods_card,o.services=[],i.beService.length>0&&(o.services=i.beService);var n=0;if(i.beService.length==i.default_service.length)for(var s in i.beService)i.beService[s]==i.default_service[s]&&n++;if(o.is_default_services=1,0!=i.beService.length&&n==i.beService.length||(o.is_default_services=0),o.status=e,o.virtual_sales=0,o.cover_pic="",o.sort=100,o.accumulative=1,o.member_price={},o.mchCats=[],!(i.goods_detail.length>0))return i.error="请设置图文描述",!1;for(var c in o.detail="",i.goods_detail)"img"==i.goods_detail[c].type?o.detail+='<p><img src="'+i.goods_detail[c].pic_url+'"/></p>':"line"==i.goods_detail[c].type?o.detail+='<p><img src="'+i.adminImg.line+'"/></p>':"text"==i.goods_detail[c].type&&(o.detail+="<p>"+i.goods_detail[c].text+"</p>");i.forehead_integral&&(i.forehead_integral>0?o.forehead_integral_type=1:(o.forehead_integral_type=2,o.forehead_integral=i.forehead_integral.replace("%",""))),i.give_integral&&(i.give_integral>0?(o.give_integral_type=1,o.give_integral=i.give_integral):(o.give_integral_type=2,o.give_integral=i.give_integral.replace("%",""))),o.freight_id=i.bePostage.id,o.freight=i.bePostage,o.individual_share=0,o.is_level=0,o.individual_share=0,o.video_url="",t&&(i.form=o,i.form.cats=a,i.id>0&&(i.form.id=i.id),0==e?i.toSubmit():i.beSubmit=!0)},close:function(){this.error=null,this.modal=!1,this.beSubmit=!1},inputAttr:function(e){this.attr[e].attr_list[0].attr_id=(+e+2).toString()},_longtap:function(t,i,o){var a=this,r=e.createSelectorQuery(),n=r.selectAll(".move-img");n.fields({dataset:!0,rect:!0},(function(e){a.elements=e})).exec();o.detail;a.img[i].pic_url="",a.x=o.currentTarget.offsetLeft,a.y=o.currentTarget.offsetTop,a.imgHidden=!1,a.flag=!0,a.beMove=!0,a.img_src=t,a.beginIndex=i},touchend:function(e){var t=this;if(t.flag){for(var i=e.changedTouches[0].pageX,o=e.changedTouches[0].pageY,a=t.elements,r=t.img,n=t.beginIndex,s=0;s<a.length;s++){var c=a[s];if(i>c.left&&i<c.right&&o>c.top&&o<c.bottom){var d=c.dataset.index;if(n<d){for(var g=r[n],u=n;u<d;u++)r[u]=r[u+1];r[d]=g}if(n>d){for(var l=r[n],f=n;f>d;f--)r[f]=r[f-1];r[d]=l}r[d].pic_url=t.img_src,t.img=r}}t.img[n].pic_url||(t.img[n].pic_url=t.img_src),t.imgHidden=!0,t.flag=!1,t.beMove=!1,t.beginIndex=null}},touchm:function(e){if(this.flag){var t=e.touches[0].pageX,i=e.touches[0].pageY;this.x=t-60,this.y=i-129}},cancelService:function(){var t=this.beService,i=this.service;t.length>0?i.forEach((function(e,i){e.isChoose=!1,t.forEach((function(t){t.id==e.id&&(e.isChoose=!0)}))})):i.forEach((function(e,t){e.isChoose=!1})),this.beService=t,this.service=i,this.set_service=!1,this.is_service=!1,setTimeout((function(t){e.pageScrollTo({scrollTop:45550,duration:0})}),0)},submitService:function(){var t=[];this.service.forEach((function(e){e.isChoose&&t.push(e)})),this.beService=t,this.set_service=!1,this.is_service=!1,setTimeout((function(t){e.pageScrollTo({scrollTop:45550,duration:0})}),0)},choose:function(e){var t=this;t.service.forEach((function(i){i.id==e.id&&(i.isChoose=!i.isChoose,t.$forceUpdate())}))},toGoodsDetail:function(){e.navigateTo({url:"/pages/app_admin/goods-detail/goods-detail"})},addImg:function(){var t=this,i=9-t.img.length;e.chooseImage({count:i,sizeType:["original","compressed"],sourceType:["album","camera"],success:function(i){var o=i.tempFilePaths,a=t.img;o.forEach((function(i,r){e.showLoading({title:"上传中..."});var n="";e.uploadFile({url:t.$api.upload.file,filePath:i,name:"file",fileType:"image",formData:{file:i,file_name:n},success:function(i){var n=JSON.parse(i.data),s={pic_url:n.data.url,id:n.data.id};0==n.code&&a.push(s),t.img=a,r==o.length-1&&e.hideLoading()},fail:function(t){console.log("upload fail:",t),t&&t.errMsg&&e.showModal({title:"错误",content:t.errMsg,showCancel:!1})}})}))}})},del_img:function(e){this.img.splice(e,1)},chooseCat:function(){e.navigateTo({url:"/pages/app_admin/goods-cat/goods-cat"})},chooseAttr:function(){var t=this;e.navigateTo({url:"/pages/app_admin/goods-attr/goods-attr"}),e.setStorage({key:"goods_unit",data:t.unit})},bindChange:function(e){this.newIndex=e.detail.value[0]},toggle:function(e){this.choose_list=[],this.dialog=!1,this.set_cat=!1,1==e?this.set_postage&&(this.bePostage=this.postage[this.newIndex]):this.set_postage=!1},chooseService:function(){var t=this;t.first_service?t.$request({url:t.$api.app_admin.service}).then((function(i){if(t.$hideLoading(),0==i.code){t.service=i.data.list,0==i.data.list.length?t.modal=!0:t.is_service=!0;var o=[];i.data.list.forEach((function(e){e.isChoose=!1,1==e.is_default&&(o.push(e),e.isChoose=!0)})),t.set_service=!0,t.beService=o,t.default_service=o,t.first_service=!1}else e.showToast({title:i.msg,icon:"none",duration:1e3})})).catch((function(e){t.$hideLoading()})):0==t.service.length?t.modal=!0:t.is_service=!0},chooseCard:function(){var t=this;t.$request({url:t.$api.app_admin.card}).then((function(i){t.$hideLoading(),0==i.code?(t.card=i.data.list,0==i.data.list.length?(t.set_card=!0,t.modal=!0):e.navigateTo({url:"/pages/app_admin/goods-card/goods-card"})):e.showToast({title:i.msg,icon:"none",duration:1e3})})).catch((function(e){t.$hideLoading()}))},chooseExpress:function(){var t=this;t.$request({url:t.$api.app_admin.postage}).then((function(i){if(t.$hideLoading(),0==i.code)if(0==i.data.list.length)t.set_postage=!0,t.modal=!0,t.postage=i.data.list;else{var o=[];i.data.list.forEach((function(e,t){o.push(i.data.list[t].id)}));var a=o.indexOf(t.bePostage.id);a>-1?(t.postageIndex=a,t.newIndex=a):t.bePostage="",t.set_postage=!0,t.dialog=!0,t.postage=i.data.list}else e.showToast({title:i.msg,icon:"none",duration:1e3})})).catch((function(e){t.$hideLoading()}))},getService:function(t){var i=this;i.$request({url:i.$api.app_admin.service}).then((function(o){if(i.$hideLoading(),0==o.code){for(var a in i.service=o.data.list,i.service)i.service[a].isChoose=!1;if(t>0)for(var r in i.beService)for(var n in i.service)i.service[n].id==i.beService[r].id&&(i.service[n].isChoose=!0,i.first_service=!1);else console.log(2),i.beService=[],o.data.list.forEach((function(e){e.isChoose=!1,1==e.is_default&&(i.beService.push(e),e.isChoose=!0)}))}else e.showToast({title:o.msg,icon:"none",duration:1e3})})).catch((function(e){i.$hideLoading()}))},getPostage:function(t){var i=this;i.$request({url:i.$api.app_admin.postage}).then((function(o){if(i.$hideLoading(),0==o.code){if(i.postage=o.data.list,t>0)return;i.bePostage="",o.data.list.forEach((function(e){1==e.status&&(i.bePostage=e)}))}else e.showToast({title:o.msg,icon:"none",duration:1e3})})).catch((function(e){i.$hideLoading()}))},getCard:function(){var t=this;t.$request({url:t.$api.app_admin.card}).then((function(i){t.$hideLoading(),0==i.code?t.card=i.data.list:e.showToast({title:i.msg,icon:"none",duration:1e3})})).catch((function(e){t.$hideLoading()}))},getDetail:function(t){var i=this;i.$request({url:i.$api.app_admin.goods_edit,data:{id:t}}).then((function(o){if(i.$hideLoading(),i.getService(t),i.getPostage(t),0==o.code){i.form=o.data.detail,i.img=i.form.pic_url,i.cats=i.form.cats,i.set_attr=i.form.use_attr,i.beService=i.form.services,i.bePostage=i.form.freight,i.goods_card=i.form.cards,i.forehead_integral=+i.form.forehead_integral,2==i.form.forehead_integral_type&&(i.forehead_integral=i.form.forehead_integral+"%"),i.give_integral=+i.form.give_integral,2==i.form.give_integral_type&&(i.give_integral=i.form.give_integral+"%"),i.form.attr_groups.length>0&&i.form.attr.length>0&&(i.attr=!0,e.setStorage({key:"goods_attr_groups",data:i.form.attr_groups}),e.setStorage({key:"goods_attr",data:i.form.attr}));var a,r=i.form.detail.split(/<\/p>|<br\/>|<img /),n=[];for(var s in console.log(r),r)r[s]=r[s].replace(/<p>/g,"").replace(/<\/p>/g,""),a={type:""},r[s].indexOf("src")>-1?(a.type="img",a.id="",a.pic_url=r[s].slice(5,r[s].length-3)):(a.type="text",a.text=r[s]),n[s]=a;for(var c in n)""==n[c].text&&n.splice(c,1);i.goods_detail=n,e.setStorage({key:"goods_card",data:i.form.cards}),e.setStorage({key:"goods_cat",data:i.cats}),e.setStorage({key:"goods_detail",data:n})}else e.showToast({title:o.msg,icon:"none",duration:1e3})})).catch((function(e){i.$hideLoading()}))}},onLoad:function(t){var i=this;e.getSystemInfo({success:function(e){(e.model.indexOf("iPhone X")>-1||e.model.indexOf("iPhone 11")>-1||e.model.indexOf("iPhone11")>-1||e.model.indexOf("iPhone12")>-1||e.model.indexOf("Unknown Device")>-1)&&(i.iphone_x=!0)}}),e.getSystemInfo({success:function(e){var t=e.windowHeight,o=e.windowWidth,a=750/o;i.height=t*a}}),i.getCard(),e.removeStorage({key:"goods_card",success:function(e){i.goods_card=[]}}),e.removeStorage({key:"goods_cat",success:function(e){console.log(e)}}),e.removeStorage({key:"goods_unit",success:function(e){console.log(e)}}),e.removeStorage({key:"goods_attr_groups",success:function(e){console.log(e)}}),e.removeStorage({key:"goods_attr",success:function(e){console.log(e)}}),e.removeStorage({key:"temp_attr",success:function(e){console.log(e)}}),e.removeStorage({key:"temp_attr_info",success:function(e){console.log(e)}}),e.removeStorage({key:"goods_detail",success:function(e){i.goods_detail=[]}}),t.id>0?(i.$showLoading({type:"global",text:"加载中..."}),i.id=t.id,setTimeout((function(o){e.setNavigationBarTitle({title:"编辑商品"}),i.getDetail(t.id)}),500)):(i.getService(),i.getPostage())},onShow:function(){var t=this;e.getStorage({key:"goods_card",success:function(e){t.goods_card=e.data}}),e.getStorage({key:"goods_cat",success:function(e){t.cats=e.data}}),e.getStorage({key:"goods_detail",success:function(e){t.goods_detail=e.data}}),e.getStorage({key:"goods_attr_groups",success:function(e){t.form.attr_groups=e.data,t.attr=!0}}),e.getStorage({key:"goods_attr",success:function(e){t.form.attr=e.data}}),e.removeStorage({key:"temp_attr",success:function(e){console.log(e)}}),e.removeStorage({key:"temp_attr_info",success:function(e){console.log(e)}})}};t.default=s}).call(this,i("543d")["default"])},"3a5e":function(e,t,i){"use strict";(function(e){i("8748");o(i("66fd"));var t=o(i("ee62"));function o(e){return e&&e.__esModule?e:{default:e}}e(t.default)}).call(this,i("543d")["createPage"])},"71b4":function(e,t,i){"use strict";i.r(t);var o=i("17ef"),a=i.n(o);for(var r in o)"default"!==r&&function(e){i.d(t,e,(function(){return o[e]}))}(r);t["default"]=a.a},"7c7b":function(e,t,i){},ee62:function(e,t,i){"use strict";i.r(t);var o=i("0a7a"),a=i("71b4");for(var r in a)"default"!==r&&function(e){i.d(t,e,(function(){return a[e]}))}(r);i("07ea");var n,s=i("f0c5"),c=Object(s["a"])(a["default"],o["b"],o["c"],!1,null,"7ee362a4",null,!1,o["a"],n);t["default"]=c.exports}},[["3a5e","common/runtime","common/vendor"]]]);
|