sendAmountModal.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <template>
  2. <a-modal
  3. centered
  4. class="promotionList-basicInfo-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="规则设置"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. width="70%">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <a-form-model
  13. id="promotionList-basicInfo-form"
  14. ref="ruleForm"
  15. :model="form"
  16. :rules="rules"
  17. :label-col="formItemLayout.labelCol"
  18. :wrapper-col="formItemLayout.wrapperCol" >
  19. <a-form-model-item label="规则简称" prop="description">
  20. <a-input
  21. size="small"
  22. id="promotionList-description"
  23. v-model.trim="form.description"
  24. allowClear
  25. placeholder="请输入规则简称(最多20个字符)"
  26. :maxLength="20"></a-input>
  27. </a-form-model-item>
  28. <a-form-model-item label="规则门槛" prop="gateFlag">
  29. <a-radio-group v-model="form.gateFlag" button-style="solid" size="small" @change="changeGateFlag">
  30. <a-radio-button value="1">
  31. </a-radio-button>
  32. <a-radio-button value="0">
  33. </a-radio-button>
  34. </a-radio-group>
  35. <div v-if="form.gateFlag && form.gateFlag === '1'">
  36. <v-select
  37. size="small"
  38. style="width:60%;"
  39. v-model="form.gateType"
  40. id="promotionList-gateType"
  41. code="PROMOTION_GATE_TYPE"
  42. placeholder="请选择"
  43. allowClear></v-select>
  44. <div v-if="form.gateType==='RATIO_AMOUNT'">
  45. 购买门槛产品金额 <a-input-number v-model="form.gateAmount" :min="0" :max="999999" :precision="2" size="small"/> %作为配额
  46. <a-tooltip title="如:填写100%,则购买10000元门槛产品,可享受10000配额购买正价产品,根据门槛金额动态调整配额">
  47. <a-icon type="question-circle" theme="filled" :style="{ fontSize: '14px', color: 'gray' }"/>
  48. </a-tooltip>
  49. </div>
  50. <div v-if="form.gateType==='MIN_AMOUNT'">
  51. 购买门槛产品满最低金额 <a-input-number v-model="form.gateAmount" :max="999999" :min="0" :precision="2" size="small"/>元,不限制配额。
  52. </div>
  53. <div class="ruleDescList" v-if="form.gateType==='FIXED_AMOUNT'">
  54. 购买满
  55. <a-input-number v-model="form.gateAmount" :min="0" :max="999999" :precision="2" size="small"/>
  56. 元门槛产品,可使用
  57. <a-input-number v-model="form.quotaAmount" :min="0" :max="999999" :precision="2" size="small"/>
  58. 元配额,采购规则中的正价商品(配额算销售额)
  59. </div>
  60. </div>
  61. </a-form-model-item>
  62. <a-form-model-item label="满赠规则" prop="regularSameFlag">
  63. <div class="ruleDescList">
  64. <a-select default-value="1" v-model="form.regularSameFlag" style="width: 100px" size="small">
  65. <a-select-option value="1">
  66. 同款
  67. </a-select-option>
  68. <a-select-option value="0">
  69. 不同款
  70. </a-select-option>
  71. </a-select>
  72. 产品购买满
  73. <a-input-number
  74. v-model="form.regularAmount"
  75. @blur="calculatePrice"
  76. :min="0"
  77. :step="1"
  78. :precision="2"
  79. :max="999999"
  80. size="small"/>
  81. 元正价产品,送
  82. <a-input-number
  83. v-model="form.giveAmount"
  84. @blur="calculatePrice"
  85. :min="0"
  86. :step="1"
  87. :max="999999"
  88. :precision="2"
  89. size="small"/>
  90. 元({{ scaleNum }}%促销品采购额)
  91. </div>
  92. </a-form-model-item>
  93. <a-form-model-item label="金额叠加" prop="accrualFlag">
  94. <a-radio-group v-model="form.accrualFlag" button-style="solid" size="small">
  95. <a-radio-button value="1">
  96. </a-radio-button>
  97. <a-radio-button value="0">
  98. </a-radio-button>
  99. </a-radio-group>
  100. <span style="color:gray;">(如:满1000送200,金额叠加则:满2000送400,以此类推)</span>
  101. </a-form-model-item>
  102. <a-form-model-item prop="minOrderFlag" label="订单起订金额">
  103. <a-select default-value="1" v-model="form.minOrderFlag" style="width: 160px" size="small">
  104. <a-select-option value="0">
  105. 不限
  106. </a-select-option>
  107. <a-select-option value="1">
  108. 限制
  109. </a-select-option>
  110. </a-select>
  111. <a-input-number
  112. v-show="form.minOrderFlag && form.minOrderFlag=='1'"
  113. size="small"
  114. style="margin-left:10px;width:300px;"
  115. v-model="form.minOrderAmount"
  116. :min="0"
  117. :step="1"
  118. :max="999999"
  119. :precision="2"
  120. placeholder="请输入金额"/>
  121. </a-form-model-item>
  122. <a-form-model-item prop="upperLimitFlag" label="活动经费上限">
  123. <a-select default-value="1" v-model="form.upperLimitFlag" style="width: 160px" size="small">
  124. <a-select-option value="0">
  125. 不限
  126. </a-select-option>
  127. <a-select-option value="1">
  128. 限制
  129. </a-select-option>
  130. </a-select>
  131. <a-input-number
  132. v-show="form.upperLimitFlag&&form.upperLimitFlag=='1'"
  133. size="small"
  134. style="margin-left:10px;width:300px;"
  135. v-model="form.upperLimitAmount"
  136. :min="0"
  137. :step="1"
  138. :max="999999"
  139. :precision="2"
  140. placeholder="请输入金额"/>
  141. </a-form-model-item>
  142. <a-form-model-item label="采购额适用范围" prop="scopeFlag">
  143. <a-radio-group v-model="form.scopeFlag" button-style="solid" size="small">
  144. <a-radio-button value="0">
  145. 部分产品
  146. </a-radio-button>
  147. <a-radio-button value="1">
  148. 全部产品
  149. </a-radio-button>
  150. </a-radio-group>
  151. </a-form-model-item>
  152. </a-form-model>
  153. <a-card size="small" :bordered="false" class="pages-wrap">
  154. <div class="flex">
  155. <a-radio-group v-model="chooseVal" button-style="solid" size="small">
  156. <a-radio-button value="a" v-show="form.gateFlag==='1'">
  157. 门槛产品
  158. </a-radio-button>
  159. <a-radio-button value="b">
  160. 正价产品
  161. </a-radio-button>
  162. <a-radio-button value="c" v-show="form.scopeFlag==='0'">
  163. 促销产品
  164. </a-radio-button>
  165. </a-radio-group>
  166. <a-button
  167. size="small"
  168. type="link"
  169. class="button-info"
  170. @click="openGuideModal=true"
  171. id="promotionList-edit-btn">+导入产品</a-button>
  172. </div>
  173. <div v-show="chooseVal=='a'"><tableType1 ref="cillProduct"></tableType1></div>
  174. <div v-show="chooseVal=='b'"><tableType1 ref="normalPriceProduct"></tableType1></div>
  175. <div v-show="chooseVal=='c'"><tableType2 ref="offerProduct"></tableType2></div>
  176. </a-card>
  177. <div class="btn-cont">
  178. <a-button id="promotionList-basicInfo-modal-back" @click="isShow = false">取消</a-button>
  179. <a-button style="margin-left: 15px;" type="primary" id="promotionList-modal-save" @click="handleSave">确定</a-button>
  180. </div>
  181. </a-spin>
  182. <!-- 导入产品 -->
  183. <importGuideModal goodFlag="1" :openModal="openGuideModal" @close="closeGuideModel" @ok="hanldeOk" />
  184. </a-modal>
  185. </template>
  186. <script>
  187. import { commonMixin } from '@/utils/mixin'
  188. import { VSelect } from '@/components'
  189. import tableType1 from './tableType1.vue'
  190. import tableType2 from './tableType2.vue'
  191. import { promotionSave, getRuleDetail } from '@/api/promotion'
  192. import ImportGuideModal from './importGuideModal.vue'
  193. export default {
  194. name: 'PromotionListBasicInfoModal',
  195. mixins: [commonMixin],
  196. components: { VSelect, tableType1, tableType2, ImportGuideModal },
  197. props: {
  198. openModal: { // 弹框显示状态
  199. type: Boolean,
  200. default: false
  201. },
  202. promotionSn: {
  203. type: [Number, String],
  204. default: ''
  205. },
  206. itemSn: {
  207. type: [Number, String],
  208. default: ''
  209. }
  210. },
  211. data () {
  212. return {
  213. isShow: this.openModal, // 是否打开弹框
  214. spinning: false,
  215. formItemLayout: {
  216. labelCol: { span: 4 },
  217. wrapperCol: { span: 17 }
  218. },
  219. form: {
  220. promotionRuleType: 'BUY_PROD_GIVE_MONEY', // 买产品送采购额
  221. description: '',
  222. gateFlag: '0', // 门槛
  223. gateType: undefined,
  224. gateAmount: undefined,
  225. quotaAmount: undefined,
  226. regularSameFlag: '1', // 满赠规则 不同款商品
  227. regularAmount: undefined,
  228. giveAmount: undefined,
  229. restrictCategory: '',
  230. accrualFlag: '1', // 数量叠加
  231. minOrderFlag: '0', // 起订金额
  232. minOrderAmount: undefined,
  233. upperLimitFlag: '0', // 活动经费上限
  234. upperLimitAmount: undefined,
  235. scopeFlag: '1'
  236. },
  237. rules: {
  238. description: [ { required: true, message: '请输入规则简称', trigger: 'blur' } ],
  239. gateFlag: [ { required: true, message: '请选择规则门槛', trigger: 'change' } ],
  240. regularSameFlag: [{ required: true, message: '请选择满赠规则', trigger: 'change' }],
  241. accrualFlag: [{ required: true, message: '请选择数量是否叠加', trigger: 'change' }],
  242. minOrderFlag: [{ required: true, message: '请选择订单起订金额', trigger: 'change' }],
  243. upperLimitFlag: [{ required: true, message: '请选择活动经费上限', trigger: 'change' }],
  244. scopeFlag: [{ required: true, message: '请选择采购额适用范围', trigger: 'change' }]
  245. },
  246. chooseVal: 'a',
  247. scaleNum: 0,
  248. openGuideModal: false
  249. }
  250. },
  251. methods: {
  252. // 导入
  253. closeGuideModel () {
  254. this.openGuideModal = false
  255. },
  256. hanldeOk (arr) {
  257. const resultArr = []
  258. arr.forEach(item => {
  259. const obj = {
  260. productCode: item.productCode,
  261. productSn: item.product.productSn
  262. }
  263. resultArr.push(obj)
  264. })
  265. const name = this.chooseVal == 'a' ? 'cill' : this.chooseVal == 'b' ? 'normalPrice' : 'offer'
  266. this.$refs[name + 'Product'].importRow(resultArr)
  267. },
  268. // 计算百分比
  269. calculatePrice () {
  270. const _this = this
  271. if (_this.form.regularAmount && _this.form.giveAmount) {
  272. _this.scaleNum = Math.floor(((_this.form.giveAmount / _this.form.regularAmount) * 100).toFixed(2))
  273. } else {
  274. _this.scaleNum = 0
  275. }
  276. },
  277. // 门槛切换 tab 按钮默认显示问题
  278. changeGateFlag (e) {
  279. if (this.chooseVal != 'c') {
  280. if (e.target.value == '0') {
  281. this.chooseVal = 'b'
  282. } else {
  283. this.chooseVal = 'a'
  284. }
  285. }
  286. },
  287. // 保存
  288. handleSave () {
  289. const _this = this
  290. this.$refs.ruleForm.validate(valid => {
  291. if (valid) {
  292. // 验证必填
  293. if (_this.form.gateFlag == '1') {
  294. if (!_this.form.gateType) {
  295. _this.$message.warning('请选择规则门槛设置类型!')
  296. return
  297. }
  298. if (!_this.form.gateAmount) {
  299. _this.$message.warning('规则门槛条件不能为空!')
  300. return
  301. }
  302. if (_this.form.gateType === 'FIXED_AMOUNT' && !_this.form.quotaAmount) {
  303. _this.$message.warning('规则门槛条件不能为空!')
  304. return
  305. }
  306. }
  307. if (!_this.form.regularAmount || !_this.form.giveAmount) {
  308. _this.$message.warning('满赠规则条件不能为空!')
  309. return
  310. }
  311. if (_this.form.minOrderFlag == 1 && !_this.form.minOrderAmount) {
  312. _this.$message.warning('请输入订单起订限制金额数!')
  313. return
  314. }
  315. if (_this.form.upperLimitFlag == 1 && !_this.form.upperLimitAmount) {
  316. _this.$message.warning('请输入活动经费上限金额!')
  317. return
  318. }
  319. const form = JSON.parse(JSON.stringify(_this.form))
  320. let rowFlag1, rowFlag2, rowFlag3
  321. if (form.gateFlag == '1') {
  322. form.gateProductList = this.$refs.cillProduct.getResultVal()
  323. form.gateAmount = form.gateType === 'RATIO_AMOUNT' ? form.gateAmount / 100 : form.gateAmount
  324. if (form.gateProductList.length == 0) {
  325. _this.$message.warning('请添加门槛产品!')
  326. return
  327. } else {
  328. const qtyFlag = form.gateProductList.some(newCon => { return (!newCon.unitType || !newCon.unitQty) })
  329. if (qtyFlag) {
  330. _this.$message.warning('订单起订量设置不能为空!')
  331. return
  332. }
  333. rowFlag1 = _this.isJudge(form.gateProductList)
  334. }
  335. } else {
  336. form.gateProductList = []
  337. form.gateAmount = ''
  338. form.quotaAmount = ''
  339. form.gateType = undefined
  340. }
  341. form.regularProductList = this.$refs.normalPriceProduct.getResultVal()
  342. // 判断表格必填
  343. if (form.regularProductList.length == 0) {
  344. _this.$message.warning('请添加正价产品!')
  345. return
  346. } else {
  347. const qtyFlag = form.regularProductList.some(newCon => { return (!newCon.unitType || !newCon.unitQty) })
  348. if (qtyFlag) {
  349. _this.$message.warning('订单起订量设置不能为空!')
  350. return
  351. }
  352. rowFlag3 = _this.isJudge(form.regularProductList)
  353. }
  354. if (form.scopeFlag == '0') {
  355. form.giftProductList = this.$refs.offerProduct.getResultVal()
  356. if (form.giftProductList.length == 0) {
  357. _this.$message.warning('请添加促销产品!')
  358. return
  359. }
  360. rowFlag2 = _this.isJudge(form.giftProductList)
  361. } else {
  362. form.giftProductList = []
  363. }
  364. if (rowFlag1 || rowFlag2 || rowFlag3) {
  365. _this.$message.warning('请选择产品分类、品牌或产品!')
  366. return
  367. }
  368. form.promotionSn = _this.promotionSn
  369. _this.spinning = true
  370. promotionSave(form).then(res => {
  371. if (res.status == 200) {
  372. _this.$message.success(res.message)
  373. setTimeout(() => {
  374. _this.isShow = false
  375. _this.$emit('ok')
  376. _this.spinning = false
  377. }, 1000)
  378. } else {
  379. _this.spinning = false
  380. }
  381. })
  382. } else {
  383. return false
  384. }
  385. })
  386. },
  387. // 判断品牌,分类,产品其中一个必填
  388. isJudge (list) {
  389. let flag = null
  390. list.forEach(con => {
  391. if (con.productThisList) {
  392. if (con.productThisList.length > 0) {
  393. flag = false
  394. } else {
  395. if ((con.productTypeList && con.productTypeList.length > 0) || (con.productBrandList && con.productBrandList.length > 0)) {
  396. flag = false
  397. } else {
  398. flag = true
  399. }
  400. }
  401. } else {
  402. if ((con.productTypeList && con.productTypeList.length > 0) || (con.productBrandList && con.productBrandList.length > 0)) {
  403. flag = false
  404. } else {
  405. flag = true
  406. }
  407. }
  408. })
  409. return flag
  410. },
  411. // 重置表格
  412. resetSearchForm () {
  413. this.form = {
  414. promotionRuleType: 'BUY_PROD_GIVE_MONEY', // 买产品送采购额
  415. description: '',
  416. gateFlag: '0', // 门槛
  417. gateType: undefined,
  418. gateAmount: undefined,
  419. quotaAmount: undefined,
  420. regularSameFlag: '1', // 满赠规则 不同款商品
  421. regularAmount: undefined,
  422. giveAmount: undefined,
  423. restrictCategory: '',
  424. accrualFlag: '1', // 数量叠加
  425. minOrderFlag: '1', // 起订金额
  426. minOrderAmount: undefined,
  427. upperLimitFlag: '1', // 活动经费上限
  428. upperLimitAmount: undefined,
  429. scopeFlag: undefined,
  430. gateProductList: undefined,
  431. giftProductList: undefined,
  432. regularProductList: undefined
  433. }
  434. this.$nextTick(() => {
  435. this.$refs.ruleForm.resetFields()
  436. this.$refs.cillProduct.reSetTableData()
  437. this.$refs.normalPriceProduct.reSetTableData()
  438. this.$refs.offerProduct.reSetTableData()
  439. })
  440. },
  441. // 获取编辑详情
  442. getDetail () {
  443. const _this = this
  444. getRuleDetail({ sn: this.itemSn }).then(res => {
  445. if (res.status == 200) {
  446. this.chooseVal = res.data.gateFlag == '0' ? 'b' : 'a'
  447. const resultObj = res.data
  448. if (resultObj.gateFlag === '1') {
  449. resultObj.gateAmount = resultObj.gateType === 'RATIO_AMOUNT' ? resultObj.gateAmount * 100 : resultObj.gateAmount
  450. }
  451. // 重新组成保存数据
  452. if (resultObj.gateProductList && resultObj.gateProductList.length > 0) {
  453. resultObj.gateProductList = _this.newData(resultObj.gateProductList)
  454. this.$refs.cillProduct.setTabVal(resultObj.gateProductList)
  455. }
  456. if (resultObj.regularProductList && resultObj.regularProductList.length > 0) {
  457. resultObj.regularProductList = _this.newData(resultObj.regularProductList)
  458. this.$refs.normalPriceProduct.setTabVal(resultObj.regularProductList)
  459. }
  460. if (resultObj.giftProductList && resultObj.giftProductList.length > 0) {
  461. resultObj.giftProductList = _this.newData(resultObj.giftProductList)
  462. this.$refs.offerProduct.setTabVal(resultObj.giftProductList)
  463. }
  464. this.form = { ...this.form, ...resultObj }
  465. }
  466. })
  467. },
  468. newData (list) {
  469. list.forEach(con => {
  470. // 品牌
  471. if (con.productBrandList) {
  472. const brandList = []
  473. con.productBrandList.forEach(item => {
  474. item.brandName = item.productBrandName
  475. const brandObj = {
  476. productBrandSn: item.productBrandSn
  477. }
  478. brandList.push(brandObj)
  479. })
  480. con.productBrandArr = con.productBrandList
  481. con.productBrandList = brandList
  482. }
  483. // 分类
  484. if (con.productTypeList) {
  485. const typeList = []
  486. con.productTypeList.forEach(item => {
  487. const typeObj = {}
  488. item.title = ''
  489. const num = 3
  490. for (var i = 0; i < num; i++) {
  491. if (item['productTypeName' + (i + 1)]) {
  492. // item.title += item['productTypeName' + (i + 1)] + (item['productTypeName' + (i + 1)] ? '/' : '')
  493. typeObj['productTypeSn' + (i + 1)] = item['productTypeSn' + (i + 1)] ? item['productTypeSn' + (i + 1)] : ''
  494. }
  495. }
  496. // item.title = item.title.slice(0, item.title.length - 1)
  497. if (item.productTypeName3) {
  498. item.title = item.productTypeName2 + '/' + item.productTypeName3
  499. } else if (!item.productTypeName3 && item.productTypeName2) {
  500. item.title = item.productTypeName2
  501. } else {
  502. item.title = item.productTypeName1
  503. }
  504. item.id = item.productTypeSn3 ? item.productTypeSn3 : item.productTypeSn2 ? item.productTypeSn2 : item.productTypeSn1
  505. typeList.push(typeObj)
  506. })
  507. con.productTypeArr = con.productTypeList
  508. con.productTypeList = typeList
  509. }
  510. // 产品
  511. if (con.productThisList) {
  512. const productList = []
  513. con.productThisList.forEach(item => {
  514. const productObj = {
  515. productCode: item.productCode,
  516. productSn: item.productSn
  517. }
  518. productList.push(productObj)
  519. })
  520. con.productThisList = productList
  521. }
  522. })
  523. return list
  524. }
  525. },
  526. watch: {
  527. // 父页面传过来的弹框状态
  528. openModal (newValue, oldValue) {
  529. this.isShow = newValue
  530. },
  531. // 重定义的弹框状态
  532. isShow (newValue, oldValue) {
  533. if (!newValue) {
  534. this.$emit('close')
  535. this.resetSearchForm()
  536. } else {
  537. if (this.itemSn) {
  538. this.getDetail()
  539. } else {
  540. this.chooseVal = this.form.gateFlag == '0' ? 'b' : 'a'
  541. }
  542. }
  543. }
  544. }
  545. }
  546. </script>
  547. <style lang="less" scoped>
  548. .promotionList-basicInfo-modal{
  549. /deep/.ant-modal-body {
  550. padding: 40px 40px 24px;
  551. max-height: 745px !important;
  552. overflow-y: scroll !important;
  553. }
  554. .ant-radio-button-wrapper{
  555. width:80px;
  556. text-align: center;
  557. }
  558. .ant-form-item{
  559. margin-bottom:5px;
  560. }
  561. .buyerBox{
  562. border:1px solid #d9d9d9;margin-top:10px;border-radius:4px;padding:4px 10px;background:#f2f2f2;max-height:130px;overflow-y:scroll;
  563. }
  564. .btn-cont {
  565. text-align: center;
  566. margin: 35px 0 10px;
  567. }
  568. .flex{
  569. display:flex;
  570. align-items:center;
  571. justify-content:space-between;
  572. }
  573. }
  574. </style>