123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636 |
- <template>
- <a-modal
- centered
- class="promotionList-basicInfo-modal"
- :footer="null"
- :maskClosable="false"
- title="规则设置"
- v-model="isShow"
- @cancel="isShow=false"
- width="70%">
- <a-spin :spinning="spinning" tip="Loading...">
- <a-form-model
- id="promotionList-basicInfo-form"
- ref="ruleForm"
- :model="form"
- :rules="rules"
- :label-col="formItemLayout.labelCol"
- :wrapper-col="formItemLayout.wrapperCol" >
- <a-form-model-item label="规则门槛" prop="gateFlag">
- <div class="fixWidthBox">
- <a-radio-group v-model="form.gateFlag" button-style="solid" size="small" @change="changeGateFlag">
- <a-radio-button value="1">
- 有
- </a-radio-button>
- <a-radio-button value="0">
- 无
- </a-radio-button>
- </a-radio-group>
- </div>
- <div v-if="form.gateFlag && form.gateFlag === '1'">
- <v-select
- size="small"
- style="width:60%;"
- v-model="form.gateType"
- id="promotionList-gateType"
- code="PROMOTION_GATE_TYPE"
- placeholder="请选择门槛与配额设置要求"
- @change="changeGateTypeFlag"
- allowClear></v-select>
- <div v-if="form.gateType==='RATIO_AMOUNT'">
- 购买门槛产品金额 <a-input-number v-model="form.gateValue" :min="0" :max="999999" :precision="2" size="small"/> %作为配额
- <a-tooltip title="如:填写100%,则购买10000元门槛产品,可享受10000配额购买正价产品,根据门槛金额动态调整配额">
- <a-icon type="question-circle" theme="filled" :style="{ fontSize: '14px', color: 'gray' }"/>
- </a-tooltip>
- </div>
- <div v-if="form.gateType==='MIN_AMOUNT'">
- 购买门槛产品满最低金额 <a-input-number v-model="form.gateValue" :max="999999" :min="0" :precision="2" size="small"/>元,不限制配额。
- </div>
- <div class="ruleDescList" v-if="form.gateType==='FIXED_AMOUNT'">
- 购买满
- <a-input-number v-model="form.gateValue" :min="0" :max="999999" :precision="2" size="small"/>
- 元门槛产品,可使用
- <a-input-number v-model="form.quotaAmount" :min="0" :max="999999" :precision="2" size="small"/>
- 元配额,采购规则中的正价商品(配额算销售额)
- </div>
- </div>
- </a-form-model-item>
- <a-form-model-item label="规则简称" prop="description">
- <a-input
- size="small"
- id="promotionList-description"
- v-model.trim="form.description"
- allowClear
- placeholder="请输入规则简称(最多20个字符)"
- :maxLength="20"></a-input>
- </a-form-model-item>
- <a-form-model-item label="满赠规则" prop="giveRuleType">
- <a-select default-value="SUM_MONEY" v-model="form.giveRuleType" style="width: 160px" size="small" allowClear>
- <a-select-option value="SUM_MONEY">
- 金额叠加
- </a-select-option>
- <a-select-option value="RATIO">
- 按比例
- </a-select-option>
- </a-select>
- <a-tooltip title="数量叠加:(如:满1000送200,金额叠加则:满2000送400,以此类推)" v-if="form.giveRuleType=='SUM_MONEY'">
- <a-icon type="question-circle" theme="filled" :style="{ fontSize: '14px', color: 'gray' ,'margin-left':'5px'}"/>
- </a-tooltip>
- <a-tooltip title="按比例:(如满100元送2%,按比例则:满120送2.4元)" v-else>
- <a-icon type="question-circle" theme="filled" :style="{ fontSize: '14px', color: 'gray' ,'margin-left':'5px'}"/>
- </a-tooltip>
- <div class="ruleDescList" v-if="form.giveRuleType==='SUM_MONEY'">
- 购买满
- <a-input-number
- v-model="fullGiftRuleList[0].regularValue"
- @blur="calculatePrice"
- :max="999999"
- :step="1"
- :precision="form.regularUnit==='YUAN'?2:0"
- :min="0"
- size="small"/>
- <a-select
- default-value="YUAN"
- v-model="form.regularUnit"
- style="width: 50px;margin-left:5px;"
- size="small"
- @change="handleUnit">
- <a-select-option value="YUAN">
- 元
- </a-select-option>
- <a-select-option value="GE">
- 个
- </a-select-option>
- </a-select>
- 正价产品,送
- <a-input-number
- v-model="fullGiftRuleList[0].promotionValue"
- @blur="calculatePrice"
- :min="0"
- :step="1"
- :max="999999"
- :precision="2"
- size="small"/>
- 元<span>({{ form.regularUnit==='YUAN'? scaleNum+'%':'' }}促销品采购额)</span>
- </div>
- <div class="fullGiftRuleBox" v-else>
- <div class="ruleDescList" v-for="(con,i) in fullGiftRuleList" :key="i">
- <span>{{ i*1+1 }}、</span>
- 购买满
- <a-input-number
- v-model="con.regularValue"
- :min="i!=0?fullGiftRuleList[i-1].regularValue:0"
- :step="1"
- :max="999999"
- :precision="form.regularUnit==='YUAN'?2:0"
- size="small"/>
- <a-select
- default-value="YUAN"
- v-model="form.regularUnit"
- @change="handleChangeUnit"
- style="width: 50px;margin-left:5px;"
- size="small"
- :disabled="i!=0">
- <a-select-option value="YUAN">
- 元
- </a-select-option>
- <a-select-option value="GE">
- 个
- </a-select-option>
- </a-select>
- 正价产品,送正价产品总金额的
- <a-input-number
- v-model="con.promotionValue"
- :min="0"
- :step="1"
- :precision="0"
- :max="999999"
- size="small"/>
- %为促销品采购额
- <a-button type="link" v-if="i==0&&fullGiftRuleList&&fullGiftRuleList.length<5" class="button-info" @click="addFullGiftRule">+新增</a-button>
- <a-button type="link" v-if="i!=0" class="button-error" @click="delFullGiftRule(i)">删除</a-button>
- </div>
- </div>
- </a-form-model-item>
- <a-form-model-item label="采购额适用范围" prop="scopeFlag">
- <div class="fixWidthBox">
- <a-radio-group v-model="form.scopeFlag" button-style="solid" size="small">
- <a-radio-button value="0">
- 部分产品
- </a-radio-button>
- <a-radio-button value="1">
- 全部产品
- </a-radio-button>
- </a-radio-group>
- </div>
- </a-form-model-item>
- </a-form-model>
- <a-card size="small" :bordered="false" class="pages-wrap">
- <div class="flex">
- <a-radio-group v-model="chooseVal" button-style="solid">
- <a-radio-button value="a" v-show="form.gateFlag==='1'">
- 门槛产品
- </a-radio-button>
- <a-radio-button value="b">
- 正价产品
- </a-radio-button>
- <a-radio-button value="c" v-show="form.scopeFlag==='0'">
- 促销产品
- </a-radio-button>
- </a-radio-group>
- <a-button
- size="small"
- type="link"
- class="button-info"
- @click="openGuideModal=true"
- id="promotionList-edit-btn">+导入产品</a-button>
- </div>
- <div v-show="chooseVal=='a'"><tableType1 ref="cillProduct"></tableType1></div>
- <div v-show="chooseVal=='b'"><tableType1 ref="normalPriceProduct"></tableType1></div>
- <div v-show="chooseVal=='c'"><tableType1 ref="offerProduct"></tableType1></div>
- </a-card>
- <div class="btn-cont">
- <a-button id="promotionList-basicInfo-modal-back" @click="isShow = false">取消</a-button>
- <a-button style="margin-left: 15px;" type="primary" id="promotionList-modal-save" @click="handleSave">确定</a-button>
- </div>
- </a-spin>
- <!-- 导入产品 -->
- <importGuideModal goodFlag="1" :openModal="openGuideModal" @close="closeGuideModel" @ok="hanldeOk" />
- </a-modal>
- </template>
- <script>
- import { commonMixin } from '@/utils/mixin'
- import { VSelect } from '@/components'
- import tableType1 from './tableType1.vue'
- import { promotionSave, getRuleDetail } from '@/api/promotion'
- import ImportGuideModal from './importGuideModal.vue'
- export default {
- name: 'PromotionListBasicInfoModal',
- mixins: [commonMixin],
- components: { VSelect, tableType1, ImportGuideModal },
- props: {
- openModal: { // 弹框显示状态
- type: Boolean,
- default: false
- },
- promotionSn: {
- type: [Number, String],
- default: ''
- },
- itemSn: {
- type: [Number, String],
- default: ''
- }
- },
- data () {
- return {
- isShow: this.openModal, // 是否打开弹框
- spinning: false,
- formItemLayout: {
- labelCol: { span: 4 },
- wrapperCol: { span: 17 }
- },
- form: {
- promotionRuleType: 'BUY_PROD_GIVE_MONEY', // 买产品送采购额
- description: '',
- gateFlag: '0', // 门槛
- gateType: undefined,
- gateValue: undefined,
- quotaAmount: undefined,
- giveRuleType: 'SUM_MONEY',
- regularUnit: 'YUAN',
- scopeFlag: '1',
- gateInfo: undefined,
- ruleInfo: undefined
- },
- rules: {
- description: [ { required: true, message: '请输入规则简称', trigger: 'blur' } ],
- gateFlag: [ { required: true, message: '请选择规则门槛', trigger: 'change' } ],
- giveRuleType: [{ required: true, message: '请选择满赠规则', trigger: 'change' }],
- scopeFlag: [{ required: true, message: '请选择采购额适用范围', trigger: 'change' }]
- },
- chooseVal: 'a',
- scaleNum: 0,
- openGuideModal: false,
- fullGiftRuleList: [{
- regularValue: undefined,
- promotionValue: undefined
- }]
- }
- },
- methods: {
- // 单位切换时,满赠规则数据清空
- handleUnit (val) {
- this.form.regularUnit = val
- this.fullGiftRuleList[0].regularValue = undefined
- },
- handleChangeUnit (e) {
- this.form.regularUnit = e
- this.fullGiftRuleList.forEach(item => {
- item.regularValue = undefined
- })
- },
- // 新增 满减规则 最多能添加五个
- addFullGiftRule () {
- const obj = {
- regularSameFlag: '1',
- regularQty: undefined,
- promotionQty: undefined
- }
- this.fullGiftRuleList.push(obj)
- },
- // 删除满减规则
- delFullGiftRule (pos) {
- this.fullGiftRuleList.splice(pos, 1)
- },
- // 导入
- closeGuideModel () {
- this.openGuideModal = false
- },
- hanldeOk (arr) {
- const name = this.chooseVal == 'a' ? 'cill' : this.chooseVal == 'b' ? 'normalPrice' : 'offer'
- this.$refs[name + 'Product'].importRow(arr)
- },
- // 计算百分比
- calculatePrice () {
- const _this = this
- if (_this.form.giveRuleType === 'SUM_MONEY' && _this.form.regularUnit === 'YUAN' && _this.fullGiftRuleList[0].promotionValue && _this.fullGiftRuleList[0].regularValue) {
- _this.scaleNum = ((_this.fullGiftRuleList[0].promotionValue / _this.fullGiftRuleList[0].regularValue) * 100).toFixed(2)
- } else {
- _this.scaleNum = 0
- }
- },
- // 门槛切换 tab 按钮默认显示问题
- changeGateFlag (e) {
- if (e.target.value == '0') {
- this.chooseVal = 'b'
- this.form.gateType = undefined
- this.form.gateValue = undefined
- this.form.quotaAmount = undefined
- } else {
- this.chooseVal = 'a'
- }
- },
- changeGateTypeFlag (val) {
- this.form.gateType = val
- this.form.gateValue = undefined
- this.form.quotaAmount = undefined
- },
- // 保存
- handleSave () {
- const _this = this
- this.$refs.ruleForm.validate(valid => {
- if (valid) {
- // 验证必填
- if (_this.form.gateFlag == '1') {
- if (!_this.form.gateType) {
- _this.$message.warning('请选择规则门槛设置类型!')
- return
- }
- if (!_this.form.gateValue) {
- _this.$message.warning('规则门槛条件不能为空!')
- return
- }
- if (_this.form.gateType === 'FIXED_AMOUNT' && !_this.form.quotaAmount) {
- _this.$message.warning('规则门槛条件不能为空!')
- return
- }
- }
- const form = JSON.parse(JSON.stringify(_this.form))
- let rowFlag1, rowFlag2, rowFlag3
- if (form.gateFlag == '1') {
- form.gateProductList = this.$refs.cillProduct.getResultVal() // 规则门槛
- form.gateValue = form.gateType === 'RATIO_AMOUNT' ? form.gateValue / 100 : form.gateValue
- if (form.gateProductList.length == 0) {
- _this.$message.warning('请添加门槛产品!')
- return
- } else {
- const qtyFlag = form.gateProductList.some(newCon => { return (!newCon.unitType || !newCon.unitQty) })
- if (qtyFlag) {
- _this.$message.warning('订单起订量设置不能为空!')
- return
- }
- rowFlag1 = _this.isJudge(form.gateProductList)
- }
- } else {
- form.gateProductList = []
- form.gateValue = ''
- form.quotaAmount = ''
- form.gateType = undefined
- }
- // 正价产品判断表格必填
- form.regularProductList = this.$refs.normalPriceProduct.getResultVal()
- if (form.regularProductList.length == 0) {
- _this.$message.warning('请添加正价产品!')
- return
- } else {
- const qtyFlag = form.regularProductList.some(newCon => { return (!newCon.unitType || !newCon.unitQty) })
- if (qtyFlag) {
- _this.$message.warning('订单起订量设置不能为空!')
- return
- }
- rowFlag2 = _this.isJudge(form.regularProductList)
- }
- // 促销产品
- if (form.scopeFlag == '0') {
- form.giftProductList = this.$refs.offerProduct.getResultVal()
- if (form.giftProductList.length == 0) {
- _this.$message.warning('请添加促销产品!')
- return
- }
- rowFlag3 = _this.isJudge(form.giftProductList)
- } else {
- form.giftProductList = []
- }
- if (rowFlag1 || rowFlag2 || rowFlag3) {
- _this.$message.warning('请选择产品分类、品牌或产品!')
- return
- }
- // 组传给后台所需数据
- _this.fullGiftRuleList.map((val, i) => {
- val.scopeLevel = i * 1 + 1
- val.regularUnit = form.regularUnit
- })
- form.promotionSn = _this.promotionSn
- form.giveRuleList = _this.fullGiftRuleList
- if (form.gateFlag == '1') {
- if (form.gateType === 'RATIO_AMOUNT') {
- form.gateInfo = '购买门槛产品金额' + form.gateValue + '作为配额'
- } else if (form.gateType === 'MIN_AMOUNT') {
- form.gateInfo = '购买门槛产品满最低金额' + form.gateValue + '不限制配额'
- } else {
- form.gateInfo = '购买满' + form.gateValue + '元门槛产品,可使用' + form.quotaAmount + '元配额,采购规则中的正价商品(配额算销售额)'
- }
- }
- var newInfo = ''
- if (form.giveRuleType == 'SUM_MONEY') {
- newInfo = `<span>金额叠加;购买满${_this.fullGiftRuleList[0].regularValue}${form.regularUnit == 'YUAN' ? '元' : '个'}正价产品,送${_this.fullGiftRuleList[0].promotionValue}元</span>`
- if (form.regularUnit == 'YUAN') {
- newInfo += `<span>(${((_this.fullGiftRuleList[0].promotionValue / _this.fullGiftRuleList[0].regularValue) * 100).toFixed(2)} %促销品采购额)</span>`
- }
- } else {
- newInfo = '按比例;'
- _this.fullGiftRuleList.forEach(item => {
- newInfo += `<div>购买满${item.regularValue}${form.regularUnit == 'YUAN' ? '元' : '个'}正价产品,送正价产品总金额的${item.promotionValue}%为促销品采购额</div>`
- })
- }
- form.ruleInfo = newInfo
- _this.spinning = true
- promotionSave(form).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- setTimeout(() => {
- _this.isShow = false
- _this.$emit('ok')
- _this.spinning = false
- }, 1000)
- } else {
- _this.spinning = false
- }
- })
- } else {
- return false
- }
- })
- },
- // 判断品牌,分类,产品其中一个必填
- isJudge (list) {
- let flag = null
- list.forEach(con => {
- if (con.productThisList) {
- if (con.productThisList.length > 0) {
- flag = false
- } else {
- if ((con.productTypeList && con.productTypeList.length > 0) || (con.productBrandList && con.productBrandList.length > 0)) {
- flag = false
- } else {
- flag = true
- }
- }
- } else {
- if ((con.productTypeList && con.productTypeList.length > 0) || (con.productBrandList && con.productBrandList.length > 0)) {
- flag = false
- } else {
- flag = true
- }
- }
- })
- return flag
- },
- // 重置表格
- resetSearchForm () {
- this.form = {
- promotionRuleType: 'BUY_PROD_GIVE_MONEY', // 买产品送采购额
- description: '',
- gateFlag: '0', // 门槛
- gateType: undefined,
- gateValue: undefined,
- quotaAmount: undefined,
- giveRuleType: 'SUM_MONEY',
- regularUnit: 'YUAN',
- scopeFlag: '1',
- gateProductList: undefined,
- giftProductList: undefined,
- regularProductList: undefined,
- gateInfo: undefined,
- ruleInfo: undefined
- }
- this.$nextTick(() => {
- this.$refs.ruleForm.resetFields()
- this.$refs.cillProduct.reSetTableData()
- this.$refs.normalPriceProduct.reSetTableData()
- this.scaleNum = 0
- })
- if (this.form.giveRuleType === 'SUM_MONEY') {
- this.$refs.offerProduct.reSetTableData()
- } else {
- this.fullGiftRuleList.forEach((val, i) => {
- this.$refs['offerProduct' + i][0].reSetTableData()
- })
- }
- this.fullGiftRuleList = [{
- regularValue: undefined,
- promotionValue: undefined
- }]
- },
- // 获取编辑详情
- getDetail () {
- const _this = this
- getRuleDetail({ sn: this.itemSn }).then(res => {
- if (res.status == 200) {
- this.chooseVal = res.data.gateFlag == '0' ? 'b' : 'a'
- const resultObj = res.data
- if (resultObj.gateFlag === '1') {
- resultObj.gateValue = resultObj.gateType === 'RATIO_AMOUNT' ? resultObj.gateValue * 100 : resultObj.gateValue
- }
- if (resultObj.giveRuleList && resultObj.giveRuleList.length > 0) {
- _this.fullGiftRuleList = resultObj.giveRuleList
- }
- // 重新组成保存数据
- if (resultObj.gateProductList && resultObj.gateProductList.length > 0) {
- resultObj.gateProductList = _this.newData(resultObj.gateProductList)
- this.$refs.cillProduct.setTabVal(resultObj.gateProductList)
- }
- if (resultObj.regularProductList && resultObj.regularProductList.length > 0) {
- resultObj.regularProductList = _this.newData(resultObj.regularProductList)
- this.$refs.normalPriceProduct.setTabVal(resultObj.regularProductList)
- }
- if (resultObj.giftProductList && resultObj.giftProductList.length > 0) {
- resultObj.giftProductList = _this.newData(resultObj.giftProductList)
- this.$refs.offerProduct.setTabVal(resultObj.giftProductList)
- }
- this.form = { ...this.form, ...resultObj }
- }
- })
- },
- newData (list) {
- list.forEach(con => {
- // 品牌
- if (con.productBrandList) {
- const brandList = []
- con.productBrandList.forEach(item => {
- item.brandName = item.productBrandName
- const brandObj = {
- productBrandSn: item.productBrandSn
- }
- brandList.push(brandObj)
- })
- con.productBrandArr = con.productBrandList
- con.productBrandList = brandList
- }
- // 分类
- if (con.productTypeList) {
- const typeList = []
- con.productTypeList.forEach(item => {
- const typeObj = {}
- item.title = ''
- const num = 3
- for (var i = 0; i < num; i++) {
- if (item['productTypeName' + (i + 1)]) {
- // item.title += item['productTypeName' + (i + 1)] + (item['productTypeName' + (i + 1)] ? '/' : '')
- typeObj['productTypeSn' + (i + 1)] = item['productTypeSn' + (i + 1)] ? item['productTypeSn' + (i + 1)] : ''
- }
- }
- // item.title = item.title.slice(0, item.title.length - 1)
- if (item.productTypeName3) {
- item.title = item.productTypeName2 + '/' + item.productTypeName3
- } else if (!item.productTypeName3 && item.productTypeName2) {
- item.title = item.productTypeName2
- } else {
- item.title = item.productTypeName1
- }
- item.id = item.productTypeSn3 ? item.productTypeSn3 : item.productTypeSn2 ? item.productTypeSn2 : item.productTypeSn1
- typeList.push(typeObj)
- })
- con.productTypeArr = con.productTypeList
- con.productTypeList = typeList
- }
- // 产品
- if (con.productThisList) {
- const productList = []
- con.productThisList.forEach(item => {
- const productObj = {
- productCode: item.productCode,
- productSn: item.productSn
- }
- productList.push(productObj)
- })
- con.productThisList = productList
- }
- })
- return list
- }
- },
- watch: {
- // 父页面传过来的弹框状态
- openModal (newValue, oldValue) {
- this.isShow = newValue
- },
- // 重定义的弹框状态
- isShow (newValue, oldValue) {
- if (!newValue) {
- this.$emit('close')
- this.resetSearchForm()
- } else {
- if (this.itemSn) {
- this.getDetail()
- } else {
- this.chooseVal = this.form.gateFlag == '0' ? 'b' : 'a'
- }
- }
- }
- }
- }
- </script>
- <style lang="less" scoped>
- .promotionList-basicInfo-modal{
- /deep/.ant-modal-body {
- padding: 20px 30px;
- max-height: 745px !important;
- overflow-y: scroll !important;
- }
- .fixWidthBox .ant-radio-button-wrapper{
- width:80px;
- text-align: center;
- }
- .ant-form-item{
- margin-bottom:5px;
- }
- .buyerBox{
- border:1px solid #d9d9d9;margin-top:10px;border-radius:4px;padding:4px 10px;background:#f2f2f2;max-height:130px;overflow-y:scroll;
- }
- .btn-cont {
- text-align: center;
- margin: 35px 0 10px;
- }
- .flex{
- display:flex;
- align-items:center;
- justify-content:space-between;
- }
- }
- </style>
|