MrShi
8 天以前 cb94ff4f0a46eb74c21dd7b34b8d958ef9a9f11c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="confirm"
  >
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="名称" prop="name">
        <el-input   v-model="form.name" placeholder="请输入名称" v-trim/>
      </el-form-item>
      <el-form-item label="战区编码" prop="detail"  v-if="form.type ==0" >
        <el-input v-model="form.detail" placeholder="请输入战区编码" v-trim/>
      </el-form-item>
      <el-form-item v-if="form.type == 3" label="图标" prop="icon">
        <UploadAvatarImage
            :file="{ imgurlfull: form.iconFull, imgurl: form.icon }"
            :uploadData="uploadData"
            @uploadSuccess="uploadAvatarSuccess"
        />
      </el-form-item>
      <el-form-item v-if="form.type == 1" label="排行榜图集" prop="icon">
        <UploadImage
            :fileList="tempfileList"
            :uploadData="uploadData"
            @beginUpload="isUploading=true"
            @endUpload="isUploading=false"/>
        <p class="tip-warn">
          建议尺寸:750px X 750px,上限6张
          支持png、jpg、jpeg格式,大小不超过2M,上传图片不允许涉及政治敏感与色情,
        </p>
      </el-form-item>
      <el-form-item label="排序码" prop="sortnum">
        <el-input v-model="form.sortnum" type="" placeholder="请输入排序码" v-trim/>
      </el-form-item>
      <el-form-item label="描述" prop="remark">
        <el-input type="textarea" v-model="form.remark" placeholder="请输入描述" v-trim/>
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import UploadImage from '@/components/common/UploadImage'
import UploadAvatarImage from '@/components/common/UploadAvatarImage'
export default {
  name: 'OperaCategoryWindow',
  extends: BaseOpera,
  components: { GlobalWindow, UploadAvatarImage,UploadImage },
  data () {
    return {
      isUploading: false,
      uploadData: {
        folder: 'dianjiang/category'
      },
      // 表单数据
      form: {
        id: null,
        status: 0,
        sortnum: null,
        name: '',
        type: null,
        detail: null,
        remark: null,
        fileList: [],
        icon: '',
        iconFull: '',
        isFixed: 0
      },
      tempfileList: [],
      // 验证规则
      rules: {
        name: [{ required: true, message: '请输入名称' }]
      }
    }
  },
  created () {
    this.config({
      api: '/business/category',
      'field.id': 'id'
    })
  },
  methods: {
    del (index) {
      if (this.form.detailList.length <= 1) {
        return
      }
      this.form.detailList.splice(index, 1)
    },
    add () {
      this.form.detailList.push('')
    },
    uploadAvatarSuccess (file) {
      this.$set(this.form, 'icon', file.imgurl)
      this.$set(this.form, 'iconFull', file.imgurlfull)
    },
    confirm () {
      this.form.fileList = this.tempfileList
      if (this.form[this.configData['field.id']] == null || this.form[this.configData['field.id']] === '') {
        this.__confirmCreate()
        return
      }
      this.__confirmEdit()
    },
    open (title, target, type) {
      this.title = title
      this.visible = true
      this.tempfileList = []
      this.form = {
        id: null,
        status: 0,
        sortnum: null,
        name: '',
        detail: null,
        type: type,
        remark: null,
        fileList: [],
        icon: '',
        iconFull: '',
        isFixed: 0
      }
      // 新建
      if (target == null) {
        this.$nextTick(() => {
          this.$refs.form.resetFields()
          this.form[this.configData['field.id']] = null
          this.form.type = type
        })
        return
      }
      // 编辑
      this.$nextTick(() => {
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        this.form.fileList = this.form.fileList||[]
        this.form.fileList.forEach(item=>{
          this.tempfileList.push({
            fileurl: item.fileurl,
            name: item.name,
            url: item.url
          })
        })
      })
    }
  }
}
</script>