sendProductsModal.vue 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. <template>
  2. <a-modal
  3. centered
  4. class="promotionList-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-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="规则叠加">
  29. <v-select
  30. style="width:40%;"
  31. size="small"
  32. v-model="form.stackFlag"
  33. id="promotionList-stackFlag"
  34. code="FLAG"
  35. placeholder="请选择是否叠加规则"
  36. allowClear></v-select>
  37. <span>(销售单内的产品可同时参与多个叠加规则)</span>
  38. </a-form-model-item>
  39. <a-form-model-item label="规则门槛" prop="gateFlag">
  40. <div class="fixWidthBox">
  41. <a-radio-group v-model="form.gateFlag" id="promotionList-gateFlag" button-style="solid" size="small" @change="changeGateFlag">
  42. <a-radio-button value="1" id="promotionList-gateFlag1">
  43. </a-radio-button>
  44. <a-radio-button value="0" id="promotionList-gateFlag0">
  45. </a-radio-button>
  46. </a-radio-group>
  47. </div>
  48. <div v-if="form.gateFlag && form.gateFlag === '1'">
  49. <v-select
  50. size="small"
  51. style="width:60%;"
  52. v-model="form.gateType"
  53. id="promotionList-gateType"
  54. code="PROMOTION_GATE_TYPE"
  55. placeholder="请选择门槛与配额设置要求"
  56. @change="changeGateTypeFlag"
  57. allowClear></v-select>
  58. <div v-if="form.gateType==='RATIO_AMOUNT'">
  59. 购买门槛产品金额 <a-input-number
  60. v-model="form.gateValue"
  61. id="promotionList-gateValue"
  62. :min="0"
  63. :max="99999999"
  64. :precision="2"
  65. size="small"/> %作为配额
  66. <a-tooltip title="如:填写100%,则购买10000元门槛产品,可享受10000配额购买正价产品,根据门槛金额动态调整配额">
  67. <a-icon type="question-circle" theme="filled" :style="{ fontSize: '14px', color: 'gray' }"/>
  68. </a-tooltip>
  69. </div>
  70. <div v-if="form.gateType==='MIN_AMOUNT'">
  71. 购买门槛产品满最低金额 <a-input-number
  72. id="promotionList-gateValue1"
  73. v-model="form.gateValue"
  74. :min="0"
  75. :max="99999999"
  76. :precision="2"
  77. size="small"/>元,不限制配额。
  78. </div>
  79. <div class="ruleDescList" v-if="form.gateType==='FIXED_AMOUNT'">
  80. 购买满
  81. <a-input-number
  82. id="promotionList-gateValue2"
  83. v-model="form.gateValue"
  84. :min="0"
  85. :max="99999999"
  86. :precision="2"
  87. size="small"/>
  88. 元门槛产品,可使用
  89. <a-input-number
  90. id="promotionList-quotaAmount"
  91. v-model="form.quotaAmount"
  92. :min="0"
  93. :max="99999999"
  94. :precision="2"
  95. size="small"/>
  96. 元配额,采购规则中的正价商品(配额算销售额)
  97. </div>
  98. </div>
  99. </a-form-model-item>
  100. <a-form-model-item label="满赠规则" prop="regularSameFlag">
  101. <div class="fullGiftRuleBox">
  102. <div class="ruleDescList" v-for="(con,i) in fullGiftRuleList" :key="i">
  103. <span v-if="fullGiftRuleList.length>1">{{ i*1+1 }}、</span>
  104. <a-select
  105. id="promotionList-regularSameFlag"
  106. default-value="1"
  107. :disabled="i!=0"
  108. v-model="form.regularSameFlag"
  109. style="width: 100px"
  110. size="small"
  111. @change="handleFullGift"
  112. allowClear>
  113. <a-select-option value="1" id="promotionList-regularSameFlag1">
  114. 同款
  115. </a-select-option>
  116. <a-select-option value="0" id="promotionList-regularSameFlag0">
  117. 不同款
  118. </a-select-option>
  119. </a-select>
  120. 产品购买满
  121. <a-input-number
  122. v-model="con.regularValue"
  123. id="promotionList-regularValue"
  124. :min="i!=0?fullGiftRuleList[i-1].regularValue:0"
  125. :step="1"
  126. :max="99999999"
  127. :precision="form.regularUnit==='YUAN'?2:0"
  128. size="small"/>
  129. <a-select
  130. id="promotionList-regularUnit"
  131. default-value="GE"
  132. :disabled="i!=0"
  133. v-model="form.regularUnit"
  134. style="width: 50px;margin-left:5px;"
  135. size="small"
  136. @change="handleChangeUnit">
  137. <a-select-option value="GE" id="promotionList-regularUnit-ge">
  138. </a-select-option>
  139. <a-select-option value="YUAN" id="promotionList-regularUnit-yuan">
  140. </a-select-option>
  141. </a-select>
  142. 正价产品,送
  143. <a-input-number
  144. id="promotionList-promotionValue"
  145. v-model="con.promotionValue"
  146. :min="0"
  147. :step="1"
  148. :precision="0"
  149. :max="99999999"
  150. size="small"/>
  151. 个促销产品
  152. <a-button type="link" id="promotionList-add" v-if="i==0&&fullGiftRuleList&&fullGiftRuleList.length<5" class="button-info" @click="addFullGiftRule">+新增</a-button>
  153. <a-button type="link" id="promotionList-del" v-if="i!=0" class="button-error" @click="delFullGiftRule(con.id)">删除</a-button>
  154. </div>
  155. </div>
  156. <div class="ruleDescList">
  157. <a-checkbox id="promotionList-restrictFlag" :checked="form.restrictFlag === '1'" size="small" @change="onChange">
  158. 限制正价产品款数
  159. </a-checkbox>
  160. <a-input-number
  161. v-if="form.restrictFlag==='1'"
  162. v-model="form.restrictCategory"
  163. :min="0"
  164. :step="1"
  165. :max="99999999"
  166. :precision="0"
  167. size="small"
  168. id="promotionList-restrictCategory"
  169. style="margin-right:10px;"/>
  170. <a-checkbox id="promotionList-convertExpenseFlag" :checked="form.convertExpenseFlag==='1'" size="small" @change="onChangeConvert">
  171. 可转费用报销单
  172. </a-checkbox>
  173. </div>
  174. </a-form-model-item>
  175. <a-form-model-item label="数量叠加" prop="accrualFlag">
  176. <a-radio-group id="promotionList-accrualFlag" v-model="form.accrualFlag" button-style="solid" size="small">
  177. <a-radio value="1" id="promotionList-accrualFlag1">
  178. </a-radio>
  179. <a-radio value="0" id="promotionList-accrualFlag0">
  180. </a-radio>
  181. </a-radio-group>
  182. <span style="color:gray;">(如:满10送2,数量叠加则:满20送4,满30送6)</span>
  183. </a-form-model-item>
  184. <a-form-model-item label="产品累计">
  185. <v-select
  186. style="width:40%;margin-right:10px;"
  187. size="small"
  188. v-model="form.borrowTimeLimtType"
  189. id="promotionList-borrowTimeLimtType"
  190. code="BORROW_TIME_LIMT_TYPE"
  191. placeholder="请选择累计时间"
  192. @change="borrowTimeLimtChange"
  193. allowClear></v-select>
  194. <a-checkbox v-if="form.borrowTimeLimtType" id="promotionList-borrowedShowFlag" :checked="form.borrowedShowFlag === '1'" size="small" @change="onBorrowedShowChange">
  195. 加盟商显示“转促”标签
  196. </a-checkbox>
  197. </a-form-model-item>
  198. <a-form-model-item label="促销品与正品一致" prop="regularPromotionSameFlag">
  199. <div class="fixWidthBox">
  200. <a-radio-group
  201. id="promotionList-regularPromotionSameFlag"
  202. v-model="form.regularPromotionSameFlag"
  203. button-style="solid"
  204. size="small"
  205. :disabled="form.regularSameFlag==0"
  206. @change="handleSameFlag">
  207. <a-radio-button value="1" id="promotionList-regularPromotionSameFlag1">
  208. </a-radio-button>
  209. <a-radio-button value="0" id="promotionList-regularPromotionSameFlag0">
  210. </a-radio-button>
  211. </a-radio-group>
  212. </div>
  213. </a-form-model-item>
  214. </a-form-model>
  215. <a-card size="small" :bordered="false" class="pages-wrap">
  216. <div class="flex" style="margin-bottom:10px;">
  217. <a-radio-group id="promotionList-chooseVal" v-model="chooseVal" button-style="solid" @change="onChooseVal">
  218. <a-radio-button value="a" id="promotionList-chooseVal-a" v-show="form.gateFlag==='1'">
  219. 门槛产品
  220. </a-radio-button>
  221. <a-radio-button value="b" id="promotionList-chooseVal-b">
  222. 正价产品
  223. </a-radio-button>
  224. <a-radio-button :id="'promotionList-chooseVal-c'+item.id" :value="'c'+item.id" v-for="(item,i) in fullGiftRuleList" :key="i" v-show="form.regularPromotionSameFlag==='0'">
  225. {{ fullGiftRuleList.length>1?'促销产品('+'阶梯'+(i*1+1)+')':'促销产品' }}
  226. </a-radio-button>
  227. </a-radio-group>
  228. <div>
  229. <a-button
  230. size="small"
  231. type="link"
  232. class="button-info"
  233. @click="openGuideModal=true"
  234. id="promotionList-import">+导入产品</a-button>
  235. <a-button type="link" id="promotionList-preview" class="button-error" @click="handlePreview">预览</a-button>
  236. </div>
  237. </div>
  238. <div v-show="chooseVal=='a'"><tableType1 :unitTypeList="unitTypeDataList" ref="cillProduct"></tableType1></div>
  239. <div v-show="chooseVal=='b'"><tableType1 :unitTypeList="unitTypeDataList" ref="normalPriceProduct"></tableType1></div>
  240. <div v-show="chooseVal==('c'+item.id)" v-for="(item,i) in fullGiftRuleList" :key="item.id"><tableType1 :unitTypeList="unitTypeDataList" :ref="'offerProduct'+i"></tableType1></div>
  241. </a-card>
  242. <div class="btn-cont">
  243. <a-button id="promotionList-cancel" @click="isShow = false">取消</a-button>
  244. <a-button style="margin-left: 15px;" type="primary" id="promotionList-save" :loading="loadingSave" @click="handleSave">确定</a-button>
  245. </div>
  246. </a-spin>
  247. <!-- 导入产品 -->
  248. <importGuideModal goodFlag="1" :openModal="openGuideModal" @close="closeGuideModel" @ok="hanldeOk" />
  249. <!-- 预览弹窗 -->
  250. <productPreviewModal ref="previewModal" :openModal="openProductModal" :dataList="previewList" @close="closeProductModal"></productPreviewModal>
  251. </a-modal>
  252. </template>
  253. <script>
  254. import { commonMixin } from '@/utils/mixin'
  255. // 组件
  256. import { VSelect } from '@/components'
  257. import tableType1 from './tableType1.vue'
  258. import ImportGuideModal from './importGuideModal.vue'
  259. import productPreviewModal from './productPreviewModal'
  260. // 接口
  261. import { getLookUpData } from '@/api/data'
  262. import { promotionSave, getRuleDetail, getNewScopeSn } from '@/api/promotion'
  263. export default {
  264. name: 'PromotionListBasicInfoModal',
  265. mixins: [commonMixin],
  266. components: { VSelect, tableType1, ImportGuideModal, productPreviewModal },
  267. props: {
  268. openModal: { // 弹框显示状态
  269. type: Boolean,
  270. default: false
  271. },
  272. promotionSn: {
  273. type: [Number, String],
  274. default: ''
  275. },
  276. itemSn: {
  277. type: [Number, String],
  278. default: ''
  279. }
  280. },
  281. data () {
  282. return {
  283. isShow: this.openModal, // 是否打开弹框
  284. spinning: false,
  285. // form表单 label布局
  286. formItemLayout: {
  287. labelCol: { span: 4 },
  288. wrapperCol: { span: 17 }
  289. },
  290. fullGiftRuleList: [], // 促销产品数据
  291. form: {
  292. giveRuleType: 'RATIO', // 满赠规则类型: SUM_MONEY[金额叠加] / RATIO[按比例] 满产品送产品写死为: 按比例
  293. promotionRuleType: 'BUY_PROD_GIVE_PROD', // 买产品送产品
  294. description: '', // 简称
  295. stackFlag: '0', // 叠加规则 1是 0否
  296. gateFlag: '0', // 门槛
  297. gateType: undefined, // 选择门槛类型
  298. gateValue: undefined, // 门槛值
  299. quotaAmount: undefined, // 门槛配额
  300. regularSameFlag: '1', // 满赠规则 同款不同款商品
  301. regularUnit: 'GE', // 单位
  302. restrictFlag: '0', // 限制正价产品款数
  303. convertExpenseFlag: '0', // 转费用报销标记
  304. restrictCategory: '', // 正价产品款数
  305. accrualFlag: '1', // 数量叠加
  306. regularPromotionSameFlag: '1', // 促销品与正品是否一致
  307. giftProductMap: {}, // 阶梯促销产品集合
  308. gateInfo: undefined, // 门槛产品规则描述
  309. ruleInfo: undefined, // 正价产品规则描述
  310. gateUnit: undefined, // 门槛产品单位
  311. quotaUnit: undefined, // 门槛配额单位
  312. borrowTimeLimtType: undefined, // 产品累计
  313. borrowedShowFlag: undefined// 显示转促标签 1是 0否
  314. },
  315. // 表单验证规则
  316. rules: {
  317. description: [ { required: true, message: '请输入规则简称', trigger: 'blur' } ],
  318. gateFlag: [ { required: true, message: '请选择规则门槛', trigger: 'change' } ],
  319. regularSameFlag: [{ required: true, message: '请选择满赠规则', trigger: 'change' }],
  320. accrualFlag: [{ required: true, message: '请选择数量是否叠加', trigger: 'change' }],
  321. regularPromotionSameFlag: [{ required: true, message: '请选择促销品与正品是否一致', trigger: 'change' }]
  322. },
  323. chooseVal: 'a', // a门槛产品 b正价产品 c 或者c+id促销产品 促销阶梯产品
  324. openGuideModal: false, // 导入弹窗
  325. id: null,
  326. code: 'SCOPE_UNIT_TYPE', // 起订类型数据字典
  327. unitTypeDataList: [], // 起订量数据
  328. loadingSave: false, // 提交按钮加载状态
  329. openProductModal: false, // 预览弹窗
  330. previewList: []// 预览值
  331. }
  332. },
  333. methods: {
  334. // 单位切换时,满赠规则数据清空
  335. handleChangeUnit (e) {
  336. this.form.regularUnit = e
  337. this.fullGiftRuleList.forEach(item => {
  338. item.regularValue = undefined
  339. })
  340. },
  341. // 新增 满减规则 最多能添加五个
  342. async addFullGiftRule () {
  343. const result = await getNewScopeSn({})
  344. const obj = {
  345. id: result.data,
  346. scopeLevel: undefined,
  347. regularValue: undefined,
  348. promotionValue: undefined
  349. }
  350. this.fullGiftRuleList.push(obj)
  351. },
  352. // 删除满减规则
  353. delFullGiftRule (id) {
  354. const pos = this.fullGiftRuleList.findIndex(con => { return con.id == id })
  355. this.fullGiftRuleList.splice(pos, 1)
  356. if (this.chooseVal == 'c' + id) {
  357. this.chooseVal = this.form.gateFlag == '0' ? 'b' : 'a'
  358. }
  359. },
  360. // 满赠 同款 促销品与正品一致 默认是 可修改
  361. // 不同款 默认否 不可修改
  362. handleFullGift (e) {
  363. if (e === '0') { // 不同款
  364. this.form.regularPromotionSameFlag = '0'
  365. } else {
  366. this.form.regularPromotionSameFlag = '1'
  367. if (this.chooseVal.indexOf('c') != -1) {
  368. this.chooseVal = this.form.gateFlag == '0' ? 'b' : 'a'
  369. }
  370. }
  371. },
  372. // 导入
  373. closeGuideModel () {
  374. this.openGuideModal = false
  375. },
  376. // 导入成功
  377. hanldeOk (arr) {
  378. if (this.chooseVal == 'a') {
  379. this.$refs['cillProduct'].importRow(arr)
  380. } else if (this.chooseVal == 'b') {
  381. this.$refs['normalPriceProduct'].importRow(arr)
  382. } else {
  383. const pos = this.fullGiftRuleList.findIndex(item => { return 'c' + item.id == this.chooseVal })
  384. if (pos != -1) {
  385. this.$refs['offerProduct' + pos][0].importRow(arr)
  386. }
  387. }
  388. this.openGuideModal = false
  389. },
  390. // 限制正价产品款数
  391. onChange (e) {
  392. this.form.restrictFlag = e.target.checked ? '1' : '0'
  393. },
  394. // 可转费用报销单
  395. onChangeConvert (e) {
  396. this.form.convertExpenseFlag = e.target.checked ? '1' : '0'
  397. },
  398. // 产品累计
  399. borrowTimeLimtChange (val) {
  400. this.form.borrowedShowFlag = '0'
  401. if (!val && this.itemSn) {
  402. this.form.borrowTimeLimtTypeDictValue = undefined
  403. }
  404. },
  405. // 加盟商显示“转促”标签
  406. onBorrowedShowChange (e) {
  407. this.form.borrowedShowFlag = e.target.checked ? '1' : '0'
  408. },
  409. // 门槛切换 tab 按钮默认显示问题
  410. changeGateFlag (e) {
  411. if (e.target.value == '0') {
  412. this.chooseVal = 'b'
  413. this.form.gateType = undefined
  414. this.form.gateValue = undefined
  415. this.form.quotaAmount = undefined
  416. } else {
  417. this.chooseVal = 'a'
  418. }
  419. },
  420. // 促销品与正品一致
  421. handleSameFlag (e) {
  422. if (e.target.value != '0') {
  423. this.chooseVal = this.form.gateFlag == '1' ? 'a' : 'b'
  424. }
  425. },
  426. // 门槛与配额设置要求
  427. changeGateTypeFlag (val) {
  428. this.form.gateType = val
  429. this.form.gateValue = undefined
  430. this.form.quotaAmount = undefined
  431. },
  432. // 保存
  433. handleSave () {
  434. const _this = this
  435. this.$refs.ruleForm.validate(valid => {
  436. if (valid) {
  437. // 验证必填
  438. if (_this.form.gateFlag == '1') {
  439. if (!_this.form.gateType) {
  440. _this.$message.warning('请选择规则门槛设置类型!')
  441. return
  442. }
  443. if (!_this.form.gateValue) {
  444. _this.$message.warning('规则门槛条件不能为空!')
  445. return
  446. }
  447. if (_this.form.gateType === 'FIXED_AMOUNT' && !_this.form.quotaAmount) {
  448. _this.$message.warning('规则门槛条件不能为空!')
  449. return
  450. }
  451. if (_this.form.gateType == 'RATIO_AMOUNT') {
  452. _this.form.gateUnit = 'RATIO'
  453. } else if (_this.form.gateType == 'MIN_AMOUNT') {
  454. _this.form.gateUnit = 'YUAN'
  455. } else {
  456. _this.form.gateUnit = 'YUAN'
  457. _this.form.quotaUnit = 'YUAN'
  458. }
  459. }
  460. const hasNullVal = _this.fullGiftRuleList.some(itemVal => {
  461. if (itemVal.regularValue && itemVal.promotionValue) {
  462. return (itemVal.regularValue <= 0 || itemVal.promotionValue <= 0)
  463. } else {
  464. return true
  465. }
  466. })
  467. if (hasNullVal) {
  468. _this.$message.warning('满赠规则条件不能为空!')
  469. return
  470. }
  471. if (_this.form.restrictFlag === '1' && !_this.form.restrictCategory) {
  472. _this.$message.warning('请输入限制正价产品款数个数!')
  473. return
  474. }
  475. var form = JSON.parse(JSON.stringify(_this.form))
  476. let rowFlag1, rowFlag2, rowFlag3
  477. if (form.gateFlag == '1') { // 门槛产品
  478. form.gateProductList = this.$refs.cillProduct.getResultVal()
  479. form.gateValue = form.gateType === 'RATIO_AMOUNT' ? form.gateValue / 100 : form.gateValue
  480. if (form.gateProductList.length == 0) {
  481. _this.$message.warning('请添加门槛产品!')
  482. return
  483. } else {
  484. const qtyFlag = form.gateProductList.some(newCon => { return (!newCon.unitType || !newCon.unitQty) })
  485. if (qtyFlag) {
  486. _this.$message.warning('订单起订量设置不能为空!')
  487. return
  488. }
  489. rowFlag1 = _this.isJudge(form.gateProductList)
  490. }
  491. } else {
  492. form.gateProductList = []
  493. form.gateType = undefined
  494. }
  495. // 正价产品
  496. form.regularProductList = this.$refs.normalPriceProduct.getResultVal()
  497. // 判断表格必填
  498. if (form.regularProductList.length == 0) {
  499. _this.$message.warning('请添加正价产品!')
  500. return
  501. } else {
  502. const qtyFlag = form.regularProductList.some(newCon => { return (!newCon.unitType || !newCon.unitQty) })
  503. if (qtyFlag) {
  504. _this.$message.warning('订单起订量设置不能为空!')
  505. return
  506. }
  507. rowFlag2 = _this.isJudge(form.regularProductList)
  508. }
  509. if (form.regularPromotionSameFlag === '0') { // 促销产品 阶梯促销产品
  510. const allGiftObj = {}
  511. _this.fullGiftRuleList.forEach((val, i) => {
  512. allGiftObj['GIFT' + (i * 1 + 1)] = _this.$refs['offerProduct' + i][0].getResultVal()
  513. })
  514. var lengthFlag = null
  515. for (const key in allGiftObj) {
  516. if (allGiftObj[key].length === 0) {
  517. lengthFlag = true
  518. }
  519. }
  520. if (lengthFlag) {
  521. _this.$message.warning('请添加促销产品!')
  522. return
  523. }
  524. const arrFlag = []
  525. for (const key in allGiftObj) {
  526. if (allGiftObj[key] && allGiftObj[key].length > 0) {
  527. arrFlag.push(_this.isJudge(allGiftObj[key]))
  528. }
  529. }
  530. rowFlag3 = arrFlag.some(val => { return val })
  531. // 组数据,添加数组标识
  532. let keyPos = 0
  533. for (const key in allGiftObj) {
  534. keyPos += 1
  535. allGiftObj[key].forEach((item, j) => {
  536. item.scopeLevel = keyPos
  537. })
  538. }
  539. form.giftProductMap = allGiftObj
  540. } else {
  541. form.giftProductMap = {}
  542. }
  543. if (rowFlag1 || rowFlag2 || rowFlag3) {
  544. _this.$message.warning('请选择产品分类、品牌或产品!')
  545. return
  546. }
  547. // 组传给后台所需数据
  548. _this.fullGiftRuleList.map((val, i) => {
  549. val.scopeLevel = i * 1 + 1
  550. val.regularSameFlag = form.regularSameFlag
  551. val.regularUnit = form.regularUnit
  552. })
  553. form.promotionSn = _this.promotionSn
  554. form.giveRuleList = _this.fullGiftRuleList
  555. if (form.gateFlag == '1') {
  556. if (form.gateType === 'RATIO_AMOUNT') {
  557. form.gateInfo = '购买门槛产品金额' + (form.gateValue * 100).toFixed(2) + '%作为配额'
  558. } else if (form.gateType === 'MIN_AMOUNT') {
  559. form.gateInfo = '购买门槛产品满最低金额' + form.gateValue.toFixed(2) + '元,不限制配额'
  560. } else {
  561. form.gateInfo = '购买满' + form.gateValue.toFixed(2) + '元门槛产品,可使用' + form.quotaAmount.toFixed(2) + '元配额,采购规则中的正价商品(配额算销售额)'
  562. }
  563. }
  564. var newInfo = `<div>${form.stackFlag == '1' ? '规则叠加;' : ''}${form.accrualFlag == '1' ? '数量叠加;' : ''}${form.convertExpenseFlag == '1' ? '可转费用报销单;' : ''}</div>`
  565. _this.fullGiftRuleList.forEach((item, i) => {
  566. newInfo += `<div>${_this.fullGiftRuleList.length > 1 ? (i * 1 + 1) + '、' : ''}${form.regularSameFlag == '1' ? '同款' : '不同款'}产品购买满${form.regularUnit == 'YUAN' ? item.regularValue.toFixed(2) : item.regularValue}${form.regularUnit == 'YUAN' ? '元' : '个'}正价产品,送${item.promotionValue}个促销产品</div>`
  567. })
  568. newInfo += `<div>${form.restrictFlag == '1' ? '限制正价产品' + form.restrictCategory + '款;' : ''}</div><div>${form.borrowTimeLimtType ? '产品累计:' + (form.borrowTimeLimtType == 'LENGTH_YEAR' ? '近一年' : '本年度') : ''}${form.borrowedShowFlag === '1' ? ',加盟商显示“转促”标签;' : ''}</div>`
  569. form.ruleInfo = newInfo
  570. _this.spinning = true
  571. _this.loadingSave = true
  572. promotionSave(form).then(res => {
  573. if (res.status == 200) {
  574. _this.$message.success(res.message)
  575. setTimeout(() => {
  576. _this.isShow = false
  577. _this.$emit('ok')
  578. _this.spinning = false
  579. _this.loadingSave = false
  580. }, 1000)
  581. } else {
  582. _this.spinning = false
  583. _this.loadingSave = false
  584. }
  585. })
  586. } else {
  587. return false
  588. }
  589. })
  590. },
  591. // 判断品牌,分类,产品其中一个必填
  592. isJudge (list) {
  593. let flag = null
  594. list.forEach(con => {
  595. if (con.productThisList) {
  596. if (con.productThisList.length > 0) {
  597. flag = false
  598. } else {
  599. if ((con.productTypeList && con.productTypeList.length > 0) || (con.productBrandList && con.productBrandList.length > 0)) {
  600. flag = false
  601. } else {
  602. flag = true
  603. }
  604. }
  605. } else {
  606. if ((con.productTypeList && con.productTypeList.length > 0) || (con.productBrandList && con.productBrandList.length > 0)) {
  607. flag = false
  608. } else {
  609. flag = true
  610. }
  611. }
  612. })
  613. return flag
  614. },
  615. // 重置表格
  616. resetSearchForm () {
  617. this.form = {
  618. giveRuleType: 'RATIO', // 满赠规则类型: SUM_MONEY[金额叠加] / RATIO[按比例] 满产品送产品写死为: 按比例
  619. promotionRuleType: 'BUY_PROD_GIVE_PROD', // 买产品送产品
  620. description: '', // 简称
  621. stackFlag: '0', // 叠加规则 1是 0否
  622. gateFlag: '0', // 门槛
  623. gateType: undefined,
  624. gateValue: undefined,
  625. quotaAmount: undefined,
  626. regularSameFlag: '1', // 满赠规则 同款不同款商品
  627. regularUnit: 'GE',
  628. restrictFlag: '0', // 限制正价产品款数
  629. convertExpenseFlag: '0', // 转费用报销标记
  630. restrictCategory: '',
  631. accrualFlag: '1', // 数量叠加
  632. regularPromotionSameFlag: '1',
  633. giftProductMap: {},
  634. gateProductList: undefined,
  635. regularProductList: undefined,
  636. gateInfo: undefined,
  637. ruleInfo: undefined,
  638. gateUnit: undefined,
  639. quotaUnit: undefined,
  640. borrowTimeLimtType: undefined, // 产品累计
  641. borrowedShowFlag: undefined// 显示转促标签 1是 0否
  642. }
  643. this.$nextTick(() => {
  644. this.$refs.ruleForm.resetFields()
  645. this.$refs.cillProduct.reSetTableData()
  646. this.$refs.normalPriceProduct.reSetTableData()
  647. })
  648. this.fullGiftRuleList.forEach((val, i) => {
  649. this.$refs['offerProduct' + i][0].reSetTableData()
  650. })
  651. this.fullGiftRuleList = []
  652. this.id = null
  653. },
  654. // 获取编辑详情
  655. getDetail () {
  656. const _this = this
  657. _this.spinning = true
  658. getRuleDetail({ sn: _this.itemSn }).then(res => {
  659. if (res.status == 200) {
  660. const resultObj = res.data
  661. _this.chooseVal = resultObj.gateFlag == '0' ? 'b' : 'a'
  662. if (resultObj.gateFlag == '1') {
  663. resultObj.gateValue = resultObj.gateType === 'RATIO_AMOUNT' ? resultObj.gateValue * 100 : resultObj.gateValue
  664. }
  665. if (resultObj.giveRuleList && resultObj.giveRuleList.length > 0) {
  666. _this.fullGiftRuleList = resultObj.giveRuleList
  667. if (resultObj.giftProductMap && Object.keys(resultObj.giftProductMap).length > 0) {
  668. _this.$nextTick(() => {
  669. resultObj.giveRuleList.forEach((item, i) => {
  670. _this.$refs['offerProduct' + i][0].setTabVal(_this.newData(resultObj.giftProductMap['GIFT' + (i * 1 + 1)]))
  671. })
  672. })
  673. }
  674. }
  675. // 重新组成保存数据
  676. if (resultObj.gateProductList && resultObj.gateProductList.length > 0) {
  677. resultObj.gateProductList = _this.newData(resultObj.gateProductList)
  678. _this.$refs.cillProduct.setTabVal(resultObj.gateProductList)
  679. }
  680. if (resultObj.regularProductList && resultObj.regularProductList.length > 0) {
  681. resultObj.regularProductList = _this.newData(resultObj.regularProductList)
  682. _this.$refs.normalPriceProduct.setTabVal(resultObj.regularProductList)
  683. }
  684. const newDataObj = { ..._this.form, ...resultObj }
  685. delete newDataObj.giftProductList
  686. _this.form = newDataObj
  687. }
  688. _this.spinning = false
  689. })
  690. },
  691. // 重组所需回显数据
  692. newData (list) {
  693. list.forEach(con => {
  694. // 品牌
  695. if (con.productBrandList) {
  696. const brandList = []
  697. con.productBrandList.forEach(item => {
  698. item.brandName = item.productBrandName
  699. item.brandSn = item.productBrandSn
  700. const brandObj = {
  701. productBrandSn: item.productBrandSn
  702. }
  703. brandList.push(brandObj)
  704. })
  705. con.productBrandArr = con.productBrandList
  706. con.productBrandList = brandList
  707. }
  708. // 分类
  709. if (con.productTypeList) {
  710. const typeList = []
  711. con.productTypeList.forEach(item => {
  712. const typeObj = {}
  713. const num = 3
  714. for (var i = 0; i < num; i++) {
  715. if (item['productTypeName' + (i + 1)]) {
  716. typeObj['productTypeSn' + (i + 1)] = item['productTypeSn' + (i + 1)] ? item['productTypeSn' + (i + 1)] : ''
  717. }
  718. }
  719. if (item.productTypeName3) {
  720. item.title = item.productTypeName2 + '/' + item.productTypeName3
  721. } else if (!item.productTypeName3 && item.productTypeName2) {
  722. item.title = item.productTypeName2
  723. } else {
  724. item.title = item.productTypeName1
  725. }
  726. item.id = item.productTypeSn3 ? item.productTypeSn3 : item.productTypeSn2 ? item.productTypeSn2 : item.productTypeSn1
  727. typeList.push(typeObj)
  728. })
  729. con.productTypeArr = con.productTypeList
  730. con.productTypeList = typeList
  731. }
  732. // 产品
  733. if (con.productThisList) {
  734. const productList = []
  735. con.productThisList.forEach(item => {
  736. const productObj = {
  737. productCode: item.productCode,
  738. productSn: item.productSn
  739. }
  740. productList.push(productObj)
  741. })
  742. con.productThisList = productList
  743. }
  744. })
  745. return list
  746. },
  747. // 重组起订量等数据
  748. getUnitTypeList () {
  749. const _this = this
  750. getLookUpData({
  751. pageNo: 1,
  752. pageSize: 1000,
  753. lookupCode: _this.code
  754. }).then(res => {
  755. if (res.status == 200) {
  756. _this.unitTypeDataList = res.data.list
  757. }
  758. })
  759. },
  760. // 获取预览产品数据
  761. getPreviewList (dataList) {
  762. if (dataList && dataList.length > 0) {
  763. let newList = []
  764. dataList.forEach(con => {
  765. if (con.productThisList) {
  766. con.productThisList.forEach((item, i) => {
  767. item.unitTypeInfo = (con.unitType === 'SL' ? '按数量设置' : '按整箱设置') + con.unitQty
  768. item.productTypeInfo = con.promotionProductType
  769. })
  770. newList = [ ...newList, ...con.productThisList ]
  771. }
  772. })
  773. return newList
  774. } else {
  775. return []
  776. }
  777. },
  778. // 预览
  779. handlePreview () {
  780. const dataName = this.chooseVal === 'a' ? 'gate' : this.chooseVal === 'b' ? 'regular' : 'giftGroup'
  781. const titName = this.chooseVal === 'a' ? '门槛产品' : this.chooseVal === 'b' ? '正价产品' : '促销产品'
  782. if (dataName != 'giftGroup') {
  783. if (!this.itemSn) {
  784. if (this.chooseVal === 'a') {
  785. this.form.gateProductList = this.$refs.cillProduct.getResultVal()
  786. } else if (this.chooseVal === 'b') {
  787. this.form.regularProductList = this.$refs.normalPriceProduct.getResultVal()
  788. }
  789. }
  790. const newPreviewList = this.getPreviewList(this.form[dataName + 'ProductList'])
  791. if (newPreviewList && newPreviewList.length > 0) {
  792. this.previewList = newPreviewList
  793. const resuleObj = {
  794. tit: titName
  795. }
  796. this.$nextTick(() => {
  797. this.$refs.previewModal.pageInit(resuleObj)
  798. })
  799. this.openProductModal = true
  800. } else {
  801. this.$message.warning('暂时没有可预览的产品')
  802. }
  803. } else {
  804. // 阶梯数据处理
  805. const idInfo = this.chooseVal.split('c')[1]
  806. const stepIndex = this.fullGiftRuleList.findIndex(item => item.id === idInfo)
  807. if (stepIndex > -1 && !this.itemSn) {
  808. this.form.giftProductMap['GIFT' + (stepIndex * 1 + 1)] = this.$refs['offerProduct' + stepIndex][0].getResultVal()
  809. }
  810. if (this.form.giftProductMap && Object.keys(this.form.giftProductMap).length > 0) {
  811. const stepPreviewList = this.getPreviewList(this.form.giftProductMap['GIFT' + (stepIndex * 1 + 1)])
  812. if (stepPreviewList && stepPreviewList.length > 0) {
  813. this.previewList = stepPreviewList
  814. const resuleObj = {
  815. tit: '促销产品(阶梯' + (stepIndex * 1 + 1) + ')'
  816. }
  817. this.$nextTick(() => {
  818. this.$refs.previewModal.pageInit(resuleObj)
  819. })
  820. this.openProductModal = true
  821. } else {
  822. this.$message.warning('暂时没有可预览的产品')
  823. }
  824. }
  825. }
  826. },
  827. // 关闭选择产品弹窗
  828. closeProductModal () {
  829. this.previewList = []
  830. this.openProductModal = false
  831. },
  832. // 选择显示产品类型
  833. onChooseVal (e) {
  834. this.chooseVal = e.target.value
  835. }
  836. },
  837. watch: {
  838. // 父页面传过来的弹框状态
  839. openModal (newValue, oldValue) {
  840. this.isShow = newValue
  841. },
  842. // 重定义的弹框状态
  843. isShow (newValue, oldValue) {
  844. if (!newValue) {
  845. this.$emit('close')
  846. this.resetSearchForm()
  847. } else {
  848. // 获取起订类型数据字典
  849. this.getUnitTypeList()
  850. this.addFullGiftRule()
  851. if (this.itemSn) {
  852. this.getDetail()
  853. } else {
  854. this.chooseVal = this.form.gateFlag == '0' ? 'b' : 'a'
  855. }
  856. }
  857. }
  858. }
  859. }
  860. </script>
  861. <style lang="less" scoped>
  862. .promotionList-modal{
  863. /deep/.ant-modal-body {
  864. padding: 20px 30px;
  865. max-height: 745px !important;
  866. overflow-y: scroll !important;
  867. }
  868. .fixWidthBox .ant-radio-button-wrapper{
  869. width:80px;
  870. text-align: center;
  871. }
  872. .ant-form-item{
  873. margin-bottom:5px;
  874. }
  875. .buyerBox{
  876. border:1px solid #d9d9d9;margin-top:10px;border-radius:4px;padding:4px 10px;background:#f2f2f2;max-height:130px;overflow-y:scroll;
  877. }
  878. .btn-cont {
  879. text-align: center;
  880. margin: 35px 0 10px;
  881. }
  882. .flex{
  883. display:flex;
  884. align-items:center;
  885. justify-content:space-between;
  886. }
  887. .ant-radio-button-wrapper-disabled.ant-radio-button-wrapper-checked{
  888. background-color: #ed1c24 !important;
  889. }
  890. }
  891. /deep/.ve-table{
  892. border-radius:5px;
  893. }
  894. </style>