create.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  6. <link href="{__FRAME_PATH}css/font-awesome.min.css" rel="stylesheet">
  7. <link href="{__ADMIN_PATH}plug/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
  8. <script type="text/javascript" src="{__ADMIN_PATH}plug/umeditor/third-party/jquery.min.js"></script>
  9. <script type="text/javascript" src="{__ADMIN_PATH}plug/umeditor/third-party/template.min.js"></script>
  10. <script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/umeditor/umeditor.config.js"></script>
  11. <script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/umeditor/umeditor.min.js"></script>
  12. <script type="text/javascript" src="{__ADMIN_PATH}plug/umeditor/lang/zh-cn/zh-cn.js"></script>
  13. <link rel="stylesheet" href="/static/plug/layui/css/layui.css">
  14. <script src="/static/plug/layui/layui.js"></script>
  15. <script src="{__PLUG_PATH}vue/dist/vue.min.js"></script>
  16. <script src="/static/plug/axios.min.js"></script>
  17. <script src="{__MODULE_PATH}widget/aliyun-oss-sdk-4.4.4.min.js"></script>
  18. <script src="{__MODULE_PATH}widget/cos-js-sdk-v5.min.js"></script>
  19. <script src="{__MODULE_PATH}widget/qiniu-js-sdk-2.5.5.js"></script>
  20. <script src="{__MODULE_PATH}widget/plupload.full.min.js"></script>
  21. <script src="{__MODULE_PATH}widget/videoUpload.js"></script>
  22. <style>
  23. .layui-form-item {
  24. margin-bottom: 0px;
  25. }
  26. .pictrueBox {
  27. display: inline-block !important;
  28. }
  29. .pictrue {
  30. width: 60px;
  31. height: 60px;
  32. border: 1px dotted rgba(0, 0, 0, 0.1);
  33. margin-right: 15px;
  34. display: inline-block;
  35. position: relative;
  36. cursor: pointer;
  37. }
  38. .pictrue img {
  39. width: 100%;
  40. height: 100%;
  41. }
  42. .upLoad {
  43. width: 58px;
  44. height: 58px;
  45. line-height: 58px;
  46. border: 1px dotted rgba(0, 0, 0, 0.1);
  47. border-radius: 4px;
  48. background: rgba(0, 0, 0, 0.02);
  49. cursor: pointer;
  50. display: flex;
  51. justify-content: center;
  52. align-items: center;
  53. }
  54. .rulesBox {
  55. display: flex;
  56. flex-wrap: wrap;
  57. margin-left: 10px;
  58. }
  59. .layui-tab-content {
  60. margin-top: 15px;
  61. }
  62. .ml110 {
  63. margin: 18px 0 4px 110px;
  64. }
  65. .rules {
  66. display: flex;
  67. }
  68. .rules-btn-sm {
  69. height: 30px;
  70. line-height: 30px;
  71. font-size: 12px;
  72. width: 109px;
  73. }
  74. .rules-btn-sm input {
  75. width: 79% !important;
  76. height: 84% !important;
  77. padding: 0 10px;
  78. }
  79. .ml10 {
  80. margin-left: 10px !important;
  81. }
  82. .ml40 {
  83. margin-left: 40px !important;
  84. }
  85. .closes {
  86. position: absolute;
  87. left: 86%;
  88. top: -18%;
  89. }
  90. .red {
  91. color: red;
  92. }
  93. .layui-input-block .layui-video-box{
  94. width: 22%;
  95. height: 180px;
  96. border-radius: 10px;
  97. background-color: #707070;
  98. margin-top: 10px;
  99. position: relative;
  100. overflow: hidden;
  101. }
  102. .layui-input-block .layui-video-box i{
  103. color: #fff;
  104. line-height: 180px;
  105. margin: 0 auto;
  106. width: 50px;
  107. height: 50px;
  108. display: inherit;
  109. font-size: 50px;
  110. }
  111. .layui-input-block .layui-video-box .mark{
  112. position: absolute;
  113. width: 100%;
  114. height: 30px;
  115. top: 0;
  116. background-color: rgba(0,0,0,.5);
  117. text-align: center;
  118. }
  119. .store_box{
  120. display: flex;
  121. }
  122. .info{
  123. color: #c9c9c9;
  124. padding-left: 10px;
  125. line-height: 30px;
  126. }
  127. #listDetial{
  128. height: 38px;
  129. line-height: 1.3;
  130. border-width: 1px;
  131. border-style: solid;
  132. padding:0 10px;
  133. background-color: #fff;
  134. border-radius: 2px;
  135. border-color: #D2D2D2!important;
  136. outline: 0;
  137. width: 100%;
  138. -webkit-appearance: none;
  139. transition: all .3s;
  140. -webkit-transition: all .3s;
  141. box-sizing: border-box;
  142. }
  143. </style>
  144. </head>
  145. <body>
  146. <div class="layui-fluid">
  147. <div class="layui-row layui-col-space15" id="app" v-cloak="">
  148. <div class="layui-card">
  149. <div class="layui-card-header">
  150. <span class="">{{id ? '商品修改': '商品添加' }}</span>
  151. <button style="margin-left: 20px" type="button" class="layui-btn layui-btn-primary layui-btn-xs" @click="goBack">返回列表</button>
  152. </div>
  153. <div class="layui-card-body">
  154. <form class="layui-form" action="" v-cloak="">
  155. <div class="layui-tab layui-tab-brief" lay-filter="docTabBrief">
  156. <ul class="layui-tab-title">
  157. <li class="layui-this" lay-id='1'>基础信息</li>
  158. <li lay-id='2'>商品详情</li>
  159. </ul>
  160. <div class="layui-tab-content">
  161. <div class="layui-tab-item layui-show">
  162. <div class="layui-row layui-col-space15">
  163. <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
  164. <div class="grid-demo grid-demo-bg1">
  165. <div class="layui-form-item">
  166. <label class="layui-form-label">商品名称<i class="red">*</i></label>
  167. <div class="layui-input-block">
  168. <input type="text" name="title" lay-verify="title" autocomplete="off"
  169. placeholder="请输入商品名称" class="layui-input" v-model="formData.title" maxlength="100">
  170. </div>
  171. </div>
  172. </div>
  173. </div>
  174. <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
  175. <div class="grid-demo grid-demo-bg1">
  176. <div class="layui-form-item">
  177. <label class="layui-form-label">单位</label>
  178. <div class="layui-input-block">
  179. <input style="width: 40%" type="text" name="unit_name" lay-verify="title" autocomplete="off"
  180. placeholder="请输入单位" class="layui-input" v-model="formData.unit_name">
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185. <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
  186. <div class="grid-demo grid-demo-bg1">
  187. <div class="layui-form-item">
  188. <label class="layui-form-label">时间</label>
  189. <div class="layui-input-block">
  190. <input style="width: 40%" type="text" name="unit_name" id="date" lay-verify="date" autocomplete="off"
  191. placeholder="选择时间" class="layui-input" :value="formData.start_time+' - '+formData.stop_time" >
  192. </div>
  193. </div>
  194. </div>
  195. </div>
  196. <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
  197. <div class="grid-demo grid-demo-bg1">
  198. <div class="layui-form-item">
  199. <label class="layui-form-label">商品封面图<i class="red">*</i></label>
  200. <div class="pictrueBox">
  201. <div class="pictrue" v-if="formData.image" @click="uploadImage('image')">
  202. <img :src="formData.image"></div>
  203. <div class="upLoad" @click="uploadImage('image')" v-else>
  204. <i class="layui-icon layui-icon-camera" class="iconfont"
  205. style="font-size: 26px;"></i>
  206. </div>
  207. </div>
  208. </div>
  209. </div>
  210. </div>
  211. <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
  212. <div class="grid-demo grid-demo-bg1">
  213. <div class="layui-form-item">
  214. <label class="layui-form-label">商品轮播图<i class="red">*</i></label>
  215. <div class="pictrueBox pictrue" v-for="(item,index) in formData.images">
  216. <img :src="item">
  217. <i class="layui-icon closes" @click="deleteImage('images',index)">&#x1007</i>
  218. </div>
  219. <div class="pictrueBox">
  220. <div class="upLoad" @click="uploadImage('images')"
  221. v-if="formData.images.length <= rule.images.maxLength">
  222. <i class="layui-icon layui-icon-camera" class="iconfont"
  223. style="font-size: 26px;"></i>
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. </div>
  229. <div class="layui-col-xs12 layui-col-sm12 layui-col-md12" v-if="formData.spec_type == 1">
  230. </div>
  231. </div>
  232. <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
  233. <div class="grid-demo grid-demo-bg1">
  234. <div class="layui-form-item">
  235. <label class="layui-form-label">时间</label>
  236. <div class="layui-input-block">
  237. <input list="browsers" id="listDetial" v-model="formData.time_id">
  238. <datalist id="browsers">
  239. <option v-for="ls in tempList" :value="ls.id">{{'开始时间:'+ls.time+' - 持续时间:'+ls.continued}}</option>
  240. </datalist>
  241. </div>
  242. </div>
  243. </div>
  244. </div>
  245. <div class="layui-row layui-col-space15">
  246. <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
  247. <div class="grid-demo grid-demo-bg1">
  248. <div class="layui-form-item">
  249. <label class="layui-form-label">商品状态</label>
  250. <div class="layui-input-block">
  251. <input type="radio" name="is_show" lay-filter="is_show" value="1" title="上架"
  252. :checked="formData.is_show == 1 ? true : false">
  253. <input type="radio" name="is_show" lay-filter="is_show" value="0" title="下架"
  254. :checked="formData.is_show == 0 ? true : false">
  255. </div>
  256. </div>
  257. </div>
  258. </div>
  259. <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
  260. <div class="grid-demo grid-demo-bg1">
  261. <div class="layui-form-item">
  262. <label class="layui-form-label">热卖单品</label>
  263. <div class="layui-input-block">
  264. <input type="radio" name="is_hot" lay-filter="is_hot" value="1" title="开启"
  265. :checked="formData.is_hot == 1 ? true : false">
  266. <input type="radio" name="is_hot" lay-filter="is_hot" value="0" title="关闭"
  267. :checked="formData.is_hot == 0 ? true : false">
  268. </div>
  269. </div>
  270. </div>
  271. </div>
  272. <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
  273. <div class="grid-demo grid-demo-bg1">
  274. <div class="layui-form-item">
  275. <label class="layui-form-label">新人礼包</label>
  276. <div class="layui-input-block">
  277. <input type="radio" name="is_news" lay-filter="is_news" value="1" title="开启"
  278. :checked="formData.is_news == 1 ? true : false">
  279. <input type="radio" name="is_news" lay-filter="is_news" value="0" title="关闭"
  280. :checked="formData.is_news == 0 ? true : false">
  281. </div>
  282. </div>
  283. </div>
  284. </div>
  285. </div>
  286. <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
  287. <div class="grid-demo grid-demo-bg1">
  288. <div class="layui-form-item">
  289. <label class="layui-form-label">价格</label>
  290. <div class="layui-input-block">
  291. <input type="number" name="price" lay-verify="price"
  292. autocomplete="off" placeholder="请输入价格" class="layui-input" v-model="formData.price">
  293. </div>
  294. </div>
  295. </div>
  296. </div>
  297. <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
  298. <div class="grid-demo grid-demo-bg1">
  299. <div class="layui-form-item">
  300. <label class="layui-form-label">成本</label>
  301. <div class="layui-input-block">
  302. <input type="number" name="cost" lay-verify="cost"
  303. autocomplete="off" placeholder="请输入成本" class="layui-input" v-model="formData.cost">
  304. </div>
  305. </div>
  306. </div>
  307. </div>
  308. <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
  309. <div class="grid-demo grid-demo-bg1">
  310. <div class="layui-form-item">
  311. <label class="layui-form-label">原价</label>
  312. <div class="layui-input-block">
  313. <input type="number" name="ot_price" lay-verify="ot_price"
  314. autocomplete="off" placeholder="请输入原价" class="layui-input" v-model="formData.ot_price">
  315. </div>
  316. </div>
  317. </div>
  318. </div>
  319. <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
  320. <div class="grid-demo grid-demo-bg1">
  321. <div class="layui-form-item">
  322. <label class="layui-form-label">库存</label>
  323. <div class="layui-input-block">
  324. <input type="number" name="stock" lay-verify="stock"
  325. autocomplete="off" placeholder="请输入库存" class="layui-input" v-model="formData.stock">
  326. </div>
  327. </div>
  328. </div>
  329. </div>
  330. <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
  331. <div class="grid-demo grid-demo-bg1">
  332. <div class="layui-form-item">
  333. <label class="layui-form-label">可的积分</label>
  334. <div class="layui-input-block">
  335. <input type="number" name="give_integral" lay-verify="title"
  336. autocomplete="off" placeholder="请输入可的积分" class="layui-input" v-model="formData.give_integral">
  337. </div>
  338. </div>
  339. </div>
  340. </div>
  341. <div class="layui-col-xs12 layui-col-sm4 layui-col-md4">
  342. <div class="grid-demo grid-demo-bg1">
  343. <div class="layui-form-item">
  344. <label class="layui-form-label">排序</label>
  345. <div class="layui-input-block">
  346. <input type="number" name="sort" lay-verify="title" autocomplete="off"
  347. placeholder="请输入排序" class="layui-input" v-model="formData.sort">
  348. </div>
  349. </div>
  350. </div>
  351. </div>
  352. </div>
  353. <div class="layui-tab-item">
  354. <div class="layui-row layui-col-space15">
  355. <textarea type="text/plain" name="description" id="myEditor" style="width:100%;">{{formData.description}}</textarea>
  356. </div>
  357. </div>
  358. </div>
  359. <div class="layui-tab-content">
  360. <div class="layui-row layui-col-space15">
  361. <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
  362. <div class="grid-demo grid-demo-bg1">
  363. <div class="layui-form-item" v-if="id">
  364. <button class="layui-btn layui-btn-primary layui-btn-sm" id="submit" type="button" @click="handleSubmit()">保存</button>
  365. <button class="layui-btn layui-btn-primary layui-btn-sm" type="button" @click="back" v-if="layTabId != 1">上一步</button>
  366. <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" v-if="layTabId != 3" @click="next">下一步</button>
  367. </div>
  368. <div class="layui-form-item" v-else>
  369. <button class="layui-btn layui-btn-primary layui-btn-sm" type="button" @click="back" v-if="layTabId != 1">上一步</button>
  370. <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" @click="next" v-if="layTabId ==1">下一步</button>
  371. <button class="layui-btn layui-btn-normal layui-btn-sm" id="submit" type="button" v-if="layTabId == 2" @click="handleSubmit()">提交</button>
  372. </div>
  373. </div>
  374. </div>
  375. </div>
  376. </div>
  377. </div>
  378. </form>
  379. </div>
  380. </div>
  381. </div>
  382. </div>
  383. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  384. <script>
  385. var id = {$id};
  386. new Vue({
  387. el: '#app',
  388. data: {
  389. id:id,
  390. //分类列表
  391. cateList: [],
  392. //运费模板
  393. tempList: [],
  394. upload:{
  395. videoIng:false
  396. },
  397. formData: {
  398. cate_id: [],
  399. temp_id: 0,
  400. commission:0,
  401. title: '',
  402. keyword: '',
  403. unit_name: '',
  404. postage: '',
  405. store_info: '',
  406. image: '',
  407. video_link: '',
  408. images: [],
  409. price: 0,
  410. cost: 0,
  411. ot_price: 0,
  412. stock: 0,
  413. spec_type: 0,
  414. attr: {
  415. pic: '',
  416. price: 0,
  417. cost: 0,
  418. ot_price: 0,
  419. stock: 0,
  420. bar_code: '',
  421. weight: 0,
  422. volume: 0,
  423. brokerage: 0,
  424. brokerage_two: 0,
  425. },
  426. where:{
  427. data:''
  428. },
  429. attrs: [],
  430. description: '',
  431. ficti: 0,
  432. give_integral: 0,
  433. sort: 0,
  434. is_show: 1,
  435. is_hot: 0,
  436. is_benefit: 0,
  437. is_best: 0,
  438. is_news: 0,
  439. is_good: 0,
  440. is_sub:0,
  441. time_id:'',
  442. items: [
  443. // {
  444. // value: '',
  445. // detailValue:'',
  446. // attrHidden:false,
  447. // detail:[]
  448. // }
  449. ],
  450. activity:['秒杀','砍价','拼团'],
  451. },
  452. videoLink:'',
  453. //批量添加属性
  454. batchAttr:{
  455. pic: '',
  456. price: 0,
  457. cost: 0,
  458. ot_price: 0,
  459. stock: 0,
  460. bar_code: '',
  461. weight: 0,
  462. volume: 0,
  463. },
  464. //多属性header头
  465. formHeader:[],
  466. // 规格数据
  467. formDynamic: {
  468. attrsName: '',
  469. attrsVal: ''
  470. },
  471. brokerage:{
  472. brokerage: '',
  473. brokerage_two: '',
  474. },
  475. activity:{'秒杀':'#1E9FFF','砍价':'#189688','拼团':'#FEB900'},
  476. attr: [],//临时属性
  477. newRule: false,//是否添加新规则
  478. radioRule: ['is_sub','is_show', 'is_hot', 'is_benefit', 'is_news','is_good' ,'is_best', 'spec_type'],//radio 当选规则
  479. rule: { //多图选择规则
  480. images: {
  481. maxLength: 5
  482. }
  483. },
  484. ruleList:[],
  485. ruleIndex:-1,
  486. progress: 0,
  487. um: null,//编译器实例化
  488. form: null,//layui.form
  489. layTabId: 1,
  490. ruleBool: id ? true : false,
  491. },
  492. watch:{
  493. 'formData.is_sub':function (n) {
  494. if (n == 1) {
  495. this.formHeader.push({title:'一级返佣(元)'});
  496. this.formHeader.push({title:'二级级返佣(元)'});
  497. } else {
  498. this.formHeader.pop();
  499. this.formHeader.pop();
  500. }
  501. },
  502. 'formData.spec_type':function (n) {
  503. if (n) {
  504. this.render();
  505. }
  506. },
  507. // 'formData.image':function (n) {
  508. // if(!this.batchAttr.pic){
  509. // this.batchAttr.pic = n;
  510. // }
  511. // if(!this.formData.attr.pic){
  512. // this.formData.attr.pic = n;
  513. // }
  514. // }
  515. },
  516. methods: {
  517. back:function(){
  518. var that = this;
  519. layui.use(['element'], function () {
  520. layui.element.tabChange('docTabBrief', that.layTabId == 1 ? 1 : parseInt(that.layTabId) - 1);
  521. });
  522. },
  523. next:function(){
  524. var that = this;
  525. layui.use(['element'], function () {
  526. layui.element.tabChange('docTabBrief', that.layTabId == 3 ? 3 : parseInt(that.layTabId) + 1);
  527. });
  528. },
  529. goBack:function(){
  530. location.href = this.U({c:'ump.StoreWholesale',a:'index'});
  531. },
  532. U: function (opt) {
  533. var m = opt.m || 'admin', c = opt.c || window.controlle || '', a = opt.a || 'index', q = opt.q || '',
  534. p = opt.p || {};
  535. var params = Object.keys(p).map(function (key) {
  536. return key + '/' + p[key];
  537. }).join('/');
  538. var gets = Object.keys(q).map(function (key) {
  539. return key+'='+ q[key];
  540. }).join('&');
  541. return '/' + m + '/' + c + '/' + a + (params == '' ? '' : '/' + params) + (gets == '' ? '' : '?' + gets);
  542. },
  543. /**
  544. * 提示
  545. * */
  546. showMsg: function (msg, success) {
  547. $('#submit').removeAttr('disabled').text('提交');
  548. layui.use(['layer'], function () {
  549. layui.layer.msg(msg, success);
  550. });
  551. },
  552. addBrokerage:function(){
  553. if (this.brokerage.brokerage >= 0 && this.brokerage.brokerage_two >= 0){
  554. var that = this;
  555. this.$set(this.formData,'attrs',this.formData.attrs.map(function (item) {
  556. item.brokerage = that.brokerage.brokerage;
  557. item.brokerage_two = that.brokerage.brokerage_two;
  558. return item;
  559. }));
  560. } else {
  561. return this.showMsg('请填写返佣金额在进行批量添加');
  562. }
  563. },
  564. batchClear:function(){
  565. this.$set(this,'batchAttr',{
  566. pic: '',
  567. price: 0,
  568. cost: 0,
  569. ot_price: 0,
  570. stock: 0,
  571. bar_code: '',
  572. weight: 0,
  573. volume: 0,
  574. });
  575. },
  576. /**
  577. * 批量添加
  578. * */
  579. batchAdd:function(){
  580. var that = this;
  581. this.$set(this.formData,'attrs',this.formData.attrs.map(function (item) {
  582. if (that.batchAttr.pic) {
  583. item.pic = that.batchAttr.pic;
  584. }
  585. if (that.batchAttr.price > 0){
  586. item.price = that.batchAttr.price;
  587. }
  588. if (that.batchAttr.cost > 0){
  589. item.cost = that.batchAttr.cost;
  590. }
  591. if (that.batchAttr.ot_price > 0){
  592. item.ot_price = that.batchAttr.ot_price;
  593. }
  594. if (that.batchAttr.stock > 0){
  595. item.stock = that.batchAttr.stock;
  596. }
  597. if (that.batchAttr.bar_code != ''){
  598. item.bar_code = that.batchAttr.bar_code;
  599. }
  600. if (that.batchAttr.weight > 0){
  601. item.weight = that.batchAttr.weight;
  602. }
  603. if (that.batchAttr.volume > 0){
  604. item.volume = that.batchAttr.volume;
  605. }
  606. return item;
  607. }));
  608. },
  609. /**
  610. * 获取商品信息
  611. * */
  612. getProductInfo: function () {
  613. var that = this;
  614. that.requestGet(that.U({c:"ump.StoreWholesale",a:'get_product_info',q:{id:that.id}})).then(function (res) {
  615. that.$set(that,'cateList',res.data.cateList);
  616. that.$set(that,'tempList',res.data.time_id);
  617. var productInfo = res.data.productInfo || {};
  618. if(productInfo.id && that.id){
  619. that.$set(that,'formData',productInfo);
  620. that.generate();
  621. }
  622. that.getRuleList();
  623. that.init();
  624. }).catch(function (res) {
  625. that.showMsg(res.msg);
  626. })
  627. },
  628. /**
  629. * 给某个属性添加属性值
  630. * @param item
  631. * */
  632. addDetail: function (item) {
  633. if (!item.detailValue) return false;
  634. if (item.detail.find(function (val) {
  635. if(item.detailValue == val){
  636. return true;
  637. }
  638. })) {
  639. return this.showMsg('添加的属性值重复');
  640. }
  641. item.detail.push(item.detailValue);
  642. item.detailValue = '';
  643. },
  644. /**
  645. * 删除某个属性值
  646. * @param item 父级循环集合
  647. * @param inx 子集index
  648. * */
  649. deleteValue: function (item, inx) {
  650. if (item.detail.length > 1) {
  651. item.detail.splice(inx, 1);
  652. } else {
  653. return this.showMsg('请设置至少一个属性');
  654. }
  655. },
  656. /**
  657. * 删除某条属性
  658. * @param index
  659. * */
  660. deleteItem: function (index) {
  661. this.formData.items.splice(index, 1);
  662. },
  663. /**
  664. * 创建属性
  665. * */
  666. createAttrName: function () {
  667. if (this.formDynamic.attrsName && this.formDynamic.attrsVal) {
  668. if (this.formData.items.find(function (val) {
  669. if (val.value == this.formDynamic.attrsName) {
  670. return true;
  671. }
  672. }.bind(this))) {
  673. return this.showMsg('添加的属性重复');
  674. }
  675. this.formData.items.push({
  676. value: this.formDynamic.attrsName,
  677. detailValue: '',
  678. attrHidden: false,
  679. detail: [this.formDynamic.attrsVal]
  680. });
  681. this.formDynamic.attrsName = '';
  682. this.formDynamic.attrsVal = '';
  683. this.newRule = false;
  684. } else {
  685. return this.showMsg('请添加完整的规格!');
  686. }
  687. },
  688. /**
  689. * 删除图片
  690. * */
  691. deleteImage: function (key, index) {
  692. var that = this;
  693. if (index != undefined) {
  694. that.formData[key].splice(index, 1);
  695. that.$set(that.formData, key, that.formData[key]);
  696. } else {
  697. that.$set(that.formData, key, '');
  698. }
  699. },
  700. createFrame: function (title, src, opt) {
  701. opt === undefined && (opt = {});
  702. var h = 0;
  703. if (window.innerHeight < 800 && window.innerHeight >= 700) {
  704. h = window.innerHeight - 50;
  705. } else if (window.innerHeight < 900 && window.innerHeight >= 800) {
  706. h = window.innerHeight - 100;
  707. } else if (window.innerHeight < 1000 && window.innerHeight >= 900) {
  708. h = window.innerHeight - 150;
  709. } else if (window.innerHeight >= 1000) {
  710. h = window.innerHeight - 200;
  711. } else {
  712. h = window.innerHeight;
  713. }
  714. var area = [(opt.w || window.innerWidth / 2) + 'px', (!opt.h || opt.h > h ? h : opt.h) + 'px'];
  715. layui.use('layer',function () {
  716. return layer.open({
  717. type: 2,
  718. title: title,
  719. area: area,
  720. fixed: false, //不固定
  721. maxmin: true,
  722. moveOut: false,//true 可以拖出窗外 false 只能在窗内拖
  723. anim: 5,//出场动画 isOutAnim bool 关闭动画
  724. offset: 'auto',//['100px','100px'],//'auto',//初始位置 ['100px','100px'] t[ 上 左]
  725. shade: 0,//遮罩
  726. resize: true,//是否允许拉伸
  727. content: src,//内容
  728. move: '.layui-layer-title'
  729. });
  730. });
  731. },
  732. changeIMG: function (name, value) {
  733. if (this.getRule(name).maxLength !== undefined) {
  734. var that = this;
  735. value.map(function (v) {
  736. that.formData[name].push(v);
  737. });
  738. this.$set(this.formData, name, this.formData[name]);
  739. } else {
  740. if(name == 'batchAttr.pic'){
  741. this.batchAttr.pic = value;
  742. } else {
  743. if (name.indexOf('.') !== -1) {
  744. var key = name.split('.');
  745. if (key.length == 2){
  746. this.formData[key[0]][key[1]] = value;
  747. } else if(key.length == 3){
  748. this.formData[key[0]][key[1]][key[2]] = value;
  749. } else if(key.length == 4){
  750. this.$set(this.formData[key[0]][key[1]][key[2]],key[3],value)
  751. }
  752. } else {
  753. this.formData[name] = value;
  754. }
  755. }
  756. }
  757. },
  758. getRule: function (name) {
  759. return this.rule[name] || {};
  760. },
  761. uploadImage: function (name) {
  762. return this.createFrame('选择图片',this.U({c:"widget.images",a:'index',p:{fodder:name}}),{h:545,w:900});
  763. },
  764. uploadVideo: function () {
  765. if (this.videoLink) {
  766. this.formData.video_link = this.videoLink;
  767. } else {
  768. $(this.$refs.filElem).click();
  769. }
  770. },
  771. delVideo: function () {
  772. var that = this;
  773. that.$set(that.formData, 'video_link', '');
  774. },
  775. insertEditor: function (list) {
  776. this.um.execCommand('insertimage', list);
  777. },
  778. insertEditorVideo: function (src) {
  779. this.um.setContent('<div><video style="width: 99%" src="'+src+'" class="video-ue" controls="controls" width="100"><source src="'+src+'"></source></video></div><br>',true);
  780. },
  781. getContent: function () {
  782. return this.um.getContent();
  783. },
  784. /**
  785. * 监听radio字段
  786. */
  787. eeventRadio: function () {
  788. var that = this;
  789. that.radioRule.map(function (val) {
  790. that.form.on('radio(' + val + ')', function (res) {
  791. that.formData[val] = res.value;
  792. });
  793. })
  794. },
  795. init: function () {
  796. var that = this;
  797. window.UMEDITOR_CONFIG.toolbar = [
  798. // 加入一个 test
  799. 'source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
  800. 'insertorderedlist insertunorderedlist | selectall cleardoc paragraph | fontfamily fontsize',
  801. '| justifyleft justifycenter justifyright justifyjustify |',
  802. 'link unlink | emotion selectimgs video | map',
  803. '| horizontal print preview fullscreen', 'drafts', 'formula'
  804. ];
  805. UM.registerUI('selectimgs', function (name) {
  806. var me = this;
  807. var $btn = $.eduibutton({
  808. icon: 'image',
  809. click: function () {
  810. that.createFrame('选择图片', "{:Url('widget.images/index',['fodder'=>'editor'])}");
  811. },
  812. title: '选择图片'
  813. });
  814. this.addListener('selectionchange', function () {
  815. //切换为不可编辑时,把自己变灰
  816. var state = this.queryCommandState(name);
  817. $btn.edui().disabled(state == -1).active(state == 1)
  818. });
  819. return $btn;
  820. });
  821. UM.registerUI('video', function (name) {
  822. var me = this;
  823. var $btn = $.eduibutton({
  824. icon: 'video',
  825. click: function () {
  826. that.createFrame('选择视频', "{:Url('widget.video/index',['fodder'=>'video'])}");
  827. },
  828. title: '选择视频'
  829. });
  830. this.addListener('selectionchange', function () {
  831. //切换为不可编辑时,把自己变灰
  832. var state = this.queryCommandState(name);
  833. $btn.edui().disabled(state == -1).active(state == 1)
  834. });
  835. return $btn;
  836. });
  837. //实例化编辑器
  838. this.um = UM.getEditor('myEditor', {initialFrameWidth: '99%', initialFrameHeight: 400});
  839. this.um.setContent(that.formData.description);
  840. that.$nextTick(function () {
  841. layui.use(['form','element','laydate'], function () {
  842. that.form = layui.form;
  843. that.laydate = layui.laydate;
  844. that.form.render();
  845. that.form.on('select(temp_id)', function (data) {
  846. that.$set(that.formData, 'temp_id', data.value);
  847. });
  848. that.form.on('select(rule_index)', function (data) {
  849. that.ruleIndex = data.value;
  850. });
  851. layui.element.on('tab(docTabBrief)', function(){
  852. that.layTabId = this.getAttribute('lay-id');
  853. });
  854. that.laydate.render({
  855. elem: '#date'
  856. ,type: 'date'
  857. ,range: true,
  858. change:function (value, date, endDate) {
  859. that.formData.start_time = `${date.year}-${date.month}-${date.date}`;
  860. that.formData.stop_time = `${endDate.year}-${endDate.month}-${endDate.date}`;
  861. }
  862. });
  863. that.eeventRadio();
  864. });
  865. // layui.config({
  866. // base : '/static/plug/layui/'
  867. // }).extend({
  868. // selectN: './selectN',
  869. // }).use('selectM',function () {
  870. // var selectM = layui.selectM;
  871. // selectM({
  872. // //元素容器【必填】
  873. // elem: '#cate_id'
  874. // //候选数据【必填】
  875. // ,data: that.cateList
  876. // //默认值
  877. // ,selected: that.formData.cate_id || []
  878. // //最多选中个数,默认5
  879. // ,max : 10
  880. // ,name: 'cate_id'
  881. // ,model: 'formData.cate_id'
  882. // //值的分隔符
  883. // ,delimiter: ','
  884. // //候选项数据的键名
  885. // ,field: {idName:'value',titleName:'label',statusName:'disabled'}
  886. // });
  887. // });
  888. })
  889. },
  890. requestPost: function (url, data) {
  891. return new Promise(function (resolve, reject) {
  892. axios.post(url, data).then(function (res) {
  893. if (res.status == 200 && res.data.code == 200) {
  894. resolve(res.data)
  895. } else {
  896. reject(res.data);
  897. }
  898. }).catch(function (err) {
  899. reject({msg:err})
  900. });
  901. })
  902. },
  903. requestGet: function (url) {
  904. return new Promise(function (resolve, reject) {
  905. axios.get(url).then(function (res) {
  906. if (res.status == 200 && res.data.code == 200) {
  907. resolve(res.data)
  908. } else {
  909. reject(res.data);
  910. }
  911. }).catch(function (err) {
  912. reject({msg:err})
  913. });
  914. })
  915. },
  916. generates: function () {
  917. var that = this;
  918. that.generate(1);
  919. },
  920. generate: function (type = 0) {
  921. var that = this;
  922. this.requestPost(that.U({c:"store.StoreProduct",a:'is_format_attr',p:{id:that.id,type:type}}), {attrs:this.formData.items}).then(function (res) {
  923. that.$set(that.formData, 'attrs', res.data.value);
  924. that.$set(that, 'formHeader', res.data.header);
  925. if (that.id && that.formData.is_sub == 1 && that.formData.spec_type == 1) {
  926. that.formHeader.push({title:'一级返佣(元)'});
  927. that.formHeader.push({title:'二级级返佣(元)'});
  928. }
  929. }).catch(function (res) {
  930. return that.showMsg(res.msg);
  931. });
  932. },
  933. handleSubmit:function () {
  934. var that = this, cate_id = $('input[name="cate_id"]').val();
  935. // if (cate_id != '') {
  936. // this.formData.cate_id = cate_id.split(',');
  937. // }
  938. // if (!that.formData.cate_id.length) {
  939. // return that.showMsg('请选择商品分类');
  940. // }
  941. // if (!that.formData.temp_id) {
  942. // return that.showMsg('请选择运费模板');
  943. // }
  944. if (!that.formData.title) {
  945. return that.showMsg('请填写商品名称');
  946. }
  947. if (!that.formData.image) {
  948. return that.showMsg('请填选择商品图');
  949. }
  950. if (!that.formData.images.length) {
  951. return that.showMsg('请填选择商品轮播图');
  952. }
  953. that.formData.description = that.getContent();
  954. $('#submit').attr('disabled', 'disabled').text('保存中...');
  955. that.requestPost(that.U({c:'ump.StoreWholesale',a:'save',p:{id:that.id}}),that.formData).then(function (res) {
  956. that.confirm();
  957. }).catch(function (res) {
  958. that.showMsg(res.msg);
  959. });
  960. },
  961. confirm: function(){
  962. var that = this;
  963. layui.use(['layer'], function () {
  964. var layer = layui.layer;
  965. layer.confirm(that.id ? '修改成功是否返回产品列表' : '添加成功是否返回产品列表', {
  966. btn: ['返回列表',that.id ? '继续修改' : '继续添加'] //按钮
  967. }, function(){
  968. location.href = that.U({c:'ump.StoreWholesale',a:'index'});
  969. }, function(){
  970. location.reload();
  971. });
  972. });
  973. },
  974. render:function(){
  975. this.$nextTick(function(){
  976. layui.use(['form'], function () {
  977. layui.form.render('select');
  978. });
  979. })
  980. },
  981. // 移动
  982. handleDragStart (e, item) {
  983. this.dragging = item;
  984. },
  985. handleDragEnd (e, item) {
  986. this.dragging = null
  987. },
  988. handleDragOver (e) {
  989. e.dataTransfer.dropEffect = 'move'
  990. },
  991. handleDragEnter (e, item) {
  992. e.dataTransfer.effectAllowed = 'move'
  993. if (item === this.dragging) {
  994. return
  995. }
  996. var newItems = [...this.formData.activity];
  997. var src = newItems.indexOf(this.dragging);
  998. var dst = newItems.indexOf(item);
  999. newItems.splice(dst, 0, ...newItems.splice(src, 1))
  1000. this.formData.activity = newItems;
  1001. },
  1002. getRuleList:function (type) {
  1003. var that = this;
  1004. that.requestGet(that.U({c:'store.StoreProduct',a:'get_rule'})).then(function (res) {
  1005. that.$set(that,'ruleList',res.data);
  1006. if(type !== undefined){
  1007. that.render();
  1008. }
  1009. });
  1010. },
  1011. addRule:function(){
  1012. return this.createFrame('添加商品规则',this.U({c:'store.StoreProductRule',a:'create'}));
  1013. },
  1014. allRule:function () {
  1015. if (this.ruleIndex != -1) {
  1016. var rule = this.ruleList[this.ruleIndex];
  1017. if (rule) {
  1018. this.ruleBool = true;
  1019. var rule_value = rule.rule_value.map(function (item) {
  1020. return item;
  1021. });
  1022. this.$set(this.formData,'items',rule_value);
  1023. this.$set(this.formData,'attrs',[]);
  1024. this.$set(this,'formHeader',[]);
  1025. return true;
  1026. }
  1027. }
  1028. this.showMsg('选择的属性无效');
  1029. }
  1030. },
  1031. mounted: function () {
  1032. var that = this;
  1033. axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
  1034. that.getProductInfo();
  1035. window.$vm = that;
  1036. window.changeIMG = that.changeIMG;
  1037. window.insertEditor = that.insertEditor;
  1038. window.insertEditorVideo = that.insertEditorVideo;
  1039. window.successFun = function(){
  1040. that.getRuleList(1);
  1041. }
  1042. $(that.$refs.filElem).change(function () {
  1043. var inputFile = this.files[0];
  1044. that.requestPost(that.U({c:"widget.video",a:'get_signature'})).then(function (res) {
  1045. AdminUpload.upload(res.data.uploadType,{
  1046. token: res.data.uploadToken || '',
  1047. file: inputFile,
  1048. accessKeyId: res.data.accessKey || '',
  1049. accessKeySecret: res.data.secretKey || '',
  1050. bucketName: res.data.storageName || '',
  1051. region: res.data.storageRegion || '',
  1052. domain: res.data.domain || '',
  1053. uploadIng:function (progress) {
  1054. that.upload.videoIng = true;
  1055. that.progress = progress;
  1056. }
  1057. }).then(function (res) {
  1058. //成功
  1059. that.$set(that.formData, 'video_link', res.url);
  1060. that.progress = 0;
  1061. that.upload.videoIng = false;
  1062. return that.showMsg('上传成功');
  1063. }).catch(function (err) {
  1064. //失败
  1065. console.info(err);
  1066. return that.showMsg('上传错误请检查您的配置');
  1067. });
  1068. }).catch(function (res) {
  1069. return that.showMsg(res.msg || '获取密钥失败,请检查您的配置');
  1070. });
  1071. })
  1072. }
  1073. });
  1074. </script>
  1075. </body>
  1076. </html>
  1077. <script>
  1078. // import Layout from "../../../../../public/static/plug/iview/dist/iview";
  1079. // export default {
  1080. // components: {Layout}
  1081. // }
  1082. </script>