detail.blade.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. @extends('layouts.base')
  2. @section('title', trans('编辑素材'))
  3. @section('content')
  4. @include('public.admin.uploadMultimediaImg')
  5. <link rel="stylesheet" type="text/css" href="{{static_url('yunshop/goods/vue-goods1.css')}}" />
  6. <style>
  7. .vue-main {
  8. padding: 10px 500px 10px 150px !important;
  9. }
  10. .el-form-item__label{
  11. color:#333333
  12. }
  13. .upload-box {
  14. flex-direction: column;
  15. margin-left: 15px;
  16. position: relative;
  17. }
  18. .tips {
  19. color: #8f8f8f;
  20. }
  21. .goods {
  22. margin-left: 10px;
  23. }
  24. .el-icon-error{
  25. font-size: 18px;
  26. }
  27. </style>
  28. <div id="app">
  29. <div class="all">
  30. <div class="vue-head">
  31. <div class="vue-main-title">
  32. <div class="vue-main-title-left"></div>
  33. <div class="vue-main-title-content">添加素材</div>
  34. </div>
  35. <div class="vue-main">
  36. <el-form label-position="right" label-width="80px" :model="form" ref="ruleForm" :rules="rules">
  37. <el-form-item prop="title" label="标题" label-width="100px" required>
  38. <el-input v-model="form.title"></el-input>
  39. </el-form-item>
  40. <el-form-item label="商品分类" label-width="100px" required>
  41. <el-select v-model="category.parentid[0]" placeholder="请选择一级分类" @change="getChildCategory">
  42. <el-option v-for="item in firstTypeOptions" :key="item.id" :label="item.name" :value="item.id">
  43. </el-option>
  44. </el-select>
  45. <el-select v-model="category.childid[0]" placeholder="请选择二级级分类">
  46. <el-option v-for="item in secondTypeOptions" :key="item.id" :label="item.name" :value="item.id">
  47. </el-option>
  48. </el-select>
  49. </el-form-item>
  50. <el-form-item label="商品" label-width="100px">
  51. <el-button type="primary" @click="selectShop">选择商品</el-button>
  52. <div v-if="selectGoods" style="margin-top:10px;display:flex;flex-direction: column">
  53. <div style="position: relative;">
  54. <i class="el-icon-error" style="position: absolute;top: -5px;left: 140px;cursor: pointer;" @click="deleteGoods"></i>
  55. <img :src="selectGoods.thumb" alt="" style="width: 150px;height:150px">
  56. </div>
  57. <span style="line-height: 16px;">[[selectGoods.title]]</span>
  58. <span style="line-height: 16px;">[ID:[[selectGoods.id]]]</span>
  59. </div>
  60. </el-form-item>
  61. <el-form-item prop="content" label="素材文案" label-width="100px" required>
  62. <el-input type="textarea" placeholder="请输入文案 10-200字" v-model="form.content" maxlength="200" minlength="10" show-word-limit :rows="8">
  63. </el-input>
  64. </el-form-item>
  65. <el-form-item label="商品图" label-width="100px" required>
  66. <div style="display: flex;">
  67. <div :class=" index !== 0 ? 'goods' :''" v-for="(item,index) in form.images" :key="index" style="position: relative;">
  68. <i class="el-icon-error" style=" position: absolute; right: 0;top: 0px;cursor: pointer;" @click="deleteGoodsPicture(index)"></i>
  69. <img :src="item" alt="" style="width: 150px;height:150px">
  70. </div>
  71. <div class="upload-box" @click="uploadImgList">
  72. <i class="el-icon-plus" style="font-size:32px"></i>
  73. <div style=" width: 100%;
  74. text-align: center;
  75. margin-top: 0px;
  76. position: relative;
  77. top: 39px;
  78. background-color: #333333c2;
  79. color: #ffffff;">点击上传照片</div>
  80. </div>
  81. </div>
  82. <div class="tips">建议尺寸:640*640,或正方形图片,最多添加9张图</div>
  83. </el-form-item>
  84. <el-form-item label="上传视频" label-width="100px">
  85. <div style="display:flex;">
  86. <div class="upload-box" @click="openVideoShow">
  87. <video :src="form.videos.video_url" v-if="form.videos.video_url" style="width:150px;height:150px"></video>
  88. <i class="el-icon-plus" style="font-size:32px" v-else></i>
  89. <i class="el-icon-error" style=" position: absolute; right: 0;top: 0px;cursor: pointer;" @click="deleteVideo" v-if="form.videos.video_url"></i>
  90. <div v-if="!form.videos.video_url" style="width: 100%;
  91. text-align: center;
  92. margin-top: 0px;
  93. position: relative;
  94. top: 39px;
  95. background-color: #333333c2;
  96. color: #ffffff;">点击重新上传视频</div>
  97. <div v-else style="width: 100%;
  98. text-align: center;
  99. margin-top: 0px;
  100. position: relative;
  101. background-color: #333333c2;
  102. color: #ffffff;">点击重新上传视频</div>
  103. </div>
  104. <div class="upload-box" @click="uploadImageShow =true" :style="[{marginLeft:'100px'},{backgroundImage:form.videos.video_image? `url(${form.videos.video_image})`:''},{backgroundSize: '100% 100%'}]">
  105. <i class="el-icon-plus" style="font-size:32px" v-if="!form.videos.video_image"></i>
  106. <i class="el-icon-error" style=" position: absolute; right: 0;top: 0px;cursor: pointer;" @click="deleteVideoPicture" v-else></i>
  107. <div style=" width: 100%;
  108. text-align: center;
  109. position: relative;
  110. background-color: #333333c2;
  111. color: #ffffff;" :style="{top: !form.videos.video_image ? '39px' : '55px' }">点击重新上传封面</div>
  112. </div>
  113. </div>
  114. <div class="tips">设置后商品详情首图默认显示视频,建议时长9-30秒</div>
  115. <div class="tips">视频封面不上传默认商品主图</div>
  116. </el-form-item>
  117. <el-form-item label="是否显示" label-width="100px">
  118. <el-switch v-model="form.is_show" active-color="#13ce66" inactive-color="#ff4949" :active-value=1 :inactive-value=0 >
  119. </el-switch>
  120. </el-form-item>
  121. </el-form>
  122. </div>
  123. </div>
  124. <div class="vue-page">
  125. <div class="vue-center">
  126. <el-button type="primary" @click="submit">提交</el-button>
  127. <el-button @click="backTo">返回</el-button>
  128. </div>
  129. </div>
  130. <select-shop :select-member-visible="selectMemberVisible" @select-good='selectGood' @close="selectMemberVisible = false"></select-shop>
  131. <upload-multimedia-img :upload-show="uploadImgListShow" @sure="uploadImageList" :type="uploadType" @replace="uploadImgListShow = false" sel-num="more" select="open"></upload-multimedia-img>
  132. <upload-multimedia-img :upload-show="uploadVideoShow" @sure="uploadVideo" :type="uploadTypes" @replace="uploadVideoShow = false" sel-num="one"></upload-multimedia-img>
  133. <upload-multimedia-img :upload-show="uploadImageShow" @sure="uploadImage" :type="uploadType" @replace="uploadImageShow = false" sel-num="one"></upload-multimedia-img>
  134. </div>
  135. </div>
  136. @include('Yunshop\MaterialCenter::material.SelectShop')
  137. <script language='javascript'>
  138. let id = "{{ request()-> id }}"
  139. //vue
  140. var app = new Vue({
  141. el: "#app",
  142. delimiters: ['[[', ']]'],
  143. data() {
  144. return {
  145. selectGoods: null,
  146. uploadType:"",
  147. uploadTypes:"",
  148. uploadImgListShow: false,
  149. uploadVideoShow: false,
  150. uploadImageShow: false,
  151. firstTypeOptions: [],
  152. secondTypeOptions: [],
  153. selectMemberVisible: false,
  154. shopKeyword: '',
  155. tableData: [],
  156. page: 1,
  157. total: 1,
  158. pageSize: 12,
  159. category: {
  160. parentid: [],
  161. childid: []
  162. },
  163. form: {
  164. is_show: 0,
  165. title: '',
  166. goods_id: '',
  167. content: '',
  168. images: [],
  169. videos: {
  170. video_url: '',
  171. video_image: ''
  172. }
  173. },
  174. value: '',
  175. rules: {
  176. title: [{
  177. required: true,
  178. message: '请输入标题',
  179. trigger: 'blur'
  180. }],
  181. content: [{
  182. required: true,
  183. message: '请输入素材文案',
  184. trigger: 'blur'
  185. }],
  186. }
  187. }
  188. },
  189. computed: {
  190. },
  191. created() {
  192. this.getCategory()
  193. },
  194. mounted() {
  195. if (id) {
  196. this.getDetail(id)
  197. }
  198. },
  199. methods: {
  200. //返回列表
  201. backTo() {
  202. let url = "{!! yzWebUrl('plugin.material-center.admin.material.index') !!}"
  203. window.location.href = url
  204. },
  205. //提交表单
  206. submit() {
  207. if (id) {
  208. this.$refs["ruleForm"].validate((valid) => {
  209. if (valid && this.form.images.length > 0 && this.category.parentid && this.form.images.length < 10) {
  210. this.$http.post('{!! yzWebFullUrl("plugin.material-center.admin.material.edit") !!}', {
  211. data: {
  212. ...this.form
  213. },
  214. category: this.category,
  215. id:id
  216. }).then(({
  217. data
  218. }) => {
  219. if (data.result) {
  220. let url = "{!! yzWebUrl('plugin.material-center.admin.material.index') !!}"
  221. window.location.href = url
  222. } else {
  223. this.$message.error(data.msg);
  224. }
  225. }, (response) => {
  226. console.log(response);
  227. });
  228. } else if (this.form.images.length = 0) {
  229. this.$message.error('请选择商品图')
  230. return false;
  231. } else if (!this.category.parentid) {
  232. this.$message.error('请选择分类')
  233. return false;
  234. } else if (this.form.images.length > 9) {
  235. this.$message.error('商品图多于9张')
  236. return false;
  237. }
  238. });
  239. } else {
  240. this.$refs["ruleForm"].validate((valid) => {
  241. if (valid && this.form.images.length > 0 && this.category.parentid && this.form.images.length < 10) {
  242. this.$http.post('{!! yzWebFullUrl("plugin.material-center.admin.material.add") !!}', {
  243. data: {
  244. ...this.form
  245. },
  246. category: this.category
  247. }).then(({
  248. data
  249. }) => {
  250. if (data.result) {
  251. let url = "{!! yzWebUrl('plugin.material-center.admin.material.index') !!}"
  252. window.location.href = url
  253. } else {
  254. this.$message.error(data.msg);
  255. }
  256. }, (response) => {
  257. console.log(response);
  258. });
  259. } else if (this.form.images.length = 0) {
  260. this.$message.error('请选择商品图')
  261. return false;
  262. } else if (!this.category.parentid) {
  263. this.$message.error('请选择分类')
  264. return false;
  265. } else if (this.form.images.length > 9) {
  266. this.$message.error('商品图多于9张')
  267. return false;
  268. }
  269. });
  270. }
  271. },
  272. //选择商品
  273. select() {
  274. this.selectMemberVisible = false
  275. },
  276. selectShop() {
  277. this.selectMemberVisible = true
  278. },
  279. uploadImageList(name, image, imageUrl) {
  280. this.uploadImgListShow = false
  281. imageUrl.forEach(item => {
  282. this.form.images.push(item.url)
  283. });
  284. },
  285. uploadVideo(name, show, video) {
  286. this.form.videos.video_url = video[0].url
  287. },
  288. uploadImage(name, image, imageUrl) {
  289. this.form.videos.video_image = imageUrl[0].url
  290. },
  291. replace() {
  292. this.uploadShow = false
  293. },
  294. getDetail(id) {
  295. console.log(id);
  296. this.$http.post('{!! yzWebFullUrl("plugin.material-center.admin.material.detail") !!}', {
  297. id: id
  298. }).then(({
  299. data
  300. }) => {
  301. if (data.result) {
  302. this.form.is_show = data.data.is_show
  303. this.form.goods_id = data.data.goods_id
  304. this.form.content = data.data.content
  305. this.form.images = data.data.images
  306. this.form.videos = data.data.videos
  307. this.form.title = data.data.title
  308. this.category.parentid[0]= parseInt(data.data.has_many_goods_category.category_ids.split(',')[0])
  309. this.getChildCategory(this.category.parentid[0])
  310. this.category.childid[0]= parseInt(data.data.has_many_goods_category.category_ids.split(',')[1])
  311. this.selectGoods = {}
  312. this.selectGoods.thumb = data.data.goods.thumb
  313. this.selectGoods.title = data.data.goods.title
  314. this.selectGoods.id = data.data.goods.id
  315. console.log(this.selectGoods);
  316. } else {
  317. this.$message.error(data.msg);
  318. }
  319. }, (response) => {
  320. console.log(response);
  321. });
  322. },
  323. //选择商品后回调
  324. selectGood(item) {
  325. this.selectMemberVisible = false
  326. this.selectGoods = item
  327. this.form.goods_id = item.id
  328. },
  329. //获取商品分类接口
  330. getCategory() {
  331. this.$http.post('{!! yzWebFullUrl("plugin.material-center.admin.material.get-category") !!}', {}).then(({
  332. data
  333. }) => {
  334. if (data.result) {
  335. this.firstTypeOptions = data.data
  336. } else {
  337. this.$message.error(data.msg);
  338. }
  339. }, (response) => {
  340. console.log(response);
  341. });
  342. },
  343. getChildCategory(id) {
  344. this.$http.post('{!! yzWebFullUrl("plugin.material-center.admin.material.get-category") !!}', {
  345. parent_id: id
  346. }).then(({
  347. data
  348. }) => {
  349. if (data.result) {
  350. this.secondTypeOptions = data.data
  351. } else {
  352. this.$message.error(data.msg);
  353. }
  354. }, (response) => {
  355. console.log(response);
  356. });
  357. },
  358. deleteGoods() {
  359. this.selectGoods = null
  360. this.form.goods_id = ''
  361. },
  362. //移除商品图片
  363. deleteGoodsPicture(index) {
  364. this.form.images.splice(index, 1)
  365. },
  366. //删除视频封面
  367. deleteVideoPicture(event) {
  368. event.stopPropagation()
  369. this.form.videos.video_image = ''
  370. },
  371. //删除视频
  372. deleteVideo(event) {
  373. event.stopPropagation()
  374. this.form.videos.video_url = ''
  375. },
  376. uploadImgList(){
  377. this.uploadImgListShow = true
  378. this.uploadType = '1'
  379. },
  380. openVideoShow(){
  381. this.uploadVideoShow = true
  382. this.uploadTypes = '3'
  383. }
  384. },
  385. components: {
  386. }
  387. })
  388. </script>
  389. @endsection