edit.php 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('component/com-add-cat', __DIR__);
  4. ComponentHelper::loadComponentView('component/com-attr-group', __DIR__);
  5. ComponentHelper::loadComponentView('component/com-attr', __DIR__);
  6. ComponentHelper::loadComponentView('component/com-attrs-setting', __DIR__);
  7. ComponentHelper::loadComponentView('com-rich-text');
  8. ComponentHelper::loadComponentView('com-district');
  9. ComponentHelper::loadComponentView('com-coupon', Yii::$app->basePath . '/../addons/Coupon/backend/views/goods');
  10. ComponentHelper::loadComponentView('component/com-package-attr', Yii::$app->basePath . '/../addons/Store/client/views/goods');
  11. $addons_settings = empty($addons_settings) ? [] : $addons_settings;
  12. foreach ($addons_settings as $key => $item) {
  13. ComponentHelper::loadComponentView($item['components'], Yii::$app->basePath . '/../addons/' . ucfirst($key) . '/backend/views/goods');
  14. }
  15. $addons_settings = \yii\helpers\Json::encode($addons_settings);
  16. if (!empty($components)) {
  17. foreach ($components as $addons => $component) {
  18. if(!file_exists($component['path'])) continue;
  19. ComponentHelper::loadComponentView($component['component'], $component['path']);
  20. }
  21. $components = \yii\helpers\Json::encode($components);
  22. }
  23. ?>
  24. <script src="/resources/js/Sortable.min.js"></script>
  25. <script src="/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
  26. <style>
  27. <?= ComponentHelper::loadComponentView('edit', __DIR__ . '/css', [], true, 'css'); ?>
  28. </style>
  29. <div id="app" v-cloak>
  30. <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">
  31. <!-- <div slot="header">
  32. <div flex="cross:center box:first">
  33. <div><span @click="$navigate({r:'mall/goods/index'})" class="text">商品列表</span>/编辑商品</div>
  34. </div>
  35. </div> -->
  36. <div class="goods-box">
  37. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" size="mini" label-width="150px" class="demo-ruleForm">
  38. <!-- tab切换 -->
  39. <div class="tabs-box">
  40. <div class="tabs-list" flex="cross:center">
  41. <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>
  42. </div>
  43. </div>
  44. <!-- 基础设置 -->
  45. <div v-show="activeName == 'basic'">
  46. <?= ComponentHelper::loadComponentView('goods-basic', __DIR__) ?>
  47. </div>
  48. <div v-show="activeName == 'mode'">
  49. <template v-if="addonsSettings">
  50. <div class="goods-box">
  51. <!-- <el-form :model="settingForm" ref="settingForm" size="mini" label-width="150px" class="demo-ruleForm"> -->
  52. <div class="basic">
  53. <!-- 分润设置 -->
  54. <component v-for="(addons,index) in addonsSettings" v-bind:is="addons.components" :goods="goods" :level_arr="level" :commission_type_map="commission_type_map" :coupon_type_map="coupon_type_map" :setting="setting[index]" @change="getData" :key="index" :boss_commission_type="{commission: '佣金'}" style="margin-bottom:20px"></component>
  55. </div>
  56. <!-- </el-form> -->
  57. </div>
  58. </template>
  59. <template v-else>
  60. <el-button size="mini" type="info" >相关应用分润未设置</el-button>
  61. </template>
  62. </div>
  63. <div v-show="activeName == 'marketing'">
  64. <?= ComponentHelper::loadComponentView('goods-marketing', __DIR__) ?>
  65. </div>
  66. <!-- 关联商品 -->
  67. <div v-show="activeName == 'goods_association'">
  68. <?= ComponentHelper::loadComponentView('goods-association', __DIR__) ?>
  69. </div>
  70. </el-form>
  71. </div>
  72. </el-card>
  73. <div v-if="isAudit" class="bottom-btns" flex="main:center cross:center">
  74. <el-button size="mini" type="primary" @click="goodAudit('adopt')" :loading="btnLoading">通过</el-button>
  75. <el-button size="mini" type="primary" @click="goodAuditFailed('failed')" :loading="btnLoading">不通过</el-button>
  76. </div>
  77. <div v-else-if="supplier_type != 4" class="bottom-btns" flex="main:center cross:center">
  78. <el-button size="mini" type="primary" @click="submit()" :loading="btnLoading">保存</el-button>
  79. </div>
  80. </div>
  81. <script>
  82. const app = new Vue({
  83. el: '#app',
  84. data() {
  85. return {
  86. tabs: [{
  87. name: '基础设置',
  88. value: 'basic'
  89. },
  90. {
  91. name: '营销配置',
  92. value: 'marketing'
  93. },
  94. {
  95. name: '模式设置',
  96. value: 'mode'
  97. },
  98. {
  99. name: '关联商品',
  100. value: 'goods_association'
  101. },
  102. ],
  103. activeName: 'basic',
  104. typeArr: [],
  105. goods_type: 'physical',
  106. is_base_show: false,
  107. is_mch: false,
  108. is_default_services: 1,
  109. typeIndex: 0,
  110. btnLoading: false,
  111. cardLoading: false,
  112. cats: [],
  113. freight_id: 0,
  114. goodsId: null,
  115. // freight: {
  116. // dialog: false,
  117. // list: [],
  118. // checked: {},
  119. // loading: false
  120. // },
  121. attrGroups: [], //规格组
  122. attrGroupName: '',
  123. attrName: [],
  124. // 批量设置
  125. batch: {},
  126. label_list: [], // 商品标签列表
  127. service_list: [], // 商品服务列表
  128. freight_rules: [ // 运费模板
  129. // {
  130. // id: '1',
  131. // name: '全国包邮'
  132. // },
  133. // {
  134. // id: '2',
  135. // name: '北京包邮'
  136. // }
  137. ],
  138. is_show_freight: false,
  139. defaultMemberPrice: [],
  140. member_level_list: [
  141. // {level: 1, name: '普通用户', value: {"sign_id_2:4":40, "sign_id_3:4": 41, "sign_id_2:5": 41, "sign_id_3:5": 41}},
  142. // {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}},
  143. // {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}},
  144. // {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}}
  145. ],
  146. dialogVisible: false, // 配送范围弹出框
  147. earaRule: [],
  148. multiple_selection: [], //优惠券
  149. is_show_counpon: 0, //优惠券是否展示
  150. show_addons: <?= $components ?? '{}'; ?>, //插件营销是否展示
  151. the_addons_name: 'Store',
  152. ruleForm: {
  153. /*********************************** 基础设置 ****************************************/
  154. goods_type: 1,
  155. goods_name: '',
  156. subtitle: '',
  157. cover_pic: '',
  158. bannar_pic: [],
  159. video_url: '',
  160. cats: [],
  161. mchCats: [], //多商户系统分类
  162. services: [],
  163. freight: null,
  164. labels: '', // 商品标签
  165. is_attr: 0, // 是否有规格
  166. attr: [],
  167. price: 0,
  168. original_price: 0,
  169. cost_price: 0,
  170. stock: '',
  171. unit: '', // 单位
  172. stock_warning: 0, // 库存预警 - 自定义字段,后面改
  173. goods_weight: 0, // 商品重量 - 自定义字段,后面改
  174. goods_no: '', // 商品货号
  175. is_show_stock: 1, // 是否显示库存 - 自定义字段,后面改
  176. is_show_sales: 1, // 是否显示销量 - 自定义字段,后面改
  177. virtual_sales: 0,
  178. coupon_is_enable: 0, //优惠卷的开关
  179. // logistics_way: [{
  180. // name: '快递发货',
  181. // checked: true
  182. // }], // 快递发货 - 自定义字段,后面改
  183. freight_type: [1], //物流方式 1快递物流
  184. freight_rules_type: 1, // 运费规则类型 1运费模板 2统一运费
  185. freight_id: '', // 运费模板ID
  186. shipping_fee: 0, //统一运费
  187. free_shipping_num: 0, //满N件包邮
  188. free_shipping_money: 0, //满N元包邮
  189. is_cross_border: 0, // 是否跨境商品 - 自定义字段,后面改
  190. is_id_card: 0, // 是否身份证上传 - 自定义字段,后面改
  191. is_on_sale: 1, // 是否上架
  192. show_style: 1, // 展示风格
  193. extra: {
  194. full_reduce_price_limit: 0, // 单品满额减免价格阈值
  195. full_reduce_money: 0, // 单品满额减免金额
  196. score_give_setting: {
  197. is_alone:0,
  198. code: 'score',
  199. name: '积分',
  200. give_num: 0, // 货币赠送
  201. give_type: 1, // 货币赠送 1.固定值 2售价百分比
  202. condition: 0, // 条件
  203. },
  204. is_member_price: 0,
  205. member_price_setting: {},
  206. member_buy_limit_setting: {
  207. member_level: [],
  208. every_num: 0,
  209. every_day_num: 0,
  210. every_week_num: 0,
  211. every_month_num: 0,
  212. nums: 0,
  213. total_num: 0,
  214. },
  215. currency_deduct_setting: [], // 货币这块有bug,暂时不需要展示,所以不需要提交数据
  216. repurchase_setting: [],
  217. is_repurchase: 0,
  218. is_alone_settle:0,
  219. alone_settle_price:0,
  220. service_fee_setting: {
  221. is_alone: 0,
  222. service_fee_ratio: null
  223. },
  224. platform_service_fee_setting: {
  225. service_fee_type: 0,
  226. max_platform_ratio: 0,
  227. min_platform_ratio: 0,
  228. }
  229. },
  230. coupon_selection: [],
  231. goods_setting: {
  232. /*********************************** 用户权益 **********************************************/
  233. member_setting: { // 用户权益模块提交的格式
  234. member_price_setting: '',
  235. member_price: {},
  236. member_buy_limit_setting: {
  237. member_level: [],
  238. every_num: 0,
  239. every_day_num: 0,
  240. every_week_num: 0,
  241. every_month_num: 0,
  242. nums: 0,
  243. total_num: 0,
  244. }
  245. },
  246. /*********************************** 营销设置 **********************************************/
  247. marketing_setting: { // 营销配置模块提交的格式
  248. full_reduce_price_limit: 0, // 单品满额减免价格阈值
  249. full_reduce_money: 0, // 单品满额减免金额
  250. score_give_setting: {
  251. code: 'score',
  252. name: '积分',
  253. give_num: 0, // 货币赠送
  254. give_type: 1, // 货币赠送 1.固定值 2售价百分比
  255. },
  256. score_deduct_setting: {
  257. code: 'score',
  258. name: '积分',
  259. deduct_num: 0, // 货币抵扣
  260. deduct_type: 1, // 1.单件抵扣 2.多件累计抵扣
  261. },
  262. currency_deduct_setting: [], // 货币这块有bug,暂时不需要展示,所以不需要提交数据
  263. }
  264. },
  265. /******************************* 配送范围 ************************************/
  266. is_area_limit: 0,
  267. // area_limit: [{ list: [] }]
  268. area_limit: [],
  269. is_sync_goods: 0,
  270. addons: {},
  271. // 预约商品
  272. reserve: {
  273. reserve_date_type: 1, // 可预约时间类型(1范围 2自选日期)
  274. reserve_date: null, // 可预约日期
  275. reserve_time_range_type: 1, //预约模式(1按天预约 2按时间段预约)
  276. time_slot_type: 1, // 时间段划分方式(1自定义划分 2自动划分)
  277. reserve_time_slot: null, // 时间段划分
  278. reserve_price_type: 0, // 价格设置方式(0统一售价 1按日期时间段设置)
  279. reserve_time_slot_price: [], // 按时间段设置的价格
  280. reserve_week: [0,1,2,3,4,5,6], // 可预约周,如:0,1,2,3,4,5,6
  281. reserve_max_buy: 0, // 每天最大预约数量
  282. reserve_advance_hourse: 0, // 提前预约时间(小时)
  283. reserve_days_range: 0, //限制选择并购买的时间在设置内天数的商品
  284. cancel_type: 1, // 取消类型(1不允许取消 2服务开始前取消 3订单类型取消)
  285. cancel_rule: {
  286. cancel_hour: 0,
  287. cancel_fee_percent: 0
  288. }, // 取消规则
  289. expired_handle_type: 1, // 预约码过期后处理方式(1不退款 2自动退款)
  290. service_type: 1, // 服务方式(1上门 2到店)
  291. // 位置信息
  292. province_id: 0, // 省份Id
  293. city_id: 0, // 城市Id
  294. district_id: 0, // 区县Id
  295. detail: '', // 详细地址
  296. lat: '', // 纬度
  297. lng: '', // 经度
  298. skus: [], // 预约多规格
  299. ordering_information: '', // 订购须知
  300. information_detail: '', // 须知详情
  301. reserve_type: 1, // 门店只能是1
  302. distance: '', // 有效距离
  303. },
  304. },
  305. rules: {
  306. cats: [{
  307. required: true,
  308. type: 'array',
  309. validator: (rule, value, callback) => {
  310. if (this.ruleForm.cats instanceof Array && this.ruleForm.cats.length > 0) {
  311. callback();
  312. }
  313. callback('请选择分类');
  314. }
  315. }],
  316. mchCats: [{
  317. required: true,
  318. type: 'array',
  319. validator: (rule, value, callback) => {
  320. if (this.ruleForm.mchCats instanceof Array && this.ruleForm.mchCats.length > 0) {
  321. callback();
  322. }
  323. callback('请选择系统分类');
  324. }
  325. }],
  326. goods_name: [{
  327. required: true,
  328. message: '请输入商品名称',
  329. trigger: 'blur'
  330. }],
  331. cover_pic: [{
  332. required: true,
  333. message: '请添加图片',
  334. trigger: 'change'
  335. }],
  336. price: [{
  337. required: true,
  338. message: '请输入价格',
  339. trigger: 'blur'
  340. }],
  341. extra: {
  342. full_reduce_price_limit: [{
  343. validator: (rule, value, callback) => {
  344. if (value > 1000000) {
  345. callback('不能大于1000000');
  346. }
  347. callback();
  348. }
  349. }],
  350. full_reduce_money: [{
  351. validator: (rule, value, callback) => {
  352. if (value > 1000000) {
  353. callback('不能大于1000000');
  354. }
  355. callback();
  356. }
  357. }]
  358. },
  359. stock: [{
  360. required: true,
  361. message: '请输入商品库存',
  362. trigger: 'blur'
  363. }],
  364. // area_limit: [{
  365. // required: true,
  366. // type: 'array',
  367. // validator: (rule, value, callback) => {
  368. // if (value instanceof Array && value[0]['list'].length === 0) {
  369. // callback('允许购买区域不能为空');
  370. // }
  371. // callback();
  372. // }
  373. // }],
  374. },
  375. revealArea: [],
  376. extra1_goods_list:[],
  377. extra2_goods_list:[],
  378. isAudit: false,
  379. addonsSettings: <?= $addons_settings ?? '{}'; ?>, // 各个插件模式配置
  380. setting: {},
  381. commission_type_map: {},
  382. coupon_type_map: {},
  383. goods: {},
  384. level: {},
  385. settingForm: {},
  386. storeId: 0,
  387. package_data: [],
  388. supplier_type: 0,
  389. store_login_url: '',
  390. };
  391. },
  392. created() {
  393. this.goodsId = parseInt(getQuery('id'));
  394. this.isAudit = getQuery('is_audit');
  395. let isMode = getQuery('is_mode');
  396. if (isMode) {
  397. this.activeName = 'mode';
  398. } else {
  399. this.activeName = 'basic';
  400. }
  401. },
  402. mounted: function() {
  403. this.getGoodsDetail();
  404. this.getModelDetail();
  405. },
  406. watch: {
  407. 'ruleForm.detail'(newVal, oldVal) {
  408. this.cForm.detail = newVal
  409. },
  410. 'ruleForm.show_style'(newVal, oldVal) {
  411. if (newVal != oldVal) {
  412. // this.attrGroups = []
  413. // this.ruleForm.attr = []
  414. }
  415. if (newVal == 2) {
  416. this.ruleForm.is_attr = 1
  417. }
  418. }
  419. },
  420. computed: {
  421. cForm() {
  422. let form = {};
  423. let ruleForm = JSON.parse(JSON.stringify(this.ruleForm));
  424. if (this.form) {
  425. form = Object.assign(ruleForm, JSON.parse(JSON.stringify(this.form)));
  426. } else {
  427. form = ruleForm;
  428. }
  429. if (getQuery('id')) {
  430. form.id = getQuery('id')
  431. }
  432. return form;
  433. },
  434. cRule() {
  435. return this.rule ? Object.assign({}, this.rules, this.rule) : this.rules;
  436. },
  437. },
  438. methods: {
  439. changeFreightType() {
  440. this.is_show_freight = inArray(1, this.ruleForm.freight_type);
  441. },
  442. getGoodsDetail() {
  443. let self = this;
  444. self.cardLoading = true;
  445. request({
  446. params: {
  447. r: 'store/store-goods/edit',
  448. id: getQuery('id')
  449. },
  450. method: 'get',
  451. }).then(e => {
  452. self.cardLoading = false;
  453. if (e.data.code == 0) {
  454. if (!isEmpty(e.data.data.detail)) {
  455. if(e.data.data.detail.goods_type && e.data.data.detail.goods_type == 3){
  456. self.isEdit = true;
  457. self.ruleForm = e.data.data.detail;
  458. console.log("gggvv",e.data.data.detail);
  459. //self.ruleForm = JSON.parse(JSON.stringify(e.data.data.detail));
  460. self.long_lat = self.ruleForm.reserve.lat + '-' + self.ruleForm.reserve.lng;
  461. if(!(self.ruleForm.reserve && self.ruleForm.reserve.cancel_rule)){
  462. self.ruleForm.reserve.cancel_rule = {
  463. cancel_hour: 0,
  464. cancel_fee_percent: 0
  465. }
  466. }
  467. if(this.ruleForm.is_attr == 1){
  468. if(self.ruleForm.reserve && self.ruleForm.reserve.skus && self.ruleForm.reserve.skus.length){
  469. self.ruleForm.attr = [];
  470. let receiveList = self.ruleForm.reserve.skus;
  471. receiveList.forEach(item => {
  472. item.checkRangeList = [];
  473. item.dayArr = [];
  474. item.checkWeekList = [];
  475. item.selectTimeList = [];
  476. item.finalData = [];
  477. if(item.reserve_date_type == 1 && this.ruleForm.reserve.reserve_type == 0){
  478. item.reserve_date.sort(function (a, b) {
  479. return new Date(a) - new Date(b);
  480. });
  481. item.checkRangeList.push(item.reserve_date[0],item.reserve_date[item.reserve_date.length-1]);
  482. let val = [new Date(item.checkRangeList[0]),new Date(item.checkRangeList[1])];
  483. let arr = [];
  484. 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: []}];
  485. if (val.length) {
  486. let arr1 = [];
  487. let str1 = val[0];
  488. let str2 = val[1];
  489. let unixDb = str1.getTime() - 24 * 60 * 60 * 1000;
  490. let unixDe = str2.getTime() - 24 * 60 * 60 * 1000;
  491. for(let j = unixDb; j <= unixDe;){
  492. j = j + 24 * 60 * 60 * 1000
  493. arr1.push(new Date(parseInt(j)))
  494. }
  495. for(let i = 0; i < arr1.length; i++){
  496. txtArr.forEach(it => {
  497. if(it.val == arr1[i].getDay()){
  498. let fm = this.formatDate(arr1[i])
  499. it.children.push(fm);
  500. }
  501. })
  502. }
  503. txtArr.forEach(it => {
  504. if(it.children.length){
  505. arr.push(it);
  506. }
  507. });
  508. item.dayArr = arr;
  509. }
  510. let warr = [];
  511. item.dayArr.forEach(it => {
  512. warr.push(it.txt);
  513. });
  514. item.checkWeekList = [...new Set(warr)];
  515. let selectArr = [];
  516. let selectDateArr = [];
  517. for(let i = 0; i < item.dayArr.length; i++){
  518. item.checkWeekList.forEach(it => {
  519. if(it == item.dayArr[i].txt){
  520. selectArr.push(item.dayArr[i]);
  521. }
  522. });
  523. }
  524. for(let j = 0; j < selectArr.length; j++){
  525. selectDateArr = selectDateArr.concat(selectArr[j].children);
  526. }
  527. item.reserve_date = selectDateArr;
  528. }
  529. if(item.reserve_time_slot_price && item.reserve_time_slot_price.length){
  530. item.reserve_time_slot_price.forEach(it => {
  531. item.finalData.push({
  532. date: it.reserve_time,
  533. time_spec: it.time_spec,
  534. isSelect: false,
  535. times: [],
  536. selectTimes: []
  537. });
  538. item.selectTimeList.push({
  539. date: it.reserve_time,
  540. isSelect: false,
  541. children: [],
  542. intervalList: [],
  543. checkAll: false,
  544. isIndeterminate: true,
  545. checkedIntervalList: [],
  546. time_spec: it.time_spec,
  547. });
  548. });
  549. } else if (item.reserve_price_type == 2 && typeof item.reserve_time_slot_price == "object") { // 按天设置价格
  550. for (let day in item.reserve_time_slot_price) {
  551. item.finalData.push({
  552. date: day,
  553. price: item.reserve_time_slot_price[day].price || 0,
  554. linePrice: item.reserve_time_slot_price[day].original_price || 0,
  555. reservationNum: item.reserve_time_slot_price[day].reserve_max_buy || 0,
  556. children: item.reserve_time_slot_price[day].children || [],
  557. times: item.reserve_time_slot_price[day].times || []
  558. })
  559. }
  560. }
  561. item.finalData.forEach(ite => {
  562. if(ite.time_spec.length){
  563. ite.time_spec.forEach(it => {
  564. ite.times.push(it.spec_time);
  565. ite.selectTimes.push({
  566. time: it.spec_time,
  567. price: it.price,
  568. linePrice: it.original_price,
  569. reservationNum: it.reserve_max_buy
  570. });
  571. });
  572. }
  573. });
  574. item.selectTimeList.forEach(ite => {
  575. if(ite.time_spec.length){
  576. ite.time_spec.forEach(it => {
  577. ite.children.push(it.spec_time);
  578. });
  579. }
  580. });
  581. });
  582. let targetArr = [];
  583. receiveList.forEach(item => {
  584. targetArr.push({
  585. attr_list: item.attr_list || [],
  586. reserve_date_type: item.reserve_date_type || 1,
  587. reserve_date: item.reserve_date || [],
  588. reserve_time_range_type: item.reserve_time_range_type || 1,
  589. time_slot_type: item.time_slot_type || 1,
  590. reserve_time_slot: item.reserve_time_slot || null,
  591. reserve_price_type: item.reserve_price_type || 0,
  592. reserve_time_slot_price: JSON.parse(JSON.stringify(item.reserve_time_slot_price)) || null,
  593. reserve_week: JSON.parse(JSON.stringify(item.reserve_week)) || [0,1,2,3,4,5,6],
  594. reserve_max_buy: item.reserve_max_buy || null,
  595. price: item.price || null,
  596. original_price: item.original_price || null,
  597. dayArr: item.dayArr || [],
  598. checkWeekList: item.checkWeekList || [],
  599. checkRangeList: item.checkRangeList || [],
  600. selectTimeList: JSON.parse(JSON.stringify(item.selectTimeList)) || [],
  601. finalData: item.finalData || [],
  602. service_min: item.service_min || 0,
  603. unit: item.unit || '',
  604. });
  605. });
  606. targetArr.forEach(item => {
  607. item.selectTimeList.forEach(it => {
  608. it.children = JSON.stringify(it.children);
  609. it.time_spec = JSON.stringify(it.time_spec);
  610. });
  611. });
  612. targetArr.forEach(item => {
  613. let obj = {
  614. attr_list: JSON.parse(JSON.stringify(item.attr_list)),
  615. reserve_date_type: item.reserve_date_type,
  616. reserve_date: JSON.parse(JSON.stringify(item.reserve_date)),
  617. reserve_time_range_type: item.reserve_time_range_type,
  618. time_slot_type: item.time_slot_type,
  619. reserve_time_slot: item.reserve_time_slot,
  620. reserve_price_type: item.reserve_price_type,
  621. reserve_time_slot_price: JSON.parse(JSON.stringify(item.reserve_time_slot_price)),
  622. reserve_week: JSON.parse(JSON.stringify(item.reserve_week)),
  623. reserve_max_buy: item.reserve_max_buy,
  624. price: item.price,
  625. original_price: item.original_price,
  626. dayArr: JSON.parse(JSON.stringify(item.dayArr)),
  627. checkWeekList: JSON.parse(JSON.stringify(item.checkWeekList)),
  628. checkRangeList: JSON.parse(JSON.stringify(item.checkRangeList)),
  629. selectTimeList: JSON.parse(JSON.stringify(item.selectTimeList)),
  630. finalData: JSON.parse(JSON.stringify(item.finalData)),
  631. service_min: item.service_min || 0,
  632. unit: item.unit || '',
  633. }
  634. self.ruleForm.attr.push(JSON.stringify(obj));
  635. });
  636. for(let i = 0; i < self.ruleForm.attr.length; i++){
  637. self.ruleForm.attr[i] = JSON.parse(self.ruleForm.attr[i]);
  638. }
  639. self.ruleForm.attr.forEach(item => {
  640. item.selectTimeList.forEach(it => {
  641. it.children = JSON.parse(it.children);
  642. it.time_spec = JSON.parse(it.time_spec);
  643. });
  644. });
  645. }
  646. }else{
  647. if(self.ruleForm.reserve && self.ruleForm.reserve.reserve_date && self.ruleForm.reserve.reserve_date.length){
  648. if(self.ruleForm.reserve.reserve_date_type == 1){
  649. self.ruleForm.reserve.reserve_date.sort(function (a, b) {
  650. return new Date(a) - new Date(b);
  651. });
  652. self.checkRangeList.push(self.ruleForm.reserve.reserve_date[0],self.ruleForm.reserve.reserve_date[self.ruleForm.reserve.reserve_date.length-1]);
  653. this.dateSelectChange([new Date(self.checkRangeList[0]),new Date(self.checkRangeList[1])]);
  654. }
  655. self.ruleForm.reserve.reserve_time_slot_price.forEach(item => {
  656. self.initializationDates.push({
  657. date: item.reserve_time,
  658. time_spec: item.time_spec,
  659. isSelect: false,
  660. times: [],
  661. selectTimes: []
  662. });
  663. });
  664. self.initializationDates.forEach(item => {
  665. if(item.time_spec.length){
  666. item.time_spec.forEach(it => {
  667. item.times.push(it.spec_time);
  668. item.selectTimes.push({
  669. time: it.spec_time,
  670. price: it.price,
  671. linePrice: it.original_price,
  672. reservationNum: it.reserve_max_buy
  673. });
  674. });
  675. }
  676. });
  677. }
  678. }
  679. }else{
  680. self.ruleForm = Object.assign(self.ruleForm, e.data.data.detail);
  681. self.ruleForm.attr = e.data.data.detail.attr;
  682. }
  683. self.attrGroups = e.data.data.detail.attr_groups;
  684. self.storeId = e.data.data.detail.store_id;
  685. self.cats = e.data.data.detail.cats;
  686. self.selectCat(e.data.data.detail.cats)
  687. for (let key in e.data.data.detail.freight_type) {
  688. if (e.data.data.detail.freight_type[key] == 1) {
  689. this.is_show_freight = true;
  690. break;
  691. }
  692. }
  693. if (self.ruleForm.area_limit) {
  694. self.deduplicationArea();
  695. }
  696. }
  697. self.label_list = e.data.data.labels;
  698. self.service_list = e.data.data.services;
  699. self.member_level_list = e.data.data.levels;
  700. // 以下数据用于默认规格情况下的 用户价设置
  701. if (!e.data.data.detail.is_attr && e.data.data.detail.is_attr != 0) {
  702. self.member_level_list.forEach((item, index) => {
  703. let obj = {};
  704. obj['id'] = index;
  705. obj['name'] = item.name;
  706. obj['level'] = 'level' + parseInt(item.level);
  707. var key = item.level + '';
  708. self.$set(this.ruleForm.extra.member_price_setting, key, 0);
  709. });
  710. }
  711. // 以下数据用于默认规格情况下的 用户价设置
  712. var memberSetting = e.data.data.detail.extra;
  713. self.member_level_list.forEach(function(item, index) {
  714. let obj = {};
  715. let key = 'level' + parseInt(item.level);
  716. obj['id'] = index;
  717. obj['name'] = item.name;
  718. obj['level'] = key;
  719. if (memberSetting && memberSetting.member_price_setting && memberSetting.member_price_setting[key]) {
  720. self.member_level_list[index]['value'] = memberSetting.member_price_setting[key]; // 赋值到用户列表数据中
  721. } else {
  722. self.member_level_list[index]['value'] = {};
  723. }
  724. self.defaultMemberPrice.push(obj);
  725. });
  726. self.typeArr = e.data.data.goods_type;
  727. self.freight_rules = e.data.data.freight_rules;
  728. // 默认运费模板
  729. if (self.ruleForm.freight_rules_type == 1 && isEmpty(self.ruleForm.freight_id) && self.freight_rules.length > 0) {
  730. self.ruleForm.freight_id = self.freight_rules[0].id;
  731. }
  732. this.extra1_goods_list = e.data.data.extra1_goods_list;
  733. this.extra2_goods_list = e.data.data.extra2_goods_list;
  734. self.ruleForm.show_style = self.ruleForm.show_style;
  735. this.store_login_url = e.data.data.store_login_url;
  736. // 套餐数据
  737. self.package_data = e.data.data.detail.package_data
  738. this.supplier_type = e.data.data.detail.supplier_type;
  739. } else {
  740. self.$message.error(e.data.msg);
  741. }
  742. }).catch(e => {
  743. console.log(e);
  744. });
  745. },
  746. /* 配送范围start */
  747. openDistrict() {
  748. this.dialogVisible = true;
  749. this.earaRule = this.ruleForm.area_limit;
  750. },
  751. selectDistrict(e) {
  752. let list = [];
  753. for (let i in e) {
  754. let obj = {
  755. id: e[i].id,
  756. name: e[i].name
  757. };
  758. list.push(obj);
  759. }
  760. this.earaRule = list;
  761. },
  762. districtConfirm() {
  763. this.ruleForm.area_limit = JSON.parse(JSON.stringify(this.earaRule));
  764. this.deduplicationArea();
  765. this.dialogVisible = false;
  766. // this.$refs['ruleForm'].validate((valid) => {
  767. // return false;
  768. // })
  769. },
  770. deduplicationArea() {
  771. let that = this;
  772. let reg = /市$|特别行政区$/;
  773. let filt = [...new Set(this.ruleForm.area_limit.filter(v => reg.test(v.name)).map(v => v.name))];
  774. this.ruleForm.area_limit.forEach(v => {
  775. let length = that.revealArea.filter(f => f.name == v.name).length;
  776. if (filt.findIndex(f => f == v.name) != -1 && length > 0) {
  777. return;
  778. }
  779. that.revealArea.push(v);
  780. })
  781. },
  782. space() { // 删除地区
  783. this.ruleForm.area_limit = [];
  784. },
  785. /* 配送范围end */
  786. showMore(type) { // 展开更多
  787. switch (type) {
  788. case 'base':
  789. this.is_base_show = !this.is_base_show
  790. }
  791. },
  792. toggle(it, i, type) { // tab切换
  793. console.log(it, i, type, 'toggle ==========');
  794. switch (type) {
  795. case 'tabs':
  796. this.activeName = it.value
  797. break;
  798. case 'select':
  799. if (this.ruleForm.id > 0) return;
  800. this.ruleForm.goods_type = it.type
  801. break;
  802. default:
  803. break;
  804. }
  805. },
  806. coverPic(e) { // 选择图片
  807. this.ruleForm.cover_pic = e[0].url
  808. },
  809. bannerPic(e) { // 选择轮播图
  810. if (e.length) {
  811. e.forEach((item, index) => {
  812. if (this.ruleForm.bannar_pic.length >= 9) return;
  813. this.ruleForm.bannar_pic.push({
  814. id: item.id,
  815. pic_url: item.url
  816. });
  817. })
  818. }
  819. },
  820. delPic(type, index) { // 删除图片
  821. switch (type) {
  822. case 'cover_pic':
  823. this.ruleForm.cover_pic = ''
  824. break;
  825. case 'bannar_pic':
  826. this.ruleForm.bannar_pic.splice(index, 1)
  827. break;
  828. default:
  829. break;
  830. }
  831. },
  832. // 商品视频
  833. videoUrl(e) {
  834. if (e.length) {
  835. this.ruleForm.video_url = e[0].url;
  836. }
  837. },
  838. /*---商品分类----*/
  839. selectCat(cats) {
  840. this.cats = cats;
  841. let arr = [];
  842. cats.map(v => {
  843. arr.push(v.id);
  844. })
  845. this.ruleForm.cats = arr;
  846. this.$refs.ruleForm.validateField('cats');
  847. },
  848. selectMchCat(cats) {
  849. this.mchCats = cats;
  850. let arr = [];
  851. cats.map(v => {
  852. arr.push(v.id);
  853. })
  854. this.ruleForm.mchCats = arr;
  855. this.$refs.ruleForm.validateField('mchCats');
  856. },
  857. /*---商品分类end----*/
  858. /*----规格start----*/
  859. // 规格组合
  860. makeAttrGroup(e) {
  861. let self = this;
  862. let array = [];
  863. self.attrGroups.forEach(function(attrGroupItem, attrGroupIndex) {
  864. attrGroupItem.attr_list.forEach(function(attrListItem, attrListIndex) {
  865. let object = {
  866. attr_group_id: attrGroupItem.attr_group_id,
  867. attr_group_name: attrGroupItem.attr_group_name,
  868. attr_id: attrListItem.attr_id,
  869. attr_name: attrListItem.attr_name,
  870. };
  871. if (!array[attrGroupIndex]) {
  872. array[attrGroupIndex] = [];
  873. }
  874. array[attrGroupIndex].push(object)
  875. });
  876. });
  877. // 2.属性排列组合
  878. const res = array.reduce((osResult, options) => {
  879. return options.reduce((oResult, option) => {
  880. if (!osResult.length) {
  881. return oResult.concat(option)
  882. } else {
  883. return oResult.concat(osResult.map(o => [].concat(o, option)))
  884. }
  885. }, [])
  886. }, []);
  887. // 3.组合结果赋值
  888. for (let i in res) {
  889. const options = Array.isArray(res[i]) ? res[i] : [res[i]];
  890. const row = {
  891. attr_list: options,
  892. stock: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].stock,
  893. price: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].price,
  894. original_price: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].original_price,
  895. cost_price: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].cost_price,
  896. no: typeof(self.ruleForm.attr[i]) == 'undefined' ? '' : self.ruleForm.attr[i].no,
  897. weight: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].weight,
  898. pic_url: typeof(self.ruleForm.attr[i]) == 'undefined' ? '' : self.ruleForm.attr[i].pic_url,
  899. distributionLevelList: [],
  900. levelPrice: typeof(self.ruleForm.attr[i]) == 'undefined' ? {} : self.ruleForm.attr[i].levelPrice,
  901. sign_id: typeof(self.ruleForm.attr[i]) == 'undefined' ? '' : self.ruleForm.attr[i].sign_id,
  902. };
  903. let arr = [];
  904. row.attr_list.forEach(val => {
  905. arr.push(val.attr_id);
  906. })
  907. // console.info(arr.join(":"),"::::");
  908. row.sign_id = arr.join(":");
  909. // 动态绑定多规格用户价
  910. let obj = {};
  911. self.member_level_list.forEach(function(item, index) {
  912. let key = 'level' + item.level;
  913. obj[key] = 0;
  914. });
  915. row['member_price'] = obj;
  916. // 3-1.已设置数据的优先使用原数据
  917. if (self.ruleForm.attr.length) {
  918. for (let j in self.ruleForm.attr) {
  919. const oldOptions = [];
  920. for (let k in self.ruleForm.attr[j].attr_list) {
  921. oldOptions.push(self.ruleForm.attr[j].attr_list[k].attr_name)
  922. }
  923. const newOptions = [];
  924. for (let k in options) {
  925. newOptions.push(options[k].attr_name)
  926. }
  927. if (oldOptions.toString() === newOptions.toString()) {
  928. row['price'] = self.ruleForm.attr[j].price;
  929. row['stock'] = self.ruleForm.attr[j].stock;
  930. row['no'] = self.ruleForm.attr[j].no;
  931. row['weight'] = self.ruleForm.attr[j].weight;
  932. row['pic_url'] = self.ruleForm.attr[j].pic_url;
  933. break
  934. }
  935. }
  936. }
  937. res[i] = row;
  938. }
  939. self.ruleForm.attr = res;
  940. console.log(self.ruleForm.attr, '-------------------------------attr');
  941. },
  942. // 批量设置
  943. batchAttr(key) {
  944. let self = this;
  945. if (self.batch[key] && self.batch[key] >= 0 || key === 'no') {
  946. self.ruleForm.attr.forEach(function(item, index) {
  947. // 批量设置用户价
  948. // 判断字符串是否出现过,并返回位置
  949. if (key.indexOf('level') !== -1) {
  950. item['member_price'][key] = self.batch[key];
  951. } else {
  952. item[key] = self.batch[key];
  953. }
  954. });
  955. }
  956. },
  957. destroyCat(value, index) {
  958. let self = this;
  959. self.ruleForm.cats.splice(self.ruleForm.cats.indexOf(value), 1)
  960. self.cats.splice(index, 1)
  961. },
  962. /*----规格end----*/
  963. submit() {
  964. if(this.ruleForm.cats.length && (typeof this.ruleForm.cats[0]) !== 'number'){
  965. let idarr = [];
  966. this.ruleForm.cats.forEach(item => {
  967. idarr.push(item.id);
  968. });
  969. this.ruleForm.cats = JSON.parse(JSON.stringify(idarr));
  970. }
  971. let _ = this
  972. if(this.ruleForm.goods_type == 3){
  973. if(this.ruleForm.is_attr == 1){
  974. let skus = [];
  975. this.ruleForm.attr.forEach(item => {
  976. skus.push({
  977. attr_list: JSON.parse(JSON.stringify(item.attr_list)),
  978. reserve_date_type: item.reserve_date_type,
  979. reserve_date: item.reserve_date,
  980. reserve_time_range_type: item.reserve_time_range_type,
  981. time_slot_type: item.time_slot_type,
  982. reserve_price_type: item.reserve_price_type,
  983. reserve_max_buy: item.reserve_max_buy,
  984. price: item.price,
  985. original_price: item.original_price,
  986. reserve_time_slot: item.reserve_time_slot,
  987. reserve_time_slot_price: [],
  988. reserve_week: item.reserve_week,
  989. service_min: item.service_min,
  990. unit: item.unit,
  991. finalData: JSON.parse(JSON.stringify(item.finalData)),
  992. selectTimeList: JSON.parse(JSON.stringify(item.selectTimeList))
  993. });
  994. });
  995. skus.forEach(item => {
  996. // 0统一设置价格 1 按时间段设置 2按天设置 - 只有按时间段才有finalData数据
  997. // reserve_time_range_type 按天=1 时间段=2 2,2,0
  998. // time_slot_type 自定义=1 自动划分=2
  999. // reserve_price_type 统一售价=0 按时间段设置=1 按天设置=2
  1000. if(item.reserve_price_type == 1 && item.finalData && item.finalData.length){ // 按时间段设置价格
  1001. item.finalData.forEach(it => {
  1002. item.reserve_time_slot_price.push({
  1003. reserve_time: it.date,
  1004. price: it.selectTimes[0].price,
  1005. original_price: it.selectTimes[0].linePrice,
  1006. cost_price: 0,
  1007. reserve_max_buy: it.selectTimes[0].reservationNum,
  1008. time_spec: it.selectTimes
  1009. });
  1010. });
  1011. }
  1012. if(item.reserve_price_type == 0 && item.selectTimeList && item.selectTimeList.length){ // 统一设置价格
  1013. // time_slot_type = 1 自定义时间段 = 2 自动划分
  1014. if(item.time_slot_type == 1){ // 自定义时间段
  1015. item.selectTimeList.forEach(it => {
  1016. item.reserve_time_slot_price.push({
  1017. reserve_time: it.date,
  1018. price: item.price,
  1019. original_price: item.original_price,
  1020. cost_price: 0,
  1021. reserve_max_buy: item.reserve_max_buy,
  1022. time_spec: it.children
  1023. });
  1024. });
  1025. }
  1026. if(item.time_slot_type == 2){ // 自动划分
  1027. item.selectTimeList.forEach(it => {
  1028. item.reserve_time_slot_price.push({
  1029. reserve_time: it.date,
  1030. price: item.price,
  1031. original_price: item.original_price,
  1032. cost_price: 0,
  1033. reserve_max_buy: item.reserve_max_buy,
  1034. time_spec: it.checkedIntervalList
  1035. });
  1036. });
  1037. }
  1038. }
  1039. if (item.reserve_price_type == 2) { // 按天设置价格
  1040. console.log('item.reserve_price_type == 2item.reserve_price_type == 2item.reserve_price_type == 2', item)
  1041. }
  1042. });
  1043. skus.forEach(item => {
  1044. // 0 统一,1 时间段,2 按天
  1045. if(item.reserve_price_type == 1){ // 时间段
  1046. item.reserve_time_slot_price.forEach(it => {
  1047. it.time_spec = it.time_spec.map(itc => {
  1048. _.setFormPrice(itc.price, 'price', 3)
  1049. _.setFormPrice(itc.linePrice, 'original_price', 3)
  1050. return {
  1051. spec_time: itc.time,
  1052. start: itc.time ? itc.time.split('-')[0] : '',
  1053. end: itc.time ? itc.time.split('-')[1] : '',
  1054. price: itc.price,
  1055. original_price: itc.linePrice,
  1056. cost_price: 0,
  1057. reserve_max_buy: itc.reservationNum,
  1058. checked: 1,
  1059. is_next: 0,
  1060. }
  1061. });
  1062. });
  1063. } else if(item.reserve_price_type == 2) { // 按天
  1064. item.reserve_time_slot_price = {}
  1065. item.finalData.forEach(it => {
  1066. _.setFormPrice(it.price, 'price', 2)
  1067. _.setFormPrice(it.linePrice, 'original_price', 2)
  1068. item.reserve_time_slot_price[it.date] = {
  1069. reserve_time: it.date,
  1070. price: it.price,
  1071. original_price: it.linePrice,
  1072. cost_price: 0,
  1073. reserve_max_buy: it.reservationNum,
  1074. }
  1075. });
  1076. }else{ // 统一
  1077. _.setFormPrice(item.price, 'price', 2)
  1078. _.setFormPrice(item.original_price, 'original_price', 2)
  1079. item.reserve_time_slot_price.forEach(it => {
  1080. // _.setFormPrice(it.price, 'price', 2)
  1081. // _.setFormPrice(it.linePrice, 'original_price', 2)
  1082. it.time_spec = it.time_spec.map(itc => {
  1083. return {
  1084. spec_time: itc,
  1085. start: itc.split('-')[0] || '',
  1086. end: itc.split('-')[1] || '',
  1087. price: it.price,
  1088. original_price: it.linePrice || item.original_price,
  1089. cost_price: 0,
  1090. reserve_max_buy: it.reservationNum || item.reserve_max_buy,
  1091. checked: 1,
  1092. is_next: 0,
  1093. }
  1094. });
  1095. });
  1096. }
  1097. });
  1098. this.ruleForm.reserve.skus = JSON.parse(JSON.stringify(skus));
  1099. }else{
  1100. this.ruleForm.reserve.reserve_time_slot_price = [];
  1101. let preList = [];
  1102. if(this.ruleForm.reserve.reserve_price_type == 1){
  1103. preList = this.$refs.priceSet && this.$refs.priceSet.selectedDates ? this.$refs.priceSet.selectedDates : [];
  1104. } else if (this.ruleForm.reserve.reserve_price_type == 2) { // 按天 - 有可能需要修改
  1105. preList = this.$refs.priceSet && this.$refs.priceSet.selectedDates ? this.$refs.priceSet.selectedDates : [];
  1106. }else{
  1107. preList = this.$refs.timeSelect && this.$refs.timeSelect.selectedDates ? this.$refs.timeSelect.selectedDates : [];
  1108. if(this.ruleForm.reserve.time_slot_type == 1){
  1109. preList.forEach(item => {
  1110. item.selectTimes = item.children
  1111. });
  1112. }
  1113. if(this.ruleForm.reserve.time_slot_type == 2){
  1114. preList.forEach(item => {
  1115. item.selectTimes = item.checkedIntervalList
  1116. });
  1117. }
  1118. }
  1119. if (this.ruleForm.reserve.reserve_price_type == 2) { // 按天
  1120. this.ruleForm.reserve.reserve_time_slot_price = {}
  1121. preList.forEach(item => {
  1122. _.setFormPrice(item.price, 'price', 1)
  1123. _.setFormPrice(item.linePrice, 'original_price', 1)
  1124. this.ruleForm.reserve.reserve_time_slot_price[item.date] = {
  1125. reserve_time: item.date,
  1126. price: item.price,
  1127. original_price: item.linePrice,
  1128. cost_price: 0,
  1129. reserve_max_buy: item.reservationNum,
  1130. }
  1131. });
  1132. } else { // 统一/时间段
  1133. preList.forEach(item => {
  1134. this.ruleForm.reserve.reserve_time_slot_price.push({
  1135. reserve_time: item.date,
  1136. price: this.ruleForm.price,
  1137. original_price: this.ruleForm.original_price,
  1138. cost_price: 0,
  1139. reserve_max_buy: this.ruleForm.reserve.reserve_max_buy,
  1140. time_spec: item.selectTimes
  1141. });
  1142. });
  1143. }
  1144. if(this.ruleForm.reserve.reserve_price_type == 1){ // 按时间段
  1145. this.ruleForm.reserve.reserve_time_slot_price.forEach(item => {
  1146. item.time_spec = item.time_spec.map(it => {
  1147. _.setFormPrice(it.price, 'price', 1)
  1148. _.setFormPrice(it.linePrice, 'original_price', 1)
  1149. return {
  1150. spec_time: it.time,
  1151. start: it.time ? it.time.split('-')[0] : '',
  1152. end: it.time ? it.time.split('-')[1] : '',
  1153. price: it.price,
  1154. original_price: it.linePrice,
  1155. cost_price: 0,
  1156. reserve_max_buy: it.reservationNum,
  1157. checked: 1,
  1158. is_next: 0,
  1159. }
  1160. });
  1161. });
  1162. } else if(this.ruleForm.reserve.reserve_price_type == 2){ // 按天
  1163. }else{ // 统一
  1164. this.ruleForm.reserve.reserve_time_slot_price.forEach(item => {
  1165. item.time_spec = item.time_spec.map(it => {
  1166. return {
  1167. spec_time: it,
  1168. start: it.split('-')[0] || '',
  1169. end: it.split('-')[1] || '',
  1170. price: this.ruleForm.price,
  1171. original_price: this.ruleForm.original_price,
  1172. cost_price: 0,
  1173. reserve_max_buy: this.ruleForm.reserve.reserve_max_buy,
  1174. checked: 1,
  1175. is_next: 0,
  1176. }
  1177. });
  1178. });
  1179. }
  1180. }
  1181. }
  1182. // console.log('submit ========: ', this.ruleForm, this.settingForm); return null;
  1183. if ('basic' == this.activeName || 'marketing' == this.activeName) {
  1184. this.$refs['ruleForm'].validate((valid) => {
  1185. if (valid) {
  1186. let self = this;
  1187. 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)) {
  1188. this.$message.error('每次限购数量不能小于起购数量');
  1189. return
  1190. }
  1191. 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)) {
  1192. this.$message.error('每天限购数量不能小于起购数量');
  1193. return
  1194. }
  1195. if (self.ruleForm.is_attr == 1) {
  1196. if (this.attrGroups.length == 0) {
  1197. this.$message.error('请完善规格组');
  1198. return
  1199. }
  1200. self.ruleForm.extra.member_price_setting = this.getMemberPrice(this.ruleForm.attr);
  1201. }
  1202. //把纯数字转字符
  1203. this.ruleForm.goods_name = this.ruleForm.goods_name + '';
  1204. this.ruleForm.subtitle = this.ruleForm.subtitle + '';
  1205. self.btnLoading = true;
  1206. // package-list 套餐内容
  1207. let packageList = {}
  1208. if (this.$refs['package']) {
  1209. packageList = {
  1210. package_data: this.$refs['package'].list
  1211. }
  1212. }
  1213. params = Object.assign(self.ruleForm, this.cForm, packageList)
  1214. request({
  1215. params: {
  1216. r: 'store/store-goods/edit'
  1217. },
  1218. method: 'post',
  1219. data: {
  1220. form: JSON.stringify(params),
  1221. }
  1222. }).then(e => {
  1223. self.btnLoading = false;
  1224. if (e.data.code == 0) {
  1225. self.$message.success(e.data.msg);
  1226. this.$navigate({
  1227. r: 'store/store-goods/index'
  1228. })
  1229. } else {
  1230. self.$message.error(e.data.msg);
  1231. }
  1232. }).catch(e => {
  1233. self.$message.error(e.data.msg);
  1234. self.btnLoading = false;
  1235. });
  1236. }
  1237. });
  1238. } else if ('mode' == this.activeName) {
  1239. this.commissionSettingSubmit();
  1240. }
  1241. },
  1242. //添加优惠券
  1243. add_coupon(e) {
  1244. this.ruleForm.coupon_selection = e;
  1245. },
  1246. //跳转新增优惠券界面
  1247. // handle_coupon() {
  1248. // this.$navigate({
  1249. // r: 'coupon/default/edit'
  1250. // })
  1251. // },
  1252. checkoutChange(it) {
  1253. console.log(it)
  1254. },
  1255. setFormPrice(price, key) {
  1256. if (this.ruleForm.is_attr == 1 && this.ruleForm.goods_type == 3) {
  1257. // 重新设置价格
  1258. if (price > 0) {
  1259. // this.$set(this.ruleForm, key, this.ruleForm[key] > 0 ? Math.min(this.ruleForm[key], price) : price)
  1260. // if (this.ruleForm[key] <= 0) this.$message.error("价格不能为0")
  1261. }
  1262. }
  1263. },
  1264. getFreight() { // 获取运费规则选项
  1265. let self = this;
  1266. request({
  1267. params: {
  1268. r: 'mall/postage-rules/all-list'
  1269. },
  1270. method: 'get',
  1271. data: {}
  1272. }).then(e => {
  1273. if (e.data.code == 0) {
  1274. self.freight.list = e.data.data.list;
  1275. // 添加商品时使用默认运费
  1276. self.freight.list.unshift({
  1277. id: 0,
  1278. name: '默认运费',
  1279. status: 1
  1280. })
  1281. console.log(self.freight.list)
  1282. } else {
  1283. self.$message.error(e.data.msg);
  1284. }
  1285. }).catch(e => {
  1286. console.log(e);
  1287. });
  1288. },
  1289. freightChange(e) {
  1290. console.log(e)
  1291. },
  1292. // 获取规格用户价
  1293. getMemberPrice(attr) {
  1294. let that = this;
  1295. let member_price_setting = {};
  1296. let levels = objectKeys(attr[0].member_price_setting);
  1297. levels.forEach(level => {
  1298. that.$set(member_price_setting, level, {});
  1299. });
  1300. attr.forEach((v) => {
  1301. let sign_id = v.sign_id;
  1302. for (const key in v.member_price_setting) {
  1303. member_price_setting[key][sign_id] = v.member_price_setting[key];
  1304. }
  1305. })
  1306. member_price_setting = member_price_setting;
  1307. return member_price_setting;
  1308. },
  1309. // 商品审核不通过
  1310. goodAuditFailed(type) {
  1311. this.$prompt('不通过原因', '审核', {
  1312. confirmButtonText: '确定',
  1313. cancelButtonText: '取消',
  1314. }).then(({
  1315. value
  1316. }) => {
  1317. if (!value) {
  1318. this.$message.error('驳回原因不能为空');
  1319. return false;
  1320. }
  1321. let self = this;
  1322. // self.btnLoading = true;
  1323. request({
  1324. params: {
  1325. r: 'store/store-goods/audit',
  1326. },
  1327. method: 'post',
  1328. data: {
  1329. goods_id: self.goodsId,
  1330. type: type,
  1331. check_remark: value,
  1332. },
  1333. }).then(e => {
  1334. if (e.data.code == 0) {
  1335. self.$message.success('操作成功');
  1336. setTimeout(function() {
  1337. navigateTo({
  1338. r: 'store/store-goods/index'
  1339. });
  1340. }, 300);
  1341. } else {
  1342. self.$message.error(e.data.msg);
  1343. }
  1344. }).catch(e => {
  1345. self.btnLoading = false;
  1346. self.$message.error('网络错误');
  1347. console.log(e);
  1348. });
  1349. }).catch(() => {
  1350. this.btnLoading = false;
  1351. console.log('取消驳回审核');
  1352. });
  1353. },
  1354. // 商品审核
  1355. goodAudit(adopt) {
  1356. let self = this;
  1357. request({
  1358. params: {
  1359. r: 'store/store-goods/audit',
  1360. },
  1361. method: 'post',
  1362. data: {
  1363. goods_id: self.goodsId,
  1364. type: adopt,
  1365. check_remark: '',
  1366. },
  1367. }).then(e => {
  1368. if (e.data.code == 0) {
  1369. self.$message.success('操作成功');
  1370. setTimeout(function() {
  1371. navigateTo({
  1372. r: 'store/store-goods/index'
  1373. });
  1374. }, 300);
  1375. } else {
  1376. self.$message.error(e.data.msg);
  1377. }
  1378. }).catch(e => {
  1379. self.btnLoading = false;
  1380. self.$message.error('网络错误');
  1381. console.log(e);
  1382. });
  1383. },
  1384. getModelDetail() {
  1385. let self = this;
  1386. self.cardLoading = true;
  1387. request({
  1388. params: {
  1389. r: 'store/store-goods/goods-model',
  1390. id: getQuery('id')
  1391. },
  1392. method: 'get',
  1393. }).then(e => {
  1394. // console.log(e, '===============');
  1395. self.cardLoading = false;
  1396. if (e.data.code == 0) {
  1397. if (e.data.data.detail) {
  1398. self.storeId = e.data.data.detail.store_id;
  1399. }
  1400. self.level = e.data.data.level;
  1401. if (!isEmpty(e.data.data.setting)) {
  1402. self.setting = e.data.data.setting;
  1403. for (let key in self.setting) {
  1404. // 将空的
  1405. if (isEmpty(self.setting[key])) self.setting[key] = {};
  1406. }
  1407. }
  1408. self.commission_type_map = e.data.data.commission_type_map;
  1409. self.coupon_type_map = e.data.data.coupon_type_map;
  1410. } else {
  1411. self.$message.error(e.data.msg);
  1412. }
  1413. }).catch(e => {
  1414. console.log(e);
  1415. });
  1416. },
  1417. commissionSettingSubmit() {
  1418. let self = this;
  1419. self.btnLoading = true;
  1420. self.settingForm.goods_id = getQuery('id');
  1421. self.settingForm.store_id = self.storeId;
  1422. params = Object.assign(self.settingForm, this.cForm);
  1423. request({
  1424. params: {
  1425. r: 'store/store-goods/goods-model'
  1426. },
  1427. method: 'post',
  1428. data: {
  1429. form: params
  1430. }
  1431. }).then(e => {
  1432. self.btnLoading = false;
  1433. if (e.data.code == 0) {
  1434. self.$message.success(e.data.msg);
  1435. } else {
  1436. self.$message.error(e.data.msg);
  1437. }
  1438. }).catch(e => {
  1439. self.$message.error(e.data.msg);
  1440. self.btnLoading = false;
  1441. });
  1442. },
  1443. getData(val, key) {
  1444. this.settingForm[key] = val;
  1445. },
  1446. /**
  1447. * 显示规格套餐
  1448. */
  1449. packageShow () {
  1450. return this.ruleForm.show_style == 2
  1451. },
  1452. /**
  1453. * 限制添加规格
  1454. */
  1455. attrLimit () {
  1456. return this.ruleForm.show_style == 2 ? 2 : 1
  1457. },
  1458. appendRepurchaseItem(){
  1459. item = {start: 0, end: 0, price: 0}
  1460. this.ruleForm.extra.repurchase_setting.push(item)
  1461. },
  1462. delRepurchaseItem(index){
  1463. this.ruleForm.extra.repurchase_setting.splice(index, 1);
  1464. },
  1465. setRepurchase(index, field, val){
  1466. item = this.ruleForm.extra.repurchase_setting[index]
  1467. item[field] = Number(val)
  1468. this.$set(this.ruleForm.extra.repurchase_setting, index, item)
  1469. },
  1470. addons_data_change(e) {
  1471. Object.assign(this.ruleForm.addons, e);
  1472. console.log(this.ruleForm.addons, '=======addons====');
  1473. // this.ruleForm.addons.coupon_selection = e;
  1474. },
  1475. upDownBatch(command) {
  1476. // 要复制的链接
  1477. const linkToCopy = this.store_login_url; // 直接从 #app 获取
  1478. this.$confirm(`<div class="title">O2O门店分类只能到门店后台进行操作添加,且门店后台与主商城不能使用同一浏览器</div><br>请复制下方链接使用别的浏览器进行登录<br><br><div>门店管理端登录入口链接:<br>${linkToCopy}</div>`, {
  1479. title: '警告',
  1480. customClass: 'custom-confirm-width',
  1481. dangerouslyUseHTMLString: true,
  1482. confirmButtonText: '复制去登录',
  1483. cancelButtonText: '取消',
  1484. type: 'warning',
  1485. }).then(() => {
  1486. // 用户点击"复制去登录"时执行复制
  1487. this.copyToClipboard(linkToCopy);
  1488. }).catch(() => {
  1489. // 用户点击"取消"什么都不做
  1490. });
  1491. },
  1492. copyToClipboard(text) {
  1493. if (navigator.clipboard) {
  1494. // 现代浏览器(Chrome/Firefox/Edge)
  1495. navigator.clipboard.writeText(text)
  1496. .then(() => {
  1497. this.$message.success('链接已复制!');
  1498. })
  1499. .catch((err) => {
  1500. console.error('复制失败:', err);
  1501. this.$message.error('复制失败,请手动复制');
  1502. });
  1503. } else {
  1504. // 兼容旧浏览器(如IE)
  1505. const textarea = document.createElement('textarea');
  1506. textarea.value = text;
  1507. document.body.appendChild(textarea);
  1508. textarea.select();
  1509. try {
  1510. document.execCommand('copy');
  1511. this.$message.success('链接已复制!');
  1512. } catch (err) {
  1513. console.error('复制失败:', err);
  1514. this.$message.error('复制失败,请手动复制');
  1515. }
  1516. document.body.removeChild(textarea);
  1517. }
  1518. }
  1519. }
  1520. });
  1521. </script>