| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322 |
- <?php
- use common\helpers\ComponentHelper;
- use common\helpers\AddonHelper;
- ComponentHelper::loadComponentView('component/com-add-cat', __DIR__);
- ComponentHelper::loadComponentView('component/com-attr-group', __DIR__);
- ComponentHelper::loadComponentView('component/com-attr', __DIR__);
- ComponentHelper::loadComponentView('com-rich-text');
- ComponentHelper::loadComponentView('com-district');
- 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-qq-map');
- ComponentHelper::loadComponentView('com-dialog-select');
- 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);
- }
- if (!empty($smart_form_components)) {
- ComponentHelper::loadComponentView('com-smartform-goods', AddonHelper::getAddonRootPath('SmartForm') . 'backend/views/components');
- $smart_form_components = \yii\helpers\Json::encode($smart_form_components);
- } else {
- $smart_form_components = '{}';
- }
- if (!empty($community_components)) {
- ComponentHelper::loadComponentView('com-community-goods', AddonHelper::getAddonRootPath('Community') . 'backend/views/components');
- $community_components = \yii\helpers\Json::encode($community_components);
- } else {
- $community = '{}';
- }
- if (!empty($valet_order_components)) {
- ComponentHelper::loadComponentView('com-valet-order-goods', AddonHelper::getAddonRootPath('ValetOrder') . 'backend/views/components');
- $valet_order_components = \yii\helpers\Json::encode($valet_order_components);
- } else {
- $valet_order = '{}';
- }
- ?>
- <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'); ?>
- </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">
- <div><span @click="$navigate({r:'mall/goods/index'})" class="text">商品列表</span>/添加商品</div>
- </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>
- <!-- 智能表单 -->
- <div v-show="activeName == 'smartform_addons'" v-if="smartform_addons_arr && smartform_addons_arr.component && goodsId > 0">
- <com-smartform-goods :goods_id=goodsId ref="smartForm"></com-smartform-goods>
- </div>
- <!-- 社区团购 -->
- <div v-show="activeName == 'community_addons'" v-if="ruleForm.goods_type == 1 && community_addons_arr && community_addons_arr.component">
- <com-community-goods :goods_id=goodsId ref="community"></com-community-goods>
- </div>
- <!-- 代客下单-->
- <div v-show="activeName == 'valet_order_addons'" v-if="valet_order_addons_arr && valet_order_addons_arr.component && goodsId > 0">
- <com-valet-order-goods :goods_id=goodsId ref="valet_order"></com-valet-order-goods>
- </div>
- <!-- 支付配置 -->
- <div v-show="activeName == 'pay_limit'">
- <?= ComponentHelper::loadComponentView('goods-pay', __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">保存</el-button>
- </div>
- </div>
- <script>
- const app = new Vue({
- el: '#app',
- data() {
- return {
- tabs: [{
- name: '基础设置',
- value: 'basic'
- },
- {
- name: '营销配置',
- value: 'marketing'
- },
- {
- name: '会员权益',
- value: 'member_benefits'
- },
- {
- name: '关联商品',
- value: 'goods_association'
- },
- {
- name: '支付配置',
- value: 'pay_limit'
- },
- ],
- activeName: 'basic',
- typeArr: [
- // {
- // name: '实体商品',
- // desc: '物流发货',
- // img: '/resources/img/goods/goods.png',
- // goods_type: 'physical'
- // },
- // {
- // name: '虚拟商品',
- // desc: '无需物流',
- // img: '/resources/img/goods/xuni.png',
- // goods_type: 'virtual'
- // },
- // {
- // name: '预约商品',
- // desc: '无需物流',
- // img: '/resources/img/goods/kami.png',
- // goods_type: 'reserve'
- // }
- ],
- 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,
- // 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: [],
- show_addons: <?= !empty($components) ? $components : '{}'; ?>, //优惠券是否展示
- smartform_addons: <?= !empty($smart_form_components) ? $smart_form_components : '{}'; ?>, //智能表单是否展示
- smartform_addons_arr: [],
- goods_template_list: [],
- community_addons: <?= !empty($community_components) ? $community_components : '{}'; ?>, //智能表单是否展示
- valet_order_addons: <?= !empty($valet_order_components) ? $valet_order_components : '{}'; ?>, //智能表单是否展示
- community_addons_arr: [],
- valet_order_addons_arr: [],
- digital_name : '',
- marketing_score_calculation_list: [ // 积分营销赠送计算方式选项
- {
- value: 0,
- label: '订单实付金额'
- },
- {
- value: 1,
- label: '商品利润'
- },
- {
- value: 2,
- label: '商品售价'
- }
- ],
- ruleForm: {
- /*********************************** 基础设置 ****************************************/
- goods_type: 1,
- can_feedback: 1,
- goods_name: '',
- subtitle: '',
- cover_pic: '',
- video_cover_pic: '',
- bannar_pic: [],
- video_url: '',
- cats: [],
- mchCats: [], //多商户系统分类
- services: [],
- freight: null,
- labels: '', // 商品标签
- is_attr: 0, // 是否有规格
- attr: [],
- price: 0,
- original_price: 0,
- cost_price: 0,
- stock: 0,
- 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, // 是否上架
- is_show: 1, // 是否上架
- goods_subtype: 0, // 商品子类型 0普通商品 1药品商品
- extra: {
- enable_full_reduce: 0, //是否开启满减
- full_reduce_price_limit: 0, // 单品满额减免价格阈值
- full_reduce_money: 0, // 单品满额减免金额
- score_give_setting: {
- code: 'score',
- name: '积分',
- enable_give_score: 0, //是否开启赠送积分
- give_num: 0, // 货币赠送
- give_type: 1, // 货币赠送 1.固定值 2售价百分比
- settlement: 0, // 结算方式 1.支付完成 0订单完成
- enable_limit_level: 0,
- limit_level: [],
- calculation_value: 0, // 赠送计算方式
- score_giving_goods_type: [], //商品类型
- score_giving_calculation: 0, //计算方式
- },
- balance_give_setting: {
- enable_give_balance: 0, //是否开启赠送余额
- code: 'balance',
- name: '余额',
- give_num: 0, // 赠送数量
- give_type: 1, // 类型 1.固定值 2售价百分比
- settlement: 1, // 结算方式:0:订单完成,1:支付完成
- },
- is_member_price: 0,
- is_show_price: 0,
- member_price_switch: 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,
- },
- is_member_alone_buy_limit : 0,
- member_alone_buy_limit_setting: [],
- currency_deduct_setting: [], // 货币这块有bug,暂时不需要展示,所以不需要提交数据
- is_repurchase: 0,
- repurchase_setting: [],
- score_deduct_setting: {
- code: 'score',
- name: '积分',
- is_enable: 0, // 是否启用抵扣
- deduct_num: 0, // 抵扣数量
- deduct_type: 1, // 1.单件抵扣 2.多件累计抵扣
- type: 1,
- },
- digital_give_setting: {
- code: 'digital',
- name: '数字币',
- give_num: 0, // 货币赠送
- give_type: 1, // 货币赠送 1.固定值 2售价百分比
- settlement: 0, // 结算方式 1.支付完成 0订单完成
- },
- is_alone_show_return_btn: 0,//设置独立放弃退换货:0.否,1.是
- is_show_return_btn: 1,//是否显示放弃退换货:0.否,1.是
- description_template_id: undefined, // 商品说明模板id
- symptom_list: [''], // 疾病列表,药品商品类型使用
- description_list: [], // 商品说明列表
- drug_generic_name: '', // 药品通用名称
- },
- addons: {},
- 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售价百分比
- settlement: 1, // 结算方式:0订单完成;1支付完成
- },
- 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: [],
- goods_template_id: '',
- alipay_mini_app_id: null,
- extra1_goods_id:[],
- extra2_goods_id:[],
- is_show_attr: false,
- // 预约商品
- 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: 0,
- service_min: 0, // 项目时间
- },
- searchAddress: {
- is_enable: 0,
- province_id: 0,
- city_id: 0,
- district_id: 0,
- town_id: '',
- addressIdsMap: [],
- },
- is_pay_limit:0,
- pay_limit:{
- WECHAT:0,
- SCORE:0,
- BALANCE:0,
- ALI:0,
- MIXED:0
- }
- },
- smartGoodForm: {},
- communityGoodForm: {},
- valetOrderGoodForm: {},
- 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'
- }],
- cost_price: [
- {
- required: true,
- message: '请输入成本价',
- trigger: 'blur'
- }
- ],
- original_price: [
- {
- required: true,
- message: '请输入划线价',
- trigger: 'blur'
- }
- ],
- stock_warning: [
- {
- required: true,
- message: '请输入库存预警',
- trigger: 'blur'
- }
- ],
- goods_weight: [
- {
- 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();
- }
- }],
- drug_generic_name: [
- {
- required: true,
- message: '请输入药品通用名称',
- trigger: 'blur'
- }
- ]
- },
- 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'
- }
- ],
- cancel_type:[{
- validator: (rule, value, callback) => {
- if(value=='2' && this.ruleForm.reserve.cancel_rule.cancel_hour ==''){
- callback('请填写具体数额');
- }
- if(value=='3' && this.ruleForm.reserve.cancel_rule.cancel_fee_percent ==''){
- callback('请填写具体数额');
- }
- callback();
- }
- }
- ]
- },
- attr: [
- // 规格属性
- {
- required: true,
- type: 'array',
- validator: (rule, value, callback) => {
- if (value.length == 0) {
- callback('请完善多规格数据')
- }
- callback()
- }
- },
- // 规格名称
- {
- required: true,
- type: 'array',
- validator: (rule, value, callback) => {
- if (value.length) {
- value.forEach(item => {
- if (!(item.attr_list instanceof Array)) {
- item.attr_list = Object.values(item.attr_list)
- }
- item.attr_list.forEach(attr => {
- if (attr.attr_group_name == '') {
- callback('请完善多规格名称')
- }
- if (attr.attr_name == '') {
- callback('请完善多规格名称')
- }
- })
- })
- }
- callback()
- }
- },
- // 规格价格
- {
- required: true,
- type: 'array',
- validator: (rule, value, callback) => {
- if (value.length) {
- value.forEach(item => {
- if (item.cost_price === '') {
- callback('请完善多规格价格')
- }
- if (item.original_price === '') {
- callback('请完善多规格价格')
- }
- if (item.price === '') {
- callback('请完善多规格价格')
- }
- if (item.stock === '') {
- callback('请完善多规格库存')
- }
- })
- }
- callback()
- }
- },
- ],
- },
- revealArea: [],
- extra1_goods_list:[],
- extra2_goods_list:[],
- extra_goods_params: {},
- mall_id: <?= $mall_id ?>,
- dayArr: [], //预约商品
- checkWeekList: [], //预约商品
- checkRangeList: [], //预约商品
- provinces: {}, //预约商品
- provinceInfo: {}, //预约商品
- citys: {}, //预约商品
- cityInfo: {}, //预约商品
- districts: {}, //预约商品
- districtInfo: {}, //预约商品
- long_lat: '', // 经纬度
- initializationDates: [], // 编辑商品时格式化传进来的数据
- isEdit: false, // 预约商品,
- is_reserve_type: <?= $is_reserve_type ?>,
- districtList: [],
- townList: [],
- goodsAddressProps: {
- value: 'id',
- label: 'name',
- children: 'list',
- },
- descriptionTemplateList: [], // 商品说明模板
- };
- },
- created() {
- //this.smartform_addons_arr = json.parse(this.smartform_addons);
- this.smartform_addons_arr = this.smartform_addons;
- this.community_addons_arr = this.community_addons;
- this.valet_order_addons_arr = this.valet_order_addons;
- // 给预约商品一个默认类型
- this.ruleForm.reserve.reserve_type = this.is_reserve_type == 2 || this.is_reserve_type == 0 ? 0 : 1
- console.log('*****', this.smartform_addons_arr);
- this.goodsId = getQuery('id');
- this.extra_goods_params['goods_id'] = this.goodsId;
- console.log(this.extra_goods_params);
- if (this.smartform_addons_arr && this.smartform_addons_arr.component) {
- console.log('*****11');
- this.tabs.push({
- name: '智能表单',
- value: 'smartform_addons'
- });
- }
- if (this.community_addons_arr && this.community_addons_arr.component) {
- this.tabs.push({
- name: '社区团购',
- value: 'community_addons'
- });
- }
- if (this.valet_order_addons_arr && this.valet_order_addons_arr.component) {
- this.tabs.push({
- name: '代客下单',
- value: 'valet_order_addons'
- });
- }
- },
- async mounted() {
- await this.loadData();
- this.getDistrict(3);
- this.getGoodsDetail();
- },
- watch: {
- 'ruleForm.detail'(newVal, oldVal) {
- this.cForm.detail = newVal
- },
- },
- 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: {
- assiginObj(target = {}, sources = {}) {
- let obj = target;
- if (typeof target != 'object' || typeof sources != 'object') {
- return sources; // 如果其中一个不是对象 就返回sources
- }
- for (let key in sources) {
- // 如果target也存在 那就再次合并
- if (target.hasOwnProperty(key)) {
- obj[key] = this.assiginObj(target[key], sources[key]);
- } else {
- // 不存在就直接添加
- obj[key] = sources[key];
- }
- }
- return obj;
- },
- changeFreightType() {
- this.is_show_freight = inArray(1, this.ruleForm.freight_type);
- },
- getGoodsDetail() {
- let self = this;
- self.cardLoading = true;
- request({
- params: {
- r: 'mall/goods/edit',
- id: getQuery('id')
- },
- method: 'get',
- }).then(e => {
- self.cardLoading = false;
- if (e.data.code == 0) {
- if (!isEmpty(e.data.data.detail)) {
- self.typeArr = e.data.data.goods_type;
- self.selectCat(e.data.data.detail.cats)
- self.attrGroups = e.data.data.detail.attr_groups;
- if (!isEmpty(e.data.data.detail.goods_no)) {
- e.data.data.detail.goods_no = e.data.data.detail.goods_no.trimEnd();
- }
- // self.ruleForm = Object.assign(self.ruleForm, 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));
- if(self.ruleForm.addons == undefined) {
- self.ruleForm.addons = {};
- }
- 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
- }
- }
- // 处理cancel_rule空数组的情况
- if (self.ruleForm.reserve && JSON.stringify(self.ruleForm.reserve.cancel_rule) == '[]') {
- self.ruleForm.reserve.cancel_rule = {}
- }
- 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 && 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 = self.assiginObj(self.ruleForm, e.data.data.detail);
- self.ruleForm.attr = e.data.data.detail.attr;
- }
- // 因为上面方法赋值物流模版错误需要从新赋值
- self.ruleForm.freight_type = e.data.data.detail.freight_type;
- self.ruleForm.extra1_goods_id = e.data.data.detail.extra1_goods_id
- self.ruleForm.extra2_goods_id = e.data.data.detail.extra2_goods_id
- // self.ruleForm.extra.score_give_setting.settlement = self.ruleForm.extra.score_give_setting.settlement.toString()
- // console.log(111111111)
- console.log(self.ruleForm.extra.score_give_setting.settlement)
- console.info(self.ruleForm);
- self.cats = e.data.data.detail.cats;
- self.ruleForm.freight_type = [];
- e.data.data.detail.freight_type.forEach((item, index) => {
- self.ruleForm.freight_type[index] = item;
- });
- console.log('freight_type',self.ruleForm.freight_type);
- if (self.ruleForm.freight_type.includes(1)) {
- this.is_show_freight = true;
- }
- self.label_list = e.data.data.labels;
- self.service_list = e.data.data.services;
- self.goods_template_list = e.data.data.templates;
- 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);
- });
- if (self.ruleForm.area_limit) {
- self.deduplicationArea();
- }
- if (!isEmpty(memberSetting?.description_list)) {
- this.$set(self.ruleForm.extra, 'description_list', memberSetting.description_list)
- }
- if (this.ruleForm?.extra?.description_template_id == 0) {
- this.ruleForm.extra.description_template_id = undefined
- }
- }
- this.$forceUpdate();
- 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.digital_name = e.data.data.detail.digital_name;
- console.log(self.digital_name);
- if(this.ruleForm.searchAddress.district_id > 0){
- this.getTownList(this.ruleForm.searchAddress.district_id)
- }
- this.descriptionTemplateList = e.data.data.descriptionTemplateList
- } 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.revealArea = 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 != 1) {
- this.$set(this.ruleForm, 'goods_subtype', 0)
- }
- if (this.ruleForm.goods_type !== 2) {
- this.ruleForm.can_feedback = 1;
- } else {
- this.ruleForm.can_feedback = 0;
- }
- break;
- default:
- break;
- }
- },
- coverPic(e) { // 选择图片
- this.ruleForm.cover_pic = e[0].url
- },
- videoCoverPic(e) { // 选择图片
- this.ruleForm.video_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;
- case 'video_cover_pic':
- this.ruleForm.video_cover_pic = '';
- break;
- default:
- break;
- }
- },
- // 商品视频
- videoUrl(e) {
- if (e.length) {
- this.ruleForm.video_url = e[0].url;
- this.ruleForm.video_cover_pic = e[0].thumb_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)))
- }
- }, [])
- }, []);
- console.log('makeAttrGroup', res)
- // 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,
- goods_no: typeof(self.ruleForm.attr[i]) == 'undefined' ? '' : self.ruleForm.attr[i].goods_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,
- is_show: true,
- 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['original_price'] = self.ruleForm.attr[j].original_price;
- row['cost_price'] = self.ruleForm.attr[j].cost_price;
- row['goods_no'] = self.ruleForm.attr[j].goods_no;
- row['weight'] = self.ruleForm.attr[j].weight;
- row['pic_url'] = self.ruleForm.attr[j].pic_url;
- row['is_show'] = Boolean(self.ruleForm.attr[j].is_show);
- 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 === 'goods_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 => {
- // 0统一设置价格 1 按时间段设置 2按天设置 - 只有按时间段才有finalData数据
- // reserve_time_range_type 按天=1 时间段=2 2,2,0
- // time_slot_type 自定义=1 自动划分=2
- // reserve_price_type 统一售价=0 按时间段设置=1 按天设置=2
- 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){ // 统一设置价格
- // time_slot_type = 1 自定义时间段 = 2 自动划分
- 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 => {
- // 0 统一,1 时间段,2 按天
- 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 => {
- // _.setFormPrice(it.price, 'price', 2)
- // _.setFormPrice(it.linePrice, 'original_price', 2)
- 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) {
- // console.log(this.ruleForm)
- // return ;
- 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 (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);
- }
- if (!self.ruleForm.extra.full_reduce_price_limit) {
- self.ruleForm.extra.full_reduce_price_limit = 0;
- }
- if (!self.ruleForm.extra.full_reduce_money) {
- self.ruleForm.extra.full_reduce_money = 0;
- }
- if (!self.ruleForm.extra.score_give_setting.give_num) {
- self.ruleForm.extra.score_give_setting.give_num = 0;
- }
- if(self.ruleForm.extra.is_repurchase == 1){
- let repurchase_setting = self.ruleForm.extra.repurchase_setting
- if(repurchase_setting.length <= 0){
- this.$message.error('请完善复购设置')
- return
- }
- let err = 0
- let flag_start = -1
- let flag_end = -1
- for(let i = 0; i < repurchase_setting.length; i++){
- if(repurchase_setting[i].start < 0 || repurchase_setting[i].end <= 0 || repurchase_setting[i].price < 0 || repurchase_setting[i].start > repurchase_setting[i].end){
- err = 1
- break
- }
- if(i > 0){
- if(repurchase_setting[i].start >= flag_start && repurchase_setting[i].start <= flag_end){
- err = 2
- break
- }
- }
- flag_start = repurchase_setting[i].start
- flag_end = repurchase_setting[i].end
- }
- if(err > 0){
- if(err == 1){
- this.$message.error('请输入正确的复购设置')
- }else{
- this.$message.error('复购件数区间必须递增')
- }
- return
- }
- }
- //把纯数字转字符
- this.ruleForm.goods_name = this.ruleForm.goods_name + '';
- this.ruleForm.subtitle = this.ruleForm.subtitle + '';
- self.btnLoading = true;
- let requesturl = 'mall/goods/edit'
- if (this.smartform_addons_arr && this.smartform_addons_arr.component && this.goodsId > 0) {
- this.smartGoodForm.goods_id = this.goodsId
- let taohua = JSON.parse(JSON.stringify(self.ruleForm))
- if (this.$refs.smartForm.smartForm[0]) {
- this.smartGoodForm.template_id = this.$refs.smartForm.smartForm[0].id
- this.smartGoodForm.status = this.$refs.smartForm.smartGoodForm.is_relation
- this.ruleForm.addons.SmartForm = this.smartGoodForm;
- //params = Object.assign(taohua);
- params = Object.assign(this.ruleForm);
- } else {
- params = Object.assign(taohua, this.cForm);
- }
- } else {
- // params = Object.assign(self.ruleForm, this.cForm);
- params = Object.assign(self.ruleForm);
- }
- // 过滤虚拟商品
- if (this.ruleForm.goods_type == 1 && this.community_addons_arr && this.community_addons_arr.component) {
- if (this.$refs.community.communityGoodsForm) {
- if (this.$refs.community.communityGoodsForm.enable == 1 && (this.ruleForm.freight_type.includes(2) || this.ruleForm.freight_type.includes(3))) {
- self.$message.error('快递方式已勾选到店自提或同城配送,无法开启社区团购');
- self.btnLoading = false;
- return;
- }
- this.communityGoodForm.enable = this.$refs.community.communityGoodsForm.enable
- this.communityGoodForm.enable_refund = this.$refs.community.communityGoodsForm.enable_refund
- this.communityGoodForm.supported_logistics = this.$refs.community.communityGoodsForm.supported_logistics
- this.communityGoodForm.community_arr_ids = this.$refs.community.community_arr_ids
- if (this.communityGoodForm.enable == 1 && this.communityGoodForm.supported_logistics.length == 0) {
- self.$message.error('社区团购配送方式至少选择一种');
- return;
- }
- this.ruleForm.addons.Community = this.communityGoodForm;
- params = Object.assign(this.ruleForm);
- }
- }
- if (this.valet_order_addons_arr && this.valet_order_addons_arr.component && this.goodsId > 0) {
- if (this.$refs.valet_order.valetOrderGoodsForm) {
- if (this.$refs.valet_order.valetOrderGoodsForm.status == 1 && (this.ruleForm.freight_type.includes(2) || this.ruleForm.freight_type.includes(3))) {
- self.$message.error('快递方式已勾选到店自提或同城配送,无法设为代购买商品');
- self.btnLoading = false;
- return;
- }
- this.valetOrderGoodForm.status = this.$refs.valet_order.valetOrderGoodsForm.status
- this.ruleForm.addons.ValetOrder = this.valetOrderGoodForm;
- params = Object.assign(this.ruleForm);
- }
- }
- // 深拷贝一份数据,让checkbox正常显示
- let submitForm = JSON.parse(JSON.stringify(params))
- if (submitForm.is_attr == 1) {
- for(let i = 0; i < submitForm.attr.length; i++){
- submitForm.attr[i]['is_show'] = submitForm.attr[i]['is_show'] ? 1 : 0
- }
- }
- if (this.ruleForm.goods_subtype == 1) {
- for (let item of submitForm.extra.symptom_list) {
- item = item + ''
- if (item.trim() === '') {
- self.$message.error('请填写疾病名称');
- self.btnLoading = false;
- return
- }
- }
- }
- // console.log(params, self.ruleForm, this.cForm, 'sumbit ============ ');return null;
- console.log(params, self.ruleForm, this.cForm, 'sumbit ============ ');
- console.log(submitForm, 'submitForm ============ ');
- // return null;
- // if (this.ruleForm.price <= 0) {
- // self.btnLoading = false;
- // this.$message.error('价格不能为0')
- // return null
- // }
- request({
- params: {
- r: requesturl
- },
- method: 'post',
- data: {
- form: JSON.stringify(submitForm),
- }
- }).then(e => {
- self.btnLoading = false;
- if (e.data.code == 0) {
- self.$message.success(e.data.msg);
- this.$navigate({
- r: 'mall/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")
- }
- }
- },
- addons_data_change(e) {
- Object.assign(this.ruleForm.addons, e);
- console.log(this.ruleForm.addons, '=======addons====');
- // this.ruleForm.addons.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;
- },
- // // 轮播图拖拽
- // dragBannarPic(e){
- // // 拖拽后下标之前的值
- // let oldValue = this.ruleForm.bannar_pic[e.newIndex];
- // // 拖拽下标对应的值
- // let newValue = this.ruleForm.bannar_pic[e.oldIndex];
- // let bannarPic = [...this.ruleForm.bannar_pic];
- // bannarPic.splice(e.oldIndex, 1);
- // bannarPic.splice(e.newIndex, 0, newValue);
- // Vue.set(this.ruleForm, 'bannar_pic', [...bannarPic]);
- // },
- dragBannarPic(e) {
- // 拖拽后下标之前的值
- let oldValue = this.ruleForm.bannar_pic[e.newIndex];
- // 拖拽下标对应的值
- let newValue = this.ruleForm.bannar_pic[e.oldIndex];
- this.ruleForm.bannar_pic[e.newIndex] = newValue;
- this.ruleForm.bannar_pic[e.oldIndex] = oldValue;
- },
- appendRepurchaseItem(){
- item = {start: 0, end: 0, price: 0}
- this.ruleForm.extra.repurchase_setting.push(item)
- },
- delRepurchaseItem(index){
- this.ruleForm.extra.repurchase_setting.splice(index, 1);
- },
- setRepurchase(index, field, val){
- item = this.ruleForm.extra.repurchase_setting[index]
- item[field] = Number(val)
- this.$set(this.ruleForm.extra.repurchase_setting, index, item)
- },
- formatGiveNumber(value, pindex) {
- if (this.ruleForm.extra[pindex].give_type == 2) {
- this.ruleForm.extra[pindex].give_num = value.replace(/[^\d]/g, "")
- } else {
- let temp = value.toString();
- temp = temp.replace(/。/g, ".");
- temp = temp.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
- temp = temp.replace(/^\./g, ""); //验证第一个字符是数字
- temp = temp.replace(/\.{2,}/g, ""); //只保留第一个, 清除多余的
- temp = temp.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
- temp = temp.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
- this.ruleForm.extra[pindex].give_num = temp
- }
- },
- handleGiveTypeChange(pindex) {
- if (this.ruleForm.extra[pindex].give_type == 2) {
- let giveNum = this.ruleForm.extra[pindex].give_num
- giveNum = giveNum ? giveNum : 0
- this.ruleForm.extra[pindex].give_num = parseInt(giveNum)
- }
- },
-
- // 预约商品-时间范围选择处理
- 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, 'from7');
- });
- }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, 'from9');
- });
- }else{
- this.$nextTick(() => {
- this.$refs.priceSet.initData(this.initializationDates);
- this.isEdit = false;
- });
- }
- }
- }
- },
- async loadData(id = 1) {
- await request({
- params: {
- r: 'mall/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: 'mall/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: 'mall/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: 'mall/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();
- },
- changeSwitch()
- {
- 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: 'mall/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: 'mall/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
- },
- addressChange(e) {
- this.ruleForm.searchAddress.province_id = e[0]
- this.ruleForm.searchAddress.city_id = e[1]
- this.ruleForm.searchAddress.district_id = e[2]
- this.townList = []
- this.ruleForm.searchAddress.town_id = ''
- if (e.length == 3) {
- this.getTownList(e[2]);
- }
- console.log(this.ruleForm.searchAddress.addressIdsMap, 'ruleForm.searchAddress.addressIdsMap')
- },
- getDistrict(level) {
- if (level) {
- level1 = level;
- } else{
- level1 = 1;
- }
- request({
- params: {
- r: 'common/region/get-district-list',
- level: level1
- },
- }).then(e => {
- if (e.data.code == 0) {
- this.districtList = e.data.data
- }
- }).catch(e => {
- });
- },
- getTownList(district_id) {
- request({
- params: {
- r: 'common/region/get-town-list',
- district_id: district_id
- },
- }).then(e => {
- if (e.data.code == 0) {
- this.townList = e.data.data.list;
- }
- }).catch(e => {
- });
- },
- onChangeTown(val) {
- this.ruleForm.searchAddress.town_id = val
- },
- 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;
- }
- }
- 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,
- });
- 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;
- }
- },
- descriptionTemplateChange(val) {
- this.ruleForm.extra.description_list = []
- for (const field of this.descriptionTemplateList[val]?.fields ?? []) {
- this.ruleForm.extra.description_list.push({
- 'field': field,
- 'value': ''
- })
- }
- },
- removeSymptom(index) {
- if (this.ruleForm.extra.symptom_list.length > 1) {
- this.ruleForm.extra.symptom_list.splice(index, 1);
- } else {
- this.$message.warning('至少保留一种疾病');
- }
- },
- addMemberAloneBuyLimitSetting()
- {
- this.ruleForm.extra.member_alone_buy_limit_setting.push({
- "level": '',
- "every_month_num": 0,
- });
- this.$forceUpdate();
- }
- }
- });
- </script>
|