sendAmountModal.vue 19 KB

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