cloudroam
2025-03-28 cef2bb0eeeb91a22860cf5d23c7348af1ba921dc
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<template>
  <div class="base-page-wrapper">
    <el-bus-form
      ref="form"
      :content="formContent"
      :readonly="!editable"
      label-width="auto"
    ></el-bus-form>
    <div class="text-center mt-20">
      <el-button class="min-w-100" @click="goBack">返回</el-button>
      <el-button
        v-if="editable"
        type="primary"
        :loading="loading"
        class="min-w-100"
        @click="save"
        >保存</el-button
      >
    </div>
  </div>
</template>
 
<script>
import GoodsParams from '@/components/goods/goods-params.vue'
export default {
  data() {
    return {
      loading: false,
      formContent: [
        {
          type: 'row',
          items: [
            { label: '商品名称:', id: 'name', type: 'input', readonly: true },
            {
              label: '商品分类:',
              id: 'categoryStr',
              type: 'input',
              readonly: true,
            },
            { label: '商品规格:', id: 'unit', type: 'input', readonly: true },
            { label: '级别:', id: 'levelStr', type: 'input', readonly: true },
            { label: '商品售价:', id: 'price', type: 'input', readonly: true },
            {
              label: '销量:',
              id: 'sales',
              type: 'input-number',
              el: { precision: 0, min: 0, style: 'width:100%' },
            },
            { label: '库存:', id: 'stock', type: 'input', readonly: true },
            { label: '商品标签:', id: 'tags', type: 'input', readonly: true },
            {
              label: '所属专区:',
              id: 'zoneName',
              type: 'input',
              readonly: true,
            },
            {
              label: '供应商名称:',
              id: 'supplierName',
              type: 'input',
              readonly: true,
            },
            {
              label: '供应商类型:',
              id: 'supplierType',
              type: 'input',
              readonly: true,
            },
            {
              label: '供应商电话:',
              id: 'supplierTel',
              type: 'input',
              readonly: true,
            },
            {
              label: '商品状态:',
              id: 'status',
              type: 'input',
              str: true,
              readonly: true,
            },
            {
              label: '限购数量:',
              id: 'limited',
              type: 'input-number',
              el: { precision: 0,  min:1, max: 99999999,  style: 'width:100%' },
            },
            {
              label: '驳回原因:',
              id: 'auditRemarks',
              type: 'input',
              el: {
                type: 'textarea',
              },
              hidden: (row) => row.status !== 'REJECT',
              readonly: true,
              span: 24,
            },
            {
              label: '列表封面图片:',
              id: 'cover',
              type: 'bus-upload',
              el: {
                listType: 'picture-card',
                valueType: 'string',
              },
              forceDisabled: true,
              span: 24,
              readonly: true,
            },
            {
              label: '轮播图:',
              id: 'bannerList',
              type: 'bus-upload',
              el: {
                listType: 'picture-card',
              },
              forceDisabled: true,
              span: 24,
              inputFormat: (row) => {
                if ('bannerList' in row) {
                  return Array.isArray(row.bannerList)
                    ? row.bannerList.map((item) => ({ url: item }))
                    : []
                }
              },
              readonly: true,
            },
            {
              label: '商品参数:',
              id: 'params',
              component: GoodsParams,
              span: 24,
              forceDisabled: true,
              el: {
                style: 'width:50%',
              },
            },
          ],
        },
      ],
    }
  },
  head() {
    return {
      title: this.title,
    }
  },
  computed: {
    title() {
      return this.$route.params.action === 'edit' ? '编辑商品' : '商品详情'
    },
    editable() {
      return this.$route.params.action === 'edit'
    },
  },
  mounted() {
    this.getDetail()
  },
  methods: {
    async getDetail() {
      this.loading = true
      const { code, data } = await this.$elBusHttp.request(
        'flower/api/flower/list/view',
        { params: { id: this.$route.params.id } }
      )
      if (code === 0) {
        const limited = data.limited;
        if (limited === null) {
          data.limited = undefined;
        }
        this.$refs.form.updateForm(data)
      }
      this.loading = false
    },
    goBack() {
      this.$router.back()
    },
    async save() {
      this.loading = true
      const formValue = this.$refs.form.getFormValue()
      const { code } = await this.$elBusHttp.request(
        'flower/api/flower/list/edit',
        {
          method: 'post',
          data: { ...formValue, id: this.$route.params.id },
        }
      )
      if (code === 0) {
        this.$message.success('保存成功')
        this.goBack()
      } else {
        this.loading = false
      }
    },
  },
}
</script>