sendAmountModal.vue 29 KB

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