sendProductsModal.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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="请输入促销简称(最多10个字符)"
  26. :maxLength="10"></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="100" 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" :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" :precision="2" size="small"/>
  56. 元门槛产品,可使用
  57. <a-input-number v-model="form.quotaAmount" :max="form.gateAmount" :min="0" :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="0" 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 v-model="form.regularQty" :min="0" :step="1" :precision="0" size="small"/>
  74. 个正价产品,送
  75. <a-input-number
  76. v-model="form.promotionQty"
  77. :max="form.regularQty"
  78. :min="0"
  79. :step="1"
  80. :precision="0"
  81. size="small"/>
  82. 个促销产品
  83. </div>
  84. <div class="ruleDescList">
  85. <a-checkbox size="small" @change="onChange">
  86. 限制正价产品款数
  87. </a-checkbox>
  88. <a-input-number
  89. v-if="form.restrictFlag==='1'"
  90. v-model="form.restrictCategory"
  91. :min="0"
  92. :step="1"
  93. :precision="0"
  94. size="small"/>
  95. </div>
  96. </a-form-model-item>
  97. <a-form-model-item label="数量叠加" prop="accrualFlag">
  98. <a-radio-group v-model="form.accrualFlag" button-style="solid" size="small">
  99. <a-radio-button value="1">
  100. </a-radio-button>
  101. <a-radio-button value="0">
  102. </a-radio-button>
  103. </a-radio-group>
  104. <span style="color:gray;">(如:满10送2,数量叠加则:满20送4,满30送6)</span>
  105. </a-form-model-item>
  106. <a-form-model-item prop="minOrderFlag">
  107. <span slot="label">
  108. <!-- <a-tooltip title="What do you want others to call you?">
  109. <a-icon type="info-circle" />
  110. </a-tooltip> -->
  111. 订单起订金额
  112. </span>
  113. <a-select v-model="form.minOrderFlag" style="width: 160px" size="small">
  114. <a-select-option value="0">
  115. 不限
  116. </a-select-option>
  117. <a-select-option value="1">
  118. 限制
  119. </a-select-option>
  120. </a-select>
  121. <a-input-number
  122. v-show="form.minOrderFlag && form.minOrderFlag=='1'"
  123. size="small"
  124. style="margin-left:10px;width:300px;"
  125. v-model="form.minOrderAmount"
  126. :min="0"
  127. :step="1"
  128. :precision="2"
  129. placeholder="请输入金额"/>
  130. </a-form-model-item>
  131. <a-form-model-item prop="upperLimitFlag">
  132. <span slot="label">
  133. <!-- <a-tooltip title="What do you want others to call you?">
  134. <a-icon type="info-circle" />
  135. </a-tooltip> -->
  136. 活动经费上限
  137. </span>
  138. <a-select v-model="form.upperLimitFlag" style="width: 160px" size="small">
  139. <a-select-option value="0">
  140. 不限
  141. </a-select-option>
  142. <a-select-option value="1">
  143. 限制
  144. </a-select-option>
  145. </a-select>
  146. <a-input-number
  147. v-show="form.upperLimitFlag&&form.upperLimitFlag=='1'"
  148. size="small"
  149. style="margin-left:10px;width:300px;"
  150. v-model="form.upperLimitAmount"
  151. :min="0"
  152. :step="1"
  153. :precision="2"
  154. placeholder="请输入金额"/>
  155. </a-form-model-item>
  156. <a-form-model-item label="促销品与正品一致" prop="regularPromotionSameFlag">
  157. <a-radio-group v-model="form.regularPromotionSameFlag" button-style="solid" size="small">
  158. <a-radio-button value="1">
  159. </a-radio-button>
  160. <a-radio-button value="0">
  161. </a-radio-button>
  162. </a-radio-group>
  163. </a-form-model-item>
  164. </a-form-model>
  165. <a-card size="small" :bordered="false" class="pages-wrap">
  166. <div class="flex">
  167. <a-radio-group v-model="chooseVal" button-style="solid" size="small">
  168. <a-radio-button value="a" v-show="form.gateFlag==='1'">
  169. 门槛产品
  170. </a-radio-button>
  171. <a-radio-button value="b">
  172. 正价产品
  173. </a-radio-button>
  174. <a-radio-button value="c" v-show="form.regularPromotionSameFlag==='0'">
  175. 促销产品
  176. </a-radio-button>
  177. </a-radio-group>
  178. <a-button
  179. size="small"
  180. type="link"
  181. class="button-info"
  182. id="promotionList-edit-btn">+导入产品</a-button>
  183. </div>
  184. <div v-show="chooseVal=='a'"><tableType1 ref="cillProduct"></tableType1></div>
  185. <div v-show="chooseVal=='b'"><tableType1 ref="normalPriceProduct"></tableType1></div>
  186. <div v-show="chooseVal=='c'"><tableType2 ref="offerProduct"></tableType2></div>
  187. </a-card>
  188. <div class="btn-cont">
  189. <a-button id="promotionList-basicInfo-modal-back" @click="isShow = false">取消</a-button>
  190. <a-button style="margin-left: 15px;" type="primary" id="promotionList-modal-save" @click="handleSave">确定</a-button>
  191. </div>
  192. </a-spin>
  193. </a-modal>
  194. </template>
  195. <script>
  196. import { commonMixin } from '@/utils/mixin'
  197. import { VSelect } from '@/components'
  198. import tableType1 from './tableType1.vue'
  199. import tableType2 from './tableType2.vue'
  200. import { promotionSave, getRuleDetail } from '@/api/promotion'
  201. export default {
  202. name: 'PromotionListBasicInfoModal',
  203. mixins: [commonMixin],
  204. components: { VSelect, tableType1, tableType2 },
  205. props: {
  206. openModal: { // 弹框显示状态
  207. type: Boolean,
  208. default: false
  209. },
  210. promotionSn: {
  211. type: [Number, String],
  212. default: ''
  213. },
  214. itemSn: {
  215. type: [Number, String],
  216. default: ''
  217. }
  218. },
  219. data () {
  220. return {
  221. isShow: this.openModal, // 是否打开弹框
  222. spinning: false,
  223. formItemLayout: {
  224. labelCol: { span: 4 },
  225. wrapperCol: { span: 17 }
  226. },
  227. form: {
  228. promotionRuleType: 'BUY_PROD_GIVE_PROD', // 买产品送产品
  229. description: '', // 简称
  230. gateFlag: '0', // 门槛
  231. gateType: undefined,
  232. gateAmount: undefined,
  233. quotaAmount: undefined,
  234. regularSameFlag: '0', // 满赠规则 不同款商品
  235. regularQty: undefined,
  236. promotionQty: undefined,
  237. restrictFlag: undefined, // 限制正价产品款数
  238. restrictCategory: '',
  239. accrualFlag: '1', // 数量叠加
  240. minOrderFlag: '1', // 起订金额
  241. minOrderAmount: undefined,
  242. upperLimitFlag: '1', // 活动经费上限
  243. upperLimitAmount: undefined,
  244. regularPromotionSameFlag: undefined
  245. },
  246. rules: {
  247. description: [ { required: true, message: '请输入规则简称', trigger: 'blur' } ],
  248. gateFlag: [ { required: true, message: '请选择规则门槛', trigger: 'change' } ],
  249. regularSameFlag: [{ required: true, message: '请选择满赠规则', trigger: 'change' }],
  250. accrualFlag: [{ required: true, message: '请选择数量是否叠加', trigger: 'change' }],
  251. minOrderFlag: [{ required: true, message: '请选择订单起订金额', trigger: 'change' }],
  252. upperLimitFlag: [{ required: true, message: '请选择活动经费上限', trigger: 'change' }],
  253. regularPromotionSameFlag: [{ required: true, message: '请选择促销品与正品是否一致', trigger: 'change' }]
  254. },
  255. chooseVal: 'a'
  256. }
  257. },
  258. methods: {
  259. onChange (e) {
  260. this.form.restrictFlag = e.target.checked ? '1' : '0'
  261. },
  262. // 门槛切换 tab 按钮默认显示问题
  263. changeGateFlag (e) {
  264. if (this.chooseVal != 'c') {
  265. if (e.target.value == '0') {
  266. this.chooseVal = 'b'
  267. } else {
  268. this.chooseVal = 'a'
  269. }
  270. }
  271. },
  272. // 保存
  273. handleSave () {
  274. const _this = this
  275. this.$refs.ruleForm.validate(valid => {
  276. if (valid) {
  277. // 验证必填
  278. if (_this.form.gateFlag == '1') {
  279. if (!_this.form.gateType) {
  280. _this.$message.warning('请选择规则门槛设置类型!')
  281. return
  282. }
  283. if (!_this.form.gateAmount) {
  284. _this.$message.warning('规则门槛条件不能为空!')
  285. return
  286. }
  287. if (_this.form.gateType === 'FIXED_AMOUNT' && !_this.form.quotaAmount) {
  288. _this.$message.warning('规则门槛条件不能为空!')
  289. return
  290. }
  291. }
  292. if (!_this.form.regularQty || !_this.form.promotionQty) {
  293. _this.$message.warning('满赠规则条件不能为空!')
  294. return
  295. }
  296. if (_this.form.restrictFlag && !_this.form.restrictCategory) {
  297. _this.$message.warning('请输入限制正价产品款数个数!')
  298. return
  299. }
  300. if (_this.form.minOrderFlag == 1 && !_this.form.minOrderAmount) {
  301. _this.$message.warning('请输入订单起订限制金额数!')
  302. return
  303. }
  304. if (_this.form.upperLimitFlag == 1 && !_this.form.upperLimitAmount) {
  305. _this.$message.warning('请输入活动经费上限金额!')
  306. return
  307. }
  308. const form = JSON.parse(JSON.stringify(_this.form))
  309. if (form.gateFlag == '1') {
  310. form.gateProductList = this.$refs.cillProduct.getResultVal()
  311. form.gateAmount = form.gateType === 'RATIO_AMOUNT' ? form.gateAmount / 100 : form.gateAmount
  312. } else {
  313. form.gateProductList = []
  314. form.gateAmount = ''
  315. form.quotaAmount = ''
  316. form.gateType = undefined
  317. }
  318. if (form.regularPromotionSameFlag == '0') {
  319. form.giftProductList = this.$refs.offerProduct.getResultVal()
  320. } else {
  321. form.giftProductList = []
  322. }
  323. form.regularProductList = this.$refs.normalPriceProduct.getResultVal()
  324. form.promotionSn = _this.promotionSn
  325. _this.spinning = true
  326. promotionSave(form).then(res => {
  327. if (res.status == 200) {
  328. _this.$message.success(res.message)
  329. setTimeout(() => {
  330. _this.isShow = false
  331. _this.$emit('ok')
  332. _this.spinning = false
  333. }, 1000)
  334. } else {
  335. _this.spinning = false
  336. }
  337. })
  338. } else {
  339. return false
  340. }
  341. })
  342. },
  343. // 重置表格
  344. resetSearchForm () {
  345. this.form = {
  346. promotionRuleType: 'BUY_PROD_GIVE_PROD', // 买产品送产品
  347. description: '', // 简称
  348. gateFlag: '0', // 门槛
  349. gateType: undefined,
  350. gateAmount: undefined,
  351. quotaAmount: undefined,
  352. regularSameFlag: '0', // 满赠规则 不同款商品
  353. regularQty: undefined,
  354. promotionQty: undefined,
  355. restrictFlag: undefined, // 限制正价产品款数
  356. restrictCategory: '',
  357. accrualFlag: '1', // 数量叠加
  358. minOrderFlag: '1', // 起订金额
  359. minOrderAmount: undefined,
  360. upperLimitFlag: '1', // 活动经费上限
  361. upperLimitAmount: undefined,
  362. regularPromotionSameFlag: undefined,
  363. gateProductList: undefined,
  364. giftProductList: undefined,
  365. regularProductList: undefined
  366. }
  367. this.$nextTick(() => {
  368. this.$refs.ruleForm.resetFields()
  369. this.$refs.cillProduct.reSetTableData()
  370. this.$refs.normalPriceProduct.reSetTableData()
  371. this.$refs.offerProduct.reSetTableData()
  372. })
  373. },
  374. // 获取编辑详情
  375. getDetail () {
  376. const _this = this
  377. getRuleDetail({ sn: this.itemSn }).then(res => {
  378. if (res.status == 200) {
  379. const resultObj = res.data
  380. _this.chooseVal = resultObj.gateFlag == '0' ? 'b' : 'a'
  381. if (resultObj.gateFlag === '1') {
  382. resultObj.gateAmount = resultObj.gateType === 'RATIO_AMOUNT' ? resultObj.gateAmount * 100 : resultObj.gateAmount
  383. }
  384. // 重新组成保存数据
  385. if (resultObj.gateProductList && resultObj.gateProductList.length > 0) {
  386. resultObj.gateProductList = _this.newData(resultObj.gateProductList)
  387. this.$refs.cillProduct.setTabVal(resultObj.gateProductList)
  388. }
  389. if (resultObj.regularProductList && resultObj.regularProductList.length > 0) {
  390. resultObj.regularProductList = _this.newData(resultObj.regularProductList)
  391. this.$refs.normalPriceProduct.setTabVal(resultObj.regularProductList)
  392. }
  393. if (resultObj.giftProductList && resultObj.giftProductList.length > 0) {
  394. resultObj.giftProductList = _this.newData(resultObj.giftProductList)
  395. this.$refs.offerProduct.setTabVal(resultObj.giftProductList)
  396. }
  397. this.form = { ...this.form, ...resultObj }
  398. }
  399. })
  400. },
  401. newData (list) {
  402. list.forEach(con => {
  403. // 品牌
  404. if (con.productBrandList) {
  405. const brandList = []
  406. con.productBrandList.forEach(item => {
  407. item.brandName = item.productBrandName
  408. const brandObj = {
  409. productBrandSn: item.productBrandSn
  410. }
  411. brandList.push(brandObj)
  412. })
  413. con.productBrandArr = con.productBrandList
  414. con.productBrandList = brandList
  415. }
  416. // 分类
  417. if (con.productTypeList) {
  418. const typeList = []
  419. con.productTypeList.forEach(item => {
  420. const typeObj = {}
  421. item.title = ''
  422. const num = 3
  423. for (var i = 0; i < num; i++) {
  424. if (item['productTypeName' + (i + 1)]) {
  425. item.title += item['productTypeName' + (i + 1)] + (item['productTypeName' + (i + 1)] ? '/' : '')
  426. typeObj['productTypeSn' + (i + 1)] = item['productTypeSn' + (i + 1)] ? item['productTypeSn' + (i + 1)] : ''
  427. }
  428. }
  429. item.title = item.title.slice(0, item.title.length - 1)
  430. item.id = item.productTypeSn3 ? item.productTypeSn3 : item.productTypeSn2 ? item.productTypeSn2 : item.productTypeSn1
  431. typeList.push(typeObj)
  432. })
  433. con.productTypeArr = con.productTypeList
  434. con.productTypeList = typeList
  435. }
  436. // 产品
  437. if (con.productThisList) {
  438. const productList = []
  439. con.productThisList.forEach(item => {
  440. const productObj = {
  441. productCode: item.productCode,
  442. productSn: item.productSn
  443. }
  444. productList.push(productObj)
  445. })
  446. con.productThisList = productList
  447. }
  448. })
  449. return list
  450. }
  451. },
  452. watch: {
  453. // 父页面传过来的弹框状态
  454. openModal (newValue, oldValue) {
  455. this.isShow = newValue
  456. },
  457. // 重定义的弹框状态
  458. isShow (newValue, oldValue) {
  459. if (!newValue) {
  460. this.$emit('close')
  461. this.resetSearchForm()
  462. } else {
  463. if (this.itemSn) {
  464. this.getDetail()
  465. } else {
  466. this.chooseVal = this.form.gateFlag == '0' ? 'b' : 'a'
  467. }
  468. }
  469. }
  470. }
  471. }
  472. </script>
  473. <style lang="less" scoped>
  474. .promotionList-basicInfo-modal{
  475. /deep/.ant-modal-body {
  476. padding: 40px 40px 24px;
  477. max-height: 745px !important;
  478. overflow-y: scroll !important;
  479. }
  480. .ant-radio-button-wrapper{
  481. width:80px;
  482. text-align: center;
  483. }
  484. .ant-form-item{
  485. margin-bottom:5px;
  486. }
  487. .buyerBox{
  488. border:1px solid #d9d9d9;margin-top:10px;border-radius:4px;padding:4px 10px;background:#f2f2f2;max-height:130px;overflow-y:scroll;
  489. }
  490. .btn-cont {
  491. text-align: center;
  492. margin: 35px 0 10px;
  493. }
  494. .flex{
  495. display:flex;
  496. align-items:center;
  497. justify-content:space-between;
  498. }
  499. }
  500. </style>