|
@@ -1,50 +1,242 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
<el-dialog
|
|
|
- :title="exData.id ? '编辑': ''"
|
|
|
+ :title="exData.id ? '编辑': '新增'"
|
|
|
:visible.sync="dialog"
|
|
|
- width="800px"
|
|
|
+ width="900px"
|
|
|
:close-on-click-modal="false"
|
|
|
top="50px">
|
|
|
<el-form
|
|
|
ref="form"
|
|
|
- :rules="formRules"
|
|
|
:model="form"
|
|
|
+ :rules="formRules"
|
|
|
label-width="120px">
|
|
|
<el-form-item
|
|
|
- label="审核:"
|
|
|
- prop="type"
|
|
|
- :rules="formRules.select">
|
|
|
- <el-radio-group
|
|
|
- v-model="form.type">
|
|
|
- <el-radio
|
|
|
- :label="item.value"
|
|
|
- v-for="item in reviewStatus"
|
|
|
- :key="item.value">{{ item.name }}
|
|
|
- </el-radio>
|
|
|
- </el-radio-group>
|
|
|
+ prop="product_title"
|
|
|
+ :rules="formRules.required"
|
|
|
+ label="商品名称:">
|
|
|
+ <el-input
|
|
|
+ v-model="form.product_title"
|
|
|
+ placeholder="请输入商品名称"
|
|
|
+ clearable></el-input>
|
|
|
</el-form-item>
|
|
|
<el-form-item
|
|
|
- label="备注:"
|
|
|
- prop="product_check_remark">
|
|
|
+ prop="product_desc"
|
|
|
+ :rules="formRules.required"
|
|
|
+ label="商品描述:">
|
|
|
<el-input
|
|
|
type="textarea"
|
|
|
- :rows="6"
|
|
|
- placeholder="请输入备注"
|
|
|
- v-model="form.product_check_remark"
|
|
|
- maxlength="1000"
|
|
|
- show-word-limit>
|
|
|
+ :rows="4"
|
|
|
+ placeholder="请输入商品描述"
|
|
|
+ v-model="form.product_desc">
|
|
|
</el-input>
|
|
|
</el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ prop="product_img_url"
|
|
|
+ :rules="formRules.uploadImgs"
|
|
|
+ label="商品主图:">
|
|
|
+ <el-upload
|
|
|
+ :on-remove="(file) => {handleRemove(file, 'product_img_url')}"
|
|
|
+ :on-success="(file) => {handleAvatarSuccess(file, 'product_img_url')}"
|
|
|
+ :before-upload="beforeAvatarUpload"
|
|
|
+ :on-exceed="hadnleExceed"
|
|
|
+ :accept="'image/*'"
|
|
|
+ :limit="1"
|
|
|
+ :file-list="product_img_url"
|
|
|
+ list-type="picture-card"
|
|
|
+ action="/api/upload/img"
|
|
|
+ multiple
|
|
|
+ ref="product_img_url">
|
|
|
+ <i class="el-icon-plus"></i>
|
|
|
+ <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过5M</div>
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ prop="product_rotation_img_list"
|
|
|
+ :rules="formRules.uploadImgs"
|
|
|
+ label="商品轮播图:">
|
|
|
+ <el-upload
|
|
|
+ :on-remove="(file) => {handleRemove(file, 'product_rotation_img_list')}"
|
|
|
+ :on-success="(file) => {handleAvatarSuccess(file, 'product_rotation_img_list')}"
|
|
|
+ :before-upload="beforeAvatarUpload"
|
|
|
+ :on-exceed="hadnleExceed"
|
|
|
+ :accept="'image/*'"
|
|
|
+ :limit="5"
|
|
|
+ :file-list="product_rotation_img_list"
|
|
|
+ list-type="picture-card"
|
|
|
+ action="/api/upload/img"
|
|
|
+ multiple
|
|
|
+ ref="product_rotation_img_list">
|
|
|
+ <i class="el-icon-plus"></i>
|
|
|
+ <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过5M</div>
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ prop="product_detail_img_list"
|
|
|
+ :rules="formRules.uploadImgs"
|
|
|
+ label="商品详情图:">
|
|
|
+ <el-upload
|
|
|
+ :on-remove="(file) => {handleRemove(file, 'product_detail_img_list')}"
|
|
|
+ :on-success="(file) => {handleAvatarSuccess(file, 'product_detail_img_list')}"
|
|
|
+ :before-upload="beforeAvatarUpload"
|
|
|
+ :on-exceed="hadnleExceed"
|
|
|
+ :accept="'image/*'"
|
|
|
+ :limit="5"
|
|
|
+ :file-list="product_detail_img_list"
|
|
|
+ list-type="picture-card"
|
|
|
+ action="/api/upload/img"
|
|
|
+ multiple
|
|
|
+ ref="product_detail_img_list">
|
|
|
+ <i class="el-icon-plus"></i>
|
|
|
+ <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过5M</div>
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ prop="product_category_id"
|
|
|
+ :rules="formRules.select"
|
|
|
+ label="商品分类:">
|
|
|
+ <el-select
|
|
|
+ style="width: 100%;"
|
|
|
+ v-model="form.product_category_id"
|
|
|
+ filterable
|
|
|
+ clearable
|
|
|
+ placeholder="请选择商品分类">
|
|
|
+ <el-option
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.value"
|
|
|
+ v-for="item in []"
|
|
|
+ :key="item.value"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ prop="product_brand_id"
|
|
|
+ :rules="formRules.select"
|
|
|
+ label="商品品牌:">
|
|
|
+ <el-select
|
|
|
+ style="width: 100%;"
|
|
|
+ v-model="form.product_brand_id"
|
|
|
+ filterable
|
|
|
+ clearable
|
|
|
+ placeholder="请选择商品品牌">
|
|
|
+ <el-option
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.value"
|
|
|
+ v-for="item in []"
|
|
|
+ :key="item.value"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ prop="product_spec"
|
|
|
+ :rules="formRules.required"
|
|
|
+ label="商品规格:">
|
|
|
+ <el-input
|
|
|
+ v-model="form.product_spec"
|
|
|
+ placeholder="请输入商品规格"
|
|
|
+ clearable></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ prop="product_unit"
|
|
|
+ :rules="formRules.select"
|
|
|
+ label="单位:">
|
|
|
+ <el-select
|
|
|
+ style="width: 100%;"
|
|
|
+ v-model="form.product_unit"
|
|
|
+ filterable
|
|
|
+ clearable
|
|
|
+ placeholder="请选择单位">
|
|
|
+ <el-option
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.value"
|
|
|
+ v-for="item in []"
|
|
|
+ :key="item.value"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ label="批发价:"
|
|
|
+ prop="product_all_price"
|
|
|
+ :rules="formRules.required">
|
|
|
+ <el-input
|
|
|
+ v-model="form.product_all_price"
|
|
|
+ placeholder="精确到小数点后两位"
|
|
|
+ @input="form.product_all_price=form.product_all_price.replace(/^0[0-9]*/, '0').replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ label="零售价:"
|
|
|
+ prop="product_price"
|
|
|
+ :rules="formRules.required">
|
|
|
+ <el-input
|
|
|
+ v-model="form.product_price"
|
|
|
+ placeholder="精确到小数点后两位"
|
|
|
+ @input="form.product_price=form.product_price.replace(/^0[0-9]*/, '0').replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ label="库存:"
|
|
|
+ prop="product_count"
|
|
|
+ :rules="formRules.required">
|
|
|
+ <el-input
|
|
|
+ v-model="form.product_count"
|
|
|
+ placeholder="请输入库存"
|
|
|
+ @input="form.product_count=form.product_count.replace(/[^\d]/g, '').replace(/^0/, '')"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ label="发售时间:"
|
|
|
+ prop="product_sale_at"
|
|
|
+ :rules="formRules.required">
|
|
|
+ <el-radio
|
|
|
+ v-model="form.product_sale_at"
|
|
|
+ label="0">预售
|
|
|
+ </el-radio>
|
|
|
+ <el-radio
|
|
|
+ v-model="form.product_sale_at"
|
|
|
+ label="1">现售
|
|
|
+ </el-radio>
|
|
|
+ <el-date-picker
|
|
|
+ v-model="value1"
|
|
|
+ type="datetime"
|
|
|
+ placeholder="选择预售日期时间">
|
|
|
+ </el-date-picker>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ prop="product_status"
|
|
|
+ :rules="formRules.select"
|
|
|
+ label="状态:">
|
|
|
+ <el-select
|
|
|
+ style="width: 100%;"
|
|
|
+ v-model="form.product_status"
|
|
|
+ filterable
|
|
|
+ clearable
|
|
|
+ placeholder="请选择状态">
|
|
|
+ <el-option
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.value"
|
|
|
+ v-for="item in []"
|
|
|
+ :key="item.value"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item
|
|
|
+ prop="product_is_recommend"
|
|
|
+ :rules="formRules.select"
|
|
|
+ label="是否推荐:">
|
|
|
+ <el-select
|
|
|
+ style="width: 100%;"
|
|
|
+ v-model="form.product_is_recommend"
|
|
|
+ filterable
|
|
|
+ clearable
|
|
|
+ placeholder="请选择是否推荐">
|
|
|
+ <el-option
|
|
|
+ :label="item.name"
|
|
|
+ :value="item.value"
|
|
|
+ v-for="item in arrProductIsRecommend"
|
|
|
+ :key="item.value"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
</el-form>
|
|
|
- <div slot="footer" style="text-align: center">
|
|
|
- <el-button
|
|
|
- @click="dialog = false">取 消
|
|
|
- </el-button>
|
|
|
+ <div slot="footer" class="dialog-footer text-center">
|
|
|
+ <el-button @click="dialog = false">取 消</el-button>
|
|
|
<el-button
|
|
|
type="primary"
|
|
|
- @click="handleSubmit"
|
|
|
- :disabled="booLock">保存
|
|
|
+ :disabled="booLock"
|
|
|
+ @click="handleSubmit">确 定
|
|
|
</el-button>
|
|
|
</div>
|
|
|
</el-dialog>
|
|
@@ -52,6 +244,8 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { fen2Yuan, yuan2Fen } from '@/utils'
|
|
|
+
|
|
|
export default {
|
|
|
props: {
|
|
|
value: {
|
|
@@ -63,51 +257,148 @@ export default {
|
|
|
default: function () {
|
|
|
return {}
|
|
|
}
|
|
|
+ },
|
|
|
+ arrRecommend: {
|
|
|
+ type: Array,
|
|
|
+ default: function () {
|
|
|
+ return []
|
|
|
+ }
|
|
|
+ },
|
|
|
+ arrHideAndShow: {
|
|
|
+ type: Array,
|
|
|
+ default: function () {
|
|
|
+ return []
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
dialog: !!this.value,
|
|
|
form: {
|
|
|
- 'product_check_remark': '', // 审核备注
|
|
|
- 'type': '1' // 状态(1通过2未通过)
|
|
|
+ 'product_title': '测试商品', // 标题
|
|
|
+ 'product_desc': '', // 商品描述
|
|
|
+ 'product_img_url': [], // 商品主图
|
|
|
+ 'product_rotation_img_list': [], // 商品轮播图
|
|
|
+ 'product_detail_img_list': [], // 商品详情图
|
|
|
+ 'product_category_id': 1,
|
|
|
+ 'product_category_name': '水果', // 分类名称 TODO 获取分类列表
|
|
|
+ 'product_brand_id': 1,
|
|
|
+ 'product_brand_name': '大众', // 品牌名称 TODO 获取品牌列表
|
|
|
+ 'product_spec': 'xl', // 规格
|
|
|
+ 'product_unit': '个', // 单位 TODO 获取单位列表
|
|
|
+ 'product_all_price': 10000, // 批发价
|
|
|
+ 'product_price': 9000, // 零售价
|
|
|
+ 'product_count': 1000, // 库存
|
|
|
+ 'product_sale_at': '0', // 发售时间(0代表非预售 时间戳代表预售时间)
|
|
|
+ 'product_status': 0, // 商品状态(0未上架1已上架2审核中3审核未通过)
|
|
|
+ 'product_is_recommend': 0 // 是否推荐(0否1是)
|
|
|
},
|
|
|
- booLock: false
|
|
|
+ product_img_url: [],
|
|
|
+ product_rotation_img_list: [],
|
|
|
+ product_detail_img_list: [],
|
|
|
+ booLock: false,
|
|
|
+ radio: '1',
|
|
|
+ value1: ''
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- reviewStatus() {
|
|
|
- return [
|
|
|
- {
|
|
|
- name: '通过',
|
|
|
- value: '1'
|
|
|
- },
|
|
|
- {
|
|
|
- name: '拒绝',
|
|
|
- value: '2'
|
|
|
- }
|
|
|
- ]
|
|
|
+ arrProductIsRecommend() {
|
|
|
+ return this.$store.state.common.arrProductIsRecommend
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- async handleSubmit() {
|
|
|
+ beforeAvatarUpload(file) {
|
|
|
+ const isLt2M = file.size / 1024 / 1024 < 5
|
|
|
+ if (!isLt2M) {
|
|
|
+ this.$message.error('上传图片大小不能超过 5MB!')
|
|
|
+ }
|
|
|
+ return isLt2M
|
|
|
+ },
|
|
|
+ hadnleExceed(files, fileList) {
|
|
|
+ this.$message({
|
|
|
+ message: '最多上传一张',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleRemove(file, formKey) {
|
|
|
+ let path = file.url
|
|
|
+ if (file.response && file.response.data) {
|
|
|
+ path = file.response.data.path
|
|
|
+ }
|
|
|
+ this.form[formKey] = this.form[formKey].filter(item => item !== path)
|
|
|
+ },
|
|
|
+ handleAvatarSuccess(res, formKey) {
|
|
|
+ if (res.code === 200) {
|
|
|
+ const { path } = res.data
|
|
|
+ this.form[formKey].push(path)
|
|
|
+ } else {
|
|
|
+ this.$message.error('图片上传失败')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleSubmit() {
|
|
|
+ const url = this.exData.id ? '' : ''
|
|
|
this.$refs.form.validate(async valid => {
|
|
|
if (valid) {
|
|
|
+ const formData = JSON.parse(JSON.stringify(this.form))
|
|
|
+ const postData = {
|
|
|
+ ...formData,
|
|
|
+ product_img_url: formData.product_img_url[0],
|
|
|
+ product_rotation_img_list: JSON.stringify(formData.product_rotation_img_list),
|
|
|
+ product_detail_img_list: JSON.stringify(formData.product_detail_img_list)
|
|
|
+ }
|
|
|
this.booLock = true
|
|
|
- const data = await this.$fetch('/api/admin/product/check', this.form)
|
|
|
+ const data = await this.$fetch(url, postData)
|
|
|
+ this.booLock = false
|
|
|
if (data.code === 200) {
|
|
|
- this.dialog = false
|
|
|
- this.$message.success('已审核')
|
|
|
+ this.$message.success('提交成功')
|
|
|
this.$emit('success')
|
|
|
+ this.dialog = false
|
|
|
}
|
|
|
- this.booLock = false
|
|
|
}
|
|
|
})
|
|
|
+ },
|
|
|
+ showVideoPlayDialog() {
|
|
|
+ this.$store.commit('common/SET_VIDEOPLAYDIALOG', {
|
|
|
+ src: this.form.video_url[0],
|
|
|
+ show: true
|
|
|
+ })
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
if (this.exData.id) {
|
|
|
this.$set(this.form, 'id', this.exData.id)
|
|
|
+ this.product_img_url = [
|
|
|
+ {
|
|
|
+ name: '',
|
|
|
+ url: this.exData.product_img_url
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ this.product_rotation_img_list = [
|
|
|
+ {
|
|
|
+ name: '',
|
|
|
+ url: this.exData.product_rotation_img_list
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ this.product_detail_img_list = [
|
|
|
+ {
|
|
|
+ name: '',
|
|
|
+ url: this.exData.product_detail_img_list
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ for (const key in this.exData) {
|
|
|
+ if (this.form.hasOwnProperty(key)) {
|
|
|
+ let value = this.exData[key]
|
|
|
+ if ((Array.isArray(value) && value.length >= 1) || (Object.prototype.toString.call(value) === '[object Object]') || (typeof value === 'string' && value) || typeof value === 'number') {
|
|
|
+ if (key === 'product_img_url' || key === 'product_rotation_img_list' || key === 'product_detail_img_list') {
|
|
|
+ value = [value]
|
|
|
+ }
|
|
|
+ if (key === 'product_all_price' || key === 'product_price') {
|
|
|
+ value = fen2Yuan(value)
|
|
|
+ }
|
|
|
+ this.$set(this.form, key, value)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
@@ -119,9 +410,22 @@ export default {
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
-.hide-el-upload {
|
|
|
- ::v-deep .el-upload--picture-card {
|
|
|
- visibility: hidden;
|
|
|
+.top-tip {
|
|
|
+ margin-top: -20px;
|
|
|
+ margin-bottom: 20px;
|
|
|
+}
|
|
|
+
|
|
|
+.af-put-line-radio {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+
|
|
|
+ p.lalel {
|
|
|
+ padding: 0 10px;
|
|
|
+ }
|
|
|
+
|
|
|
+ p {
|
|
|
+ padding: 0;
|
|
|
+ margin: 0;
|
|
|
}
|
|
|
}
|
|
|
</style>
|