sendProductsModal.vue 31 KB

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