|
@ -1,403 +1,408 @@ |
|
|
<template> |
|
|
<template> |
|
|
<el-card class="form-container" shadow="never"> |
|
|
<el-card class="form-container" shadow="never"> |
|
|
<el-form :model="coupon" |
|
|
<el-form :model="coupon" :rules="rules" ref="couponFrom" label-width="150px" size="small"> |
|
|
:rules="rules" |
|
|
<el-form-item label="优惠券类型:"> |
|
|
ref="couponFrom" |
|
|
<span>全场赠券</span> |
|
|
label-width="150px" |
|
|
</el-form-item> |
|
|
size="small"> |
|
|
<el-form-item label="优惠券名称:" prop="name"> |
|
|
<el-form-item label="优惠券类型:"> |
|
|
<el-input v-model="coupon.name" class="input-width"></el-input> |
|
|
<el-select v-model="coupon.type"> |
|
|
</el-form-item> |
|
|
<el-option v-for='type in typeOptions' :key='type.value' :label='type.label' :value='type.value'></el-option> |
|
|
<el-form-item label="适用平台:"> |
|
|
</el-select> |
|
|
|
|
|
</el-form-item> |
|
|
<span>全平台</span> |
|
|
<el-form-item label="优惠券名称:" prop="name"> |
|
|
</el-form-item> |
|
|
<el-input v-model="coupon.name" class="input-width"></el-input> |
|
|
<el-form-item label="总发行量:" prop="publishCount"> |
|
|
</el-form-item> |
|
|
<el-input v-model.number="coupon.publishCount" placeholder="只能输入正整数" class="input-width"></el-input> |
|
|
<el-form-item label="适用平台:"> |
|
|
</el-form-item> |
|
|
<el-select v-model="coupon.platform"> |
|
|
<el-form-item label="面额:" prop="amount"> |
|
|
<el-option |
|
|
<el-input v-model="coupon.amount" @keyup.native="coupon.amount = UpNumber(coupon.amount,2)" |
|
|
v-for="item in platformOptions" |
|
|
placeholder="面值只能是数值,限2位小数" class="input-width"> |
|
|
:key="item.value" |
|
|
<template slot="append">元</template> |
|
|
:label="item.label" |
|
|
</el-input> |
|
|
:value="item.value"> |
|
|
</el-form-item> |
|
|
</el-option> |
|
|
<el-form-item label="每人限领:"> |
|
|
</el-select> |
|
|
<el-input v-model="coupon.perLimit" placeholder="只能输入正整数" class="input-width"> |
|
|
</el-form-item> |
|
|
<template slot="append">张</template> |
|
|
<el-form-item label="总发行量:" prop="publishCount"> |
|
|
</el-input> |
|
|
<el-input v-model.number="coupon.publishCount" placeholder="只能输入正整数" class="input-width"></el-input> |
|
|
</el-form-item> |
|
|
</el-form-item> |
|
|
<el-form-item label="使用门槛:" prop="minPoint"> |
|
|
<el-form-item label="面额:" prop="amount"> |
|
|
<el-input v-model.number="coupon.minPoint" placeholder="只能输入正整数" class="input-width"> |
|
|
<el-input v-model="coupon.amount" @keyup.native="coupon.amount = UpNumber(coupon.amount,2)" placeholder="面值只能是数值,限2位小数" class="input-width"> |
|
|
<template slot="prepend">满</template> |
|
|
<template slot="append">元</template> |
|
|
<template slot="append">元可用</template> |
|
|
</el-input> |
|
|
</el-input> |
|
|
</el-form-item> |
|
|
</el-form-item> |
|
|
<el-form-item label="每人限领:"> |
|
|
<el-form-item label="有效期:" > |
|
|
<el-input v-model="coupon.perLimit" placeholder="只能输入正整数" class="input-width"> |
|
|
<el-date-picker type="date" placeholder="选择日期" v-model="coupon.startTime" style="width: 150px"> |
|
|
<template slot="append">张</template> |
|
|
</el-date-picker> |
|
|
</el-input> |
|
|
<span style="margin-left: 20px;margin-right: 20px">至</span> |
|
|
</el-form-item> |
|
|
<el-date-picker type="date" placeholder="选择日期" v-model="coupon.endTime" style="width: 150px"> |
|
|
<el-form-item label="使用门槛:" prop="minPoint"> |
|
|
</el-date-picker> |
|
|
<el-input v-model.number="coupon.minPoint" placeholder="只能输入正整数" class="input-width"> |
|
|
</el-form-item> |
|
|
<template slot="prepend">满</template> |
|
|
<el-form-item label="可使用商品:"> |
|
|
<template slot="append">元可用</template> |
|
|
<el-radio-group v-model="coupon.useType"> |
|
|
</el-input> |
|
|
<el-radio-button :label="0">全场通用</el-radio-button> |
|
|
</el-form-item> |
|
|
<el-radio-button :label="1">指定分类</el-radio-button> |
|
|
<el-form-item label="有效期:"> |
|
|
<el-radio-button :label="2">指定商品</el-radio-button> |
|
|
<el-date-picker type="date" placeholder="选择日期" v-model="coupon.startTime" style="width: 150px"></el-date-picker> |
|
|
</el-radio-group> |
|
|
<span style="margin-left: 20px;margin-right: 20px">至</span> |
|
|
</el-form-item> |
|
|
<el-date-picker type="date" placeholder="选择日期" v-model="coupon.endTime" style="width: 150px"></el-date-picker> |
|
|
<el-form-item v-show="coupon.useType===1"> |
|
|
</el-form-item> |
|
|
<el-cascader clearable placeholder="请选择分类名称" v-model="selectProductCate" :options="productCateOptions"> |
|
|
<el-form-item label="可使用商品:"> |
|
|
</el-cascader> |
|
|
<el-radio-group v-model="coupon.useType"> |
|
|
<el-button @click="handleAddProductCategoryRelation()">添加</el-button> |
|
|
<el-radio-button :label="0">全场通用</el-radio-button> |
|
|
<el-table ref="productCateRelationTable" :data="coupon.productCategoryRelationList" |
|
|
<el-radio-button :label="1">指定分类</el-radio-button> |
|
|
style="width: 100%;margin-top: 20px" border> |
|
|
<el-radio-button :label="2">指定商品</el-radio-button> |
|
|
<el-table-column label="分类名称" align="center"> |
|
|
</el-radio-group> |
|
|
<template |
|
|
</el-form-item> |
|
|
slot-scope="scope">{{scope.row.parentCategoryName}}>{{scope.row.productCategoryName}}</template> |
|
|
<el-form-item v-show="coupon.useType===1"> |
|
|
</el-table-column> |
|
|
<el-cascader |
|
|
<el-table-column label="操作" align="center" width="100"> |
|
|
clearable |
|
|
<template slot-scope="scope"> |
|
|
placeholder="请选择分类名称" |
|
|
<el-button size="mini" type="text" |
|
|
v-model="selectProductCate" |
|
|
@click="handleDeleteProductCateRelation(scope.$index, scope.row)">删除 |
|
|
:options="productCateOptions"> |
|
|
</el-button> |
|
|
</el-cascader> |
|
|
</template> |
|
|
<el-button @click="handleAddProductCategoryRelation()">添加</el-button> |
|
|
</el-table-column> |
|
|
<el-table ref="productCateRelationTable" |
|
|
</el-table> |
|
|
:data="coupon.productCategoryRelationList" |
|
|
</el-form-item> |
|
|
style="width: 100%;margin-top: 20px" |
|
|
<el-form-item v-show="coupon.useType===2"> |
|
|
border> |
|
|
<el-select v-model="selectProduct" filterable remote reserve-keyword placeholder="商品名称/商品货号" |
|
|
<el-table-column label="分类名称" align="center"> |
|
|
:remote-method="searchProductMethod" :loading="selectProductLoading"> |
|
|
<template slot-scope="scope">{{scope.row.parentCategoryName}}>{{scope.row.productCategoryName}}</template> |
|
|
<el-option v-for="item in selectProductOptions" :key="item.productId" :label="item.productName" |
|
|
</el-table-column> |
|
|
:value="item.productId"> |
|
|
<el-table-column label="操作" align="center" width="100"> |
|
|
<span style="float: left">{{ item.productName }}</span> |
|
|
<template slot-scope="scope"> |
|
|
<span style="float: right; color: #8492a6; font-size: 13px">NO.{{ item.productSn }}</span> |
|
|
<el-button size="mini" |
|
|
</el-option> |
|
|
type="text" |
|
|
</el-select> |
|
|
@click="handleDeleteProductCateRelation(scope.$index, scope.row)">删除 |
|
|
<el-button @click="handleAddProductRelation()">添加</el-button> |
|
|
</el-button> |
|
|
<el-table ref="productRelationTable" :data="coupon.productRelationList" |
|
|
</template> |
|
|
style="width: 100%;margin-top: 20px" border> |
|
|
</el-table-column> |
|
|
<el-table-column label="商品名称" align="center"> |
|
|
</el-table> |
|
|
<template slot-scope="scope">{{scope.row.productName}}</template> |
|
|
</el-form-item> |
|
|
</el-table-column> |
|
|
<el-form-item v-show="coupon.useType===2"> |
|
|
<el-table-column label="货号" align="center" width="120"> |
|
|
<el-select |
|
|
<template slot-scope="scope">NO.{{scope.row.productSn}}</template> |
|
|
v-model="selectProduct" |
|
|
</el-table-column> |
|
|
filterable |
|
|
<el-table-column label="操作" align="center" width="100"> |
|
|
remote |
|
|
<template slot-scope="scope"> |
|
|
reserve-keyword |
|
|
<el-button size="mini" type="text" |
|
|
placeholder="商品名称/商品货号" |
|
|
@click="handleDeleteProductRelation(scope.$index, scope.row)">删除 |
|
|
:remote-method="searchProductMethod" |
|
|
</el-button> |
|
|
:loading="selectProductLoading"> |
|
|
</template> |
|
|
<el-option |
|
|
</el-table-column> |
|
|
v-for="item in selectProductOptions" |
|
|
</el-table> |
|
|
:key="item.productId" |
|
|
</el-form-item> |
|
|
:label="item.productName" |
|
|
<el-form-item label="备注:"> |
|
|
:value="item.productId"> |
|
|
<el-input class="input-width" type="textarea" :rows="5" placeholder="请输入内容" v-model="coupon.note"> |
|
|
<span style="float: left">{{ item.productName }}</span> |
|
|
</el-input> |
|
|
<span style="float: right; color: #8492a6; font-size: 13px">NO.{{ item.productSn }}</span> |
|
|
</el-form-item> |
|
|
</el-option> |
|
|
<el-form-item> |
|
|
</el-select> |
|
|
<el-button type="primary" @click="onSubmit('couponFrom')">提交</el-button> |
|
|
<el-button @click="handleAddProductRelation()">添加</el-button> |
|
|
<el-button v-if="!isEdit" @click="resetForm('couponFrom')">重置</el-button> |
|
|
<el-table ref="productRelationTable" |
|
|
</el-form-item> |
|
|
:data="coupon.productRelationList" |
|
|
</el-form> |
|
|
style="width: 100%;margin-top: 20px" |
|
|
</el-card> |
|
|
border> |
|
|
|
|
|
<el-table-column label="商品名称" align="center"> |
|
|
|
|
|
<template slot-scope="scope">{{scope.row.productName}}</template> |
|
|
|
|
|
</el-table-column> |
|
|
|
|
|
<el-table-column label="货号" align="center" width="120" > |
|
|
|
|
|
<template slot-scope="scope">NO.{{scope.row.productSn}}</template> |
|
|
|
|
|
</el-table-column> |
|
|
|
|
|
<el-table-column label="操作" align="center" width="100"> |
|
|
|
|
|
<template slot-scope="scope"> |
|
|
|
|
|
<el-button size="mini" |
|
|
|
|
|
type="text" |
|
|
|
|
|
@click="handleDeleteProductRelation(scope.$index, scope.row)">删除 |
|
|
|
|
|
</el-button> |
|
|
|
|
|
</template> |
|
|
|
|
|
</el-table-column> |
|
|
|
|
|
</el-table> |
|
|
|
|
|
</el-form-item> |
|
|
|
|
|
<el-form-item label="备注:"> |
|
|
|
|
|
<el-input |
|
|
|
|
|
class="input-width" |
|
|
|
|
|
type="textarea" |
|
|
|
|
|
:rows="5" |
|
|
|
|
|
placeholder="请输入内容" |
|
|
|
|
|
v-model="coupon.note"> |
|
|
|
|
|
</el-input> |
|
|
|
|
|
</el-form-item> |
|
|
|
|
|
<el-form-item> |
|
|
|
|
|
<el-button type="primary" @click="onSubmit('couponFrom')">提交</el-button> |
|
|
|
|
|
<el-button v-if="!isEdit" @click="resetForm('couponFrom')">重置</el-button> |
|
|
|
|
|
</el-form-item> |
|
|
|
|
|
</el-form> |
|
|
|
|
|
</el-card> |
|
|
|
|
|
</template> |
|
|
</template> |
|
|
<script> |
|
|
<script> |
|
|
import {createCoupon,getCoupon,updateCoupon} from '@/api/coupon'; |
|
|
import { |
|
|
import {fetchSimpleList as fetchProductList} from '@/api/product'; |
|
|
createCoupon, |
|
|
import {fetchListWithChildren} from '@/api/productCate' |
|
|
getCoupon, |
|
|
const defaultCoupon = { |
|
|
updateCoupon |
|
|
type: 0, |
|
|
} from '@/api/coupon'; |
|
|
name: null, |
|
|
import { |
|
|
platform: 0, |
|
|
fetchSimpleList as fetchProductList |
|
|
amount: null, |
|
|
} from '@/api/product'; |
|
|
perLimit: 1, |
|
|
import { |
|
|
minPoint: null, |
|
|
fetchListWithChildren |
|
|
startTime: null, |
|
|
} from '@/api/productCate' |
|
|
endTime: null, |
|
|
const defaultCoupon = { |
|
|
useType: 0, |
|
|
type: 0, |
|
|
note: null, |
|
|
name: null, |
|
|
publishCount: null, |
|
|
platform: 0, |
|
|
productRelationList: [], |
|
|
amount: null, |
|
|
productCategoryRelationList: [] |
|
|
perLimit: 1, |
|
|
}; |
|
|
minPoint: null, |
|
|
const defaultTypeOptions = [ |
|
|
startTime: null, |
|
|
{ |
|
|
endTime: null, |
|
|
label: '全场赠券', |
|
|
useType: 0, |
|
|
value: 0 |
|
|
note: null, |
|
|
}, |
|
|
publishCount: null, |
|
|
{ |
|
|
productRelationList: [], |
|
|
label: '会员赠券', |
|
|
productCategoryRelationList: [] |
|
|
value: 1 |
|
|
}; |
|
|
}, |
|
|
const defaultTypeOptions = [{ |
|
|
{ |
|
|
label: '全场赠券', |
|
|
label: '购物赠券', |
|
|
value: 0 |
|
|
value: 2 |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
label: '会员赠券', |
|
|
label: '注册赠券', |
|
|
value: 1 |
|
|
value: 3 |
|
|
}, |
|
|
} |
|
|
{ |
|
|
]; |
|
|
label: '购物赠券', |
|
|
const defaultPlatformOptions = [ |
|
|
value: 2 |
|
|
{ |
|
|
}, |
|
|
label: '全平台', |
|
|
{ |
|
|
value: 0 |
|
|
label: '注册赠券', |
|
|
}, |
|
|
value: 3 |
|
|
{ |
|
|
} |
|
|
label: '移动平台', |
|
|
]; |
|
|
value: 1 |
|
|
const defaultPlatformOptions = [{ |
|
|
}, |
|
|
label: '全平台', |
|
|
{ |
|
|
value: 0 |
|
|
label: 'PC平台', |
|
|
}, |
|
|
value: 2 |
|
|
{ |
|
|
} |
|
|
label: '移动平台', |
|
|
]; |
|
|
value: 1 |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
label: 'PC平台', |
|
|
|
|
|
value: 2 |
|
|
|
|
|
} |
|
|
|
|
|
]; |
|
|
var validatePrice = (rule, value, callback) => { |
|
|
var validatePrice = (rule, value, callback) => { |
|
|
if (!value) { |
|
|
if (!value) { |
|
|
callback(new Error("面额不能为空")); |
|
|
callback(new Error("面额不能为空")); |
|
|
} else if (value.split(".").length > 2) { |
|
|
} else if (value.split(".").length > 2) { |
|
|
callback(new Error("请输入正确格式的金额")); //防止输入多个小数点 |
|
|
callback(new Error("请输入正确格式的金额")); //防止输入多个小数点 |
|
|
|
|
|
} |
|
|
|
|
|
// else if (value > add_Com.Retail_Price) { |
|
|
|
|
|
// callback(new Error("金额不能大于零售价")); |
|
|
|
|
|
// } |
|
|
|
|
|
else { |
|
|
|
|
|
value = Math.round(value * Math.pow(10, 2)) / Math.pow(10, 2); //四舍五入 |
|
|
|
|
|
value = Number(value).toFixed(2); //不足补位 |
|
|
|
|
|
this.add_Com.Cost_Price = value; |
|
|
|
|
|
callback(); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
|
name: 'CouponDetail', |
|
|
|
|
|
props: { |
|
|
|
|
|
isEdit: { |
|
|
|
|
|
type: Boolean, |
|
|
|
|
|
default: false |
|
|
} |
|
|
} |
|
|
// else if (value > add_Com.Retail_Price) { |
|
|
}, |
|
|
// callback(new Error("金额不能大于零售价")); |
|
|
data() { |
|
|
// } |
|
|
return { |
|
|
else { |
|
|
coupon: Object.assign({}, defaultCoupon), |
|
|
value = Math.round(value * Math.pow(10, 2)) / Math.pow(10, 2); //四舍五入 |
|
|
typeOptions: Object.assign({}, defaultTypeOptions), |
|
|
value = Number(value).toFixed(2); //不足补位 |
|
|
platformOptions: Object.assign({}, defaultPlatformOptions), |
|
|
this.add_Com.Cost_Price = value; |
|
|
rules: { |
|
|
callback(); |
|
|
name: [{ |
|
|
|
|
|
required: true, |
|
|
|
|
|
message: '请输入优惠券名称', |
|
|
|
|
|
trigger: 'blur' |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
min: 2, |
|
|
|
|
|
max: 140, |
|
|
|
|
|
message: '长度在 2 到 140 个字符', |
|
|
|
|
|
trigger: 'blur' |
|
|
|
|
|
} |
|
|
|
|
|
], |
|
|
|
|
|
publishCount: [{ |
|
|
|
|
|
type: 'number', |
|
|
|
|
|
required: true, |
|
|
|
|
|
message: '只能输入正整数', |
|
|
|
|
|
trigger: 'blur' |
|
|
|
|
|
}], |
|
|
|
|
|
amount: [{ |
|
|
|
|
|
|
|
|
|
|
|
required: true, |
|
|
|
|
|
message: '面值只能是数值,0.01-10000,限2位小数', |
|
|
|
|
|
trigger: 'blur' |
|
|
|
|
|
}], |
|
|
|
|
|
minPoint: [{ |
|
|
|
|
|
type: 'number', |
|
|
|
|
|
required: true, |
|
|
|
|
|
message: '只能输入正整数', |
|
|
|
|
|
trigger: 'blur' |
|
|
|
|
|
}] |
|
|
|
|
|
}, |
|
|
|
|
|
selectProduct: null, |
|
|
|
|
|
selectProductLoading: false, |
|
|
|
|
|
selectProductOptions: [], |
|
|
|
|
|
selectProductCate: null, |
|
|
|
|
|
productCateOptions: [] |
|
|
} |
|
|
} |
|
|
}; |
|
|
}, |
|
|
|
|
|
created() { |
|
|
export default { |
|
|
if (this.isEdit) { |
|
|
name: 'CouponDetail', |
|
|
getCoupon(this.$route.query.id).then(response => { |
|
|
props: { |
|
|
this.coupon = response.data; |
|
|
isEdit: { |
|
|
}); |
|
|
type: Boolean, |
|
|
} |
|
|
default: false |
|
|
this.getProductCateList(); |
|
|
} |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
data() { |
|
|
UpNumber(val, limit = 2) { |
|
|
return { |
|
|
val = val.replace(/[^\d.]/g, '') // 保留数字 |
|
|
coupon: Object.assign({}, defaultCoupon), |
|
|
val = val.replace(/^00/, '0.') // 开头不能有两个0 |
|
|
typeOptions: Object.assign({}, defaultTypeOptions), |
|
|
val = val.replace(/^\./g, '0.') // 开头为小数点转换为0. |
|
|
platformOptions: Object.assign({}, defaultPlatformOptions), |
|
|
val = val.replace(/\.{2,}/g, '.') // 两个以上的小数点转换成一个 |
|
|
rules: { |
|
|
val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.'); // 只保留一个小数点 |
|
|
name: [ |
|
|
/^0\d+/.test(val) ? val = val.slice(1) : '' // 两位以上数字开头不能为0 |
|
|
{required: true, message: '请输入优惠券名称', trigger: 'blur'}, |
|
|
const str = '^(\\d+)\\.(\\d{' + limit + '}).*$' |
|
|
{min: 2, max: 140, message: '长度在 2 到 140 个字符', trigger: 'blur'} |
|
|
const reg = new RegExp(str) |
|
|
], |
|
|
if (limit === 0) { |
|
|
publishCount: [ |
|
|
// 不需要小数点 |
|
|
{type: 'number',required: true, message: '只能输入正整数', trigger: 'blur'} |
|
|
val = val.replace(reg, '$1') |
|
|
], |
|
|
} else { |
|
|
// amount: [ |
|
|
// 通过正则保留小数点后指定的位数 |
|
|
// // {type: 'number',required: true,message: '面值只能是数值,0.01-10000,限2位小数',trigger: 'blur'} |
|
|
val = val.replace(reg, '$1.$2') |
|
|
// // { required: true, validator: validatePrice, trigger: "blur" }, |
|
|
} |
|
|
// ], |
|
|
return val |
|
|
minPoint: [ |
|
|
}, |
|
|
{type: 'number',required: true,message: '只能输入正整数',trigger: 'blur'} |
|
|
onSubmit(formName) { |
|
|
] |
|
|
this.$refs[formName].validate((valid) => { |
|
|
}, |
|
|
if (valid) { |
|
|
selectProduct:null, |
|
|
this.$confirm('是否提交数据', '提示', { |
|
|
selectProductLoading: false, |
|
|
confirmButtonText: '确定', |
|
|
selectProductOptions:[], |
|
|
cancelButtonText: '取消', |
|
|
selectProductCate: null, |
|
|
type: 'warning' |
|
|
productCateOptions: [] |
|
|
}).then(() => { |
|
|
} |
|
|
if (this.isEdit) { |
|
|
}, |
|
|
updateCoupon(this.$route.query.id, this.coupon).then(response => { |
|
|
created(){ |
|
|
this.$refs[formName].resetFields(); |
|
|
if(this.isEdit){ |
|
|
this.$message({ |
|
|
getCoupon(this.$route.query.id).then(response=>{ |
|
|
message: '修改成功', |
|
|
this.coupon=response.data; |
|
|
type: 'success', |
|
|
}); |
|
|
duration: 1000 |
|
|
} |
|
|
}); |
|
|
this.getProductCateList(); |
|
|
this.$router.back(); |
|
|
}, |
|
|
}); |
|
|
methods:{ |
|
|
} else { |
|
|
UpNumber(val, limit = 2) { |
|
|
createCoupon(this.coupon).then(response => { |
|
|
val = val.replace(/[^\d.]/g, '') // 保留数字 |
|
|
this.$refs[formName].resetFields(); |
|
|
val = val.replace(/^00/, '0.') // 开头不能有两个0 |
|
|
this.$message({ |
|
|
val = val.replace(/^\./g, '0.') // 开头为小数点转换为0. |
|
|
message: '提交成功', |
|
|
val = val.replace(/\.{2,}/g, '.') // 两个以上的小数点转换成一个 |
|
|
type: 'success', |
|
|
val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.'); // 只保留一个小数点 |
|
|
duration: 1000 |
|
|
/^0\d+/.test(val) ? val = val.slice(1) : '' // 两位以上数字开头不能为0 |
|
|
}); |
|
|
const str = '^(\\d+)\\.(\\d{' + limit + '}).*$' |
|
|
this.$router.back(); |
|
|
const reg = new RegExp(str) |
|
|
}); |
|
|
if (limit === 0) { |
|
|
} |
|
|
// 不需要小数点 |
|
|
}); |
|
|
val = val.replace(reg, '$1') |
|
|
} else { |
|
|
} else { |
|
|
this.$message({ |
|
|
// 通过正则保留小数点后指定的位数 |
|
|
message: '验证失败', |
|
|
val = val.replace(reg, '$1.$2') |
|
|
type: 'error', |
|
|
} |
|
|
duration: 1000 |
|
|
return val |
|
|
}); |
|
|
}, |
|
|
return false; |
|
|
onSubmit(formName) { |
|
|
} |
|
|
this.$refs[formName].validate((valid) => { |
|
|
}); |
|
|
if (valid) { |
|
|
}, |
|
|
this.$confirm('是否提交数据', '提示', { |
|
|
resetForm(formName) { |
|
|
confirmButtonText: '确定', |
|
|
this.$refs[formName].resetFields(); |
|
|
cancelButtonText: '取消', |
|
|
this.coupon = Object.assign({}, defaultCoupon); |
|
|
type: 'warning' |
|
|
}, |
|
|
}).then(() => { |
|
|
searchProductMethod(query) { |
|
|
if(this.isEdit){ |
|
|
if (query !== '') { |
|
|
updateCoupon(this.$route.query.id,this.coupon).then(response=>{ |
|
|
this.loading = true; |
|
|
this.$refs[formName].resetFields(); |
|
|
fetchProductList({ |
|
|
this.$message({ |
|
|
keyword: query |
|
|
message: '修改成功', |
|
|
}).then(response => { |
|
|
type: 'success', |
|
|
this.loading = false; |
|
|
duration:1000 |
|
|
let productList = response.data; |
|
|
}); |
|
|
this.selectProductOptions = []; |
|
|
this.$router.back(); |
|
|
for (let i = 0; i < productList.length; i++) { |
|
|
}); |
|
|
let item = productList[i]; |
|
|
}else{ |
|
|
this.selectProductOptions.push({ |
|
|
createCoupon(this.coupon).then(response=>{ |
|
|
productId: item.id, |
|
|
this.$refs[formName].resetFields(); |
|
|
productName: item.name, |
|
|
this.$message({ |
|
|
productSn: item.productSn |
|
|
message: '提交成功', |
|
|
}); |
|
|
type: 'success', |
|
|
} |
|
|
duration:1000 |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
this.$router.back(); |
|
|
this.selectProductOptions = []; |
|
|
}); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}); |
|
|
handleAddProductRelation() { |
|
|
} else { |
|
|
if (this.selectProduct === null) { |
|
|
this.$message({ |
|
|
this.$message({ |
|
|
message: '验证失败', |
|
|
message: '请先选择商品', |
|
|
type: 'error', |
|
|
type: 'warning' |
|
|
duration:1000 |
|
|
}); |
|
|
}); |
|
|
return |
|
|
return false; |
|
|
} |
|
|
} |
|
|
this.coupon.productRelationList.push(this.getProductById(this.selectProduct)); |
|
|
}); |
|
|
this.selectProduct = null; |
|
|
}, |
|
|
}, |
|
|
resetForm(formName) { |
|
|
handleDeleteProductRelation(index, row) { |
|
|
this.$refs[formName].resetFields(); |
|
|
this.coupon.productRelationList.splice(index, 1); |
|
|
this.coupon = Object.assign({},defaultCoupon); |
|
|
}, |
|
|
}, |
|
|
handleAddProductCategoryRelation() { |
|
|
searchProductMethod(query){ |
|
|
if (this.selectProductCate === null || this.selectProductCate.length === 0) { |
|
|
if (query !== '') { |
|
|
this.$message({ |
|
|
this.loading = true; |
|
|
message: '请先选择商品分类', |
|
|
fetchProductList({keyword:query}).then(response=>{ |
|
|
type: 'warning' |
|
|
this.loading=false; |
|
|
}); |
|
|
let productList = response.data; |
|
|
return |
|
|
this.selectProductOptions = []; |
|
|
} |
|
|
for(let i=0;i<productList.length;i++){ |
|
|
this.coupon.productCategoryRelationList.push(this.getProductCateByIds(this.selectProductCate)); |
|
|
let item = productList[i]; |
|
|
this.selectProductCate = []; |
|
|
this.selectProductOptions.push({productId:item.id,productName:item.name,productSn:item.productSn}); |
|
|
}, |
|
|
} |
|
|
handleDeleteProductCateRelation(index, row) { |
|
|
}); |
|
|
this.coupon.productCategoryRelationList.splice(index, 1); |
|
|
} else { |
|
|
}, |
|
|
this.selectProductOptions = []; |
|
|
getProductById(id) { |
|
|
} |
|
|
for (let i = 0; i < this.selectProductOptions.length; i++) { |
|
|
}, |
|
|
if (id === this.selectProductOptions[i].productId) { |
|
|
handleAddProductRelation(){ |
|
|
return this.selectProductOptions[i]; |
|
|
if(this.selectProduct===null){ |
|
|
} |
|
|
this.$message({ |
|
|
} |
|
|
message: '请先选择商品', |
|
|
return null; |
|
|
type: 'warning' |
|
|
}, |
|
|
}); |
|
|
getProductCateList() { |
|
|
return |
|
|
fetchListWithChildren().then(response => { |
|
|
} |
|
|
let list = response.data; |
|
|
this.coupon.productRelationList.push(this.getProductById(this.selectProduct)); |
|
|
this.productCateOptions = []; |
|
|
this.selectProduct=null; |
|
|
for (let i = 0; i < list.length; i++) { |
|
|
}, |
|
|
let children = []; |
|
|
handleDeleteProductRelation(index,row){ |
|
|
if (list[i].children != null && list[i].children.length > 0) { |
|
|
this.coupon.productRelationList.splice(index,1); |
|
|
for (let j = 0; j < list[i].children.length; j++) { |
|
|
}, |
|
|
children.push({ |
|
|
handleAddProductCategoryRelation(){ |
|
|
label: list[i].children[j].name, |
|
|
if(this.selectProductCate===null||this.selectProductCate.length===0){ |
|
|
value: list[i].children[j].id |
|
|
this.$message({ |
|
|
}); |
|
|
message: '请先选择商品分类', |
|
|
} |
|
|
type: 'warning' |
|
|
} |
|
|
}); |
|
|
this.productCateOptions.push({ |
|
|
return |
|
|
label: list[i].name, |
|
|
} |
|
|
value: list[i].id, |
|
|
this.coupon.productCategoryRelationList.push(this.getProductCateByIds(this.selectProductCate)); |
|
|
children: children |
|
|
this.selectProductCate=[]; |
|
|
}); |
|
|
}, |
|
|
} |
|
|
handleDeleteProductCateRelation(index,row){ |
|
|
}); |
|
|
this.coupon.productCategoryRelationList.splice(index,1); |
|
|
}, |
|
|
}, |
|
|
getProductCateByIds(ids) { |
|
|
getProductById(id){ |
|
|
let name; |
|
|
for(let i=0;i<this.selectProductOptions.length;i++){ |
|
|
let parentName; |
|
|
if(id===this.selectProductOptions[i].productId){ |
|
|
for (let i = 0; i < this.productCateOptions.length; i++) { |
|
|
return this.selectProductOptions[i]; |
|
|
if (this.productCateOptions[i].value === ids[0]) { |
|
|
} |
|
|
parentName = this.productCateOptions[i].label; |
|
|
} |
|
|
for (let j = 0; j < this.productCateOptions[i].children.length; j++) { |
|
|
return null; |
|
|
if (this.productCateOptions[i].children[j].value === ids[1]) { |
|
|
}, |
|
|
name = this.productCateOptions[i].children[j].label; |
|
|
getProductCateList() { |
|
|
} |
|
|
fetchListWithChildren().then(response => { |
|
|
} |
|
|
let list = response.data; |
|
|
} |
|
|
this.productCateOptions = []; |
|
|
} |
|
|
for (let i = 0; i < list.length; i++) { |
|
|
return { |
|
|
let children = []; |
|
|
productCategoryId: ids[1], |
|
|
if (list[i].children != null && list[i].children.length > 0) { |
|
|
productCategoryName: name, |
|
|
for (let j = 0; j < list[i].children.length; j++) { |
|
|
parentCategoryName: parentName |
|
|
children.push({label: list[i].children[j].name, value: list[i].children[j].id}); |
|
|
}; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
this.productCateOptions.push({label: list[i].name, value: list[i].id, children: children}); |
|
|
} |
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
getProductCateByIds(ids){ |
|
|
|
|
|
let name; |
|
|
|
|
|
let parentName; |
|
|
|
|
|
for (let i = 0; i < this.productCateOptions.length; i++) { |
|
|
|
|
|
if (this.productCateOptions[i].value === ids[0]) { |
|
|
|
|
|
parentName = this.productCateOptions[i].label; |
|
|
|
|
|
for (let j = 0; j < this.productCateOptions[i].children.length; j++) { |
|
|
|
|
|
if (this.productCateOptions[i].children[j].value === ids[1]) { |
|
|
|
|
|
name = this.productCateOptions[i].children[j].label; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return {productCategoryId: ids[1], productCategoryName: name, parentCategoryName: parentName}; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
</script> |
|
|
</script> |
|
|
<style scoped> |
|
|
<style scoped> |
|
|
.input-width { |
|
|
.input-width { |
|
|
width: 60%; |
|
|
width: 60%; |
|
|
} |
|
|
} |
|
|
</style> |
|
|
</style> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|