| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874 |
- <?php
- use common\helpers\ComponentHelper;
- ComponentHelper::loadComponentView('component/com-add-cat', __DIR__);
- ComponentHelper::loadComponentView('component/com-attr-group', __DIR__);
- ComponentHelper::loadComponentView('component/com-attr', __DIR__);
- ComponentHelper::loadComponentView('component/com-attachment', dirname(__DIR__));
- ComponentHelper::loadComponentView('component/com-attachment-edit', dirname(__DIR__));
- ComponentHelper::loadComponentView('component/com-upload', dirname(__DIR__));
- ComponentHelper::loadComponentView('com-rich-text');
- ComponentHelper::loadComponentView('com-district');
- ComponentHelper::loadComponentView('component/coupon-select', __DIR__);
- ComponentHelper::loadComponentView('component/com-package-attr', __DIR__);
- ComponentHelper::loadComponentView('component/com-time-select', __DIR__);
- ComponentHelper::loadComponentView('component/com-price-set', __DIR__);
- ComponentHelper::loadComponentView('component/com-price-day-set', __DIR__);
- ComponentHelper::loadComponentView('component/com-attrs-setting', __DIR__);
- ComponentHelper::loadComponentView('com-map');
- ComponentHelper::loadComponentView('com-dialog-select-store');
- if (!empty($components)) {
- foreach ($components as $addons => $component) {
- if(!file_exists($component['path'])) continue;
- ComponentHelper::loadComponentView($component['component'], $component['path']);
- }
- $components = \yii\helpers\Json::encode($components);
- }
- ?>
- <script src="/resources/js/Sortable.min.js"></script>
- <script src="/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
- <style>
- <?= ComponentHelper::loadComponentView('edit', __DIR__ . '/css', [], true, 'css'); ?>
- /* 商品轮播图样式 */
- .banner-images-container {
- width: 100%;
- padding: 10px 0;
- }
- .banner-images {
- display: grid;
- grid-template-columns: repeat(3, 80px);
- grid-gap: 10px;
- align-items: start;
- }
- .card-coverimg {
- position: relative;
- width: 80px;
- height: 80px;
- border-radius: 4px;
- }
- .delete-btn {
- position: absolute;
- top: -6px;
- right: -6px;
- width: 16px !important;
- height: 16px !important;
- padding: 0 !important;
- border: none !important;
- background-color: rgba(0, 0, 0, 0.6) !important;
- display: flex;
- align-items: center;
- justify-content: center;
- z-index: 1;
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
- }
- .delete-btn:hover {
- background-color: rgba(0, 0, 0, 0.8) !important;
- }
- .delete-btn i {
- font-size: 10px;
- color: #fff;
- margin: 0;
- line-height: 1;
- }
- .elImages {
- width: 100%;
- height: 100%;
- object-fit: cover;
- display: block;
- border-radius: 4px;
- }
- /* 上传按钮样式 */
- .card-upload {
- width: 80px;
- height: 80px;
- border: 1px dashed #d9d9d9;
- border-radius: 6px;
- cursor: pointer;
- position: relative;
- overflow: hidden;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .card-upload:hover {
- border-color: #409EFF;
- }
- .card-upload i {
- font-size: 28px;
- color: #8c939d;
- }
- </style>
- <div id="app" v-cloak>
- <el-card shadow="never" style="border:0" class="box-card" body-style="background-color: #f3f3f3;padding: 20px 0 0;" class="box-card" v-loading="cardLoading">
- <div slot="header">
- <div flex="cross:center box:first">
- <el-breadcrumb separator="/">
- <el-breadcrumb-item>
- <span style="color: #409EFF;cursor: pointer" @click="$navigate({r:'store/client/goods/index'})">商品列表</span>
- </el-breadcrumb-item>
- <el-breadcrumb-item>添加商品</el-breadcrumb-item>
- </el-breadcrumb>
- </div>
- </div>
- <div class="goods-box">
- <el-form :model="ruleForm" :rules="rules" ref="ruleForm" size="mini" label-width="150px" class="demo-ruleForm">
- <!-- tab切换 -->
- <div class="tabs-box">
- <div class="tabs-list" flex="cross:center">
- <span v-for="(item, index) in tabs" :key="index" class="tabs-item" :class="item.value == activeName ? 'tabActive' : ''" @click="toggle(item, index, 'tabs')">{{item.name}}</span>
- </div>
- </div>
- <!-- 基础设置 -->
- <div v-show="activeName == 'basic'">
- <?= ComponentHelper::loadComponentView('goods-basic', __DIR__) ?>
- </div>
- <!-- 营销配置 -->
- <div v-show="activeName == 'marketing'">
- <?= ComponentHelper::loadComponentView('goods-marketing', __DIR__) ?>
- </div>
- <!-- 会员权益 -->
- <div v-show="activeName == 'member_benefits'">
- <?= ComponentHelper::loadComponentView('goods-member', __DIR__) ?>
- </div>
- <!-- 关联商品 -->
- <div v-show="activeName == 'goods_association'">
- <?= ComponentHelper::loadComponentView('goods-association', __DIR__) ?>
- </div>
- </el-form>
- </div>
- </el-card>
- <div class="bottom-btns" flex="main:center cross:center">
- <el-button size="mini" type="primary" @click="submit()" :loading="btnLoading" v-if="supplier_type != 4">保存</el-button>
- </div>
- </div>
- <script>
- const app = new Vue({
- el: '#app',
- data() {
- return {
- default_goods_style1: "/resources/addons/store/img/default_goods_style1.png",
- default_goods_style2: "/resources/addons/store/img/default_goods_style2.png",
- storeConfig: {},
- tabs: [{
- name: '基础设置',
- value: 'basic'
- },
- {
- name: '营销配置',
- value: 'marketing'
- },
- {
- name: '会员权益',
- value: 'member_benefits'
- },
- {
- name: '关联商品',
- value: 'goods_association'
- },
- ],
- activeName: 'basic',
- typeArr: [],
- goods_type: 'physical',
- is_base_show: false,
- is_mch: false,
- is_default_services: 1,
- typeIndex: 0,
- btnLoading: false,
- cardLoading: false,
- cats: [],
- freight_id: 0,
- goodsId: null,
- storeId: 0,
- // freight: {
- // dialog: false,
- // list: [],
- // checked: {},
- // loading: false
- // },
- attrGroups: [], //规格组
- attrGroupName: '',
- attrName: [],
- // 批量设置
- batch: {},
- label_list: [], // 商品标签列表
- service_list: [], // 商品服务列表
- freight_rules: [ // 运费模板
- // {
- // id: '1',
- // name: '全国包邮'
- // },
- // {
- // id: '2',
- // name: '北京包邮'
- // }
- ],
- is_show_freight: false,
- defaultMemberPrice: [],
- member_level_list: [
- // {level: 1, name: '普通会员', value: {"sign_id_2:4":40, "sign_id_3:4": 41, "sign_id_2:5": 41, "sign_id_3:5": 41}},
- // {level: 2, name: '等级2', value: {"sign_id_2:4":30, "sign_id_3:4": 31, "sign_id_2:5": 32, "sign_id_3:5": 33}},
- // {level: 3, name: '等级3', value: {"sign_id_2:4":20, "sign_id_3:4": 21, "sign_id_2:5": 22, "sign_id_3:5": 23}},
- // {level: 4, name: '等级4', value: {"sign_id_2:6":10, "sign_id_3:4": 11, "sign_id_2:5": 12, "sign_id_3:5": 13}}
- ],
- dialogVisible: false, // 配送范围弹出框
- earaRule: [],
- multiple_selection: [], //优惠券
- is_show_counpon: 0, //优惠券是否展示
- show_addons: <?= $components ?? '{}'; ?>, //插件营销是否展示
- the_addons_name: 'Store',
- ruleForm: {
- /*********************************** 基础设置 ****************************************/
- goods_type: 1,
- goods_name: '',
- subtitle: '',
- cover_pic: '',
- bannar_pic: [],
- video_url: '',
- cats: [],
- mchCats: [], //多商户系统分类
- services: [],
- freight: null,
- labels: '', // 商品标签
- is_attr: 0, // 是否有规格
- attr_open: 0, // 是否开启商品规格的“无”
- attr: [],
- price: 0,
- original_price: 0,
- cost_price: 0,
- stock: '',
- unit: '', // 单位
- stock_warning: 0, // 库存预警 - 自定义字段,后面改
- goods_weight: 0, // 商品重量 - 自定义字段,后面改
- goods_no: '', // 商品货号
- is_show_stock: 1, // 是否显示库存 - 自定义字段,后面改
- is_show_sales: 1, // 是否显示销量 - 自定义字段,后面改
- virtual_sales: 0,
- coupon_is_enable: 0, //优惠卷的开关
- // logistics_way: [{
- // name: '快递发货',
- // checked: true
- // }], // 快递发货 - 自定义字段,后面改
- freight_type: [], //物流方式 1快递物流
- freight_rules_type: 1, // 运费规则类型 1运费模板 2统一运费
- freight_id: '', // 运费模板ID
- shipping_fee: 0, //统一运费
- free_shipping_num: 0, //满N件包邮
- free_shipping_money: 0, //满N元包邮
- is_cross_border: 0, // 是否跨境商品 - 自定义字段,后面改
- is_id_card: 0, // 是否身份证上传 - 自定义字段,后面改
- is_on_sale: 1, // 是否上架
- show_style: 1, // 展示风格
- extra: {
- full_reduce_price_limit: 0, // 单品满额减免价格阈值
- full_reduce_money: 0, // 单品满额减免金额
- score_give_setting: {
- is_alone:0,
- code: 'score',
- name: '积分',
- give_num: 0, // 货币赠送
- give_type: 1, // 货币赠送 1.固定值 2售价百分比
- condition: 0,
- settlement: 0,
- },
- is_member_price: 0,
- member_price_setting: {},
- member_buy_limit_setting: {
- member_level: [],
- every_num: 0,
- every_day_num: 0,
- every_week_num: 0,
- every_month_num: 0,
- nums: 0,
- total_num: 0,
- },
- currency_deduct_setting: [], // 货币这块有bug,暂时不需要展示,所以不需要提交数据
- // is_hidden_member_price: 0,
- member_price_switch: 0,
- is_show_price: 0,
- },
- coupon_selection: [],
- goods_setting: {
- /*********************************** 会员权益 **********************************************/
- member_setting: { // 会员权益模块提交的格式
- member_price_setting: '',
- member_price: {},
- member_buy_limit_setting: {
- member_level: [],
- every_num: 0,
- every_day_num: 0,
- every_week_num: 0,
- every_month_num: 0,
- nums: 0,
- total_num: 0,
- }
- },
- /*********************************** 营销设置 **********************************************/
- marketing_setting: { // 营销配置模块提交的格式
- full_reduce_price_limit: 0, // 单品满额减免价格阈值
- full_reduce_money: 0, // 单品满额减免金额
- score_give_setting: {
- code: 'score',
- name: '积分',
- give_num: 0, // 货币赠送
- give_type: 1, // 货币赠送 1.固定值 2售价百分比
- },
- score_deduct_setting: {
- code: 'score',
- name: '积分',
- deduct_num: 0, // 货币抵扣
- deduct_type: 1, // 1.单件抵扣 2.多件累计抵扣
- },
- currency_deduct_setting: [], // 货币这块有bug,暂时不需要展示,所以不需要提交数据
- }
- },
- /******************************* 配送范围 ************************************/
- is_area_limit: 0,
- // area_limit: [{ list: [] }]
- area_limit: [],
- coupon: {
- 'is_enable': 0,
- 'multiple_selection': [],
- },
- addons: {},
- // 预约商品
- reserve: {
- reserve_date_type: 1, // 可预约时间类型(1范围 2自选日期)
- reserve_date: null, // 可预约日期
- reserve_time_range_type: 1, //预约模式(1按天预约 2按时间段预约)
- time_slot_type: 1, // 时间段划分方式(1自定义划分 2自动划分)
- reserve_time_slot: null, // 时间段划分
- reserve_price_type: 0, // 价格设置方式(0统一售价 1按日期时间段设置)
- reserve_time_slot_price: [], // 按时间段设置的价格
- reserve_week: [0,1,2,3,4,5,6], // 可预约周,如:0,1,2,3,4,5,6
- reserve_max_buy: 0, // 每天最大预约数量
- reserve_advance_hourse: 0, // 提前预约时间(小时)
- reserve_days_range: 0, //限制选择并购买的时间在设置内天数的商品
- cancel_type: 1, // 取消类型(1不允许取消 2服务开始前取消 3订单类型取消)
- cancel_rule: {
- cancel_hour: 0,
- cancel_fee_percent: 0
- }, // 取消规则
- expired_handle_type: 1, // 预约码过期后处理方式(1不退款 2自动退款)
- service_type: 1, // 服务方式(1上门 2到店)
- // 位置信息
- province_id: 0, // 省份Id
- city_id: 0, // 城市Id
- district_id: 0, // 区县Id
- detail: '', // 详细地址
- lat: '', // 纬度
- lng: '', // 经度
- skus: [], // 预约多规格
- ordering_information: '', // 订购须知
- information_detail: '', // 须知详情
- reserve_type: 1, // 门店只能是1
- distance: '', // 有效距离
- appointments_number: '', // 有效距离
- },
- },
- rules: {
- cats: [{
- required: true,
- type: 'array',
- validator: (rule, value, callback) => {
- if (this.ruleForm.cats instanceof Array && this.ruleForm.cats.length > 0) {
- callback();
- }
- callback('请选择分类');
- }
- }],
- mchCats: [{
- required: true,
- type: 'array',
- validator: (rule, value, callback) => {
- if (this.ruleForm.mchCats instanceof Array && this.ruleForm.mchCats.length > 0) {
- callback();
- }
- callback('请选择系统分类');
- }
- }],
- goods_name: [{
- required: true,
- message: '请输入商品名称',
- trigger: 'blur'
- }],
- cover_pic: [{
- required: true,
- message: '请添加图片',
- trigger: 'change'
- }],
- price: [{
- required: true,
- message: '请输入价格',
- trigger: 'blur'
- }],
- extra: {
- full_reduce_price_limit: [{
- validator: (rule, value, callback) => {
- if (value > 1000000) {
- callback('不能大于1000000');
- }
- callback();
- }
- }],
- full_reduce_money: [{
- validator: (rule, value, callback) => {
- if (value > 1000000) {
- callback('不能大于1000000');
- }
- callback();
- }
- }]
- },
- stock: [{
- required: true,
- message: '请输入商品库存',
- trigger: 'blur'
- }],
- // area_limit: [{
- // required: true,
- // type: 'array',
- // validator: (rule, value, callback) => {
- // if (value instanceof Array && value[0]['list'].length === 0) {
- // callback('允许购买区域不能为空');
- // }
- // callback();
- // }
- // }],
- reserve: {
- service_min: [
- {
- required: true,
- message: '请输入项目时间',
- trigger: 'blur'
- }
- ]
- }
- },
- revealArea: [],
- extra1_goods_list:[],
- extra2_goods_list:[],
- extra_goods_url: 'store/client/goods/search',
- extra_goods_params:[],
- couponLoading: false,
- package_data: [],
- dayArr: [], //预约商品
- checkWeekList: [], //预约商品
- checkRangeList: [], //预约商品
- provinces: {}, //预约商品
- provinceInfo: {}, //预约商品
- citys: {}, //预约商品
- cityInfo: {}, //预约商品
- districts: {}, //预约商品
- districtInfo: {}, //预约商品
- long_lat: '', // 经纬度
- initializationDates: [], // 编辑商品时格式化传进来的数据
- isEdit: false, // 预约商品,
- is_reserve_type: <?= $is_reserve_type ?>,
- score_give_is_store_alone:false,
- supplier_type: 0,
- };
- },
- created() {
- // 给预约商品一个默认类型
- this.ruleForm.reserve.reserve_type = this.is_reserve_type == 2 || this.is_reserve_type == 0 ? 0 : 1
- this.ruleForm.reserve.reserve_type = 1
- this.goodsId = getQuery('id');
- this.extra_goods_params['goods_id'] = this.goodsId;
- },
- async mounted() {
- // 默认为中国,所以默认上级ID为1
- await this.loadData(1)
- this.getGoodsDetail()
- this.changeFreightType()
- this.getStoreConfig()
- },
- watch: {
- 'ruleForm.detail'(newVal, oldVal) {
- this.cForm.detail = newVal
- },
- 'ruleForm.show_style'(newVal, oldVal) {
- if (newVal != oldVal) {
- if (newVal == 2){
- this.ruleForm.attr_open = 1
- }else{
- this.ruleForm.attr_open = 0
- }
- // this.attrGroups = []
- // this.ruleForm.attr = []
- }
- if (newVal == 2) {
- this.ruleForm.is_attr = 1
- }
- }
- },
- computed: {
- cForm() {
- let form = {};
- let ruleForm = JSON.parse(JSON.stringify(this.ruleForm));
- if (this.form) {
- form = Object.assign(ruleForm, JSON.parse(JSON.stringify(this.form)));
- } else {
- form = ruleForm;
- }
- if (getQuery('id')) {
- form.id = getQuery('id')
- }
- return form;
- },
- cRule() {
- return this.rule ? Object.assign({}, this.rules, this.rule) : this.rules;
- },
- },
- methods: {
- changeFreightType() {
- this.is_show_freight = inArray(1, this.ruleForm.freight_type);
- },
- getGoodsDetail() {
- let self = this;
- self.cardLoading = true;
- request({
- params: {
- r: 'store/client/goods/edit',
- id: getQuery('id')
- },
- method: 'get',
- }).then(e => {
- self.cardLoading = false;
- if (e.data.code == 0) {
- if(e.data.data.score_give_is_store_alone==0){
- this.score_give_is_store_alone = true;
- }
- if (!isEmpty(e.data.data.detail)) {
- if(e.data.data.detail.goods_type && e.data.data.detail.goods_type == 3){
- self.isEdit = true;
- self.ruleForm = JSON.parse(JSON.stringify(e.data.data.detail));
- self.long_lat = self.ruleForm.reserve.lat + '-' + self.ruleForm.reserve.lng;
- self.getReservePlace();
- if(!(self.ruleForm.reserve && self.ruleForm.reserve.cancel_rule)){
- self.ruleForm.reserve.cancel_rule = {
- cancel_hour: 0,
- cancel_fee_percent: 0
- }
- }
- if(this.ruleForm.is_attr == 1){
- if(self.ruleForm.reserve && self.ruleForm.reserve.skus && self.ruleForm.reserve.skus.length){
- self.ruleForm.attr = [];
- let receiveList = self.ruleForm.reserve.skus;
- receiveList.forEach(item => {
- item.checkRangeList = [];
- item.dayArr = [];
- item.checkWeekList = [];
- item.selectTimeList = [];
- item.finalData = [];
- if(item.reserve_date_type == 1 && this.ruleForm.reserve.reserve_type == 0){
- item.reserve_date.sort(function (a, b) {
- return new Date(a) - new Date(b);
- });
- item.checkRangeList.push(item.reserve_date[0],item.reserve_date[item.reserve_date.length-1]);
- let val = [new Date(item.checkRangeList[0]),new Date(item.checkRangeList[1])];
- let arr = [];
- let txtArr = [{val: 0,txt: '周日',children: []},{val: 1,txt: '周一',children: []},{val: 2,txt: '周二',children: []},{val: 3,txt: '周三',children: []},{val: 4,txt: '周四',children: []},{val: 5,txt: '周五',children: []},{val: 6,txt: '周六',children: []}];
- if (val.length) {
- let arr1 = [];
- let str1 = val[0];
- let str2 = val[1];
- let unixDb = str1.getTime() - 24 * 60 * 60 * 1000;
- let unixDe = str2.getTime() - 24 * 60 * 60 * 1000;
- for(let j = unixDb; j <= unixDe;){
- j = j + 24 * 60 * 60 * 1000
- arr1.push(new Date(parseInt(j)))
- }
- for(let i = 0; i < arr1.length; i++){
- txtArr.forEach(it => {
- if(it.val == arr1[i].getDay()){
- let fm = this.formatDate(arr1[i])
- it.children.push(fm);
- }
- })
- }
- txtArr.forEach(it => {
- if(it.children.length){
- arr.push(it);
- }
- });
- item.dayArr = arr;
- }
- let warr = [];
- item.dayArr.forEach(it => {
- warr.push(it.txt);
- });
- item.checkWeekList = [...new Set(warr)];
- let selectArr = [];
- let selectDateArr = [];
- for(let i = 0; i < item.dayArr.length; i++){
- item.checkWeekList.forEach(it => {
- if(it == item.dayArr[i].txt){
- selectArr.push(item.dayArr[i]);
- }
- });
- }
- for(let j = 0; j < selectArr.length; j++){
- selectDateArr = selectDateArr.concat(selectArr[j].children);
- }
- item.reserve_date = selectDateArr;
- }
- if(item.reserve_time_slot_price && item.reserve_time_slot_price.length){
- item.reserve_time_slot_price.forEach(it => {
- item.finalData.push({
- date: it.reserve_time,
- time_spec: it.time_spec,
- isSelect: false,
- times: [],
- selectTimes: []
- });
- item.selectTimeList.push({
- date: it.reserve_time,
- isSelect: false,
- children: [],
- intervalList: [],
- checkAll: false,
- isIndeterminate: true,
- checkedIntervalList: [],
- time_spec: it.time_spec,
- });
- });
- } else if (item.reserve_price_type == 2 && typeof item.reserve_time_slot_price == "object") { // 按天设置价格
- for (let day in item.reserve_time_slot_price) {
- item.finalData.push({
- date: day,
- price: item.reserve_time_slot_price[day].price || 0,
- linePrice: item.reserve_time_slot_price[day].original_price || 0,
- reservationNum: item.reserve_time_slot_price[day].reserve_max_buy || 0,
- children: item.reserve_time_slot_price[day].children || [],
- times: item.reserve_time_slot_price[day].times || []
- })
- }
- }
- item.finalData.forEach(ite => {
- if(ite.time_spec.length){
- ite.time_spec.forEach(it => {
- ite.times.push(it.spec_time);
- ite.selectTimes.push({
- time: it.spec_time,
- price: it.price,
- linePrice: it.original_price,
- reservationNum: it.reserve_max_buy
- });
- });
- }
- });
- item.selectTimeList.forEach(ite => {
- if(ite.time_spec.length){
- ite.time_spec.forEach(it => {
- ite.children.push(it.spec_time);
- });
- }
- });
- });
- let targetArr = [];
- receiveList.forEach(item => {
- targetArr.push({
- attr_list: item.attr_list || [],
- reserve_date_type: item.reserve_date_type || 1,
- reserve_date: item.reserve_date || [],
- reserve_time_range_type: item.reserve_time_range_type || 1,
- time_slot_type: item.time_slot_type || 1,
- reserve_time_slot: item.reserve_time_slot || null,
- reserve_price_type: item.reserve_price_type || 0,
- reserve_time_slot_price: JSON.parse(JSON.stringify(item.reserve_time_slot_price)) || null,
- reserve_week: JSON.parse(JSON.stringify(item.reserve_week)) || [0,1,2,3,4,5,6],
- reserve_max_buy: item.reserve_max_buy || null,
- price: item.price || null,
- original_price: item.original_price || null,
- dayArr: item.dayArr || [],
- checkWeekList: item.checkWeekList || [],
- checkRangeList: item.checkRangeList || [],
- selectTimeList: JSON.parse(JSON.stringify(item.selectTimeList)) || [],
- finalData: item.finalData || [],
- service_min: item.service_min || 0,
- unit: item.unit || '',
- });
- });
- targetArr.forEach(item => {
- item.selectTimeList.forEach(it => {
- it.children = JSON.stringify(it.children);
- it.time_spec = JSON.stringify(it.time_spec);
- });
- });
- targetArr.forEach(item => {
- let obj = {
- attr_list: JSON.parse(JSON.stringify(item.attr_list)),
- reserve_date_type: item.reserve_date_type,
- reserve_date: JSON.parse(JSON.stringify(item.reserve_date)),
- reserve_time_range_type: item.reserve_time_range_type,
- time_slot_type: item.time_slot_type,
- reserve_time_slot: item.reserve_time_slot,
- reserve_price_type: item.reserve_price_type,
- reserve_time_slot_price: JSON.parse(JSON.stringify(item.reserve_time_slot_price)),
- reserve_week: JSON.parse(JSON.stringify(item.reserve_week)),
- reserve_max_buy: item.reserve_max_buy,
- price: item.price,
- original_price: item.original_price,
- dayArr: JSON.parse(JSON.stringify(item.dayArr)),
- checkWeekList: JSON.parse(JSON.stringify(item.checkWeekList)),
- checkRangeList: JSON.parse(JSON.stringify(item.checkRangeList)),
- selectTimeList: JSON.parse(JSON.stringify(item.selectTimeList)),
- finalData: JSON.parse(JSON.stringify(item.finalData)),
- service_min: item.service_min || 0,
- unit: item.unit || '',
- }
- self.ruleForm.attr.push(JSON.stringify(obj));
- });
- for(let i = 0; i < self.ruleForm.attr.length; i++){
- self.ruleForm.attr[i] = JSON.parse(self.ruleForm.attr[i]);
- }
- self.ruleForm.attr.forEach(item => {
- item.selectTimeList.forEach(it => {
- it.children = JSON.parse(it.children);
- it.time_spec = JSON.parse(it.time_spec);
- });
- });
- console.log('self.ruleForm.attr',self.ruleForm.attr);
- }
- }else{
- if(self.ruleForm.reserve && self.ruleForm.reserve.reserve_date && self.ruleForm.reserve.reserve_date.length){
- if(self.ruleForm.reserve.reserve_date_type == 1){
- self.ruleForm.reserve.reserve_date.sort(function (a, b) {
- return new Date(a) - new Date(b);
- });
- self.checkRangeList.push(self.ruleForm.reserve.reserve_date[0],self.ruleForm.reserve.reserve_date[self.ruleForm.reserve.reserve_date.length-1]);
- this.dateSelectChange([new Date(self.checkRangeList[0]),new Date(self.checkRangeList[1])]);
- }
- self.ruleForm.reserve.reserve_time_slot_price.forEach(item => {
- self.initializationDates.push({
- date: item.reserve_time,
- time_spec: item.time_spec,
- isSelect: false,
- times: [],
- selectTimes: []
- });
- });
- self.initializationDates.forEach(item => {
- if(item.time_spec.length){
- item.time_spec.forEach(it => {
- item.times.push(it.spec_time);
- item.selectTimes.push({
- time: it.spec_time,
- price: it.price,
- linePrice: it.original_price,
- reservationNum: it.reserve_max_buy
- });
- });
- }
- });
- }
- }
- }else{
- self.ruleForm = Object.assign(self.ruleForm, e.data.data.detail);
- self.ruleForm.attr = e.data.data.detail.attr;
- }
- self.attrGroups = e.data.data.detail.attr_groups;
- self.storeId = e.data.data.detail.store_id;
- self.typeArr = e.data.data.goods_type;
- console.info(self.ruleForm);
- self.selectCat(e.data.data.detail.cats)
- self.cats = e.data.data.detail.cats;
- for (let key in e.data.data.detail.freight_type) {
- if (e.data.data.detail.freight_type[key] == 1) {
- this.is_show_freight = true;
- break;
- }
- }
- if (self.ruleForm.area_limit) {
- self.deduplicationArea();
- }
- this.supplier_type = e.data.data.detail.supplier_type;
- }
- self.label_list = e.data.data.labels;
- self.service_list = e.data.data.services;
- self.member_level_list = e.data.data.levels;
- // 以下数据用于默认规格情况下的 会员价设置
- if (!e.data.data.detail.is_attr && e.data.data.detail.is_attr != 0) {
- self.member_level_list.forEach((item, index) => {
- let obj = {};
- obj['id'] = index;
- obj['name'] = item.name;
- obj['level'] = 'level' + parseInt(item.level);
- var key = item.level + '';
- self.$set(this.ruleForm.extra.member_price_setting, key, 0);
- });
- }
- // 以下数据用于默认规格情况下的 会员价设置
- var memberSetting = e.data.data.detail.extra;
- self.member_level_list.forEach(function(item, index) {
- let obj = {};
- let key = 'level' + parseInt(item.level);
- obj['id'] = index;
- obj['name'] = item.name;
- obj['level'] = key;
- if (memberSetting && memberSetting.member_price_setting && memberSetting.member_price_setting[key]) {
- self.member_level_list[index]['value'] = memberSetting.member_price_setting[key]; // 赋值到会员列表数据中
- } else {
- self.member_level_list[index]['value'] = {};
- }
- self.defaultMemberPrice.push(obj);
- });
- self.freight_rules = e.data.data.freight_rules;
- // 默认运费模板
- if (self.ruleForm.freight_rules_type == 1 && isEmpty(self.ruleForm.freight_id) && self.freight_rules.length > 0) {
- self.ruleForm.freight_id = self.freight_rules[0].id;
- }
- this.extra1_goods_list = e.data.data.extra1_goods_list;
- this.extra2_goods_list = e.data.data.extra2_goods_list;
- self.ruleForm.show_style = self.ruleForm.show_style.toString();
- // 套餐数据
- self.package_data = e.data.data.detail.package_data
- } else {
- self.$message.error(e.data.msg);
- }
- }).catch(e => {
- console.log(e);
- });
- },
- /* 配送范围start */
- openDistrict() {
- this.dialogVisible = true;
- this.earaRule = this.ruleForm.area_limit;
- },
- selectDistrict(e) {
- let list = [];
- for (let i in e) {
- let obj = {
- id: e[i].id,
- name: e[i].name
- };
- list.push(obj);
- }
- this.earaRule = list;
- },
- districtConfirm() {
- this.ruleForm.area_limit = JSON.parse(JSON.stringify(this.earaRule));
- this.deduplicationArea();
- this.dialogVisible = false;
- // this.$refs['ruleForm'].validate((valid) => {
- // return false;
- // })
- },
- deduplicationArea() {
- let that = this;
- let reg = /市$|特别行政区$/;
- let filt = [...new Set(this.ruleForm.area_limit.filter(v => reg.test(v.name)).map(v => v.name))];
- this.ruleForm.area_limit.forEach(v => {
- let length = that.revealArea.filter(f => f.name == v.name).length;
- if (filt.findIndex(f => f == v.name) != -1 && length > 0) {
- return;
- }
- that.revealArea.push(v);
- })
- },
- space() { // 删除地区
- this.ruleForm.area_limit = [];
- },
- /* 配送范围end */
- showMore(type) { // 展开更多
- switch (type) {
- case 'base':
- this.is_base_show = !this.is_base_show
- }
- },
- toggle(it, i, type) { // tab切换
- switch (type) {
- case 'tabs':
- this.activeName = it.value
- break;
- case 'select':
- if (this.ruleForm.id > 0) return;
- this.ruleForm.goods_type = it.type
- if(this.ruleForm.goods_type == 2){
- this.ruleForm.freight_type = [];
- this.ruleForm.freight_rules_type = 0;
- }else if(this.ruleForm.goods_type == 1){
- this.ruleForm.freight_type = [1];
- this.ruleForm.freight_rules_type = 1;
- }
- break;
- default:
- break;
- }
- },
- coverPic(e) { // 选择图片
- this.ruleForm.cover_pic = e[0].url
- },
- bannerPic(e) { // 选择轮播图
- if (e.length) {
- e.forEach((item, index) => {
- if (this.ruleForm.bannar_pic.length >= 9) return;
- this.ruleForm.bannar_pic.push({
- id: item.id,
- pic_url: item.url
- });
- })
- }
- },
- delPic(type, index) { // 删除图片
- switch (type) {
- case 'cover_pic':
- this.ruleForm.cover_pic = ''
- break;
- case 'bannar_pic':
- this.ruleForm.bannar_pic.splice(index, 1)
- break;
- default:
- break;
- }
- },
- // 商品视频
- videoUrl(e) {
- if (e.length) {
- this.ruleForm.video_url = e[0].url;
- }
- },
- /*---商品分类----*/
- selectCat(cats) {
- this.cats = cats;
- let arr = [];
- cats.map(v => {
- arr.push(v.id);
- })
- this.ruleForm.cats = arr;
- this.$refs.ruleForm.validateField('cats');
- },
- selectMchCat(cats) {
- this.mchCats = cats;
- let arr = [];
- cats.map(v => {
- arr.push(v.id);
- })
- this.ruleForm.mchCats = arr;
- this.$refs.ruleForm.validateField('mchCats');
- },
- /*---商品分类end----*/
- /*----规格start----*/
- // 规格组合
- makeAttrGroup(e) {
- let self = this;
- let array = [];
- self.attrGroups.forEach(function(attrGroupItem, attrGroupIndex) {
- attrGroupItem.attr_list.forEach(function(attrListItem, attrListIndex) {
- let object = {
- attr_group_id: attrGroupItem.attr_group_id,
- attr_group_name: attrGroupItem.attr_group_name,
- attr_id: attrListItem.attr_id,
- attr_name: attrListItem.attr_name,
- };
- if (!array[attrGroupIndex]) {
- array[attrGroupIndex] = [];
- }
- array[attrGroupIndex].push(object)
- });
- });
- // 2.属性排列组合
- const res = array.reduce((osResult, options) => {
- return options.reduce((oResult, option) => {
- if (!osResult.length) {
- return oResult.concat(option)
- } else {
- return oResult.concat(osResult.map(o => [].concat(o, option)))
- }
- }, [])
- }, []);
- // 3.组合结果赋值
- for (let i in res) {
- const options = Array.isArray(res[i]) ? res[i] : [res[i]];
- const row = {
- attr_list: options,
- stock: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].stock,
- price: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].price,
- original_price: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].original_price,
- cost_price: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].cost_price,
- no: typeof(self.ruleForm.attr[i]) == 'undefined' ? '' : self.ruleForm.attr[i].no,
- weight: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].weight,
- pic_url: typeof(self.ruleForm.attr[i]) == 'undefined' ? '' : self.ruleForm.attr[i].pic_url,
- distributionLevelList: [],
- levelPrice: typeof(self.ruleForm.attr[i]) == 'undefined' ? {} : self.ruleForm.attr[i].levelPrice,
- sign_id: typeof(self.ruleForm.attr[i]) == 'undefined' ? '' : self.ruleForm.attr[i].sign_id,
- reserve_max_buy: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].reserve_max_buy,
- reserve_date_type: typeof(self.ruleForm.attr[i]) == 'undefined' ? 1 : self.ruleForm.attr[i].reserve_date_type,
- reserve_date: typeof(self.ruleForm.attr[i]) == 'undefined' ? null : self.ruleForm.attr[i].reserve_date,
- reserve_time_range_type: typeof(self.ruleForm.attr[i]) == 'undefined' ? 1 : self.ruleForm.attr[i].reserve_time_range_type,
- time_slot_type: typeof(self.ruleForm.attr[i]) == 'undefined' ? 1 : self.ruleForm.attr[i].time_slot_type,
- reserve_time_slot: typeof(self.ruleForm.attr[i]) == 'undefined' ? null : self.ruleForm.attr[i].reserve_time_slot,
- reserve_price_type: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].reserve_price_type,
- reserve_time_slot_price: typeof(self.ruleForm.attr[i]) == 'undefined' ? null : self.ruleForm.attr[i].reserve_time_slot_price,
- reserve_week: typeof(self.ruleForm.attr[i]) == 'undefined' ? [0,1,2,3,4,5,6] : self.ruleForm.attr[i].reserve_week,
- dayArr: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].dayArr,
- checkWeekList: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].checkWeekList,
- checkRangeList: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].checkRangeList,
- selectTimeList: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].selectTimeList,
- finalData: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].finalData,
- service_min: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].service_min,
- unit: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].unit,
- };
- let arr = [];
- row.attr_list.forEach(val => {
- arr.push(val.attr_id);
- })
- // console.info(arr.join(":"),"::::");
- row.sign_id = arr.join(":");
- // 动态绑定多规格会员价
- let obj = {};
- self.member_level_list.forEach(function(item, index) {
- let key = 'level' + item.level;
- obj[key] = 0;
- });
- row['member_price'] = obj;
- // 3-1.已设置数据的优先使用原数据
- if (self.ruleForm.attr.length) {
- for (let j in self.ruleForm.attr) {
- const oldOptions = [];
- for (let k in self.ruleForm.attr[j].attr_list) {
- oldOptions.push(self.ruleForm.attr[j].attr_list[k].attr_name)
- }
- const newOptions = [];
- for (let k in options) {
- newOptions.push(options[k].attr_name)
- }
- if (oldOptions.toString() === newOptions.toString()) {
- row['price'] = self.ruleForm.attr[j].price;
- row['stock'] = self.ruleForm.attr[j].stock;
- row['no'] = self.ruleForm.attr[j].no;
- row['weight'] = self.ruleForm.attr[j].weight;
- row['pic_url'] = self.ruleForm.attr[j].pic_url;
- break
- }
- }
- }
- res[i] = row;
- }
- self.ruleForm.attr = res;
- self.ruleForm.attr_groups = JSON.parse(JSON.stringify(self.attrGroups));
- console.log(self.ruleForm.attr, '-------------------------------attr');
- },
- // 批量设置
- batchAttr(key) {
- let self = this;
- if (self.batch[key] && self.batch[key] >= 0 || key === 'no') {
- self.ruleForm.attr.forEach(function(item, index) {
- // 批量设置会员价
- // 判断字符串是否出现过,并返回位置
- if (key.indexOf('level') !== -1) {
- item['member_price'][key] = self.batch[key];
- } else {
- item[key] = self.batch[key];
- }
- });
- }
- },
- destroyCat(value) {
- this.cats = this.cats.filter(function(item) {
- return value.id !== item.id
- });
- this.ruleForm.cats = this.cats.map(function(item) {
- return item.id;
- })
- },
- /*----规格end----*/
- submit() {
- if(this.ruleForm.cats.length && (typeof this.ruleForm.cats[0]) !== 'number'){
- let idarr = [];
- this.ruleForm.cats.forEach(item => {
- idarr.push(item.id);
- });
- this.ruleForm.cats = JSON.parse(JSON.stringify(idarr));
- }
- let _ = this
- if(this.ruleForm.goods_type == 3){
- if(this.ruleForm.is_attr == 1){
- let skus = [];
- this.ruleForm.attr.forEach(item => {
- skus.push({
- attr_list: JSON.parse(JSON.stringify(item.attr_list)),
- reserve_date_type: item.reserve_date_type,
- reserve_date: item.reserve_date,
- reserve_time_range_type: item.reserve_time_range_type,
- time_slot_type: item.time_slot_type,
- reserve_price_type: item.reserve_price_type,
- reserve_max_buy: item.reserve_max_buy,
- price: item.price,
- original_price: item.original_price,
- reserve_time_slot: item.reserve_time_slot,
- reserve_time_slot_price: [],
- reserve_week: item.reserve_week,
- service_min: item.service_min,
- unit: item.unit,
- finalData: JSON.parse(JSON.stringify(item.finalData)),
- selectTimeList: JSON.parse(JSON.stringify(item.selectTimeList))
- });
- });
- skus.forEach(item => {
- if(item.reserve_price_type == 1 && item.finalData && item.finalData.length){
- item.finalData.forEach(it => {
- item.reserve_time_slot_price.push({
- reserve_time: it.date,
- price: it.selectTimes[0].price,
- original_price: it.selectTimes[0].linePrice,
- cost_price: 0,
- reserve_max_buy: it.selectTimes[0].reservationNum,
- time_spec: it.selectTimes
- });
- });
- }
- if(item.reserve_price_type == 0 && item.selectTimeList && item.selectTimeList.length){
- if(item.time_slot_type == 1){
- item.selectTimeList.forEach(it => {
- item.reserve_time_slot_price.push({
- reserve_time: it.date,
- price: item.price,
- original_price: item.original_price,
- cost_price: 0,
- reserve_max_buy: item.reserve_max_buy,
- time_spec: it.children
- });
- });
- }
- if(item.time_slot_type == 2){
- item.selectTimeList.forEach(it => {
- item.reserve_time_slot_price.push({
- reserve_time: it.date,
- price: item.price,
- original_price: item.original_price,
- cost_price: 0,
- reserve_max_buy: item.reserve_max_buy,
- time_spec: it.checkedIntervalList
- });
- });
- }
- }
- if (item.reserve_price_type == 2) { // 按天设置价格
- console.log('item.reserve_price_type == 2item.reserve_price_type == 2item.reserve_price_type == 2', item)
- }
- });
- skus.forEach(item => {
- if(item.reserve_price_type == 1){
- item.reserve_time_slot_price.forEach(it => {
- it.time_spec = it.time_spec.map(itc => {
- _.setFormPrice(itc.price, 'price', 3)
- _.setFormPrice(itc.linePrice, 'original_price', 3)
- return {
- spec_time: itc.time,
- start: itc.time ? itc.time.split('-')[0] : '',
- end: itc.time ? itc.time.split('-')[1] : '',
- price: itc.price,
- original_price: itc.linePrice,
- cost_price: 0,
- reserve_max_buy: itc.reservationNum,
- checked: 1,
- is_next: 0,
- }
- });
- });
- } else if(item.reserve_price_type == 2) { // 按天
- item.reserve_time_slot_price = {}
- item.finalData.forEach(it => {
- _.setFormPrice(it.price, 'price', 2)
- _.setFormPrice(it.linePrice, 'original_price', 2)
- item.reserve_time_slot_price[it.date] = {
- reserve_time: it.date,
- price: it.price,
- original_price: it.linePrice,
- cost_price: 0,
- reserve_max_buy: it.reservationNum,
- }
- });
- }else{
- _.setFormPrice(item.price, 'price', 2)
- _.setFormPrice(item.original_price, 'original_price', 2)
- item.reserve_time_slot_price.forEach(it => {
- it.time_spec = it.time_spec.map(itc => {
- return {
- spec_time: itc,
- start: itc.split('-')[0] || '',
- end: itc.split('-')[1] || '',
- price: it.price,
- original_price: it.linePrice || item.original_price,
- cost_price: 0,
- reserve_max_buy: it.reservationNum || item.reserve_max_buy,
- checked: 1,
- is_next: 0,
- }
- });
- });
- }
- });
- this.ruleForm.reserve.skus = JSON.parse(JSON.stringify(skus));
- }else{
- this.ruleForm.reserve.reserve_time_slot_price = [];
- let preList = [];
- if(this.ruleForm.reserve.reserve_price_type == 1){
- preList = this.$refs.priceSet && this.$refs.priceSet.selectedDates ? this.$refs.priceSet.selectedDates : [];
- } else if (this.ruleForm.reserve.reserve_price_type == 2) { // 按天 - 有可能需要修改
- preList = this.$refs.priceSet && this.$refs.priceSet.selectedDates ? this.$refs.priceSet.selectedDates : [];
- }else{
- preList = this.$refs.timeSelect && this.$refs.timeSelect.selectedDates ? this.$refs.timeSelect.selectedDates : [];
- if(this.ruleForm.reserve.time_slot_type == 1){
- preList.forEach(item => {
- item.selectTimes = item.children
- });
- }
- if(this.ruleForm.reserve.time_slot_type == 2){
- preList.forEach(item => {
- item.selectTimes = item.checkedIntervalList
- });
- }
- }
- if (this.ruleForm.reserve.reserve_price_type == 2) { // 按天
- this.ruleForm.reserve.reserve_time_slot_price = {}
- preList.forEach(item => {
- _.setFormPrice(item.price, 'price', 1)
- _.setFormPrice(item.linePrice, 'original_price', 1)
- this.ruleForm.reserve.reserve_time_slot_price[item.date] = {
- reserve_time: item.date,
- price: item.price,
- original_price: item.linePrice,
- cost_price: 0,
- reserve_max_buy: item.reservationNum,
- }
- });
- } else {
- preList.forEach(item => {
- this.ruleForm.reserve.reserve_time_slot_price.push({
- reserve_time: item.date,
- price: this.ruleForm.price,
- original_price: this.ruleForm.original_price,
- cost_price: 0,
- reserve_max_buy: this.ruleForm.reserve.reserve_max_buy,
- time_spec: item.selectTimes
- });
- });
- }
- if(this.ruleForm.reserve.reserve_price_type == 1){
- this.ruleForm.reserve.reserve_time_slot_price.forEach(item => {
- item.time_spec = item.time_spec.map(it => {
- _.setFormPrice(it.price, 'price', 1)
- _.setFormPrice(it.linePrice, 'original_price', 1)
- return {
- spec_time: it.time,
- start: it.time ? it.time.split('-')[0] : '',
- end: it.time ? it.time.split('-')[1] : '',
- price: it.price,
- original_price: it.linePrice,
- cost_price: 0,
- reserve_max_buy: it.reservationNum,
- checked: 1,
- is_next: 0,
- }
- });
- });
- } else if(this.ruleForm.reserve.reserve_price_type == 2){ // 按天
- }else{
- this.ruleForm.reserve.reserve_time_slot_price.forEach(item => {
- item.time_spec = item.time_spec.map(it => {
- return {
- spec_time: it,
- start: it.split('-')[0] || '',
- end: it.split('-')[1] || '',
- price: this.ruleForm.price,
- original_price: this.ruleForm.original_price,
- cost_price: 0,
- reserve_max_buy: this.ruleForm.reserve.reserve_max_buy,
- checked: 1,
- is_next: 0,
- }
- });
- });
- }
- }
- }
- this.$refs['ruleForm'].validate((valid) => {
- if (valid) {
- let self = this;
- if (Number(self.ruleForm.extra.member_buy_limit_setting.every_num) > 0 && Number(self.ruleForm.extra.member_buy_limit_setting.every_num) < Number(self.ruleForm.extra.member_buy_limit_setting.nums)) {
- this.$message.error('每次限购数量不能小于起购数量');
- return
- }
- if (Number(self.ruleForm.extra.member_buy_limit_setting.every_day_num) > 0 && Number(self.ruleForm.extra.member_buy_limit_setting.every_day_num) < Number(self.ruleForm.extra.member_buy_limit_setting.nums)) {
- this.$message.error('每天限购数量不能小于起购数量');
- return
- }
- if (this.ruleForm.goods_type == 1 && self.ruleForm.freight_type.length === 0) {
- this.$message.error('请至少选择一个物流方式');
- return
- }
- if (self.ruleForm.is_attr == 1) {
- if (this.attrGroups.length == 0) {
- this.$message.error('请完善规格组');
- return
- }
- self.ruleForm.extra.member_price_setting = this.getMemberPrice(this.ruleForm.attr);
- }
- //把纯数字转字符
- this.ruleForm.goods_name = this.ruleForm.goods_name + '';
- this.ruleForm.subtitle = this.ruleForm.subtitle + '';
- self.btnLoading = true;
- // package-list 套餐内容
- let packageList = {}
- if (this.$refs['package']) {
- packageList = {
- package_data: this.$refs['package'].list
- }
- }
- let taohua = JSON.parse(JSON.stringify(self.ruleForm))
- params = Object.assign(taohua, this.cForm, packageList)
- request({
- params: {
- r: 'store/client/goods/edit'
- },
- method: 'post',
- data: {
- form: JSON.stringify(params),
- }
- }).then(e => {
- // self.btnLoading = false;
- if (e.data.code == 0) {
- self.$message.success(e.data.msg);
- this.$navigate({
- r: 'store/client/goods/index'
- })
- } else {
- self.$message.error(e.data.msg);
- }
- }).catch(e => {
- self.$message.error(e.data.msg);
- self.btnLoading = false;
- });
- }
- });
- },
- setFormPrice(price, key) {
- if (this.ruleForm.is_attr == 1 && this.ruleForm.goods_type == 3) {
- // 重新设置价格
- if (price > 0) {
- this.$set(this.ruleForm, key, this.ruleForm[key] > 0 ? Math.min(this.ruleForm[key], price) : price)
- if (this.ruleForm[key] <= 0) this.$message.error("价格不能为0")
- }
- }
- },
- //添加优惠券
- add_coupon(e) {
- this.ruleForm.coupon_selection = e;
- },
- //跳转新增优惠券界面
- // handle_coupon() {
- // this.$navigate({
- // r: 'coupon/default/edit'
- // })
- // },
- checkoutChange(it) {
- console.log(it)
- },
- getFreight() { // 获取运费规则选项
- let self = this;
- request({
- params: {
- r: 'mall/postage-rules/all-list'
- },
- method: 'get',
- data: {}
- }).then(e => {
- if (e.data.code == 0) {
- self.freight.list = e.data.data.list;
- // 添加商品时使用默认运费
- self.freight.list.unshift({
- id: 0,
- name: '默认运费',
- status: 1
- })
- console.log(self.freight.list)
- } else {
- self.$message.error(e.data.msg);
- }
- }).catch(e => {
- console.log(e);
- });
- },
- freightChange(e) {
- console.log(e)
- },
- // 获取规格会员价
- getMemberPrice(attr) {
- let that = this;
- let member_price_setting = {};
- let levels = objectKeys(attr[0].member_price_setting);
- levels.forEach(level => {
- that.$set(member_price_setting, level, {});
- });
- attr.forEach((v) => {
- let sign_id = v.sign_id;
- for (const key in v.member_price_setting) {
- member_price_setting[key][sign_id] = v.member_price_setting[key];
- }
- })
- member_price_setting = member_price_setting;
- return member_price_setting;
- },
- handleCoupon(data) {
- this.couponLoading = false;
- console.log(data);
- this.ruleForm.coupon_selection = data
- },
- handle(type, data = null, data2 = null) {
- switch (type) {
- case 'select':
- this.couponLoading = true;
- break;
- case 'delete':
- this.ruleForm.coupon_selection.splice(data, 1);
- break;
- }
- },
- addons_data_change(e) {
- Object.assign(this.ruleForm.addons, e);
- console.log(this.ruleForm.addons, '=======addons====');
- // this.ruleForm.addons.coupon_selection = e;
- },
- /**
- * 显示规格套餐
- */
- packageShow () {
- return this.ruleForm.show_style == 2
- },
- /**
- * 限制添加规格
- */
- attrLimit () {
- return this.ruleForm.show_style == 2 ? 2 : 1
- },
- getStoreConfig() {
- let self = this;
- request({
- params: {
- r: 'store/client/setting/config'
- },
- method: 'get',
- data: {}
- }).then(e => {
- if (e.data.code == 0) {
- self.storeConfig = e.data.data
- }
- }).catch(e => {
- console.log(e);
- });
- },
- // 预约商品-时间范围选择处理
- dateSelectChange(val) {
- let arr = [];
- let txtArr = [{val: 0,txt: '周日',children: []},{val: 1,txt: '周一',children: []},{val: 2,txt: '周二',children: []},{val: 3,txt: '周三',children: []},{val: 4,txt: '周四',children: []},{val: 5,txt: '周五',children: []},{val: 6,txt: '周六',children: []}];
- if (val) {
- let arr1 = [];
- let str1 = val[0];
- let str2 = val[1];
- let unixDb = str1.getTime() - 24 * 60 * 60 * 1000;
- let unixDe = str2.getTime() - 24 * 60 * 60 * 1000;
- for(let j = unixDb; j <= unixDe;){
- j = j + 24 * 60 * 60 * 1000
- arr1.push(new Date(parseInt(j)))
- }
- for(let i = 0; i < arr1.length; i++){
- txtArr.forEach(item => {
- if(item.val == arr1[i].getDay()){
- let fm = this.formatDate(arr1[i])
- item.children.push(fm);
- }
- })
- }
- txtArr.forEach(item => {
- if(item.children.length){
- arr.push(item);
- }
- });
- this.dayArr = arr;
- }
- this.checkWeekList = [];
- let warr = [];
- this.dayArr.forEach(item => {
- warr.push(item.txt);
- });
- this.checkWeekList = [...new Set(warr)];
- this.weekSelectChange();
- },
- weekSelectChange() {
- let selectArr = [];
- let selectDateArr = [];
- for(let i = 0; i < this.dayArr.length; i++){
- this.checkWeekList.forEach(item => {
- if(item == this.dayArr[i].txt){
- selectArr.push(this.dayArr[i]);
- }
- });
- }
- for(let j = 0; j < selectArr.length; j++){
- selectDateArr = selectDateArr.concat(selectArr[j].children);
- }
- this.ruleForm.reserve.reserve_date = selectDateArr;
- },
- formatDate(date) {
- let result = '';
- let year = date.getFullYear().toString().padStart(4, '0');
- let month = (date.getMonth() + 1).toString().padStart(2, '0');
- let day = date.getDate().toString().padStart(2, '0');
- let hour = date.getHours().toString().padStart(2, '0');
- let minute = date.getMinutes().toString().padStart(2, '0');
- let second = date.getSeconds().toString().padStart(2, '0');
- result = `${year}-${month}-${day}`;
- return result;
- },
- resetDateInfo(e) {
- if(this.ruleForm.reserve.reserve_price_type == 1){
- let dates = e;
- if(this.ruleForm.reserve.time_slot_type == 1){
- let arr = [];
- dates.forEach(item => {
- arr.push({
- date: item.date,
- times: item.children,
- isSelect: false
- });
- });
- if(arr.length){
- arr[0].isSelect = true;
- }
- if(!this.isEdit){
- this.$nextTick(() => {
- this.$refs.priceSet.initData(arr);
- });
- }else{
- this.$nextTick(() => {
- this.$refs.priceSet.initData(this.initializationDates);
- this.isEdit = false;
- });
- }
- }
- if(this.ruleForm.reserve.time_slot_type == 2){
- let arr1 = [];
- dates.forEach(item => {
- arr1.push({
- date: item.date,
- times: item.checkedIntervalList,
- isSelect: false
- });
- });
- if(arr1.length){
- arr1[0].isSelect = true;
- }
- if(!this.isEdit){
- this.$nextTick(() => {
- this.$refs.priceSet.initData(arr1);
- });
- }else{
- this.$nextTick(() => {
- this.$refs.priceSet.initData(this.initializationDates);
- this.isEdit = false;
- });
- }
- }
- }
- },
- async loadData(id = 1) {
- await request({
- params: {
- r: 'store/client/goods/regions',
- id: id,
- },
- method: 'get',
- }).then(e => {
- if (e.data.code == 0) {
- this.provinces = e.data.data;
- }
- }).catch(e => {
- console.log(e);
- this.listLoading = false;
- this.$message.error('网络错误');
- });
- },
- // 省市区三级联动
- regionChange(e, level) {
- let self = this;
- self.ruleForm.reserve.lng = e.lng;
- self.ruleForm.reserve.lat = e.lat;
- self.long_lat = e.lng + '-' + e.lat;
- request({
- params: {
- r: 'store/client/goods/regions',
- id: e.id,
- },
- method: 'get',
- }).then(e => {
- if (e.data.code == 0) {
- switch (level) {
- case 1:
- self.citys = e.data.data;
- this.ruleForm.reserve.province_id = this.provinceInfo.id
- break;
- case 2:
- self.districts = e.data.data;
- this.ruleForm.reserve.city_id = this.cityInfo.id
- break;
- case 3:
- self.streets = e.data.data;
- this.ruleForm.reserve.district_id = this.districtInfo.id
- break;
- }
- } else {
- self.$message.error(e.data.msg);
- }
- }).catch(e => {
- console.log(e);
- self.$message.error('网络错误');
- return false;
- });
- },
- //地图确定事件
- mapEvent(e) {
- for (let i in this.provinces) {
- if (e.address.indexOf(this.provinces[i].name) !== -1) {
- this.ruleForm.reserve.province_id = this.provinces[i].id;
- this.provinceInfo = this.provinces[i];
- request({
- params: {
- r: 'store/client/goods/get-regions',
- region_id: this.provinces[i].id,
- },
- method: 'get',
- }).then(res => {
- if (res.data.code == 0) {
- this.citys = res.data.data;
- for (let i in this.citys) {
- if (e.address.indexOf(this.citys[i].name) !== -1) {
- this.ruleForm.reserve.city_id = this.citys[i].id;
- this.cityInfo = this.citys[i];
- request({
- params: {
- r: 'store/client/goods/get-regions',
- region_id: this.citys[i].id,
- },
- method: 'get',
- }).then(resp => {
- if (resp.data.code == 0) {
- this.districts = resp.data.data;
- for (let i in this.districts) {
- if (e.address.indexOf(this.districts[i].name) !== -1) {
- this.ruleForm.reserve.district_id = this.districts[i].id;
- this.districtInfo = this.districts[i];
- }
- }
- } else {
- this.$message.error(resp.data.msg);
- }
- }).catch(error => {
- console.log(error);
- this.$message.error('网络错误');
- });
- }
- }
- } else {
- this.$message.error(res.data.msg);
- }
- }).catch(err => {
- console.log(err);
- this.$message.error('网络错误');
- });
- }
- }
- this.ruleForm.reserve.lng = e.long;
- this.ruleForm.reserve.lat = e.lat;
- this.ruleForm.reserve.detail = e.address;
- this.long_lat = e.lat + '-' + e.long;
- this.$forceUpdate();
- },
- getReservePlace() {
- let self = this;
- for (let i in self.provinces) {
- if (self.ruleForm.reserve.province_id == self.provinces[i].id) {
- self.provinceInfo = self.provinces[i];
- request({
- params: {
- r: 'store/client/goods/get-regions',
- region_id: self.provinces[i].id,
- },
- method: 'get',
- }).then(res => {
- if (res.data.code == 0) {
- self.citys = res.data.data;
- for (let i in self.citys) {
- if (self.ruleForm.reserve.city_id == self.citys[i].id) {
- self.cityInfo = self.citys[i];
- request({
- params: {
- r: 'store/client/goods/get-regions',
- region_id: self.citys[i].id,
- },
- method: 'get',
- }).then(resp => {
- if (resp.data.code == 0) {
- self.districts = resp.data.data;
- for (let i in self.districts) {
- if (self.ruleForm.reserve.district_id == self.districts[i].id) {
- self.districtInfo = self.districts[i];
- }
- }
- } else {
- self.$message.error(resp.data.msg);
- }
- }).catch(error => {
- console.log(error);
- self.$message.error('网络错误');
- });
- }
- }
- } else {
- self.$message.error(res.data.msg);
- }
- }).catch(err => {
- console.log(err);
- self.$message.error('网络错误');
- });
- }
- }
- },
- onChangeReserveTimeRangeType(val) {
- this.ruleForm.reserve.reserve_price_type = 0
- },
- goodsSelect1(param) {
- console.log(1111222);
- console.log(this.ruleForm.extra1_goods_id);
- for (let j in param) {
- let item = param[j];
- if(this.ruleForm.id&&item.id==this.ruleForm.id){
- continue;
- }
- let flag = true;
- for (let i in this.extra1_goods_list) {
- if (this.extra1_goods_list[i].goods_id == item.id) {
- flag = false;
- break;
- }
- }
- if (flag) {
- if(this.extra1_goods_list.length>=20){
- this.$message.error('最多只能添加20件商品');
- break;
- }
- this.extra1_goods_list.push({
- goods_id: item.id,
- price: item.price,
- status: item.status,
- goods_stock: item.stock,
- goods_name: item.goods_name,
- cover_pic: item.cover_pic,
- });
- this.ruleForm.extra1_goods_id.push(item.id);
- }
- }
- },
- goodsSelect2(param) {
-
- for (let j in param) {
- let item = param[j];
- if(this.ruleForm.id&&item.id==this.ruleForm.id){
- continue;
- }
- let flag = true;
- for (let i in this.extra2_goods_list) {
- if (this.extra2_goods_list[i].goods_id == item.id) {
- flag = false;
- break;
- }
- }
- console.log(this.extra2_goods_list);
- if (flag) {
- if(this.extra2_goods_list.length>=20){
- this.$message.error('最多只能添加20件商品');
- break;
- }
- this.extra2_goods_list.push({
- goods_id: item.id,
- price: item.price,
- status: item.status,
- goods_stock: item.stock,
- goods_name: item.goods_name,
- cover_pic: item.cover_pic,
- store_id: item.store_id,
- });
- this.ruleForm.extra2_goods_id.push(item.id);
- }
- }
- },
- // 删除商品
- // 删除商品
- delFun(index,type) {
- switch (type){
- case 1:
- this.extra1_goods_list.splice(index, 1);
- var extra1_goods_id =[];
- for(var item of this.extra1_goods_list){
- extra1_goods_id.push(item.goods_id)
- }
- this.ruleForm.extra1_goods_id =extra1_goods_id;
- break;
- case 2:
- this.extra2_goods_list.splice(index, 1);
- var extra2_goods_id =[];
- for(var item of this.extra2_goods_list){
- extra2_goods_id.push(item.goods_id)
- }
- this.ruleForm.extra2_goods_id =extra2_goods_id;
- break;
- }
- },
- }
- });
- </script>
|