AddGood.vue 13 KB

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