EditGoodsDescribe.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div>
  3. <el-upload :action="uploadAction" list-type="picture-card" :file-list="items" :on-success="onUploadSuccess" :before-upload="onBeforeUpload">
  4. <i class="el-icon-plus"></i>
  5. </el-upload>
  6. <div>
  7. <el-button type="primary" @click="save">保存</el-button>
  8. <el-button @click="goBack">取消</el-button>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. export default {
  14. data() {
  15. return {
  16. uploadAction: process.env.SERVER_PATH + 'upload',
  17. items: [],
  18. gid: 0
  19. }
  20. },
  21. methods: {
  22. onBeforeUpload: function(file) {
  23. const isJPG = file.type === 'image/jpeg'
  24. const isPNG = file.type === 'image/png'
  25. if (!isJPG && !isPNG) {
  26. this.$message.error('上传商品图标只能是 JPG/PNG 格式!')
  27. return false
  28. } else {
  29. return true
  30. }
  31. },
  32. onUploadSuccess: function(res, file) {
  33. if (res.code != 0) {
  34. this.$message.error(
  35. '上传图片失败 原因:' + res.msg + '(' + res.code + ')'
  36. )
  37. } else {
  38. this.items.push({ name: '', url: res.obj })
  39. }
  40. },
  41. save: function() {
  42. var items = []
  43. this.items.forEach(it => {
  44. items.push({ title: it.name, content: it.url })
  45. })
  46. var that = this
  47. this.$http
  48. .saveGoodDescribe({ gid: this.gid, items: items }, this)
  49. .then(res => {
  50. if (res.code === 0) {
  51. this.$message({
  52. message: '操作成功',
  53. type: 'success',
  54. duration: 1000,
  55. onClose: function() {
  56. that.goBack()
  57. }
  58. })
  59. }
  60. })
  61. },
  62. goBack: function(){
  63. this.$router.back();
  64. }
  65. },
  66. mounted: function() {
  67. let gid = this.$route.query.gid
  68. this.gid = gid
  69. this.$http.getGoodDescribe({ gid: gid }, this).then(res => {
  70. if (res.code === 0) {
  71. var items = []
  72. res.obj.forEach(item => {
  73. items.push({ id: item.id, name: item.title, url: item.content })
  74. })
  75. this.items = items
  76. }
  77. })
  78. }
  79. }
  80. </script>