product.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. {extend name="public/container"}
  2. {block name='head_top'}
  3. <style>
  4. #app .layui-form-label{padding: 9px 15px;width: 80px;}
  5. #app .layui-input-margin-5{margin-top: 5px}
  6. #app .layui-input-image{width: 100px;height: 100px;}
  7. #app .layui-box{width:100px;height:140px;display: inline-block;margin-right: 10px;margin-bottom: 10px;padding: 2px;border: 1px dashed #0d8ddb;border-radius: 3px;text-align: center;}
  8. #app .layui-box img{width: 100px;height: 100px;margin: 0 auto;display: block;}
  9. #app .layui-box.box-border-color{border: 1px solid #0bb20c;}
  10. #app .layui-box .layui-text{background: rgba(0,0,0,.3);}
  11. #app .layui-box .layui-text p{width: 50%;display: inline;text-align: center;}
  12. #app .spinner {margin: 50px auto;width: 50px;height: 60px;text-align: center;font-size: 10px;}
  13. #app .spinner > div {background-color: #0092DC;height: 100%;width: 6px;display: inline-block;-webkit-animation: stretchdelay 1.2s infinite ease-in-out;animation: stretchdelay 1.2s infinite ease-in-out;}
  14. #app .spinner .rect2 {-webkit-animation-delay: -1.1s;animation-delay: -1.1s;}
  15. #app .spinner .rect3 {-webkit-animation-delay: -1.0s;animation-delay: -1.0s;}
  16. #app .spinner .rect4 {-webkit-animation-delay: -0.9s;animation-delay: -0.9s;}
  17. #app .spinner .rect5 {-webkit-animation-delay: -0.8s;animation-delay: -0.8s;}
  18. #app .save-button{position: fixed;width: 100%;bottom: 0;}
  19. .red {color: red;}
  20. @-webkit-keyframes stretchdelay { 0%, 40%, 100% { -webkit-transform: scaleY(0.4) } 20% { -webkit-transform: scaleY(1.0) } }
  21. @keyframes stretchdelay { 0%, 40%, 100% {transform: scaleY(0.4);-webkit-transform: scaleY(0.4);} 20% {transform: scaleY(1.0);-webkit-transform: scaleY(1.0);} }
  22. </style>
  23. {/block}
  24. {block name="content"}
  25. <div class="layui-fluid">
  26. <div class="layui-row layui-col-space15" id="app" v-cloak="">
  27. <div class="layui-col-md12">
  28. <div class="layui-card">
  29. <div class="layui-card-body">
  30. <blockquote class="layui-elem-quote layui-quote-nm">
  31. <p >生成的商品默认是没有上架的,请手动上架商品!
  32. </blockquote>
  33. <div class="layui-form-item">
  34. <label class="layui-form-label"></label>
  35. <div class="layui-input-block">
  36. <div class="radio i-checks" style="display:inline;margin-left: 16px;">
  37. <label class="" style="padding-left: 0;">
  38. <input style="position: relative;top: 1px;left: 3px;" checked="checked" v-model="type" type="radio" value="taobao" name="type">
  39. 淘宝</label>
  40. </div>
  41. <div class="radio i-checks" style="display:inline;margin-left: 16px;">
  42. <label class="" style="padding-left: 0;">
  43. <input style="position: relative;top: 1px;left: 3px;" checked="checked" v-model="type" type="radio" value="tmall" name="type">
  44. 天猫</label>
  45. </div>
  46. <div class="radio i-checks" style="display:inline;margin-left: 16px;">
  47. <label class="" style="padding-left: 0;">
  48. <input style="position: relative;top: 1px;left: 3px;" checked="checked" v-model="type" type="radio" value="jd" name="type">
  49. 京东</label>
  50. </div>
  51. <div class="radio i-checks" style="display:inline;margin-left: 16px;">
  52. <label class="" style="padding-left: 0;">
  53. <input style="position: relative;top: 1px;left: 3px;" checked="checked" v-model="type" type="radio" value="pdd" name="type">
  54. 拼多多</label>
  55. </div>
  56. <div class="radio i-checks" style="display:inline;margin-left: 16px;">
  57. <label class="" style="padding-left: 0;">
  58. <input style="position: relative;top: 1px;left: 3px;" checked="checked" v-model="type" type="radio" value="suning" name="type">
  59. 苏宁</label>
  60. </div>
  61. <div class="radio i-checks" style="display:inline;margin-left: 16px;">
  62. <label class="" style="padding-left: 0;">
  63. <input style="position: relative;top: 1px;left: 3px;" checked="checked" v-model="type" type="radio" value="1688" name="type">
  64. 1688</label>
  65. </div>
  66. </div>
  67. </div>
  68. <div class="layui-form-item">
  69. <label class="layui-form-label">链接地址</label>
  70. <div class="layui-input-block">
  71. <input type="text" style="width: 80%;display: inline-block;vertical-align: middle" v-model="link" autocomplete="off" placeholder="链接地址" class="layui-input">
  72. <button @click="checkUrl" class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search" lay-filter="search" style="vertical-align: middle">
  73. <i class="layui-icon layui-icon-add-1"></i>确定</button>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. <div class="layui-card" v-if="isLink && link">
  79. <div class="layui-card-header">商品编辑</div>
  80. <div class="layui-card-body">
  81. <form class="layui-form" action="">
  82. <div class="layui-form-item">
  83. <label class="layui-form-label">选择分类<i class="red">*</i></label>
  84. <div class="layui-input-block">
  85. <select name="cate_id" v-model="productInfo.cate_id" lay-verify="cate_id" lay-filter="cate_id">
  86. <option value="">请选择</option>
  87. <option :value="item.value" v-for="item in categoryList" :key="item.id" :disabled="item.disabled" v-text="item.label"></option>
  88. </select>
  89. </div>
  90. </div>
  91. <div class="layui-form-item">
  92. <label class="layui-form-label">产品名称<i class="red">*</i></label>
  93. <div class="layui-input-block">
  94. <input type="text" name="title" v-model="productInfo.store_name" autocomplete="off" placeholder="请输入产品名称" class="layui-input">
  95. </div>
  96. </div>
  97. <div class="layui-form-item layui-form-text">
  98. <label class="layui-form-label">产品简介</label>
  99. <div class="layui-input-block">
  100. <textarea placeholder="请输入内容" class="layui-textarea" v-model="productInfo.store_info"></textarea>
  101. </div>
  102. </div>
  103. <div class="layui-form-item layui-input-margin-5">
  104. <div class="layui-inline">
  105. <label class="layui-form-label">产品关键字</label>
  106. <div class="layui-input-inline">
  107. <input type="text" name="text" autocomplete="off" class="layui-input" v-model="productInfo.keyword">
  108. </div>
  109. </div>
  110. <div class="layui-inline">
  111. <label class="layui-form-label">产品单位</label>
  112. <div class="layui-input-inline">
  113. <input type="text" name="text" autocomplete="off" class="layui-input" v-model="productInfo.unit_name">
  114. </div>
  115. </div>
  116. <div class="layui-inline">
  117. <label class="layui-form-label">产品售价<i class="red">*</i></label>
  118. <div class="layui-input-inline">
  119. <input type="number" name="number" autocomplete="off" class="layui-input" v-model="productInfo.price">
  120. </div>
  121. </div>
  122. </div>
  123. <div class="layui-form-item layui-input-margin-5">
  124. <div class="layui-inline">
  125. <label class="layui-form-label">产品市场价<i class="red">*</i></label>
  126. <div class="layui-input-inline">
  127. <input type="number" name="number" autocomplete="off" class="layui-input" v-model="productInfo.ot_price">
  128. </div>
  129. </div>
  130. <div class="layui-inline">
  131. <label class="layui-form-label">赠送积分</label>
  132. <div class="layui-input-inline">
  133. <input type="number" name="number" autocomplete="off" class="layui-input" v-model="productInfo.give_integral">
  134. </div>
  135. </div>
  136. <div class="layui-inline">
  137. <label class="layui-form-label">运费模板<i class="red">*</i></label>
  138. <div class="layui-input-inline">
  139. <select name="cate_id" v-model="productInfo.temp_id" lay-filter="temp_id">
  140. <option value="">请选择</option>
  141. <option :value="item.id" v-for="item in templatesList" :key="item.id" v-text="item.name"></option>
  142. </select>
  143. </div>
  144. </div>
  145. </div>
  146. <div class="layui-form-item layui-input-margin-5">
  147. <div class="layui-inline">
  148. <label class="layui-form-label">虚拟销量</label>
  149. <div class="layui-input-inline">
  150. <input type="number" name="number" autocomplete="off" class="layui-input" v-model="productInfo.ficti">
  151. </div>
  152. </div>
  153. <div class="layui-inline">
  154. <label class="layui-form-label">库存<i class="red">*</i></label>
  155. <div class="layui-input-inline">
  156. <input type="number" name="number" autocomplete="off" class="layui-input" v-model="productInfo.stock">
  157. </div>
  158. </div>
  159. <div class="layui-inline">
  160. <label class="layui-form-label">产品成本价<i class="red">*</i></label>
  161. <div class="layui-input-inline">
  162. <input type="number" name="number" autocomplete="off" class="layui-input" v-model="productInfo.cost">
  163. </div>
  164. </div>
  165. </div>
  166. <div class="layui-form-item">
  167. <label class="layui-form-label">产品主图片(305*305px)<i class="red">*</i></label>
  168. <div class="layui-input-block">
  169. <div class="layui-box box-border-color" style="height: 100px;">
  170. <img :src="productInfo.image" alt="" class="layui-input-image" @click="lookImage(productInfo.image)">
  171. </div>
  172. </div>
  173. </div>
  174. <div class="layui-form-item">
  175. <label class="layui-form-label">产品轮播图(640*640px)<i class="red">*</i></label>
  176. <div class="layui-input-block">
  177. <div class="layui-box" :class="item.isSelect ? 'box-border-color':'' " v-for="(item,index) in productInfo.slider_image" >
  178. <img :src="item.pic" alt="" class="layui-input-image" @click="lookImage(item.pic)">
  179. <div class="layui-btn-group" style="margin-top: 12px">
  180. <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" @click=" productInfo.image=item.pic ">主图</button>
  181. <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" @click="item.isSelect = !item.isSelect">{{ item.isSelect ? '移除': '选中' }}</button>
  182. </div>
  183. </div>
  184. </div>
  185. </div>
  186. <!-- <div class="layui-form-item" v-if="productInfo.description_images.length">-->
  187. <!-- <label class="layui-form-label">详情图片</label>-->
  188. <!-- <div class="layui-input-block">-->
  189. <!-- <div class="layui-box" :class="item.isSelect ? 'box-border-color':'' " v-for="(item,index) in productInfo.description_images" >-->
  190. <!-- <img :src="item.pic" alt="" class="layui-input-image" @click="lookImage(item.pic)">-->
  191. <!-- <div class="layui-btn-group" style="margin-top: 12px">-->
  192. <!-- <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" @click="item.isSelect = !item.isSelect">{{ item.isSelect ? '移除': '选中' }}</button>-->
  193. <!-- </div>-->
  194. <!-- </div>-->
  195. <!-- </div>-->
  196. <!-- </div>-->
  197. <div class="layui-form-item layui-input-margin-5" style="margin-bottom: 40px;">
  198. <label class="layui-form-label">详情内容</label>
  199. <div class="layui-input-block">
  200. <textarea id="description" style="display: none;" class="layui-textarea" v-model="productInfo.description"></textarea>
  201. </div>
  202. </div>
  203. </form>
  204. </div>
  205. <button class="layui-btn save-button" type="button" @click="saveProduct">立即保存</button>
  206. </div>
  207. <div class="layui-card" v-if="isLink==false && link && loading">
  208. <div class="spinner">
  209. <div class="rect1"></div>
  210. <div class="rect2"></div>
  211. <div class="rect3"></div>
  212. <div class="rect4"></div>
  213. <div class="rect5"></div>
  214. </div>
  215. </div>
  216. </div>
  217. </div>
  218. </div>
  219. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  220. {/block}
  221. {block name="script"}
  222. <script>
  223. layList.form.render();
  224. require(['vue'],function(Vue) {
  225. new Vue({
  226. el: "#app",
  227. data: {
  228. categoryList:<?=json_encode($menus)?>,
  229. link:'',
  230. type:'',
  231. linkhistory:'',
  232. isLink:false,
  233. loading:false,
  234. productInfo:{
  235. description_images:[],
  236. },
  237. slider_image:[],
  238. editIndex:0,
  239. templatesList:[],
  240. },
  241. methods:{
  242. checkUrl:function () {
  243. if(!this.link) return layList.msg('请输入链接地址');
  244. if(this.link==this.linkhistory) return false;
  245. this.linkhistory=this.link;
  246. this.loading=true;
  247. layList.basePost(layList.U({a:'get_product_info'}),{type:this.type,link:this.link},function (res) {
  248. this.loading=false;
  249. this.linkhistory='';
  250. var slider_image=res.data.slider_image,slider_image_new=[],description_images=res.data.description_images,description_images_new=[];
  251. for (var i=0;i<slider_image.length;i++){
  252. slider_image_new.push({pic:slider_image[i],isSelect:true});
  253. }
  254. for(var k=0;k<description_images.length;k++){
  255. description_images_new.push({pic:description_images[k],isSelect:true});
  256. }
  257. res.data.slider_image=slider_image_new;
  258. res.data.description_images=description_images_new;
  259. this.productInfo=res.data;
  260. this.isLink=true;
  261. this.$set(this,'productInfo',this.productInfo);
  262. this.$nextTick(function () {
  263. this.editIndex = layList.layedit.build('description',{
  264. tool: ['strong', 'italic', 'underline', 'del','|', 'left','center','right','link','unlink','face']
  265. });
  266. this.getFreightTemplateList();
  267. }.bind(this));
  268. }.bind(this),function (res) {
  269. this.loading=false;
  270. this.linkhistory='';
  271. layList.msg(res.msg);
  272. }.bind(this));
  273. },
  274. lookImage:function (pic) {
  275. if($eb) $eb.openImage(pic);
  276. },
  277. saveProduct:function () {
  278. var that=this,productInfo={
  279. cate_id:that.productInfo.cate_id,
  280. store_name:that.productInfo.store_name,
  281. store_info:that.productInfo.store_info,
  282. ficti:that.productInfo.ficti,
  283. unit_name:that.productInfo.unit_name,
  284. slider_image:that.productInfo.slider_image,
  285. price:that.productInfo.price,
  286. image:that.productInfo.image,
  287. keyword:that.productInfo.keyword,
  288. give_integral:that.productInfo.give_integral,
  289. give_integral:that.productInfo.give_integral,
  290. ot_price:that.productInfo.ot_price,
  291. stock:that.productInfo.stock,
  292. cost:that.productInfo.cost,
  293. postage:that.productInfo.postage,
  294. description:that.productInfo.description,
  295. temp_id:that.productInfo.temp_id,
  296. description_images:that.productInfo.description_images,
  297. soure_link:that.link,
  298. };
  299. if(!that.productInfo.cate_id) return layList.msg('请选择分类');
  300. if(!that.productInfo.store_name) return layList.msg('请填写商品名称');
  301. if(!that.productInfo.unit_name) return layList.msg('请填写产品单位');
  302. if(!that.productInfo.price) return layList.msg('请填写产品价格');
  303. if(!that.productInfo.ot_price) return layList.msg('请填写产品市场价');
  304. if(!that.productInfo.cost) return layList.msg('请填写产品成本价');
  305. if(!that.productInfo.stock) return layList.msg('请填写产品库存');
  306. if(!that.productInfo.temp_id) return layList.msg('请选择运费模板');
  307. productInfo.slider_image=that.setArraySelect(productInfo.slider_image);
  308. productInfo.description_images=that.setArraySelect(productInfo.description_images);
  309. productInfo.description=layList.layedit.getContent(that.editIndex);
  310. layList.layer.confirm('保存产品生成图片可能较慢,保存中请耐心等待,请不要关闭窗口!确认生成产品和图片吗?', {
  311. btn: ['确定生成','我在想想'] //按钮
  312. }, function(){
  313. var index = layList.layer.load(1, {shade: [0.5,'#000000']});
  314. layList.basePost(layList.U({a:'save_product'}),productInfo,function (res) {
  315. layList.layer.close(index);
  316. layList.msg(res.msg,function () {
  317. var res=layList.layer.confirm('是否要继续添加?', {
  318. btn: ['是的','不了我要关闭'] //按钮
  319. },function () {
  320. that.productInfo={description_images:[]};
  321. that.link='';
  322. that.linkhistory='';
  323. that.$set(that,'productInfo',that.productInfo);
  324. layList.layer.close(res);
  325. },function () {
  326. parent.layer.close(parent.layer.getFrameIndex(window.name));
  327. })
  328. })
  329. },function (res){
  330. layList.layer.close(index);
  331. layList.msg(res.msg);
  332. });
  333. });
  334. },
  335. setArraySelect:function (Arraylist) {
  336. var list=[];
  337. for(var i=0,len=Arraylist.length;i<len;i++) {
  338. if(Arraylist[i].isSelect) list.push(Arraylist[i].pic);
  339. }
  340. return list;
  341. },
  342. getFreightTemplateList:function () {
  343. var that = this;
  344. layList.baseGet(layList.U({c:"setting.shipping_templates",a:'get_template_list'}),function (res) {
  345. that.$set(that,'templatesList',res.data);
  346. that.$nextTick(function () {
  347. layList.form.render('select');
  348. layList.select('temp_id',function (data) {
  349. that.productInfo.temp_id = data.value;
  350. });
  351. })
  352. });
  353. }
  354. },
  355. mounted:function () {
  356. var that=this;
  357. this.$nextTick(function () {
  358. layList.form.render();
  359. layList.select('cate_id',function (data) {
  360. that.productInfo.cate_id=data.value;
  361. });
  362. })
  363. }
  364. })
  365. })
  366. </script>
  367. {/block}