edit.php 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874
  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-attachment', dirname(__DIR__));
  7. ComponentHelper::loadComponentView('component/com-attachment-edit', dirname(__DIR__));
  8. ComponentHelper::loadComponentView('component/com-upload', dirname(__DIR__));
  9. ComponentHelper::loadComponentView('com-rich-text');
  10. ComponentHelper::loadComponentView('com-district');
  11. ComponentHelper::loadComponentView('component/coupon-select', __DIR__);
  12. ComponentHelper::loadComponentView('component/com-package-attr', __DIR__);
  13. ComponentHelper::loadComponentView('component/com-time-select', __DIR__);
  14. ComponentHelper::loadComponentView('component/com-price-set', __DIR__);
  15. ComponentHelper::loadComponentView('component/com-price-day-set', __DIR__);
  16. ComponentHelper::loadComponentView('component/com-attrs-setting', __DIR__);
  17. ComponentHelper::loadComponentView('com-map');
  18. ComponentHelper::loadComponentView('com-dialog-select-store');
  19. if (!empty($components)) {
  20. foreach ($components as $addons => $component) {
  21. if(!file_exists($component['path'])) continue;
  22. ComponentHelper::loadComponentView($component['component'], $component['path']);
  23. }
  24. $components = \yii\helpers\Json::encode($components);
  25. }
  26. ?>
  27. <script src="/resources/js/Sortable.min.js"></script>
  28. <script src="/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
  29. <style>
  30. <?= ComponentHelper::loadComponentView('edit', __DIR__ . '/css', [], true, 'css'); ?>
  31. /* 商品轮播图样式 */
  32. .banner-images-container {
  33. width: 100%;
  34. padding: 10px 0;
  35. }
  36. .banner-images {
  37. display: grid;
  38. grid-template-columns: repeat(3, 80px);
  39. grid-gap: 10px;
  40. align-items: start;
  41. }
  42. .card-coverimg {
  43. position: relative;
  44. width: 80px;
  45. height: 80px;
  46. border-radius: 4px;
  47. }
  48. .delete-btn {
  49. position: absolute;
  50. top: -6px;
  51. right: -6px;
  52. width: 16px !important;
  53. height: 16px !important;
  54. padding: 0 !important;
  55. border: none !important;
  56. background-color: rgba(0, 0, 0, 0.6) !important;
  57. display: flex;
  58. align-items: center;
  59. justify-content: center;
  60. z-index: 1;
  61. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  62. }
  63. .delete-btn:hover {
  64. background-color: rgba(0, 0, 0, 0.8) !important;
  65. }
  66. .delete-btn i {
  67. font-size: 10px;
  68. color: #fff;
  69. margin: 0;
  70. line-height: 1;
  71. }
  72. .elImages {
  73. width: 100%;
  74. height: 100%;
  75. object-fit: cover;
  76. display: block;
  77. border-radius: 4px;
  78. }
  79. /* 上传按钮样式 */
  80. .card-upload {
  81. width: 80px;
  82. height: 80px;
  83. border: 1px dashed #d9d9d9;
  84. border-radius: 6px;
  85. cursor: pointer;
  86. position: relative;
  87. overflow: hidden;
  88. display: flex;
  89. align-items: center;
  90. justify-content: center;
  91. }
  92. .card-upload:hover {
  93. border-color: #409EFF;
  94. }
  95. .card-upload i {
  96. font-size: 28px;
  97. color: #8c939d;
  98. }
  99. </style>
  100. <div id="app" v-cloak>
  101. <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">
  102. <div slot="header">
  103. <div flex="cross:center box:first">
  104. <el-breadcrumb separator="/">
  105. <el-breadcrumb-item>
  106. <span style="color: #409EFF;cursor: pointer" @click="$navigate({r:'store/client/goods/index'})">商品列表</span>
  107. </el-breadcrumb-item>
  108. <el-breadcrumb-item>添加商品</el-breadcrumb-item>
  109. </el-breadcrumb>
  110. </div>
  111. </div>
  112. <div class="goods-box">
  113. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" size="mini" label-width="150px" class="demo-ruleForm">
  114. <!-- tab切换 -->
  115. <div class="tabs-box">
  116. <div class="tabs-list" flex="cross:center">
  117. <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>
  118. </div>
  119. </div>
  120. <!-- 基础设置 -->
  121. <div v-show="activeName == 'basic'">
  122. <?= ComponentHelper::loadComponentView('goods-basic', __DIR__) ?>
  123. </div>
  124. <!-- 营销配置 -->
  125. <div v-show="activeName == 'marketing'">
  126. <?= ComponentHelper::loadComponentView('goods-marketing', __DIR__) ?>
  127. </div>
  128. <!-- 会员权益 -->
  129. <div v-show="activeName == 'member_benefits'">
  130. <?= ComponentHelper::loadComponentView('goods-member', __DIR__) ?>
  131. </div>
  132. <!-- 关联商品 -->
  133. <div v-show="activeName == 'goods_association'">
  134. <?= ComponentHelper::loadComponentView('goods-association', __DIR__) ?>
  135. </div>
  136. </el-form>
  137. </div>
  138. </el-card>
  139. <div class="bottom-btns" flex="main:center cross:center">
  140. <el-button size="mini" type="primary" @click="submit()" :loading="btnLoading" v-if="supplier_type != 4">保存</el-button>
  141. </div>
  142. </div>
  143. <script>
  144. const app = new Vue({
  145. el: '#app',
  146. data() {
  147. return {
  148. default_goods_style1: "/resources/addons/store/img/default_goods_style1.png",
  149. default_goods_style2: "/resources/addons/store/img/default_goods_style2.png",
  150. storeConfig: {},
  151. tabs: [{
  152. name: '基础设置',
  153. value: 'basic'
  154. },
  155. {
  156. name: '营销配置',
  157. value: 'marketing'
  158. },
  159. {
  160. name: '会员权益',
  161. value: 'member_benefits'
  162. },
  163. {
  164. name: '关联商品',
  165. value: 'goods_association'
  166. },
  167. ],
  168. activeName: 'basic',
  169. typeArr: [],
  170. goods_type: 'physical',
  171. is_base_show: false,
  172. is_mch: false,
  173. is_default_services: 1,
  174. typeIndex: 0,
  175. btnLoading: false,
  176. cardLoading: false,
  177. cats: [],
  178. freight_id: 0,
  179. goodsId: null,
  180. storeId: 0,
  181. // freight: {
  182. // dialog: false,
  183. // list: [],
  184. // checked: {},
  185. // loading: false
  186. // },
  187. attrGroups: [], //规格组
  188. attrGroupName: '',
  189. attrName: [],
  190. // 批量设置
  191. batch: {},
  192. label_list: [], // 商品标签列表
  193. service_list: [], // 商品服务列表
  194. freight_rules: [ // 运费模板
  195. // {
  196. // id: '1',
  197. // name: '全国包邮'
  198. // },
  199. // {
  200. // id: '2',
  201. // name: '北京包邮'
  202. // }
  203. ],
  204. is_show_freight: false,
  205. defaultMemberPrice: [],
  206. member_level_list: [
  207. // {level: 1, name: '普通会员', value: {"sign_id_2:4":40, "sign_id_3:4": 41, "sign_id_2:5": 41, "sign_id_3:5": 41}},
  208. // {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}},
  209. // {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}},
  210. // {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}}
  211. ],
  212. dialogVisible: false, // 配送范围弹出框
  213. earaRule: [],
  214. multiple_selection: [], //优惠券
  215. is_show_counpon: 0, //优惠券是否展示
  216. show_addons: <?= $components ?? '{}'; ?>, //插件营销是否展示
  217. the_addons_name: 'Store',
  218. ruleForm: {
  219. /*********************************** 基础设置 ****************************************/
  220. goods_type: 1,
  221. goods_name: '',
  222. subtitle: '',
  223. cover_pic: '',
  224. bannar_pic: [],
  225. video_url: '',
  226. cats: [],
  227. mchCats: [], //多商户系统分类
  228. services: [],
  229. freight: null,
  230. labels: '', // 商品标签
  231. is_attr: 0, // 是否有规格
  232. attr_open: 0, // 是否开启商品规格的“无”
  233. attr: [],
  234. price: 0,
  235. original_price: 0,
  236. cost_price: 0,
  237. stock: '',
  238. unit: '', // 单位
  239. stock_warning: 0, // 库存预警 - 自定义字段,后面改
  240. goods_weight: 0, // 商品重量 - 自定义字段,后面改
  241. goods_no: '', // 商品货号
  242. is_show_stock: 1, // 是否显示库存 - 自定义字段,后面改
  243. is_show_sales: 1, // 是否显示销量 - 自定义字段,后面改
  244. virtual_sales: 0,
  245. coupon_is_enable: 0, //优惠卷的开关
  246. // logistics_way: [{
  247. // name: '快递发货',
  248. // checked: true
  249. // }], // 快递发货 - 自定义字段,后面改
  250. freight_type: [], //物流方式 1快递物流
  251. freight_rules_type: 1, // 运费规则类型 1运费模板 2统一运费
  252. freight_id: '', // 运费模板ID
  253. shipping_fee: 0, //统一运费
  254. free_shipping_num: 0, //满N件包邮
  255. free_shipping_money: 0, //满N元包邮
  256. is_cross_border: 0, // 是否跨境商品 - 自定义字段,后面改
  257. is_id_card: 0, // 是否身份证上传 - 自定义字段,后面改
  258. is_on_sale: 1, // 是否上架
  259. show_style: 1, // 展示风格
  260. extra: {
  261. full_reduce_price_limit: 0, // 单品满额减免价格阈值
  262. full_reduce_money: 0, // 单品满额减免金额
  263. score_give_setting: {
  264. is_alone:0,
  265. code: 'score',
  266. name: '积分',
  267. give_num: 0, // 货币赠送
  268. give_type: 1, // 货币赠送 1.固定值 2售价百分比
  269. condition: 0,
  270. settlement: 0,
  271. },
  272. is_member_price: 0,
  273. member_price_setting: {},
  274. member_buy_limit_setting: {
  275. member_level: [],
  276. every_num: 0,
  277. every_day_num: 0,
  278. every_week_num: 0,
  279. every_month_num: 0,
  280. nums: 0,
  281. total_num: 0,
  282. },
  283. currency_deduct_setting: [], // 货币这块有bug,暂时不需要展示,所以不需要提交数据
  284. // is_hidden_member_price: 0,
  285. member_price_switch: 0,
  286. is_show_price: 0,
  287. },
  288. coupon_selection: [],
  289. goods_setting: {
  290. /*********************************** 会员权益 **********************************************/
  291. member_setting: { // 会员权益模块提交的格式
  292. member_price_setting: '',
  293. member_price: {},
  294. member_buy_limit_setting: {
  295. member_level: [],
  296. every_num: 0,
  297. every_day_num: 0,
  298. every_week_num: 0,
  299. every_month_num: 0,
  300. nums: 0,
  301. total_num: 0,
  302. }
  303. },
  304. /*********************************** 营销设置 **********************************************/
  305. marketing_setting: { // 营销配置模块提交的格式
  306. full_reduce_price_limit: 0, // 单品满额减免价格阈值
  307. full_reduce_money: 0, // 单品满额减免金额
  308. score_give_setting: {
  309. code: 'score',
  310. name: '积分',
  311. give_num: 0, // 货币赠送
  312. give_type: 1, // 货币赠送 1.固定值 2售价百分比
  313. },
  314. score_deduct_setting: {
  315. code: 'score',
  316. name: '积分',
  317. deduct_num: 0, // 货币抵扣
  318. deduct_type: 1, // 1.单件抵扣 2.多件累计抵扣
  319. },
  320. currency_deduct_setting: [], // 货币这块有bug,暂时不需要展示,所以不需要提交数据
  321. }
  322. },
  323. /******************************* 配送范围 ************************************/
  324. is_area_limit: 0,
  325. // area_limit: [{ list: [] }]
  326. area_limit: [],
  327. coupon: {
  328. 'is_enable': 0,
  329. 'multiple_selection': [],
  330. },
  331. addons: {},
  332. // 预约商品
  333. reserve: {
  334. reserve_date_type: 1, // 可预约时间类型(1范围 2自选日期)
  335. reserve_date: null, // 可预约日期
  336. reserve_time_range_type: 1, //预约模式(1按天预约 2按时间段预约)
  337. time_slot_type: 1, // 时间段划分方式(1自定义划分 2自动划分)
  338. reserve_time_slot: null, // 时间段划分
  339. reserve_price_type: 0, // 价格设置方式(0统一售价 1按日期时间段设置)
  340. reserve_time_slot_price: [], // 按时间段设置的价格
  341. reserve_week: [0,1,2,3,4,5,6], // 可预约周,如:0,1,2,3,4,5,6
  342. reserve_max_buy: 0, // 每天最大预约数量
  343. reserve_advance_hourse: 0, // 提前预约时间(小时)
  344. reserve_days_range: 0, //限制选择并购买的时间在设置内天数的商品
  345. cancel_type: 1, // 取消类型(1不允许取消 2服务开始前取消 3订单类型取消)
  346. cancel_rule: {
  347. cancel_hour: 0,
  348. cancel_fee_percent: 0
  349. }, // 取消规则
  350. expired_handle_type: 1, // 预约码过期后处理方式(1不退款 2自动退款)
  351. service_type: 1, // 服务方式(1上门 2到店)
  352. // 位置信息
  353. province_id: 0, // 省份Id
  354. city_id: 0, // 城市Id
  355. district_id: 0, // 区县Id
  356. detail: '', // 详细地址
  357. lat: '', // 纬度
  358. lng: '', // 经度
  359. skus: [], // 预约多规格
  360. ordering_information: '', // 订购须知
  361. information_detail: '', // 须知详情
  362. reserve_type: 1, // 门店只能是1
  363. distance: '', // 有效距离
  364. appointments_number: '', // 有效距离
  365. },
  366. },
  367. rules: {
  368. cats: [{
  369. required: true,
  370. type: 'array',
  371. validator: (rule, value, callback) => {
  372. if (this.ruleForm.cats instanceof Array && this.ruleForm.cats.length > 0) {
  373. callback();
  374. }
  375. callback('请选择分类');
  376. }
  377. }],
  378. mchCats: [{
  379. required: true,
  380. type: 'array',
  381. validator: (rule, value, callback) => {
  382. if (this.ruleForm.mchCats instanceof Array && this.ruleForm.mchCats.length > 0) {
  383. callback();
  384. }
  385. callback('请选择系统分类');
  386. }
  387. }],
  388. goods_name: [{
  389. required: true,
  390. message: '请输入商品名称',
  391. trigger: 'blur'
  392. }],
  393. cover_pic: [{
  394. required: true,
  395. message: '请添加图片',
  396. trigger: 'change'
  397. }],
  398. price: [{
  399. required: true,
  400. message: '请输入价格',
  401. trigger: 'blur'
  402. }],
  403. extra: {
  404. full_reduce_price_limit: [{
  405. validator: (rule, value, callback) => {
  406. if (value > 1000000) {
  407. callback('不能大于1000000');
  408. }
  409. callback();
  410. }
  411. }],
  412. full_reduce_money: [{
  413. validator: (rule, value, callback) => {
  414. if (value > 1000000) {
  415. callback('不能大于1000000');
  416. }
  417. callback();
  418. }
  419. }]
  420. },
  421. stock: [{
  422. required: true,
  423. message: '请输入商品库存',
  424. trigger: 'blur'
  425. }],
  426. // area_limit: [{
  427. // required: true,
  428. // type: 'array',
  429. // validator: (rule, value, callback) => {
  430. // if (value instanceof Array && value[0]['list'].length === 0) {
  431. // callback('允许购买区域不能为空');
  432. // }
  433. // callback();
  434. // }
  435. // }],
  436. reserve: {
  437. service_min: [
  438. {
  439. required: true,
  440. message: '请输入项目时间',
  441. trigger: 'blur'
  442. }
  443. ]
  444. }
  445. },
  446. revealArea: [],
  447. extra1_goods_list:[],
  448. extra2_goods_list:[],
  449. extra_goods_url: 'store/client/goods/search',
  450. extra_goods_params:[],
  451. couponLoading: false,
  452. package_data: [],
  453. dayArr: [], //预约商品
  454. checkWeekList: [], //预约商品
  455. checkRangeList: [], //预约商品
  456. provinces: {}, //预约商品
  457. provinceInfo: {}, //预约商品
  458. citys: {}, //预约商品
  459. cityInfo: {}, //预约商品
  460. districts: {}, //预约商品
  461. districtInfo: {}, //预约商品
  462. long_lat: '', // 经纬度
  463. initializationDates: [], // 编辑商品时格式化传进来的数据
  464. isEdit: false, // 预约商品,
  465. is_reserve_type: <?= $is_reserve_type ?>,
  466. score_give_is_store_alone:false,
  467. supplier_type: 0,
  468. };
  469. },
  470. created() {
  471. // 给预约商品一个默认类型
  472. this.ruleForm.reserve.reserve_type = this.is_reserve_type == 2 || this.is_reserve_type == 0 ? 0 : 1
  473. this.ruleForm.reserve.reserve_type = 1
  474. this.goodsId = getQuery('id');
  475. this.extra_goods_params['goods_id'] = this.goodsId;
  476. },
  477. async mounted() {
  478. // 默认为中国,所以默认上级ID为1
  479. await this.loadData(1)
  480. this.getGoodsDetail()
  481. this.changeFreightType()
  482. this.getStoreConfig()
  483. },
  484. watch: {
  485. 'ruleForm.detail'(newVal, oldVal) {
  486. this.cForm.detail = newVal
  487. },
  488. 'ruleForm.show_style'(newVal, oldVal) {
  489. if (newVal != oldVal) {
  490. if (newVal == 2){
  491. this.ruleForm.attr_open = 1
  492. }else{
  493. this.ruleForm.attr_open = 0
  494. }
  495. // this.attrGroups = []
  496. // this.ruleForm.attr = []
  497. }
  498. if (newVal == 2) {
  499. this.ruleForm.is_attr = 1
  500. }
  501. }
  502. },
  503. computed: {
  504. cForm() {
  505. let form = {};
  506. let ruleForm = JSON.parse(JSON.stringify(this.ruleForm));
  507. if (this.form) {
  508. form = Object.assign(ruleForm, JSON.parse(JSON.stringify(this.form)));
  509. } else {
  510. form = ruleForm;
  511. }
  512. if (getQuery('id')) {
  513. form.id = getQuery('id')
  514. }
  515. return form;
  516. },
  517. cRule() {
  518. return this.rule ? Object.assign({}, this.rules, this.rule) : this.rules;
  519. },
  520. },
  521. methods: {
  522. changeFreightType() {
  523. this.is_show_freight = inArray(1, this.ruleForm.freight_type);
  524. },
  525. getGoodsDetail() {
  526. let self = this;
  527. self.cardLoading = true;
  528. request({
  529. params: {
  530. r: 'store/client/goods/edit',
  531. id: getQuery('id')
  532. },
  533. method: 'get',
  534. }).then(e => {
  535. self.cardLoading = false;
  536. if (e.data.code == 0) {
  537. if(e.data.data.score_give_is_store_alone==0){
  538. this.score_give_is_store_alone = true;
  539. }
  540. if (!isEmpty(e.data.data.detail)) {
  541. if(e.data.data.detail.goods_type && e.data.data.detail.goods_type == 3){
  542. self.isEdit = true;
  543. self.ruleForm = JSON.parse(JSON.stringify(e.data.data.detail));
  544. self.long_lat = self.ruleForm.reserve.lat + '-' + self.ruleForm.reserve.lng;
  545. self.getReservePlace();
  546. if(!(self.ruleForm.reserve && self.ruleForm.reserve.cancel_rule)){
  547. self.ruleForm.reserve.cancel_rule = {
  548. cancel_hour: 0,
  549. cancel_fee_percent: 0
  550. }
  551. }
  552. if(this.ruleForm.is_attr == 1){
  553. if(self.ruleForm.reserve && self.ruleForm.reserve.skus && self.ruleForm.reserve.skus.length){
  554. self.ruleForm.attr = [];
  555. let receiveList = self.ruleForm.reserve.skus;
  556. receiveList.forEach(item => {
  557. item.checkRangeList = [];
  558. item.dayArr = [];
  559. item.checkWeekList = [];
  560. item.selectTimeList = [];
  561. item.finalData = [];
  562. if(item.reserve_date_type == 1 && this.ruleForm.reserve.reserve_type == 0){
  563. item.reserve_date.sort(function (a, b) {
  564. return new Date(a) - new Date(b);
  565. });
  566. item.checkRangeList.push(item.reserve_date[0],item.reserve_date[item.reserve_date.length-1]);
  567. let val = [new Date(item.checkRangeList[0]),new Date(item.checkRangeList[1])];
  568. let arr = [];
  569. 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: []}];
  570. if (val.length) {
  571. let arr1 = [];
  572. let str1 = val[0];
  573. let str2 = val[1];
  574. let unixDb = str1.getTime() - 24 * 60 * 60 * 1000;
  575. let unixDe = str2.getTime() - 24 * 60 * 60 * 1000;
  576. for(let j = unixDb; j <= unixDe;){
  577. j = j + 24 * 60 * 60 * 1000
  578. arr1.push(new Date(parseInt(j)))
  579. }
  580. for(let i = 0; i < arr1.length; i++){
  581. txtArr.forEach(it => {
  582. if(it.val == arr1[i].getDay()){
  583. let fm = this.formatDate(arr1[i])
  584. it.children.push(fm);
  585. }
  586. })
  587. }
  588. txtArr.forEach(it => {
  589. if(it.children.length){
  590. arr.push(it);
  591. }
  592. });
  593. item.dayArr = arr;
  594. }
  595. let warr = [];
  596. item.dayArr.forEach(it => {
  597. warr.push(it.txt);
  598. });
  599. item.checkWeekList = [...new Set(warr)];
  600. let selectArr = [];
  601. let selectDateArr = [];
  602. for(let i = 0; i < item.dayArr.length; i++){
  603. item.checkWeekList.forEach(it => {
  604. if(it == item.dayArr[i].txt){
  605. selectArr.push(item.dayArr[i]);
  606. }
  607. });
  608. }
  609. for(let j = 0; j < selectArr.length; j++){
  610. selectDateArr = selectDateArr.concat(selectArr[j].children);
  611. }
  612. item.reserve_date = selectDateArr;
  613. }
  614. if(item.reserve_time_slot_price && item.reserve_time_slot_price.length){
  615. item.reserve_time_slot_price.forEach(it => {
  616. item.finalData.push({
  617. date: it.reserve_time,
  618. time_spec: it.time_spec,
  619. isSelect: false,
  620. times: [],
  621. selectTimes: []
  622. });
  623. item.selectTimeList.push({
  624. date: it.reserve_time,
  625. isSelect: false,
  626. children: [],
  627. intervalList: [],
  628. checkAll: false,
  629. isIndeterminate: true,
  630. checkedIntervalList: [],
  631. time_spec: it.time_spec,
  632. });
  633. });
  634. } else if (item.reserve_price_type == 2 && typeof item.reserve_time_slot_price == "object") { // 按天设置价格
  635. for (let day in item.reserve_time_slot_price) {
  636. item.finalData.push({
  637. date: day,
  638. price: item.reserve_time_slot_price[day].price || 0,
  639. linePrice: item.reserve_time_slot_price[day].original_price || 0,
  640. reservationNum: item.reserve_time_slot_price[day].reserve_max_buy || 0,
  641. children: item.reserve_time_slot_price[day].children || [],
  642. times: item.reserve_time_slot_price[day].times || []
  643. })
  644. }
  645. }
  646. item.finalData.forEach(ite => {
  647. if(ite.time_spec.length){
  648. ite.time_spec.forEach(it => {
  649. ite.times.push(it.spec_time);
  650. ite.selectTimes.push({
  651. time: it.spec_time,
  652. price: it.price,
  653. linePrice: it.original_price,
  654. reservationNum: it.reserve_max_buy
  655. });
  656. });
  657. }
  658. });
  659. item.selectTimeList.forEach(ite => {
  660. if(ite.time_spec.length){
  661. ite.time_spec.forEach(it => {
  662. ite.children.push(it.spec_time);
  663. });
  664. }
  665. });
  666. });
  667. let targetArr = [];
  668. receiveList.forEach(item => {
  669. targetArr.push({
  670. attr_list: item.attr_list || [],
  671. reserve_date_type: item.reserve_date_type || 1,
  672. reserve_date: item.reserve_date || [],
  673. reserve_time_range_type: item.reserve_time_range_type || 1,
  674. time_slot_type: item.time_slot_type || 1,
  675. reserve_time_slot: item.reserve_time_slot || null,
  676. reserve_price_type: item.reserve_price_type || 0,
  677. reserve_time_slot_price: JSON.parse(JSON.stringify(item.reserve_time_slot_price)) || null,
  678. reserve_week: JSON.parse(JSON.stringify(item.reserve_week)) || [0,1,2,3,4,5,6],
  679. reserve_max_buy: item.reserve_max_buy || null,
  680. price: item.price || null,
  681. original_price: item.original_price || null,
  682. dayArr: item.dayArr || [],
  683. checkWeekList: item.checkWeekList || [],
  684. checkRangeList: item.checkRangeList || [],
  685. selectTimeList: JSON.parse(JSON.stringify(item.selectTimeList)) || [],
  686. finalData: item.finalData || [],
  687. service_min: item.service_min || 0,
  688. unit: item.unit || '',
  689. });
  690. });
  691. targetArr.forEach(item => {
  692. item.selectTimeList.forEach(it => {
  693. it.children = JSON.stringify(it.children);
  694. it.time_spec = JSON.stringify(it.time_spec);
  695. });
  696. });
  697. targetArr.forEach(item => {
  698. let obj = {
  699. attr_list: JSON.parse(JSON.stringify(item.attr_list)),
  700. reserve_date_type: item.reserve_date_type,
  701. reserve_date: JSON.parse(JSON.stringify(item.reserve_date)),
  702. reserve_time_range_type: item.reserve_time_range_type,
  703. time_slot_type: item.time_slot_type,
  704. reserve_time_slot: item.reserve_time_slot,
  705. reserve_price_type: item.reserve_price_type,
  706. reserve_time_slot_price: JSON.parse(JSON.stringify(item.reserve_time_slot_price)),
  707. reserve_week: JSON.parse(JSON.stringify(item.reserve_week)),
  708. reserve_max_buy: item.reserve_max_buy,
  709. price: item.price,
  710. original_price: item.original_price,
  711. dayArr: JSON.parse(JSON.stringify(item.dayArr)),
  712. checkWeekList: JSON.parse(JSON.stringify(item.checkWeekList)),
  713. checkRangeList: JSON.parse(JSON.stringify(item.checkRangeList)),
  714. selectTimeList: JSON.parse(JSON.stringify(item.selectTimeList)),
  715. finalData: JSON.parse(JSON.stringify(item.finalData)),
  716. service_min: item.service_min || 0,
  717. unit: item.unit || '',
  718. }
  719. self.ruleForm.attr.push(JSON.stringify(obj));
  720. });
  721. for(let i = 0; i < self.ruleForm.attr.length; i++){
  722. self.ruleForm.attr[i] = JSON.parse(self.ruleForm.attr[i]);
  723. }
  724. self.ruleForm.attr.forEach(item => {
  725. item.selectTimeList.forEach(it => {
  726. it.children = JSON.parse(it.children);
  727. it.time_spec = JSON.parse(it.time_spec);
  728. });
  729. });
  730. console.log('self.ruleForm.attr',self.ruleForm.attr);
  731. }
  732. }else{
  733. if(self.ruleForm.reserve && self.ruleForm.reserve.reserve_date && self.ruleForm.reserve.reserve_date.length){
  734. if(self.ruleForm.reserve.reserve_date_type == 1){
  735. self.ruleForm.reserve.reserve_date.sort(function (a, b) {
  736. return new Date(a) - new Date(b);
  737. });
  738. self.checkRangeList.push(self.ruleForm.reserve.reserve_date[0],self.ruleForm.reserve.reserve_date[self.ruleForm.reserve.reserve_date.length-1]);
  739. this.dateSelectChange([new Date(self.checkRangeList[0]),new Date(self.checkRangeList[1])]);
  740. }
  741. self.ruleForm.reserve.reserve_time_slot_price.forEach(item => {
  742. self.initializationDates.push({
  743. date: item.reserve_time,
  744. time_spec: item.time_spec,
  745. isSelect: false,
  746. times: [],
  747. selectTimes: []
  748. });
  749. });
  750. self.initializationDates.forEach(item => {
  751. if(item.time_spec.length){
  752. item.time_spec.forEach(it => {
  753. item.times.push(it.spec_time);
  754. item.selectTimes.push({
  755. time: it.spec_time,
  756. price: it.price,
  757. linePrice: it.original_price,
  758. reservationNum: it.reserve_max_buy
  759. });
  760. });
  761. }
  762. });
  763. }
  764. }
  765. }else{
  766. self.ruleForm = Object.assign(self.ruleForm, e.data.data.detail);
  767. self.ruleForm.attr = e.data.data.detail.attr;
  768. }
  769. self.attrGroups = e.data.data.detail.attr_groups;
  770. self.storeId = e.data.data.detail.store_id;
  771. self.typeArr = e.data.data.goods_type;
  772. console.info(self.ruleForm);
  773. self.selectCat(e.data.data.detail.cats)
  774. self.cats = e.data.data.detail.cats;
  775. for (let key in e.data.data.detail.freight_type) {
  776. if (e.data.data.detail.freight_type[key] == 1) {
  777. this.is_show_freight = true;
  778. break;
  779. }
  780. }
  781. if (self.ruleForm.area_limit) {
  782. self.deduplicationArea();
  783. }
  784. this.supplier_type = e.data.data.detail.supplier_type;
  785. }
  786. self.label_list = e.data.data.labels;
  787. self.service_list = e.data.data.services;
  788. self.member_level_list = e.data.data.levels;
  789. // 以下数据用于默认规格情况下的 会员价设置
  790. if (!e.data.data.detail.is_attr && e.data.data.detail.is_attr != 0) {
  791. self.member_level_list.forEach((item, index) => {
  792. let obj = {};
  793. obj['id'] = index;
  794. obj['name'] = item.name;
  795. obj['level'] = 'level' + parseInt(item.level);
  796. var key = item.level + '';
  797. self.$set(this.ruleForm.extra.member_price_setting, key, 0);
  798. });
  799. }
  800. // 以下数据用于默认规格情况下的 会员价设置
  801. var memberSetting = e.data.data.detail.extra;
  802. self.member_level_list.forEach(function(item, index) {
  803. let obj = {};
  804. let key = 'level' + parseInt(item.level);
  805. obj['id'] = index;
  806. obj['name'] = item.name;
  807. obj['level'] = key;
  808. if (memberSetting && memberSetting.member_price_setting && memberSetting.member_price_setting[key]) {
  809. self.member_level_list[index]['value'] = memberSetting.member_price_setting[key]; // 赋值到会员列表数据中
  810. } else {
  811. self.member_level_list[index]['value'] = {};
  812. }
  813. self.defaultMemberPrice.push(obj);
  814. });
  815. self.freight_rules = e.data.data.freight_rules;
  816. // 默认运费模板
  817. if (self.ruleForm.freight_rules_type == 1 && isEmpty(self.ruleForm.freight_id) && self.freight_rules.length > 0) {
  818. self.ruleForm.freight_id = self.freight_rules[0].id;
  819. }
  820. this.extra1_goods_list = e.data.data.extra1_goods_list;
  821. this.extra2_goods_list = e.data.data.extra2_goods_list;
  822. self.ruleForm.show_style = self.ruleForm.show_style.toString();
  823. // 套餐数据
  824. self.package_data = e.data.data.detail.package_data
  825. } else {
  826. self.$message.error(e.data.msg);
  827. }
  828. }).catch(e => {
  829. console.log(e);
  830. });
  831. },
  832. /* 配送范围start */
  833. openDistrict() {
  834. this.dialogVisible = true;
  835. this.earaRule = this.ruleForm.area_limit;
  836. },
  837. selectDistrict(e) {
  838. let list = [];
  839. for (let i in e) {
  840. let obj = {
  841. id: e[i].id,
  842. name: e[i].name
  843. };
  844. list.push(obj);
  845. }
  846. this.earaRule = list;
  847. },
  848. districtConfirm() {
  849. this.ruleForm.area_limit = JSON.parse(JSON.stringify(this.earaRule));
  850. this.deduplicationArea();
  851. this.dialogVisible = false;
  852. // this.$refs['ruleForm'].validate((valid) => {
  853. // return false;
  854. // })
  855. },
  856. deduplicationArea() {
  857. let that = this;
  858. let reg = /市$|特别行政区$/;
  859. let filt = [...new Set(this.ruleForm.area_limit.filter(v => reg.test(v.name)).map(v => v.name))];
  860. this.ruleForm.area_limit.forEach(v => {
  861. let length = that.revealArea.filter(f => f.name == v.name).length;
  862. if (filt.findIndex(f => f == v.name) != -1 && length > 0) {
  863. return;
  864. }
  865. that.revealArea.push(v);
  866. })
  867. },
  868. space() { // 删除地区
  869. this.ruleForm.area_limit = [];
  870. },
  871. /* 配送范围end */
  872. showMore(type) { // 展开更多
  873. switch (type) {
  874. case 'base':
  875. this.is_base_show = !this.is_base_show
  876. }
  877. },
  878. toggle(it, i, type) { // tab切换
  879. switch (type) {
  880. case 'tabs':
  881. this.activeName = it.value
  882. break;
  883. case 'select':
  884. if (this.ruleForm.id > 0) return;
  885. this.ruleForm.goods_type = it.type
  886. if(this.ruleForm.goods_type == 2){
  887. this.ruleForm.freight_type = [];
  888. this.ruleForm.freight_rules_type = 0;
  889. }else if(this.ruleForm.goods_type == 1){
  890. this.ruleForm.freight_type = [1];
  891. this.ruleForm.freight_rules_type = 1;
  892. }
  893. break;
  894. default:
  895. break;
  896. }
  897. },
  898. coverPic(e) { // 选择图片
  899. this.ruleForm.cover_pic = e[0].url
  900. },
  901. bannerPic(e) { // 选择轮播图
  902. if (e.length) {
  903. e.forEach((item, index) => {
  904. if (this.ruleForm.bannar_pic.length >= 9) return;
  905. this.ruleForm.bannar_pic.push({
  906. id: item.id,
  907. pic_url: item.url
  908. });
  909. })
  910. }
  911. },
  912. delPic(type, index) { // 删除图片
  913. switch (type) {
  914. case 'cover_pic':
  915. this.ruleForm.cover_pic = ''
  916. break;
  917. case 'bannar_pic':
  918. this.ruleForm.bannar_pic.splice(index, 1)
  919. break;
  920. default:
  921. break;
  922. }
  923. },
  924. // 商品视频
  925. videoUrl(e) {
  926. if (e.length) {
  927. this.ruleForm.video_url = e[0].url;
  928. }
  929. },
  930. /*---商品分类----*/
  931. selectCat(cats) {
  932. this.cats = cats;
  933. let arr = [];
  934. cats.map(v => {
  935. arr.push(v.id);
  936. })
  937. this.ruleForm.cats = arr;
  938. this.$refs.ruleForm.validateField('cats');
  939. },
  940. selectMchCat(cats) {
  941. this.mchCats = cats;
  942. let arr = [];
  943. cats.map(v => {
  944. arr.push(v.id);
  945. })
  946. this.ruleForm.mchCats = arr;
  947. this.$refs.ruleForm.validateField('mchCats');
  948. },
  949. /*---商品分类end----*/
  950. /*----规格start----*/
  951. // 规格组合
  952. makeAttrGroup(e) {
  953. let self = this;
  954. let array = [];
  955. self.attrGroups.forEach(function(attrGroupItem, attrGroupIndex) {
  956. attrGroupItem.attr_list.forEach(function(attrListItem, attrListIndex) {
  957. let object = {
  958. attr_group_id: attrGroupItem.attr_group_id,
  959. attr_group_name: attrGroupItem.attr_group_name,
  960. attr_id: attrListItem.attr_id,
  961. attr_name: attrListItem.attr_name,
  962. };
  963. if (!array[attrGroupIndex]) {
  964. array[attrGroupIndex] = [];
  965. }
  966. array[attrGroupIndex].push(object)
  967. });
  968. });
  969. // 2.属性排列组合
  970. const res = array.reduce((osResult, options) => {
  971. return options.reduce((oResult, option) => {
  972. if (!osResult.length) {
  973. return oResult.concat(option)
  974. } else {
  975. return oResult.concat(osResult.map(o => [].concat(o, option)))
  976. }
  977. }, [])
  978. }, []);
  979. // 3.组合结果赋值
  980. for (let i in res) {
  981. const options = Array.isArray(res[i]) ? res[i] : [res[i]];
  982. const row = {
  983. attr_list: options,
  984. stock: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].stock,
  985. price: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].price,
  986. original_price: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].original_price,
  987. cost_price: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].cost_price,
  988. no: typeof(self.ruleForm.attr[i]) == 'undefined' ? '' : self.ruleForm.attr[i].no,
  989. weight: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].weight,
  990. pic_url: typeof(self.ruleForm.attr[i]) == 'undefined' ? '' : self.ruleForm.attr[i].pic_url,
  991. distributionLevelList: [],
  992. levelPrice: typeof(self.ruleForm.attr[i]) == 'undefined' ? {} : self.ruleForm.attr[i].levelPrice,
  993. sign_id: typeof(self.ruleForm.attr[i]) == 'undefined' ? '' : self.ruleForm.attr[i].sign_id,
  994. reserve_max_buy: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].reserve_max_buy,
  995. reserve_date_type: typeof(self.ruleForm.attr[i]) == 'undefined' ? 1 : self.ruleForm.attr[i].reserve_date_type,
  996. reserve_date: typeof(self.ruleForm.attr[i]) == 'undefined' ? null : self.ruleForm.attr[i].reserve_date,
  997. reserve_time_range_type: typeof(self.ruleForm.attr[i]) == 'undefined' ? 1 : self.ruleForm.attr[i].reserve_time_range_type,
  998. time_slot_type: typeof(self.ruleForm.attr[i]) == 'undefined' ? 1 : self.ruleForm.attr[i].time_slot_type,
  999. reserve_time_slot: typeof(self.ruleForm.attr[i]) == 'undefined' ? null : self.ruleForm.attr[i].reserve_time_slot,
  1000. reserve_price_type: typeof(self.ruleForm.attr[i]) == 'undefined' ? 0 : self.ruleForm.attr[i].reserve_price_type,
  1001. reserve_time_slot_price: typeof(self.ruleForm.attr[i]) == 'undefined' ? null : self.ruleForm.attr[i].reserve_time_slot_price,
  1002. reserve_week: typeof(self.ruleForm.attr[i]) == 'undefined' ? [0,1,2,3,4,5,6] : self.ruleForm.attr[i].reserve_week,
  1003. dayArr: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].dayArr,
  1004. checkWeekList: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].checkWeekList,
  1005. checkRangeList: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].checkRangeList,
  1006. selectTimeList: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].selectTimeList,
  1007. finalData: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].finalData,
  1008. service_min: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].service_min,
  1009. unit: typeof(self.ruleForm.attr[i]) == 'undefined' ? [] : self.ruleForm.attr[i].unit,
  1010. };
  1011. let arr = [];
  1012. row.attr_list.forEach(val => {
  1013. arr.push(val.attr_id);
  1014. })
  1015. // console.info(arr.join(":"),"::::");
  1016. row.sign_id = arr.join(":");
  1017. // 动态绑定多规格会员价
  1018. let obj = {};
  1019. self.member_level_list.forEach(function(item, index) {
  1020. let key = 'level' + item.level;
  1021. obj[key] = 0;
  1022. });
  1023. row['member_price'] = obj;
  1024. // 3-1.已设置数据的优先使用原数据
  1025. if (self.ruleForm.attr.length) {
  1026. for (let j in self.ruleForm.attr) {
  1027. const oldOptions = [];
  1028. for (let k in self.ruleForm.attr[j].attr_list) {
  1029. oldOptions.push(self.ruleForm.attr[j].attr_list[k].attr_name)
  1030. }
  1031. const newOptions = [];
  1032. for (let k in options) {
  1033. newOptions.push(options[k].attr_name)
  1034. }
  1035. if (oldOptions.toString() === newOptions.toString()) {
  1036. row['price'] = self.ruleForm.attr[j].price;
  1037. row['stock'] = self.ruleForm.attr[j].stock;
  1038. row['no'] = self.ruleForm.attr[j].no;
  1039. row['weight'] = self.ruleForm.attr[j].weight;
  1040. row['pic_url'] = self.ruleForm.attr[j].pic_url;
  1041. break
  1042. }
  1043. }
  1044. }
  1045. res[i] = row;
  1046. }
  1047. self.ruleForm.attr = res;
  1048. self.ruleForm.attr_groups = JSON.parse(JSON.stringify(self.attrGroups));
  1049. console.log(self.ruleForm.attr, '-------------------------------attr');
  1050. },
  1051. // 批量设置
  1052. batchAttr(key) {
  1053. let self = this;
  1054. if (self.batch[key] && self.batch[key] >= 0 || key === 'no') {
  1055. self.ruleForm.attr.forEach(function(item, index) {
  1056. // 批量设置会员价
  1057. // 判断字符串是否出现过,并返回位置
  1058. if (key.indexOf('level') !== -1) {
  1059. item['member_price'][key] = self.batch[key];
  1060. } else {
  1061. item[key] = self.batch[key];
  1062. }
  1063. });
  1064. }
  1065. },
  1066. destroyCat(value) {
  1067. this.cats = this.cats.filter(function(item) {
  1068. return value.id !== item.id
  1069. });
  1070. this.ruleForm.cats = this.cats.map(function(item) {
  1071. return item.id;
  1072. })
  1073. },
  1074. /*----规格end----*/
  1075. submit() {
  1076. if(this.ruleForm.cats.length && (typeof this.ruleForm.cats[0]) !== 'number'){
  1077. let idarr = [];
  1078. this.ruleForm.cats.forEach(item => {
  1079. idarr.push(item.id);
  1080. });
  1081. this.ruleForm.cats = JSON.parse(JSON.stringify(idarr));
  1082. }
  1083. let _ = this
  1084. if(this.ruleForm.goods_type == 3){
  1085. if(this.ruleForm.is_attr == 1){
  1086. let skus = [];
  1087. this.ruleForm.attr.forEach(item => {
  1088. skus.push({
  1089. attr_list: JSON.parse(JSON.stringify(item.attr_list)),
  1090. reserve_date_type: item.reserve_date_type,
  1091. reserve_date: item.reserve_date,
  1092. reserve_time_range_type: item.reserve_time_range_type,
  1093. time_slot_type: item.time_slot_type,
  1094. reserve_price_type: item.reserve_price_type,
  1095. reserve_max_buy: item.reserve_max_buy,
  1096. price: item.price,
  1097. original_price: item.original_price,
  1098. reserve_time_slot: item.reserve_time_slot,
  1099. reserve_time_slot_price: [],
  1100. reserve_week: item.reserve_week,
  1101. service_min: item.service_min,
  1102. unit: item.unit,
  1103. finalData: JSON.parse(JSON.stringify(item.finalData)),
  1104. selectTimeList: JSON.parse(JSON.stringify(item.selectTimeList))
  1105. });
  1106. });
  1107. skus.forEach(item => {
  1108. if(item.reserve_price_type == 1 && item.finalData && item.finalData.length){
  1109. item.finalData.forEach(it => {
  1110. item.reserve_time_slot_price.push({
  1111. reserve_time: it.date,
  1112. price: it.selectTimes[0].price,
  1113. original_price: it.selectTimes[0].linePrice,
  1114. cost_price: 0,
  1115. reserve_max_buy: it.selectTimes[0].reservationNum,
  1116. time_spec: it.selectTimes
  1117. });
  1118. });
  1119. }
  1120. if(item.reserve_price_type == 0 && item.selectTimeList && item.selectTimeList.length){
  1121. if(item.time_slot_type == 1){
  1122. item.selectTimeList.forEach(it => {
  1123. item.reserve_time_slot_price.push({
  1124. reserve_time: it.date,
  1125. price: item.price,
  1126. original_price: item.original_price,
  1127. cost_price: 0,
  1128. reserve_max_buy: item.reserve_max_buy,
  1129. time_spec: it.children
  1130. });
  1131. });
  1132. }
  1133. if(item.time_slot_type == 2){
  1134. item.selectTimeList.forEach(it => {
  1135. item.reserve_time_slot_price.push({
  1136. reserve_time: it.date,
  1137. price: item.price,
  1138. original_price: item.original_price,
  1139. cost_price: 0,
  1140. reserve_max_buy: item.reserve_max_buy,
  1141. time_spec: it.checkedIntervalList
  1142. });
  1143. });
  1144. }
  1145. }
  1146. if (item.reserve_price_type == 2) { // 按天设置价格
  1147. console.log('item.reserve_price_type == 2item.reserve_price_type == 2item.reserve_price_type == 2', item)
  1148. }
  1149. });
  1150. skus.forEach(item => {
  1151. if(item.reserve_price_type == 1){
  1152. item.reserve_time_slot_price.forEach(it => {
  1153. it.time_spec = it.time_spec.map(itc => {
  1154. _.setFormPrice(itc.price, 'price', 3)
  1155. _.setFormPrice(itc.linePrice, 'original_price', 3)
  1156. return {
  1157. spec_time: itc.time,
  1158. start: itc.time ? itc.time.split('-')[0] : '',
  1159. end: itc.time ? itc.time.split('-')[1] : '',
  1160. price: itc.price,
  1161. original_price: itc.linePrice,
  1162. cost_price: 0,
  1163. reserve_max_buy: itc.reservationNum,
  1164. checked: 1,
  1165. is_next: 0,
  1166. }
  1167. });
  1168. });
  1169. } else if(item.reserve_price_type == 2) { // 按天
  1170. item.reserve_time_slot_price = {}
  1171. item.finalData.forEach(it => {
  1172. _.setFormPrice(it.price, 'price', 2)
  1173. _.setFormPrice(it.linePrice, 'original_price', 2)
  1174. item.reserve_time_slot_price[it.date] = {
  1175. reserve_time: it.date,
  1176. price: it.price,
  1177. original_price: it.linePrice,
  1178. cost_price: 0,
  1179. reserve_max_buy: it.reservationNum,
  1180. }
  1181. });
  1182. }else{
  1183. _.setFormPrice(item.price, 'price', 2)
  1184. _.setFormPrice(item.original_price, 'original_price', 2)
  1185. item.reserve_time_slot_price.forEach(it => {
  1186. it.time_spec = it.time_spec.map(itc => {
  1187. return {
  1188. spec_time: itc,
  1189. start: itc.split('-')[0] || '',
  1190. end: itc.split('-')[1] || '',
  1191. price: it.price,
  1192. original_price: it.linePrice || item.original_price,
  1193. cost_price: 0,
  1194. reserve_max_buy: it.reservationNum || item.reserve_max_buy,
  1195. checked: 1,
  1196. is_next: 0,
  1197. }
  1198. });
  1199. });
  1200. }
  1201. });
  1202. this.ruleForm.reserve.skus = JSON.parse(JSON.stringify(skus));
  1203. }else{
  1204. this.ruleForm.reserve.reserve_time_slot_price = [];
  1205. let preList = [];
  1206. if(this.ruleForm.reserve.reserve_price_type == 1){
  1207. preList = this.$refs.priceSet && this.$refs.priceSet.selectedDates ? this.$refs.priceSet.selectedDates : [];
  1208. } else if (this.ruleForm.reserve.reserve_price_type == 2) { // 按天 - 有可能需要修改
  1209. preList = this.$refs.priceSet && this.$refs.priceSet.selectedDates ? this.$refs.priceSet.selectedDates : [];
  1210. }else{
  1211. preList = this.$refs.timeSelect && this.$refs.timeSelect.selectedDates ? this.$refs.timeSelect.selectedDates : [];
  1212. if(this.ruleForm.reserve.time_slot_type == 1){
  1213. preList.forEach(item => {
  1214. item.selectTimes = item.children
  1215. });
  1216. }
  1217. if(this.ruleForm.reserve.time_slot_type == 2){
  1218. preList.forEach(item => {
  1219. item.selectTimes = item.checkedIntervalList
  1220. });
  1221. }
  1222. }
  1223. if (this.ruleForm.reserve.reserve_price_type == 2) { // 按天
  1224. this.ruleForm.reserve.reserve_time_slot_price = {}
  1225. preList.forEach(item => {
  1226. _.setFormPrice(item.price, 'price', 1)
  1227. _.setFormPrice(item.linePrice, 'original_price', 1)
  1228. this.ruleForm.reserve.reserve_time_slot_price[item.date] = {
  1229. reserve_time: item.date,
  1230. price: item.price,
  1231. original_price: item.linePrice,
  1232. cost_price: 0,
  1233. reserve_max_buy: item.reservationNum,
  1234. }
  1235. });
  1236. } else {
  1237. preList.forEach(item => {
  1238. this.ruleForm.reserve.reserve_time_slot_price.push({
  1239. reserve_time: item.date,
  1240. price: this.ruleForm.price,
  1241. original_price: this.ruleForm.original_price,
  1242. cost_price: 0,
  1243. reserve_max_buy: this.ruleForm.reserve.reserve_max_buy,
  1244. time_spec: item.selectTimes
  1245. });
  1246. });
  1247. }
  1248. if(this.ruleForm.reserve.reserve_price_type == 1){
  1249. this.ruleForm.reserve.reserve_time_slot_price.forEach(item => {
  1250. item.time_spec = item.time_spec.map(it => {
  1251. _.setFormPrice(it.price, 'price', 1)
  1252. _.setFormPrice(it.linePrice, 'original_price', 1)
  1253. return {
  1254. spec_time: it.time,
  1255. start: it.time ? it.time.split('-')[0] : '',
  1256. end: it.time ? it.time.split('-')[1] : '',
  1257. price: it.price,
  1258. original_price: it.linePrice,
  1259. cost_price: 0,
  1260. reserve_max_buy: it.reservationNum,
  1261. checked: 1,
  1262. is_next: 0,
  1263. }
  1264. });
  1265. });
  1266. } else if(this.ruleForm.reserve.reserve_price_type == 2){ // 按天
  1267. }else{
  1268. this.ruleForm.reserve.reserve_time_slot_price.forEach(item => {
  1269. item.time_spec = item.time_spec.map(it => {
  1270. return {
  1271. spec_time: it,
  1272. start: it.split('-')[0] || '',
  1273. end: it.split('-')[1] || '',
  1274. price: this.ruleForm.price,
  1275. original_price: this.ruleForm.original_price,
  1276. cost_price: 0,
  1277. reserve_max_buy: this.ruleForm.reserve.reserve_max_buy,
  1278. checked: 1,
  1279. is_next: 0,
  1280. }
  1281. });
  1282. });
  1283. }
  1284. }
  1285. }
  1286. this.$refs['ruleForm'].validate((valid) => {
  1287. if (valid) {
  1288. let self = this;
  1289. 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)) {
  1290. this.$message.error('每次限购数量不能小于起购数量');
  1291. return
  1292. }
  1293. 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)) {
  1294. this.$message.error('每天限购数量不能小于起购数量');
  1295. return
  1296. }
  1297. if (this.ruleForm.goods_type == 1 && self.ruleForm.freight_type.length === 0) {
  1298. this.$message.error('请至少选择一个物流方式');
  1299. return
  1300. }
  1301. if (self.ruleForm.is_attr == 1) {
  1302. if (this.attrGroups.length == 0) {
  1303. this.$message.error('请完善规格组');
  1304. return
  1305. }
  1306. self.ruleForm.extra.member_price_setting = this.getMemberPrice(this.ruleForm.attr);
  1307. }
  1308. //把纯数字转字符
  1309. this.ruleForm.goods_name = this.ruleForm.goods_name + '';
  1310. this.ruleForm.subtitle = this.ruleForm.subtitle + '';
  1311. self.btnLoading = true;
  1312. // package-list 套餐内容
  1313. let packageList = {}
  1314. if (this.$refs['package']) {
  1315. packageList = {
  1316. package_data: this.$refs['package'].list
  1317. }
  1318. }
  1319. let taohua = JSON.parse(JSON.stringify(self.ruleForm))
  1320. params = Object.assign(taohua, this.cForm, packageList)
  1321. request({
  1322. params: {
  1323. r: 'store/client/goods/edit'
  1324. },
  1325. method: 'post',
  1326. data: {
  1327. form: JSON.stringify(params),
  1328. }
  1329. }).then(e => {
  1330. // self.btnLoading = false;
  1331. if (e.data.code == 0) {
  1332. self.$message.success(e.data.msg);
  1333. this.$navigate({
  1334. r: 'store/client/goods/index'
  1335. })
  1336. } else {
  1337. self.$message.error(e.data.msg);
  1338. }
  1339. }).catch(e => {
  1340. self.$message.error(e.data.msg);
  1341. self.btnLoading = false;
  1342. });
  1343. }
  1344. });
  1345. },
  1346. setFormPrice(price, key) {
  1347. if (this.ruleForm.is_attr == 1 && this.ruleForm.goods_type == 3) {
  1348. // 重新设置价格
  1349. if (price > 0) {
  1350. this.$set(this.ruleForm, key, this.ruleForm[key] > 0 ? Math.min(this.ruleForm[key], price) : price)
  1351. if (this.ruleForm[key] <= 0) this.$message.error("价格不能为0")
  1352. }
  1353. }
  1354. },
  1355. //添加优惠券
  1356. add_coupon(e) {
  1357. this.ruleForm.coupon_selection = e;
  1358. },
  1359. //跳转新增优惠券界面
  1360. // handle_coupon() {
  1361. // this.$navigate({
  1362. // r: 'coupon/default/edit'
  1363. // })
  1364. // },
  1365. checkoutChange(it) {
  1366. console.log(it)
  1367. },
  1368. getFreight() { // 获取运费规则选项
  1369. let self = this;
  1370. request({
  1371. params: {
  1372. r: 'mall/postage-rules/all-list'
  1373. },
  1374. method: 'get',
  1375. data: {}
  1376. }).then(e => {
  1377. if (e.data.code == 0) {
  1378. self.freight.list = e.data.data.list;
  1379. // 添加商品时使用默认运费
  1380. self.freight.list.unshift({
  1381. id: 0,
  1382. name: '默认运费',
  1383. status: 1
  1384. })
  1385. console.log(self.freight.list)
  1386. } else {
  1387. self.$message.error(e.data.msg);
  1388. }
  1389. }).catch(e => {
  1390. console.log(e);
  1391. });
  1392. },
  1393. freightChange(e) {
  1394. console.log(e)
  1395. },
  1396. // 获取规格会员价
  1397. getMemberPrice(attr) {
  1398. let that = this;
  1399. let member_price_setting = {};
  1400. let levels = objectKeys(attr[0].member_price_setting);
  1401. levels.forEach(level => {
  1402. that.$set(member_price_setting, level, {});
  1403. });
  1404. attr.forEach((v) => {
  1405. let sign_id = v.sign_id;
  1406. for (const key in v.member_price_setting) {
  1407. member_price_setting[key][sign_id] = v.member_price_setting[key];
  1408. }
  1409. })
  1410. member_price_setting = member_price_setting;
  1411. return member_price_setting;
  1412. },
  1413. handleCoupon(data) {
  1414. this.couponLoading = false;
  1415. console.log(data);
  1416. this.ruleForm.coupon_selection = data
  1417. },
  1418. handle(type, data = null, data2 = null) {
  1419. switch (type) {
  1420. case 'select':
  1421. this.couponLoading = true;
  1422. break;
  1423. case 'delete':
  1424. this.ruleForm.coupon_selection.splice(data, 1);
  1425. break;
  1426. }
  1427. },
  1428. addons_data_change(e) {
  1429. Object.assign(this.ruleForm.addons, e);
  1430. console.log(this.ruleForm.addons, '=======addons====');
  1431. // this.ruleForm.addons.coupon_selection = e;
  1432. },
  1433. /**
  1434. * 显示规格套餐
  1435. */
  1436. packageShow () {
  1437. return this.ruleForm.show_style == 2
  1438. },
  1439. /**
  1440. * 限制添加规格
  1441. */
  1442. attrLimit () {
  1443. return this.ruleForm.show_style == 2 ? 2 : 1
  1444. },
  1445. getStoreConfig() {
  1446. let self = this;
  1447. request({
  1448. params: {
  1449. r: 'store/client/setting/config'
  1450. },
  1451. method: 'get',
  1452. data: {}
  1453. }).then(e => {
  1454. if (e.data.code == 0) {
  1455. self.storeConfig = e.data.data
  1456. }
  1457. }).catch(e => {
  1458. console.log(e);
  1459. });
  1460. },
  1461. // 预约商品-时间范围选择处理
  1462. dateSelectChange(val) {
  1463. let arr = [];
  1464. 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: []}];
  1465. if (val) {
  1466. let arr1 = [];
  1467. let str1 = val[0];
  1468. let str2 = val[1];
  1469. let unixDb = str1.getTime() - 24 * 60 * 60 * 1000;
  1470. let unixDe = str2.getTime() - 24 * 60 * 60 * 1000;
  1471. for(let j = unixDb; j <= unixDe;){
  1472. j = j + 24 * 60 * 60 * 1000
  1473. arr1.push(new Date(parseInt(j)))
  1474. }
  1475. for(let i = 0; i < arr1.length; i++){
  1476. txtArr.forEach(item => {
  1477. if(item.val == arr1[i].getDay()){
  1478. let fm = this.formatDate(arr1[i])
  1479. item.children.push(fm);
  1480. }
  1481. })
  1482. }
  1483. txtArr.forEach(item => {
  1484. if(item.children.length){
  1485. arr.push(item);
  1486. }
  1487. });
  1488. this.dayArr = arr;
  1489. }
  1490. this.checkWeekList = [];
  1491. let warr = [];
  1492. this.dayArr.forEach(item => {
  1493. warr.push(item.txt);
  1494. });
  1495. this.checkWeekList = [...new Set(warr)];
  1496. this.weekSelectChange();
  1497. },
  1498. weekSelectChange() {
  1499. let selectArr = [];
  1500. let selectDateArr = [];
  1501. for(let i = 0; i < this.dayArr.length; i++){
  1502. this.checkWeekList.forEach(item => {
  1503. if(item == this.dayArr[i].txt){
  1504. selectArr.push(this.dayArr[i]);
  1505. }
  1506. });
  1507. }
  1508. for(let j = 0; j < selectArr.length; j++){
  1509. selectDateArr = selectDateArr.concat(selectArr[j].children);
  1510. }
  1511. this.ruleForm.reserve.reserve_date = selectDateArr;
  1512. },
  1513. formatDate(date) {
  1514. let result = '';
  1515. let year = date.getFullYear().toString().padStart(4, '0');
  1516. let month = (date.getMonth() + 1).toString().padStart(2, '0');
  1517. let day = date.getDate().toString().padStart(2, '0');
  1518. let hour = date.getHours().toString().padStart(2, '0');
  1519. let minute = date.getMinutes().toString().padStart(2, '0');
  1520. let second = date.getSeconds().toString().padStart(2, '0');
  1521. result = `${year}-${month}-${day}`;
  1522. return result;
  1523. },
  1524. resetDateInfo(e) {
  1525. if(this.ruleForm.reserve.reserve_price_type == 1){
  1526. let dates = e;
  1527. if(this.ruleForm.reserve.time_slot_type == 1){
  1528. let arr = [];
  1529. dates.forEach(item => {
  1530. arr.push({
  1531. date: item.date,
  1532. times: item.children,
  1533. isSelect: false
  1534. });
  1535. });
  1536. if(arr.length){
  1537. arr[0].isSelect = true;
  1538. }
  1539. if(!this.isEdit){
  1540. this.$nextTick(() => {
  1541. this.$refs.priceSet.initData(arr);
  1542. });
  1543. }else{
  1544. this.$nextTick(() => {
  1545. this.$refs.priceSet.initData(this.initializationDates);
  1546. this.isEdit = false;
  1547. });
  1548. }
  1549. }
  1550. if(this.ruleForm.reserve.time_slot_type == 2){
  1551. let arr1 = [];
  1552. dates.forEach(item => {
  1553. arr1.push({
  1554. date: item.date,
  1555. times: item.checkedIntervalList,
  1556. isSelect: false
  1557. });
  1558. });
  1559. if(arr1.length){
  1560. arr1[0].isSelect = true;
  1561. }
  1562. if(!this.isEdit){
  1563. this.$nextTick(() => {
  1564. this.$refs.priceSet.initData(arr1);
  1565. });
  1566. }else{
  1567. this.$nextTick(() => {
  1568. this.$refs.priceSet.initData(this.initializationDates);
  1569. this.isEdit = false;
  1570. });
  1571. }
  1572. }
  1573. }
  1574. },
  1575. async loadData(id = 1) {
  1576. await request({
  1577. params: {
  1578. r: 'store/client/goods/regions',
  1579. id: id,
  1580. },
  1581. method: 'get',
  1582. }).then(e => {
  1583. if (e.data.code == 0) {
  1584. this.provinces = e.data.data;
  1585. }
  1586. }).catch(e => {
  1587. console.log(e);
  1588. this.listLoading = false;
  1589. this.$message.error('网络错误');
  1590. });
  1591. },
  1592. // 省市区三级联动
  1593. regionChange(e, level) {
  1594. let self = this;
  1595. self.ruleForm.reserve.lng = e.lng;
  1596. self.ruleForm.reserve.lat = e.lat;
  1597. self.long_lat = e.lng + '-' + e.lat;
  1598. request({
  1599. params: {
  1600. r: 'store/client/goods/regions',
  1601. id: e.id,
  1602. },
  1603. method: 'get',
  1604. }).then(e => {
  1605. if (e.data.code == 0) {
  1606. switch (level) {
  1607. case 1:
  1608. self.citys = e.data.data;
  1609. this.ruleForm.reserve.province_id = this.provinceInfo.id
  1610. break;
  1611. case 2:
  1612. self.districts = e.data.data;
  1613. this.ruleForm.reserve.city_id = this.cityInfo.id
  1614. break;
  1615. case 3:
  1616. self.streets = e.data.data;
  1617. this.ruleForm.reserve.district_id = this.districtInfo.id
  1618. break;
  1619. }
  1620. } else {
  1621. self.$message.error(e.data.msg);
  1622. }
  1623. }).catch(e => {
  1624. console.log(e);
  1625. self.$message.error('网络错误');
  1626. return false;
  1627. });
  1628. },
  1629. //地图确定事件
  1630. mapEvent(e) {
  1631. for (let i in this.provinces) {
  1632. if (e.address.indexOf(this.provinces[i].name) !== -1) {
  1633. this.ruleForm.reserve.province_id = this.provinces[i].id;
  1634. this.provinceInfo = this.provinces[i];
  1635. request({
  1636. params: {
  1637. r: 'store/client/goods/get-regions',
  1638. region_id: this.provinces[i].id,
  1639. },
  1640. method: 'get',
  1641. }).then(res => {
  1642. if (res.data.code == 0) {
  1643. this.citys = res.data.data;
  1644. for (let i in this.citys) {
  1645. if (e.address.indexOf(this.citys[i].name) !== -1) {
  1646. this.ruleForm.reserve.city_id = this.citys[i].id;
  1647. this.cityInfo = this.citys[i];
  1648. request({
  1649. params: {
  1650. r: 'store/client/goods/get-regions',
  1651. region_id: this.citys[i].id,
  1652. },
  1653. method: 'get',
  1654. }).then(resp => {
  1655. if (resp.data.code == 0) {
  1656. this.districts = resp.data.data;
  1657. for (let i in this.districts) {
  1658. if (e.address.indexOf(this.districts[i].name) !== -1) {
  1659. this.ruleForm.reserve.district_id = this.districts[i].id;
  1660. this.districtInfo = this.districts[i];
  1661. }
  1662. }
  1663. } else {
  1664. this.$message.error(resp.data.msg);
  1665. }
  1666. }).catch(error => {
  1667. console.log(error);
  1668. this.$message.error('网络错误');
  1669. });
  1670. }
  1671. }
  1672. } else {
  1673. this.$message.error(res.data.msg);
  1674. }
  1675. }).catch(err => {
  1676. console.log(err);
  1677. this.$message.error('网络错误');
  1678. });
  1679. }
  1680. }
  1681. this.ruleForm.reserve.lng = e.long;
  1682. this.ruleForm.reserve.lat = e.lat;
  1683. this.ruleForm.reserve.detail = e.address;
  1684. this.long_lat = e.lat + '-' + e.long;
  1685. this.$forceUpdate();
  1686. },
  1687. getReservePlace() {
  1688. let self = this;
  1689. for (let i in self.provinces) {
  1690. if (self.ruleForm.reserve.province_id == self.provinces[i].id) {
  1691. self.provinceInfo = self.provinces[i];
  1692. request({
  1693. params: {
  1694. r: 'store/client/goods/get-regions',
  1695. region_id: self.provinces[i].id,
  1696. },
  1697. method: 'get',
  1698. }).then(res => {
  1699. if (res.data.code == 0) {
  1700. self.citys = res.data.data;
  1701. for (let i in self.citys) {
  1702. if (self.ruleForm.reserve.city_id == self.citys[i].id) {
  1703. self.cityInfo = self.citys[i];
  1704. request({
  1705. params: {
  1706. r: 'store/client/goods/get-regions',
  1707. region_id: self.citys[i].id,
  1708. },
  1709. method: 'get',
  1710. }).then(resp => {
  1711. if (resp.data.code == 0) {
  1712. self.districts = resp.data.data;
  1713. for (let i in self.districts) {
  1714. if (self.ruleForm.reserve.district_id == self.districts[i].id) {
  1715. self.districtInfo = self.districts[i];
  1716. }
  1717. }
  1718. } else {
  1719. self.$message.error(resp.data.msg);
  1720. }
  1721. }).catch(error => {
  1722. console.log(error);
  1723. self.$message.error('网络错误');
  1724. });
  1725. }
  1726. }
  1727. } else {
  1728. self.$message.error(res.data.msg);
  1729. }
  1730. }).catch(err => {
  1731. console.log(err);
  1732. self.$message.error('网络错误');
  1733. });
  1734. }
  1735. }
  1736. },
  1737. onChangeReserveTimeRangeType(val) {
  1738. this.ruleForm.reserve.reserve_price_type = 0
  1739. },
  1740. goodsSelect1(param) {
  1741. console.log(1111222);
  1742. console.log(this.ruleForm.extra1_goods_id);
  1743. for (let j in param) {
  1744. let item = param[j];
  1745. if(this.ruleForm.id&&item.id==this.ruleForm.id){
  1746. continue;
  1747. }
  1748. let flag = true;
  1749. for (let i in this.extra1_goods_list) {
  1750. if (this.extra1_goods_list[i].goods_id == item.id) {
  1751. flag = false;
  1752. break;
  1753. }
  1754. }
  1755. if (flag) {
  1756. if(this.extra1_goods_list.length>=20){
  1757. this.$message.error('最多只能添加20件商品');
  1758. break;
  1759. }
  1760. this.extra1_goods_list.push({
  1761. goods_id: item.id,
  1762. price: item.price,
  1763. status: item.status,
  1764. goods_stock: item.stock,
  1765. goods_name: item.goods_name,
  1766. cover_pic: item.cover_pic,
  1767. });
  1768. this.ruleForm.extra1_goods_id.push(item.id);
  1769. }
  1770. }
  1771. },
  1772. goodsSelect2(param) {
  1773. for (let j in param) {
  1774. let item = param[j];
  1775. if(this.ruleForm.id&&item.id==this.ruleForm.id){
  1776. continue;
  1777. }
  1778. let flag = true;
  1779. for (let i in this.extra2_goods_list) {
  1780. if (this.extra2_goods_list[i].goods_id == item.id) {
  1781. flag = false;
  1782. break;
  1783. }
  1784. }
  1785. console.log(this.extra2_goods_list);
  1786. if (flag) {
  1787. if(this.extra2_goods_list.length>=20){
  1788. this.$message.error('最多只能添加20件商品');
  1789. break;
  1790. }
  1791. this.extra2_goods_list.push({
  1792. goods_id: item.id,
  1793. price: item.price,
  1794. status: item.status,
  1795. goods_stock: item.stock,
  1796. goods_name: item.goods_name,
  1797. cover_pic: item.cover_pic,
  1798. store_id: item.store_id,
  1799. });
  1800. this.ruleForm.extra2_goods_id.push(item.id);
  1801. }
  1802. }
  1803. },
  1804. // 删除商品
  1805. // 删除商品
  1806. delFun(index,type) {
  1807. switch (type){
  1808. case 1:
  1809. this.extra1_goods_list.splice(index, 1);
  1810. var extra1_goods_id =[];
  1811. for(var item of this.extra1_goods_list){
  1812. extra1_goods_id.push(item.goods_id)
  1813. }
  1814. this.ruleForm.extra1_goods_id =extra1_goods_id;
  1815. break;
  1816. case 2:
  1817. this.extra2_goods_list.splice(index, 1);
  1818. var extra2_goods_id =[];
  1819. for(var item of this.extra2_goods_list){
  1820. extra2_goods_id.push(item.goods_id)
  1821. }
  1822. this.ruleForm.extra2_goods_id =extra2_goods_id;
  1823. break;
  1824. }
  1825. },
  1826. }
  1827. });
  1828. </script>