fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<template>
  <div class="platform inner-bg-style">
    <el-form size="mini" :disabled="$route.name === 'platformPgInfo'" :model="form"
             label-width="120px" ref="form" :rules="formRules">
      <h4>套餐信息</h4>
      <hr />
      <el-form-item label="套餐编码:" prop="code">
        <el-input class="custom-input-style" placeholder="请输入套餐编码,如:DY4000000789"
                  v-model.trim="form.code"></el-input>
      </el-form-item>
      <el-form-item label="套餐名称:" prop="name">
        <el-input class="custom-input-style" placeholder="请输入套餐名称"
                  v-model.trim="form.name"></el-input>
      </el-form-item>
      <el-form-item label="适用渠道:" prop="belongSource">
        <el-select v-model="form.belongSource" multiple class="custom-selet-style">
          <el-option v-for="item in applicableChannels" :key="item.id" :label="item.name"
                     :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <div class="packageSpecification">
        <h4>套餐规格</h4>
        <hr />
        <el-button size="mini" @click="addProdInfo" type="success">添加商品</el-button>
      </div>
      <!-- <div v-show="form.skuId">
          <el-form-item label="商品主编码:">
            {{form.spuNum}}
          </el-form-item>
          <el-form-item label="商品名称:">
            {{form.spuName}}
          </el-form-item>
          <el-form-item label="商品规格:">
            {{form.spec}}
          </el-form-item>
          <el-form-item label="挂牌价:">
            ¥ {{form.listPrice&&form.listPrice.toFixed(2)}}
          </el-form-item>
          <el-form-item label="销售价:">
              ¥ {{form.salePrice&&form.salePrice.toFixed(2)}}
            </el-form-item>
          <el-form-item label="扣减数量:">
            {{Number(form.skuReduceStorage)}}
          </el-form-item>
        </div> -->
      <!-- <div class="tipText" v-show="tipText&&!form.skuId">
          {{tipText}}
        </div> -->
      <el-form-item prop="mappingList">
        <el-table border size="mini" :data="form.mappingList">
          <el-table-column label="商品主编码" prop="spuNum" show-overflow-tooltip></el-table-column>
          <el-table-column label="商品名称" prop="spuName" show-overflow-tooltip></el-table-column>
          <el-table-column label="规格型号" prop="spec">
            <template slot-scope="scope">
              {{scope.row.spec || '-'}}
            </template>
          </el-table-column>
          <el-table-column label="商品类型" prop="spuType" width="150px" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.spuType ? scope.row.spuType === '1001' ? '销售商品' : '赠品/物料' : '-'}}
            </template>
          </el-table-column>
          <el-table-column label="实际扣减数量/瓶" prop="reduceStorage">
            <template slot-scope="scope">
              <el-form-item :prop="`mappingList.${scope.$index}.reduceStorage`"
                            :rules="formRules.reduceStorage">
                <el-input-number :min="0" :max="999999999"
                                 v-model="scope.row.reduceStorage"></el-input-number>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column width="100px" label="操作">
            <template slot-scope="scope">
              <el-form-item>
                <wly-btn type="danger" size="mini"
                         @click="deleteItem(scope.row,scope.$index)">删除</wly-btn>
              </el-form-item>
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>
      <h4>套餐描述</h4>
      <hr />
      <el-form-item v-if="$route.name !== 'platformPgInfo'" label="套餐描述:" prop="remark">
        <Editor ref="editor" :content.sync="form.remark" @keyup.native="handleKeyup"></Editor>
      </el-form-item>
      <el-form-item v-else label="套餐描述:" prop="remark">
        <div class="content" v-html="form.remark"></div>
      </el-form-item>
    </el-form>
    <div class="buttonPosition">
      <el-button size="mini" @click="submit" v-show="$route.name !== 'platformPgInfo'"
                 :loading="loading" type="primary">保存</el-button>
      <el-button size="mini" @click="preLogList" v-show="$route.name === 'platformPgInfo'"
                 type="primary">查看日志</el-button>
      <el-button size="mini" @click="cancel">取消</el-button>
    </div>
    <inventory-product-selected :show.sync='selectedDialog.show' :multipleSelected="true"
                                :title="selectedDialog.title"
                                @hand-selected-row-data="handSelectedRowData" :producStatus="false">
      <template #column>
        <el-table-column label="商品类型" prop="spuType" width="150px" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.spuType ? scope.row.spuType === '1001' ? '销售商品' : '赠品/物料' : '-'}}
          </template>
        </el-table-column>
      </template>
    </inventory-product-selected>
    <el-dialog :visible.sync="preDialogVisible" title="操作日志列表" :close-on-click-modal="false"
               :modal-append-to-body="false">
      <el-table border :data="logList">
        <el-table-column prop="userName" label="操作用户名称"></el-table-column>
        <!-- <el-table-column prop="" label="操作标识"></el-table-column> -->
        <!-- <el-table-column prop="" label="操作名称"></el-table-column> -->
        <el-table-column prop="createTime" label="操作时间"></el-table-column>
        <el-table-column prop="content" label="操作日志备注"></el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="preDialogVisible=false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import Editor from '@/components/editor/editor.vue'
import inventoryProductSelected from '@/views/channelInventory/components/inventoryProductSelected.vue'
import platformPackageApi from '@/api/platformPackage'
import applicableChannels from '@/utils/constant/orderSourceArr'
import { limitNumType, inputNumberValid } from '@/utils/validator'
export default {
  components: { Editor, inventoryProductSelected },
  data() {
    return {
      applicableChannels,
      selectedDialog: {
        show: false,
        title: '选择商品'
      },
      form: {
        code: null,
        name: null,
        belongSource: [],
        shopId: null,
        spuId: null,
        skuId: null,
        remark: null,
        mappingList: []
      },
      loading: false,
      formRules: {
        code: [
          { required: true, message: '请输入套餐编码', trigger: 'change' },
          { max: 50, message: '套餐编码最多只能输入 50 个字' },
          { validator: limitNumType }
        ],
        name: [
          { required: true, message: '请输入套餐名称', trigger: 'change' },
          { max: 50, message: '套餐名称最多只能输入 50 个字' }
        ],
        belongSource: [{ type: 'array', required: true, message: '请选择适用渠道' }],
        remark: [{ max: 5000, message: '套餐描述最多只能输入 5000 个字' }],
        reduceStorage: [{ required: true, validator: inputNumberValid }],
        mappingList: [{ type: 'array', required: true, message: '请选择商品' }]
      },
      preDialogVisible: false,
      logList: [],
      tipText: null // 当商品被删除时的提示
    }
  },
  created() {
    if (this.$route.query.id) {
      this.getDetails()
    }
  },
  methods: {
    /**
     * 查看日志
     */
    preLogList() {
      this.preDialogVisible = true
    },
    /**
     * 获取详情
     */
    async getDetails() {
      try {
        const res = await platformPackageApi.detailsItem(this.$route.query.id)
        if (res.code === '0' && res.data) {
          res.data.belongSource = res.data.belongSource.split(',')
          this.form = res.data
          this.form.id = this.$route.query.id
          this.logList = res.data.logList
          this.form.remark = this.form.remark.replace(/video src/g, 'video autoplay controls muted src')
        }
      } catch (error) {
      }
    },
    /**
     * 获取选择的商品数据
     */
    handSelectedRowData(rows) {
      rows.forEach(rowItem => {
        if (!this.form.mappingList.find(item => {
          return rowItem.spuNum === item.spuNum
        })) {
          this.form.mappingList.push({
            shopId: '0005',
            spuName: rowItem.spuName,
            spuNum: rowItem.spuNum,
            spec: rowItem.spec,
            reduceStorage: null,
            spuType: rowItem.spuType,
          })
        }
      })
      this.$refs.form.clearValidate('mappingList')
    },
    /**
       * 删除表格数据
       */
    deleteItem(row, index) {
      this.form.mappingList.splice(index, 1)
    },
    /**
     * 打开新增商品信息窗口
     */
    addProdInfo() {
      this.selectedDialog.show = true
    },
    /**
     * 取消
     */
    cancel() {
      this.$router.push({ name: 'platformPackage' })
    },
    handleKeyup() {
      if (this.$refs.editor.getData().length > 5000) {
        this.$refs.form.validateField('remark')
      } else {
        this.$refs.form.clearValidate('remark')
      }
    },
    /**
     * 保存
     */
    submit() {
      this.form.remark = this.$refs.editor.getData()
      this.$refs.form.validate().then((res) => {
        this.loading = true
        this.saveInfo()
      })
    },
    handleFormData() {
      const param = JSON.parse(JSON.stringify(this.form))
      param.belongSource = this.form.belongSource.join()
      delete param.logList
      return param
    },
    // 新增、修改
    async saveInfo() {
      try {
        const res = await platformPackageApi.saveInfo(this.handleFormData())
        if (res.code === '0') {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.loading = false
          this.$router.push({ name: 'platformPackage' })
        } else {
          this.loading = false
        }
      } catch (error) {
        this.loading = false
      }
    }
  }
}
</script>
 
<style lang="scss">
.platform {
  padding: 20px;
  hr {
    border: none;
    height: 1px;
    background-color: #cccccc;
  }
  .packageSpecification {
    margin-bottom: 20px;
  }
  .content {
    width: 90%;
    max-height: 440px;
    border: 1px solid #cccccc;
    padding: 25px;
    overflow-y: auto;
    overflow-x: hidden;
    img,
    video {
      width: 100%;
      height: auto;
    }
    div,
    p {
      width: 100% !important;
    }
  }
  .tipText {
    text-align: center;
    color: #d70012;
  }
}
</style>