Good.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <template>
  2. <div class="good-wrap">
  3. <div class="baseInfo-wrap">
  4. <img :src="goodMess.coverImg" />
  5. <div>
  6. <h5>{{goodMess.title}}</h5>
  7. <p>{{goodMess.produce}}</p>
  8. <span>{{goodMess.price}}</span>
  9. <el-button @click="toShowChange">修改基本信息</el-button>
  10. </div>
  11. </div>
  12. <el-tabs v-model="activeName">
  13. <el-tab-pane label="商品信息" name="goodMess">
  14. <div class="tags-wrap">
  15. <h5>个性化案例展示</h5>
  16. <el-upload
  17. class="upload-demo"
  18. action="https://jsonplaceholder.typicode.com/posts/"
  19. :on-success="handleAvatarSuccess"
  20. :on-remove="handleRemove"
  21. :file-list="fileList"
  22. list-type="picture">
  23. <el-button size="small" type="primary">点击上传</el-button>
  24. </el-upload>
  25. <h5>个性化元素管理</h5>
  26. <div class="btn-wrap">
  27. <el-button size="small" type="primary" @click="toShowAdd">点击添加</el-button>
  28. </div>
  29. <div v-for="item in tagList" class="tags-content" :key="item.id">
  30. <h6>{{item.type}}</h6>
  31. <div>
  32. <el-tag
  33. v-for="(tag,index) in item.list"
  34. :key="index"
  35. closable
  36. :disable-transitions="false"
  37. @close="handleClose(tag,item.id)">
  38. {{tag.name}}
  39. </el-tag>
  40. <el-input
  41. class="input-new-tag"
  42. v-if="item.inputVisible"
  43. v-model="inputValue1"
  44. :ref="item.type"
  45. size="small"
  46. placeholder="标签名称"
  47. ></el-input>
  48. <el-input
  49. class="input-new-tag"
  50. v-if="item.inputVisible"
  51. v-model="inputValue2"
  52. :ref="item.type"
  53. size="small"
  54. placeholder="标签价格"
  55. ></el-input>
  56. <el-button v-if="item.inputVisible" class="button-new-tag" @click="handleInputConfirm(item.id)">确定</el-button>
  57. <el-button v-else class="button-new-tag" size="small" @click="showInput(item.id,item.type)">+ 添加新元素</el-button>
  58. </div>
  59. </div>
  60. </div>
  61. </el-tab-pane>
  62. <el-tab-pane label="商品评价" name="goodEvaluate">
  63. <ul class="comments-wrap">
  64. <li v-for="comment in goodMess.commentsList">
  65. <p>{{comment.text}}</p>
  66. <span>{{comment.author}}</span>
  67. <div></div>
  68. </li>
  69. </ul>
  70. </el-tab-pane>
  71. </el-tabs>
  72. <el-dialog :title="dialogTitle" :visible.sync="dialogTableVisible" :show-close="false">
  73. <div class="dialogheader">
  74. <el-form label-position="right" label-width="80px">
  75. <el-form-item label="商品标题" v-show="dialogTitle=='修改基本信息'">
  76. <el-input v-model="showItem.title"></el-input>
  77. </el-form-item>
  78. <el-form-item label="商品描述" v-show="dialogTitle=='修改基本信息'">
  79. <el-input type="textarea" v-model="showItem.produce"></el-input>
  80. </el-form-item>
  81. <el-form-item label="商品价格" v-show="dialogTitle=='修改基本信息'">
  82. <el-input v-model="showItem.price"></el-input>
  83. </el-form-item>
  84. <el-form-item label="元素分类" v-show="dialogTitle=='添加元素分类'">
  85. <el-input v-model="showItem.type"></el-input>
  86. </el-form-item>
  87. <el-form-item label="元素标签" v-show="dialogTitle=='添加元素分类'">
  88. <el-tag
  89. v-for="(tag,index) in showItem.list"
  90. :key="index"
  91. closable
  92. :disable-transitions="false"
  93. @close="handleClose(tag,-1)">
  94. {{tag.name}}
  95. </el-tag>
  96. <el-input
  97. class="input-new-tag"
  98. v-if="showItem.inputVisible"
  99. v-model="inputValue1"
  100. ref="saveTagInput"
  101. size="small"
  102. placeholder="标签名称"
  103. >
  104. </el-input>
  105. <el-input
  106. class="input-new-tag"
  107. v-if="showItem.inputVisible"
  108. v-model="inputValue2"
  109. ref="saveTagInput"
  110. size="small"
  111. placeholder="标签价格"
  112. >
  113. </el-input>
  114. <el-button v-if="showItem.inputVisible" class="button-new-tag" @click="handleInputConfirm(-1)">确定</el-button>
  115. <el-button v-else class="button-new-tag" size="small" @click="showInput(-1,showItem.type)">+ 添加新元素</el-button>
  116. </el-form-item>
  117. <el-form-item>
  118. <el-button type="primary" @click="toChangeBasicMess" v-show="dialogTitle=='修改基本信息'">提交</el-button>
  119. <el-button type="primary" @click="toAddGoodTags" v-show="dialogTitle=='添加元素分类'">提交</el-button>
  120. <el-button @click="toCancel">取消</el-button>
  121. </el-form-item>
  122. </el-form>
  123. </div>
  124. </el-dialog>
  125. </div>
  126. </template>
  127. <script>
  128. export default{
  129. data(){
  130. return{
  131. goodMess:{},
  132. activeName:"goodMess",
  133. fileList:[],
  134. tagList:[],
  135. inputVisible: false,
  136. inputValue1: '',
  137. inputValue2: '',
  138. dialogTableVisible:false,
  139. dialogTitle:"",
  140. showItem:{
  141. title:"",
  142. produce:"",
  143. price:"",
  144. type:"",
  145. list:[],
  146. inputVisible:false
  147. }
  148. }
  149. },
  150. mounted(){
  151. this.getGoodMess();
  152. },
  153. methods:{
  154. getGoodMess(){
  155. let param = {
  156. shopId:this.$store.state.userMess.id,
  157. goodId:this.$route.params.id.slice(1)
  158. }
  159. this.axios.post(this.Api.getGoodMess,param).then((res)=>{
  160. this.goodMess=res.data;
  161. this.fileList=res.data.exampleImg;
  162. this.tagList=res.data.tags;
  163. }).catch((err)=>{
  164. console.log("getGoodMess:"+err);
  165. });
  166. },
  167. handleRemove(file, fileList) {
  168. let param = {
  169. shopId:this.$store.state.userMess.id,
  170. goodId:this.$route.params.id.slice(1),
  171. type:2,
  172. name:file.name,
  173. }
  174. this.axios.post(this.Api.changeExampleImg,param).then((res)=>{
  175. console.log(res)
  176. }).catch((err)=>{
  177. console.log("handleRemove:"+err);
  178. });
  179. },
  180. handleAvatarSuccess(res, file){
  181. let param = {
  182. shopId:this.$store.state.userMess.id,
  183. goodId:this.$route.params.id.slice(1),
  184. type:1,
  185. file:{name:file.name,url:URL.createObjectURL(file.raw)},
  186. }
  187. this.axios.post(this.Api.changeExampleImg,param).then((res)=>{
  188. console.log(res)
  189. }).catch((err)=>{
  190. console.log("handleAvatarSuccess:"+err);
  191. });
  192. },
  193. handleClose(tag,id) {
  194. if(id!=-1){
  195. this.tagList[id].list.splice(this.tagList[id].list.indexOf(tag), 1);
  196. let param = {
  197. shopId:this.$store.state.userMess.id,
  198. goodId:this.$route.params.id.slice(1),
  199. id:id,
  200. list:this.tagList[id].list,
  201. }
  202. this.axios.post(this.Api.changeTags,param).then((res)=>{
  203. console.log(res)
  204. }).catch((err)=>{
  205. console.log("handleClose:"+err);
  206. });
  207. }else{
  208. this.showItem.list.splice(this.showItem.list.indexOf(tag), 1);
  209. }
  210. },
  211. showInput(id,type) {
  212. if(id!=-1){
  213. this.tagList[id].inputVisible = true;
  214. // this.$nextTick(_ => {
  215. // this.$refs[type][0].$refs.input.focus();
  216. // });
  217. }else{
  218. this.showItem.inputVisible = true;
  219. // this.$nextTick(_ => {
  220. // this.$refs.saveTagInput.$refs.input.focus();
  221. // });
  222. }
  223. },
  224. handleInputConfirm(id) {
  225. let inputValue1 = this.inputValue1;
  226. let inputValue2 = this.inputValue2;
  227. if (inputValue1&&inputValue2&&id!=-1) {
  228. var tag={
  229. name:inputValue1,
  230. price:inputValue2
  231. }
  232. this.tagList[id].list.push(tag);
  233. let param = {
  234. shopId:this.$store.state.userMess.id,
  235. goodId:this.$route.params.id.slice(1),
  236. id:id,
  237. list:this.tagList[id].list,
  238. }
  239. this.axios.post(this.Api.changeTags,param).then((res)=>{
  240. console.log(res)
  241. }).catch((err)=>{
  242. console.log("handleInputConfirm:"+err);
  243. });
  244. this.tagList[id].inputVisible = false;
  245. }else if(inputValue1&&inputValue2&&id==-1){
  246. var tag={
  247. name:inputValue1,
  248. price:inputValue2
  249. }
  250. this.showItem.list.push(tag);
  251. this.showItem.inputVisible = false
  252. }else if(id!=-1&&(inputValue1==""||inputValue2=="")){
  253. this.tagList[id].inputVisible = false;
  254. }else if(id==-1&&(inputValue1==""||inputValue2=="")){
  255. this.showItem.inputVisible = false;
  256. }
  257. this.inputValue1 = '';
  258. this.inputValue2 = '';
  259. },
  260. toCancel(){
  261. this.dialogTableVisible=false;
  262. this.dialogTitle="";
  263. this.showItem={
  264. title:"",
  265. produce:"",
  266. price:"",
  267. type:"",
  268. list:[],
  269. inputVisible:false
  270. }
  271. },
  272. toShowChange(){
  273. this.dialogTableVisible=true;
  274. this.dialogTitle="修改基本信息";
  275. this.showItem.title=this.goodMess.title;
  276. this.showItem.produce=this.goodMess.produce;
  277. this.showItem.price=this.goodMess.price;
  278. },
  279. toChangeBasicMess(){
  280. if(this.showItem.title==""||this.showItem.produce==""||this.showItem.price==""){
  281. this.$message.error('请填写完整信息');
  282. return;
  283. }
  284. let param = {
  285. shopId:this.$store.state.userMess.id,
  286. goodId:this.$route.params.id.slice(1),
  287. title:this.showItem.title,
  288. produce:this.showItem.produce,
  289. price:this.showItem.price
  290. }
  291. this.axios.post(this.Api.changeGoodBasicMess,param).then((res)=>{
  292. console.log(res)
  293. if(res.data.code==200){
  294. this.$message({
  295. message: '编辑成功',
  296. type: 'success'
  297. });
  298. this.toCancel();
  299. this.getGoodMess();
  300. }
  301. }).catch((err)=>{
  302. console.log("toChangeBasicMess:"+err);
  303. });
  304. },
  305. toShowAdd(){
  306. this.dialogTableVisible=true;
  307. this.dialogTitle="添加元素分类";
  308. },
  309. toAddGoodTags(){
  310. console.log(this.showItem.list)
  311. if(this.showItem.type==""||this.showItem.list.length==0){
  312. this.$message.error('请填写完整信息');
  313. return;
  314. }
  315. let param = {
  316. shopId:this.$store.state.userMess.id,
  317. goodId:this.$route.params.id.slice(1),
  318. type:this.showItem.type,
  319. list:this.showItem.list,
  320. }
  321. this.axios.post(this.Api.addGoodTags,param).then((res)=>{
  322. console.log(res)
  323. if(res.data.code==200){
  324. this.$message({
  325. message: '添加成功',
  326. type: 'success'
  327. });
  328. this.toCancel();
  329. this.getGoodMess();
  330. }
  331. }).catch((err)=>{
  332. console.log("toAddGoodTags:"+err);
  333. });
  334. }
  335. }
  336. }
  337. </script>
  338. <style scoped>
  339. .good-wrap{
  340. width: 100%;
  341. padding: 0 20px;
  342. }
  343. .baseInfo-wrap{
  344. width: 100%;
  345. height: 300px;
  346. margin-top: 20px;
  347. background-color: #fff;
  348. border-left: 6px solid #3eb983;
  349. padding: 20px 20px 20px 13px;
  350. }
  351. .baseInfo-wrap img{
  352. display: block;
  353. float: left;
  354. width: 260px;
  355. height: 260px;
  356. }
  357. .baseInfo-wrap div{
  358. float: left;
  359. padding-left: 20px;
  360. text-align: left;
  361. width: calc(100% - 260px);
  362. }
  363. .baseInfo-wrap h5{
  364. font-size: 30px;
  365. margin-bottom: 10px;
  366. }
  367. .baseInfo-wrap p{
  368. font-size: 16px;
  369. color: #666;
  370. width: 100%;
  371. height: 100px;
  372. }
  373. .baseInfo-wrap span{
  374. font-size: 30px;
  375. color: #EA6A69;
  376. line-height: 65px;
  377. display: block;
  378. }
  379. .baseInfo-wrap button{
  380. float: right;
  381. }
  382. .el-tabs{
  383. background-color: #fff;
  384. margin-top: 20px;
  385. padding: 20px;
  386. }
  387. .tags-wrap{
  388. width: 100%;
  389. height: auto;
  390. }
  391. .tags-wrap h5{
  392. height: 50px;
  393. line-height: 50px;
  394. text-align: left;
  395. padding-left: 14px;
  396. border-left: 6px solid #3eb983;
  397. font-size: 16px;
  398. border-bottom: 1px solid #eee;
  399. margin-top: 15px;
  400. font-weight: bolder;
  401. }
  402. .tags-wrap .btn-wrap{
  403. width: 100%;
  404. text-align: left;
  405. padding-top: 10px;
  406. }
  407. .tags-content{
  408. width: 100%;
  409. text-align: left;
  410. }
  411. .tags-content h6{
  412. font-size: 16px;
  413. line-height: 40px;
  414. }
  415. .el-tag + .el-tag {
  416. margin-left: 10px;
  417. }
  418. .button-new-tag {
  419. margin-left: 10px;
  420. height: 32px;
  421. line-height: 30px;
  422. padding-top: 0;
  423. padding-bottom: 0;
  424. }
  425. .input-new-tag {
  426. width: 90px;
  427. margin-left: 10px;
  428. vertical-align: bottom;
  429. }
  430. .comments-wrap{
  431. width: 100%;
  432. }
  433. .comments-wrap li{
  434. width: 100%;
  435. height: auto;
  436. border-bottom: 1px solid #eee;
  437. }
  438. .comments-wrap div{
  439. width: 100%;
  440. height: auto;
  441. clear: both;
  442. }
  443. .comments-wrap p{
  444. width: calc(100% - 200px);
  445. float: left;
  446. text-align: left;
  447. line-height: 30px;
  448. padding: 5px 0 5px 10px;
  449. }
  450. .comments-wrap span{
  451. display: block;
  452. width: 200px;
  453. float: left;
  454. line-height: 40px;
  455. }
  456. </style>
  457. <style>
  458. .good-wrap .el-tabs__item.is-active{
  459. color: #3eb983;
  460. }
  461. .good-wrap .el-tabs__active-bar{
  462. background-color: #3eb983;
  463. }
  464. .good-wrap .el-tabs__header{
  465. margin: 0;
  466. }
  467. .good-wrap .el-upload-list{
  468. display: flex;
  469. flex-wrap: wrap;
  470. justify-content: space-between;
  471. }
  472. .good-wrap .el-upload-list li{
  473. width: 300px;
  474. }
  475. .good-wrap .el-upload{
  476. width: 100%;
  477. text-align: left;
  478. padding-top: 10px;
  479. }
  480. .good-wrap .el-button--primary{
  481. background-color: #3eb983;
  482. border-color: #3eb983;
  483. }
  484. .good-wrap .el-button--primary:hover{
  485. background-color: #3eb983;
  486. border-color: #3eb983;
  487. }
  488. </style>
  489. <style>
  490. .good-wrap .el-dialog{
  491. width: 500px;
  492. /*height: 280px;*/
  493. border-radius: 6px;
  494. text-align: left;
  495. }
  496. .good-wrap .el-dialog__header{
  497. padding: 20px 30px 0 40px;
  498. }
  499. .good-wrap .el-dialog__body{
  500. padding: 20px 30px;
  501. }
  502. .good-wrap .dialogheader{
  503. width: 100%;
  504. /*height: 60px;*/
  505. }
  506. .good-wrap .dialogheader p{
  507. width: 360px;
  508. height: 30px;
  509. line-height: 30px;
  510. margin-top: 10px;
  511. border:1px solid #3eb983;
  512. border-radius: 6px;
  513. text-align: left;
  514. padding-left: 10px;
  515. margin-left: 60px;
  516. }
  517. .good-wrap .dialogheader p input{
  518. height: 24px;
  519. line-height: 24px;
  520. border:0;
  521. margin-left: 20px;
  522. }
  523. .good-wrap .dialogheader .button{
  524. background: #3eb983;
  525. color: #fff;
  526. text-align: center;
  527. margin-top: 40px;
  528. cursor: pointer;
  529. }
  530. .good-wrap .dialogheader .el-button{
  531. width: 173px;
  532. padding: 10px 0;
  533. }
  534. .good-wrap .dialogheader .el-form-item{
  535. margin-bottom: 15px;
  536. }
  537. .good-wrap .dialogheader .el-button+.el-button{
  538. margin-left: 0;
  539. }
  540. .good-wrap .dialogheader .el-button--primary{
  541. background-color: #3eb983;
  542. border-color: #3eb983;
  543. }
  544. .good-wrap .dialogheader .el-button--primary:hover{
  545. background-color: #3eb983;
  546. border-color: #3eb983;
  547. }
  548. .good-wrap .dialogheader .el-button--default{
  549. background-color: #bfcbd9;
  550. color: #fff;
  551. }
  552. .good-wrap .dialogheader .el-button--default:hover{
  553. background-color: #bfcbd9;
  554. border-color: #bfcbd9;
  555. color: #fff;
  556. }
  557. .good-wrap .dialogheader .button-new-tag{
  558. width: auto;
  559. background-color: #fff;
  560. color: #606266;
  561. margin-left: 0;
  562. height: 32px;
  563. line-height: 30px;
  564. padding: 9px 15px;
  565. padding-top: 0;
  566. padding-bottom: 0;
  567. }
  568. .good-wrap .dialogheader .button-new-tag:hover{
  569. color: #409EFF;
  570. background-color: rgba(64,158,255,.1);
  571. border: 1px solid rgba(64,158,255,.2);
  572. }
  573. </style>