specialOfferModal.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  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="83%">
  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="规则叠加">
  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 id="promotionList-gateFlag" v-model="form.gateFlag" button-style="solid" size="small" @change="handleChange">
  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. id="promotionList-gateValue"
  61. v-model="form.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-gateValue"
  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. v-model="form.gateValue"
  83. id="promotionList-gateValue"
  84. :max="99999999"
  85. :min="0"
  86. :precision="form.gateUnit=='YUAN'?2:0"
  87. size="small"/>
  88. <a-select
  89. default-value="GE"
  90. id="promotionList-gateUnit"
  91. v-model="form.gateUnit"
  92. style="width: 50px;margin-left:5px;"
  93. size="small"
  94. @change="handleUnit">
  95. <a-select-option value="GE" id="promotionList-gateUnit-ge">
  96. </a-select-option>
  97. <a-select-option value="YUAN" id="promotionList-gateUnit-yuan">
  98. </a-select-option>
  99. </a-select>
  100. 门槛产品,可采购
  101. <a-input-number
  102. v-model="form.quotaAmount"
  103. id="promotionList-quotaAmount"
  104. :max="99999999"
  105. :min="0"
  106. :precision="0"
  107. size="small"/>
  108. 个特价产品(配额算销售额)
  109. </div>
  110. </div>
  111. </a-form-model-item>
  112. <a-form-model-item label="产品累计" v-if="form.gateFlag==='1'">
  113. <v-select
  114. style="width:40%;margin-right:10px;"
  115. size="small"
  116. v-model="form.borrowTimeLimtType"
  117. id="promotionList-borrowTimeLimtType"
  118. code="BORROW_TIME_LIMT_TYPE"
  119. placeholder="请选择累计时间"
  120. @change="borrowTimeLimtChange"
  121. allowClear></v-select>
  122. <a-checkbox v-if="form.borrowTimeLimtType" id="promotionList-borrowTimeLimtType" :checked="form.borrowedShowFlag === '1'" size="small" @change="onBorrowedShowChange">
  123. 加盟商显示“转促”标签
  124. </a-checkbox>
  125. </a-form-model-item>
  126. <a-form-model-item label="特价规则" prop="discountType">
  127. <a-select
  128. id="promotionList-discountType"
  129. default-value="0"
  130. v-model="form.discountType"
  131. placeholder="请选择"
  132. style="width:60%;"
  133. size="small"
  134. @change="handleDiscountType"
  135. allowClear>
  136. <a-select-option value="0" id="promotionList-discountType0">
  137. 手动输入特价
  138. </a-select-option>
  139. <a-select-option value="1" id="promotionList-discountType1">
  140. 各级别价打折
  141. </a-select-option>
  142. <a-select-option value="2" id="promotionList-discountType2">
  143. 各级别价直降
  144. </a-select-option>
  145. </a-select>
  146. <a-table
  147. v-show="form.discountType!=0"
  148. class="sTable"
  149. ref="setTable"
  150. size="small"
  151. :rowKey="(record) => record.id"
  152. :columns="setColumns"
  153. :dataSource="setTableData"
  154. :pagination="false"
  155. style="width:60%;"
  156. bordered>
  157. <template slot="provinceDiscount" slot-scope="text, record">
  158. <a-input-number
  159. size="small"
  160. :id="'promotionList-provinceDiscount'+record.id"
  161. v-model="record.provinceValue"
  162. :min="0"
  163. :step="1"
  164. :precision="2"
  165. :max="99999999"
  166. placeholder="请输入"/>%
  167. </template>
  168. <template slot="cityDiscount" slot-scope="text, record">
  169. <a-input-number
  170. size="small"
  171. :id="'promotionList-cityValue'+record.id"
  172. v-model="record.cityValue"
  173. :min="record.provinceValue||0"
  174. :step="1"
  175. :precision="2"
  176. :max="99999999"
  177. placeholder="请输入"/>%
  178. </template>
  179. <template slot="specialDiscount" slot-scope="text, record">
  180. <a-input-number
  181. size="small"
  182. :id="'promotionList-specialValue'+record.id"
  183. v-model="record.specialValue"
  184. :min="record.cityValue ||0"
  185. :step="1"
  186. :precision="2"
  187. :max="99999999"
  188. placeholder="请输入"/>%
  189. </template>
  190. <template slot="provincePrice" slot-scope="text, record">
  191. <a-input-number
  192. size="small"
  193. :value="record.provinceValue"
  194. :id="'promotionList-provinceValue'+record.id"
  195. :min="0"
  196. :step="1"
  197. :precision="2"
  198. :max="99999999"
  199. placeholder="请输入"
  200. @blur="handleProvincePrice"/>
  201. </template>
  202. <template slot="cityPrice" slot-scope="text, record">
  203. <a-input-number
  204. size="small"
  205. :value="record.cityValue"
  206. :id="'promotionList-cityValue'+record.id"
  207. :min="0"
  208. :step="1"
  209. :precision="2"
  210. :max="99999999"
  211. placeholder="请输入"
  212. @blur="handleCityPrice"/>
  213. </template>
  214. <template slot="specialPrice" slot-scope="text, record">
  215. <a-input-number
  216. size="small"
  217. :value="record.specialValue"
  218. :id="'promotionList-specialValue'+record.id"
  219. :min="0"
  220. :step="1"
  221. :precision="2"
  222. :max="99999999"
  223. placeholder="请输入"
  224. @blur="handleSpecialPrice"/>
  225. </template>
  226. </a-table>
  227. </a-form-model-item>
  228. </a-form-model>
  229. <a-card size="small" :bordered="false" class="pages-wrap">
  230. <div class="flex" style="margin-bottom:10px;">
  231. <a-radio-group id="promotionList-chooseVal" v-model="chooseVal" button-style="solid">
  232. <a-radio-button value="a" v-show="form.gateFlag==='1'" id="promotionList-chooseVal-a">
  233. 门槛产品
  234. </a-radio-button>
  235. <a-radio-button value="d" id="promotionList-chooseVal-d">
  236. 特价产品
  237. </a-radio-button>
  238. </a-radio-group>
  239. <div>
  240. <a-button
  241. size="small"
  242. type="link"
  243. class="button-info"
  244. id="promotionList-import-btn"
  245. @click="openGuideModal=true"
  246. >+导入产品</a-button>
  247. <a-button
  248. v-show="chooseVal==='d'"
  249. style="margin-left:10px;"
  250. size="small"
  251. type="link"
  252. class="button-info"
  253. id="promotionList-add-btn"
  254. @click="addProducts">+新增产品</a-button>
  255. <a-button type="link" id="promotionList-preview-btn" class="button-error" @click="handlePreview">预览</a-button>
  256. </div>
  257. </div>
  258. <div v-show="chooseVal=='a'"><tableType1 :unitTypeList="unitTypeDataList" ref="cillProduct"></tableType1></div>
  259. <div v-show="chooseVal=='d'"><tableType3 :setData="setTableData" :rulesType="form.discountType" :unitTypeList="unitTypeDataList" ref="specialProduct"></tableType3></div>
  260. </a-card>
  261. <div class="btn-cont">
  262. <a-button id="promotionList-cancel-btn" @click="isShow = false">取消</a-button>
  263. <a-button style="margin-left: 15px;" type="primary" id="promotionList-save-btn" @click="handleSave">确定</a-button>
  264. </div>
  265. </a-spin>
  266. <!-- 选择产品 -->
  267. <chooseProductsModal
  268. type="dealership"
  269. ref="productBox"
  270. :openModal="openProductsModal"
  271. :chooseData="chooseProducts"
  272. @close="openProductsModal=false"
  273. @ok="handleProductsAdd" />
  274. <!-- 导入产品 -->
  275. <importGuideModal :goodFlag="chooseVal=='a'?'1':'0'" :rulesType="form.discountType" :openModal="openGuideModal" @close="closeGuideModel" @ok="hanldeOk" />
  276. <!-- 预览弹窗 -->
  277. <productPreviewModal ref="previewModal" :openModal="openProductModal" :dataList="previewList" @close="closeProductModal"></productPreviewModal>
  278. </a-modal>
  279. </template>
  280. <script>
  281. import { commonMixin } from '@/utils/mixin'
  282. // 组件
  283. import { VSelect } from '@/components'
  284. import tableType1 from './tableType1.vue'
  285. import tableType3 from './tableType3.vue'
  286. import chooseProductsModal from './chooseProductsModal.vue'
  287. import ImportGuideModal from './importGuideModal.vue'
  288. import productPreviewModal from './productPreviewModal'
  289. // 接口
  290. import { getLookUpData } from '@/api/data'
  291. import { promotionSave, getRuleDetail } from '@/api/promotion'
  292. export default {
  293. name: 'PromotionListBasicInfoModal',
  294. mixins: [commonMixin],
  295. components: { VSelect, tableType1, tableType3, chooseProductsModal, ImportGuideModal, productPreviewModal },
  296. props: {
  297. openModal: { // 弹框显示状态
  298. type: Boolean,
  299. default: false
  300. },
  301. promotionSn: {
  302. type: [Number, String],
  303. default: ''
  304. },
  305. itemSn: {
  306. type: [Number, String],
  307. default: ''
  308. }
  309. },
  310. data () {
  311. return {
  312. isShow: this.openModal, // 是否打开弹框
  313. spinning: false,
  314. // form表单label布局
  315. formItemLayout: {
  316. labelCol: { span: 4 },
  317. wrapperCol: { span: 17 }
  318. },
  319. // 提交参数
  320. form: {
  321. promotionRuleType: 'PROMO_PROD', // 特价产品
  322. description: '', // 规则简称
  323. stackFlag: '0', // 规则叠加
  324. gateFlag: '0', // 门槛
  325. gateType: undefined, // 门槛产品类型
  326. gateValue: undefined, // 门槛产品配额值、满最低金额值、最低门槛金额和最低个数值
  327. gateUnit: 'GE', // 门槛产品单位
  328. quotaUnit: undefined, // 赠特价产品单位
  329. quotaAmount: undefined, // 赠特价产品金额
  330. discountType: '0', // 特价规则
  331. gateInfo: undefined, // 门槛产品规则描述
  332. ruleInfo: undefined, // 特价产品规则描述
  333. borrowTimeLimtType: undefined, // 产品累计
  334. borrowedShowFlag: undefined// 显示转促标签 1是 0否
  335. },
  336. // 表单验证规则
  337. rules: {
  338. description: [ { required: true, message: '请输入规则简称', trigger: 'blur' } ],
  339. gateFlag: [ { required: true, message: '请选择规则门槛', trigger: 'change' } ],
  340. discountType: [{ required: true, message: '请选择特价规则', trigger: 'change' }]
  341. },
  342. setTableData: null, // 特价表格规则
  343. chooseVal: 'a', // 显示规则类型 a门槛产品 d特价产品
  344. openProductsModal: false, // 打开选择产品弹窗
  345. chooseProducts: [], // 已选产品集合
  346. openGuideModal: false, // 导入弹窗
  347. code: 'SCOPE_UNIT_TYPE', // 起订类型数据字典
  348. unitTypeDataList: [], // 起订量集合
  349. openProductModal: false, // 预览弹窗
  350. previewList: []// 预览值
  351. }
  352. },
  353. computed: {
  354. setColumns () {
  355. const _this = this
  356. var arr = []
  357. if (_this.form.discountType === '1') {
  358. arr = [
  359. { title: '省价折扣', scopedSlots: { customRender: 'provinceDiscount' }, width: '33%', align: 'center' },
  360. { title: '市价折扣', scopedSlots: { customRender: 'cityDiscount' }, width: '33%', align: 'center' },
  361. { title: '特约折扣', scopedSlots: { customRender: 'specialDiscount' }, width: '33%', align: 'center' }
  362. ]
  363. } else if (_this.form.discountType === '2') {
  364. arr = [
  365. { title: '省价直降', scopedSlots: { customRender: 'provincePrice' }, width: '33%', align: 'center' },
  366. { title: '市价直降', scopedSlots: { customRender: 'cityPrice' }, width: '33%', align: 'center' },
  367. { title: '特约直降', scopedSlots: { customRender: 'specialPrice' }, width: '33%', align: 'center' }
  368. ]
  369. }
  370. return arr
  371. }
  372. },
  373. methods: {
  374. // 单位切换时,满赠规则数据清空
  375. handleUnit (val) {
  376. this.form.gateUnit = val
  377. this.form.gateValue = undefined
  378. },
  379. // 省价 change
  380. handleProvincePrice (e) {
  381. this.setTableData[0].provinceValue = Number(e.target.value)
  382. },
  383. // 市价 change
  384. handleCityPrice (e) {
  385. this.setTableData[0].cityValue = Number(e.target.value)
  386. },
  387. // 特约价 change
  388. handleSpecialPrice (e) {
  389. this.setTableData[0].specialValue = Number(e.target.value)
  390. },
  391. // 特价规则切换时清空数据
  392. handleDiscountType (val) {
  393. this.form.discountType = val
  394. this.$refs.specialProduct.reSetTableData()
  395. this.setTableData = [{
  396. provinceValue: undefined,
  397. cityValue: undefined,
  398. specialValue: undefined
  399. }]
  400. },
  401. // 产品累计
  402. borrowTimeLimtChange (val) {
  403. this.form.borrowedShowFlag = '0'
  404. if (!val && this.itemSn) {
  405. this.form.borrowTimeLimtTypeDictValue = undefined
  406. }
  407. },
  408. // 加盟商显示“转促”标签
  409. onBorrowedShowChange (e) {
  410. this.form.borrowedShowFlag = e.target.checked ? '1' : '0'
  411. },
  412. // 导入
  413. closeGuideModel () {
  414. this.openGuideModal = false
  415. },
  416. // 门槛产品
  417. handleChange (e) {
  418. if (e.target.value == '1') {
  419. this.chooseVal = 'a'
  420. } else {
  421. this.chooseVal = 'd'
  422. this.form.gateType = undefined
  423. this.form.gateValue = undefined
  424. this.form.quotaAmount = undefined
  425. }
  426. },
  427. // 门槛与配额设置要求
  428. changeGateTypeFlag (val) {
  429. this.form.gateType = val
  430. this.form.gateValue = undefined
  431. this.form.quotaAmount = undefined
  432. },
  433. // 保存
  434. handleSave () {
  435. const _this = this
  436. this.$refs.ruleForm.validate(valid => {
  437. if (valid) {
  438. // 验证门槛产品必填项
  439. if (_this.form.gateFlag === '1') {
  440. if (!_this.form.gateType) {
  441. _this.$message.warning('请选择规则门槛设置类型!')
  442. return
  443. }
  444. if (!_this.form.gateValue || (_this.form.gateType === 'FIXED_AMOUNT' && !_this.form.quotaAmount)) {
  445. _this.$message.warning('规则门槛条件不能为空!')
  446. return
  447. }
  448. }
  449. // 验证特价规则条件必填
  450. if (_this.form.discountType != '0' && _this.setTableData) {
  451. if (_this.setTableData[0].provinceValue == undefined || _this.setTableData[0].cityValue == undefined || _this.setTableData[0].specialValue == undefined) {
  452. _this.$message.warning('特价规则条件不能为空!')
  453. return
  454. }
  455. }
  456. // 验证表格必填项
  457. const form = JSON.parse(JSON.stringify(_this.form))
  458. if (form.gateFlag === '1') {
  459. form.gateValue = form.gateType === 'RATIO_AMOUNT' ? form.gateValue / 100 : form.gateValue
  460. // 门槛产品
  461. form.gateProductList = this.$refs.cillProduct.getResultVal()
  462. if (_this.isJudge(form.gateProductList, '门槛')) {
  463. return
  464. }
  465. form.gateUnit = form.gateType == 'RATIO_AMOUNT' ? 'RATIO' : form.gateType == 'MIN_AMOUNT' ? 'YUAN' : form.gateUnit
  466. form.quotaUnit = 'GE'
  467. } else {
  468. form.gateProductList = []
  469. form.gateValue = ''
  470. form.quotaAmount = ''
  471. form.gateType = undefined
  472. form.gateUnit = 'GE'
  473. form.quotaUnit = undefined
  474. form.borrowTimeLimtType = undefined
  475. form.borrowedShowFlag = undefined
  476. }
  477. // 特价产品
  478. form.specialProductList = _this.$refs.specialProduct.getResultVal()
  479. if (_this.isJudge(form.specialProductList, '特价')) {
  480. return
  481. }
  482. // 手动输入必填项
  483. if (form.discountType === '0') {
  484. const isCountEmpty = _this.isNumEmpty(form.specialProductList)
  485. if (isCountEmpty.flag) {
  486. _this.$message.warning('折扣不能为空!')
  487. return
  488. }
  489. if (isCountEmpty.flag1) {
  490. _this.$message.warning('折扣金额不能为空!')
  491. return
  492. }
  493. } else {
  494. form.provinceValue = _this.setTableData[0].provinceValue
  495. form.cityValue = _this.setTableData[0].cityValue
  496. form.specialValue = _this.setTableData[0].specialValue
  497. }
  498. // 组后端所需数据
  499. form.promotionSn = _this.promotionSn
  500. if (form.gateFlag == '1') {
  501. if (form.gateType === 'RATIO_AMOUNT') {
  502. form.gateInfo = '购买门槛产品金额' + (form.gateValue * 100).toFixed(2) + '%作为配额'
  503. } else if (form.gateType === 'MIN_AMOUNT') {
  504. form.gateInfo = '购买门槛产品满最低金额' + (form.gateValue).toFixed(2) + '元,不限制配额'
  505. } else {
  506. form.gateInfo = '购买每满' + (form.gateUnit == 'YUAN' ? (form.gateValue).toFixed(2) : form.gateValue) + (form.gateUnit == 'YUAN' ? '元' : '个') + '门槛产品,可采购' + form.quotaAmount + '个特价产品(配额算销售额)'
  507. }
  508. }
  509. let infoDetail = `<div>${form.stackFlag == '1' ? '规则叠加;' : ''}</div>`
  510. if (form.discountType == '0') {
  511. infoDetail += '手动输入特价'
  512. } else if (form.discountType == '1') {
  513. infoDetail += '各级别价打折;省级折扣' + form.provinceValue.toFixed(2) + '%,市级折扣' + form.cityValue.toFixed(2) + '%,特约折扣' + form.specialValue.toFixed(2) + '%'
  514. } else {
  515. infoDetail += '各级别价直降;省级直降' + form.provinceValue.toFixed(2) + ',市级直降' + form.cityValue.toFixed(2) + ',特约直降' + form.specialValue.toFixed(2)
  516. }
  517. infoDetail += `<div>${form.borrowTimeLimtType ? '产品累计:' + (form.borrowTimeLimtType == 'LENGTH_YEAR' ? '近一年' : '本年度') : ''}${form.borrowedShowFlag === '1' ? ',加盟商显示“转促”标签;' : ''}</div>`
  518. form.ruleInfo = infoDetail
  519. _this.spinning = true
  520. promotionSave(form).then(res => {
  521. if (res.status == 200) {
  522. _this.$message.success(res.message)
  523. setTimeout(() => {
  524. _this.isShow = false
  525. _this.$emit('ok')
  526. _this.spinning = false
  527. }, 1000)
  528. } else {
  529. _this.spinning = false
  530. }
  531. })
  532. } else {
  533. return false
  534. }
  535. })
  536. },
  537. // 判断是否为空
  538. isNumEmpty (dataList) {
  539. const arr = []
  540. const arr1 = []
  541. dataList.forEach(item => {
  542. if (item.dataSourceOrigin === '0') { // 判断分类品牌
  543. if (!item.provinceDiscountRate || !item.cityDiscountRate || !item.specialDiscountRate) {
  544. arr.push(item.productScopeSn)
  545. }
  546. } else {
  547. if (!item.cityDiscountPrice || !item.provinceDiscountPrice || !item.specialDiscountPrice) {
  548. arr1.push(item.productScopeSn)
  549. }
  550. }
  551. })
  552. return { flag: arr.length > 0, flag1: arr1.length > 0 }
  553. },
  554. // 判断品牌,分类,产品其中一个必填
  555. isJudge (list, typeName) {
  556. let flag, flag1, flag2
  557. flag = !(list && list.length)
  558. flag1 = list.some(con => !(con.productThisList && con.productThisList.length) && !(con.productTypeList && con.productTypeList.length) && !(con.productBrandList && con.productBrandList.length))
  559. flag2 = list.some(newCon => { return (!newCon.unitType || !newCon.unitQty) })
  560. if (flag) {
  561. const tipInfo = '请添加' + typeName + '产品!'
  562. this.$message.warning(tipInfo)
  563. } else if (flag1) {
  564. this.$message.warning('请选择产品分类、品牌或产品!')
  565. } else if (flag2) {
  566. this.$message.warning('订单起订量设置不能为空!')
  567. }
  568. return flag || flag1 || flag2
  569. },
  570. // 重置表格
  571. resetSearchForm () {
  572. this.form = {
  573. promotionRuleType: 'PROMO_PROD', // 特价产品
  574. description: '', // 规则简称
  575. stackFlag: '0', // 规则叠加
  576. gateFlag: '0', // 门槛
  577. gateType: undefined,
  578. gateValue: undefined,
  579. gateUnit: 'GE',
  580. quotaAmount: undefined,
  581. discountType: '0', // 特价规则
  582. gateProductList: undefined,
  583. specialProductList: undefined,
  584. quotaUnit: undefined,
  585. borrowTimeLimtType: undefined, // 产品累计
  586. borrowedShowFlag: undefined// 显示转促标签 1是 0否
  587. }
  588. this.$nextTick(() => {
  589. this.$refs.ruleForm.resetFields()
  590. this.$refs.cillProduct.reSetTableData()
  591. this.$refs.specialProduct.reSetTableData()
  592. })
  593. if (this.form.discountType != '0') {
  594. this.$refs[0].setTable.clearTable()
  595. }
  596. this.setTableData = []
  597. },
  598. // 获取编辑详情
  599. getDetail () {
  600. const _this = this
  601. _this.spinning = true
  602. getRuleDetail({ sn: this.itemSn }).then(res => {
  603. if (res.status == 200) {
  604. this.chooseVal = res.data.gateFlag == '0' ? 'd' : 'a'
  605. const resultObj = res.data
  606. if (resultObj.gateFlag === '1') {
  607. resultObj.gateValue = resultObj.gateType === 'RATIO_AMOUNT' ? resultObj.gateValue * 100 : resultObj.gateValue
  608. }
  609. if (resultObj.discountType != '0') {
  610. _this.setTableData = [{
  611. provinceValue: resultObj.provinceValue,
  612. cityValue: resultObj.cityValue,
  613. specialValue: resultObj.specialValue
  614. }]
  615. }
  616. // 重新组成保存数据
  617. if (resultObj.gateProductList && resultObj.gateProductList.length > 0) {
  618. resultObj.gateProductList = _this.newData(resultObj.gateProductList)
  619. this.$refs.cillProduct.setTabVal(resultObj.gateProductList)
  620. }
  621. if (resultObj.specialProductList && resultObj.specialProductList.length > 0) {
  622. resultObj.specialProductList = _this.newData(resultObj.specialProductList)
  623. this.$refs.specialProduct.setSourceData(resultObj.specialProductList)
  624. }
  625. this.form = { ...this.form, ...resultObj }
  626. }
  627. _this.spinning = false
  628. })
  629. },
  630. // 重组所需数据格式
  631. newData (list) {
  632. list.forEach(con => {
  633. // 品牌
  634. if (con.productBrandList) {
  635. const brandList = []
  636. con.productBrandList.forEach(item => {
  637. item.brandName = item.productBrandName
  638. item.brandSn = item.productBrandSn
  639. const brandObj = {
  640. productBrandSn: item.productBrandSn
  641. }
  642. brandList.push(brandObj)
  643. })
  644. con.productBrandArr = con.productBrandList
  645. con.productBrandList = brandList
  646. }
  647. // 分类
  648. if (con.productTypeList) {
  649. const typeList = []
  650. con.productTypeList.forEach(item => {
  651. const typeObj = {}
  652. item.title = ''
  653. const num = 3
  654. for (var i = 0; i < num; i++) {
  655. if (item['productTypeName' + (i + 1)]) {
  656. typeObj['productTypeSn' + (i + 1)] = item['productTypeSn' + (i + 1)] ? item['productTypeSn' + (i + 1)] : ''
  657. }
  658. }
  659. if (item.productTypeName3) {
  660. item.title = item.productTypeName2 + '/' + item.productTypeName3
  661. } else if (!item.productTypeName3 && item.productTypeName2) {
  662. item.title = item.productTypeName2
  663. } else {
  664. item.title = item.productTypeName1
  665. }
  666. item.id = item.productTypeSn3 ? item.productTypeSn3 : item.productTypeSn2 ? item.productTypeSn2 : item.productTypeSn1
  667. typeList.push(typeObj)
  668. })
  669. con.productTypeArr = con.productTypeList
  670. con.productTypeList = typeList
  671. }
  672. // 产品
  673. if (con.productThisList) {
  674. const productList = []
  675. con.productThisList.forEach(item => {
  676. const productObj = {
  677. productCode: item.productCode,
  678. productSn: item.productSn
  679. }
  680. productList.push(productObj)
  681. })
  682. con.productThisList = productList
  683. }
  684. })
  685. return list
  686. },
  687. // 导入
  688. hanldeOk (arr) {
  689. // 门槛产品导入
  690. const resultArr = []
  691. if (this.chooseVal == 'a') {
  692. const name = this.chooseVal == 'a' ? 'cill' : this.chooseVal == 'b' ? 'normalPrice' : 'offer'
  693. this.$refs[name + 'Product'].importRow(arr)
  694. } else {
  695. // 特价产品导入
  696. const dataList = this.setShowData('This')
  697. arr.forEach(item => {
  698. item = { ...item, ...item.product }
  699. item.code = item.productCode
  700. if (this.form.discountType == '0') {
  701. if (item.provincePrice) {
  702. item.provinceDiscountRate = Math.floor(((item.provinceDiscountPriceText / item.provincePrice) * 100).toFixed(2))
  703. }
  704. if (item.cityPrice) {
  705. item.cityDiscountRate = Math.floor(((item.cityDiscountPriceText / item.cityPrice) * 100).toFixed(2))
  706. }
  707. if (item.specialPrice) {
  708. item.specialDiscountRate = Math.floor(((item.specialDiscountPriceText / item.specialPrice) * 100).toFixed(2))
  709. }
  710. } else if (this.form.discountType == '1') {
  711. if (item.provincePrice) {
  712. item.provinceDiscountRate = this.form.provinceValue
  713. item.provinceDiscountPriceText = (item.provincePrice * this.form.provinceValue / 100).toFixed(2)
  714. }
  715. if (item.cityPrice) {
  716. item.cityDiscountRate = this.form.cityValue
  717. item.cityDiscountPriceText = (item.cityPrice * this.form.cityValue / 100).toFixed(2)
  718. }
  719. if (item.specialPrice) {
  720. item.specialDiscountRate = this.form.specialValue
  721. item.specialDiscountPriceText = (item.specialPrice * this.form.specialValue / 100).toFixed(2)
  722. }
  723. } else {
  724. if (item.provincePrice) {
  725. item.provinceSubtract = item.provincePrice - this.form.provinceValue
  726. }
  727. if (item.cityPrice) {
  728. item.citySubtract = item.cityPrice - this.form.cityValue
  729. }
  730. if (item.specialPrice) {
  731. item.specialSubtract = item.specialPrice - this.form.specialValue
  732. }
  733. }
  734. const flag = dataList.includes(item.productSn)
  735. if (!flag) {
  736. resultArr.push(item)
  737. }
  738. })
  739. if (resultArr.length > 0) {
  740. this.handleProductsOk(resultArr)
  741. } else {
  742. this.$message.warning('请勿添加重复数据!')
  743. }
  744. }
  745. },
  746. // 打开新增产品弹窗(禁用已选)
  747. addProducts () {
  748. this.chooseProducts = []
  749. this.openProductsModal = true
  750. const dataList = this.setShowData('This')
  751. this.$refs.productBox.handleDisabled(dataList)
  752. },
  753. // 获取回显禁用数据
  754. setShowData (name) {
  755. const _this = this
  756. const snArr = []
  757. const valList = _this.$refs.specialProduct.getResultVal()
  758. valList.forEach(item => {
  759. if (item['product' + name + 'List'] && item['product' + name + 'List'].length > 0) {
  760. item['product' + name + 'List'].forEach(con => {
  761. const newName = name === 'This' ? '' : name
  762. snArr.push(con['product' + newName + 'Sn'])
  763. })
  764. }
  765. })
  766. return snArr
  767. },
  768. // 添加产品 重组回显数据
  769. handleProductsAdd (con) {
  770. const newArr = []
  771. const newConArr = []
  772. con.forEach(newCon => {
  773. if (!newCon.provincePrice || !newCon.cityPrice || !newCon.specialPrice) {
  774. newArr.push(newCon.code)
  775. }
  776. })
  777. con.forEach((list, pos) => {
  778. if (list.provincePrice && list.cityPrice && list.specialPrice) {
  779. newConArr.push(list)
  780. }
  781. })
  782. const _this = this
  783. if (newArr && newArr.length > 0) {
  784. _this.$info({
  785. title: '提示',
  786. content: newArr.toString() + '(产品编码),没有定价,不可添加',
  787. closable: true,
  788. centered: true,
  789. onOk () {
  790. _this.handleProductsOk(newConArr)
  791. }
  792. })
  793. } else {
  794. _this.handleProductsOk(newConArr)
  795. }
  796. },
  797. // 生成随机数
  798. generateUniqueRandomNumber () {
  799. const timestamp = new Date().getTime()
  800. const randomNumber = Math.floor(Math.random() * 1e5).toString().padStart(5, '0')
  801. const uniqueRandomNumber = timestamp + randomNumber
  802. return uniqueRandomNumber
  803. },
  804. // +新增产品
  805. handleProductsOk (con) {
  806. const _this = this
  807. _this.spinning = true
  808. setTimeout(() => {
  809. _this.spinning = false
  810. }, 1500)
  811. con.forEach(async (item) => {
  812. const chooseProductsList = []
  813. const getSn = this.generateUniqueRandomNumber()
  814. if (getSn) {
  815. const newData = {
  816. productScopeSn: getSn,
  817. dataSourceOrigin: '1',
  818. productTypeArr: [],
  819. productTypeList: [],
  820. productBrandArr: [{ productBrandSn: item.productBrandSn, brandName: item.productBrandName }],
  821. productBrandList: [{ productBrandSn: item.productBrandSn }],
  822. productThisList: [{
  823. productSn: item.productSn,
  824. productCode: item.code
  825. }],
  826. provincePrice: item.provincePrice,
  827. cityPrice: item.cityPrice,
  828. specialPrice: item.specialPrice,
  829. provinceDiscountPrice: item.provinceDiscountPriceText,
  830. cityDiscountPrice: item.cityDiscountPriceText,
  831. specialDiscountPrice: item.specialDiscountPriceText,
  832. unitType: item.unitType || 'SL',
  833. unitQty: item.unitQty || '1',
  834. provinceDiscountRate: item.provinceDiscountRate ? item.provinceDiscountRate : undefined,
  835. cityDiscountRate: item.cityDiscountRate ? item.cityDiscountRate : undefined,
  836. specialDiscountRate: item.specialDiscountRate ? item.specialDiscountRate : undefined
  837. }
  838. const obj = {}
  839. if (item.productTypeSn1) {
  840. obj.productTypeSn1 = item.productTypeSn1
  841. }
  842. if (item.productTypeSn2) {
  843. obj.productTypeSn2 = item.productTypeSn2
  844. }
  845. if (item.productTypeSn3) {
  846. obj.productTypeSn3 = item.productTypeSn3
  847. }
  848. const newObj = { ...obj, ...{} }
  849. if (Object.keys(obj).length == 1) {
  850. newObj.title = item.productTypeName1
  851. newObj.id = item.productTypeSn1
  852. } else if (Object.keys(obj).length == 2) {
  853. newObj.title = item.productTypeName2
  854. newObj.id = item.productTypeSn2
  855. } else {
  856. newObj.title = item.productTypeName2 + '/' + item.productTypeName3
  857. newObj.id = item.productTypeSn3
  858. }
  859. newData.productTypeList[0] = obj
  860. newData.productTypeArr[0] = newObj
  861. chooseProductsList.push(newData)
  862. }
  863. _this.$refs.specialProduct.setSourceData(chooseProductsList)
  864. })
  865. },
  866. // 获取起订类型数据字典
  867. getUnitTypeList () {
  868. const _this = this
  869. getLookUpData({
  870. pageNo: 1,
  871. pageSize: 1000,
  872. lookupCode: _this.code
  873. }).then(res => {
  874. if (res.status == 200) {
  875. _this.unitTypeDataList = res.data.list
  876. }
  877. })
  878. },
  879. // 获取预览数据
  880. getPreviewList (dataList) {
  881. if (dataList && dataList.length > 0) {
  882. let newList = []
  883. dataList.forEach(con => {
  884. if (con.productThisList) {
  885. con.productThisList.forEach((item, i) => {
  886. item.unitTypeInfo = (con.unitType === 'SL' ? '按数量设置' : '按整箱设置') + con.unitQty
  887. item.productTypeInfo = con.promotionProductType
  888. })
  889. newList = [ ...newList, ...con.productThisList ]
  890. }
  891. })
  892. return newList
  893. } else {
  894. return []
  895. }
  896. },
  897. // 预览 删除标签,添加标签 预览按钮显示不显示
  898. handlePreview () {
  899. const dataName = this.chooseVal === 'a' ? 'gate' : 'special'
  900. const titName = this.chooseVal === 'a' ? '门槛产品' : '特价产品'
  901. if (!this.itemSn) {
  902. if (this.chooseVal === 'a') {
  903. this.form.gateProductList = this.$refs.cillProduct.getResultVal()
  904. } else {
  905. this.form.specialProductList = this.$refs.specialProduct.getResultVal()
  906. }
  907. }
  908. this.$nextTick(() => {
  909. const newPreviewList = this.getPreviewList(this.form[dataName + 'ProductList'])
  910. if (newPreviewList.length === 0) {
  911. this.$message.warning('暂时没有可预览的产品')
  912. return
  913. }
  914. this.previewList = newPreviewList
  915. const resuleObj = {
  916. tit: titName
  917. }
  918. this.$refs.previewModal.pageInit(resuleObj)
  919. this.openProductModal = true
  920. })
  921. },
  922. // 关闭产品弹窗
  923. closeProductModal () {
  924. this.previewList = []
  925. this.openProductModal = false
  926. }
  927. },
  928. watch: {
  929. // 父页面传过来的弹框状态
  930. openModal (newValue, oldValue) {
  931. this.isShow = newValue
  932. },
  933. // 重定义的弹框状态
  934. isShow (newValue, oldValue) {
  935. if (!newValue) {
  936. this.$emit('close')
  937. this.resetSearchForm()
  938. } else {
  939. // 获取起订类型数据字典
  940. this.getUnitTypeList()
  941. if (this.itemSn) {
  942. this.getDetail()
  943. } else {
  944. this.chooseVal = this.form.gateFlag == '0' ? 'd' : 'a'
  945. }
  946. }
  947. }
  948. }
  949. }
  950. </script>
  951. <style lang="less" scoped>
  952. // .ant-modal-confirm-body{
  953. // max-height: 500px;
  954. // overflow-y:scroll;
  955. // }
  956. .promotionList-basicInfo-modal{
  957. /deep/.ant-modal-body {
  958. padding: 20px 30px;
  959. max-height: 745px !important;
  960. overflow-y: scroll !important;
  961. }
  962. .fixWidthBox .ant-radio-button-wrapper{
  963. width:80px;
  964. text-align: center;
  965. }
  966. .ant-form-item{
  967. margin-bottom:5px;
  968. }
  969. .buyerBox{
  970. border:1px solid #d9d9d9;margin-top:10px;border-radius:4px;padding:4px 10px;background:#f2f2f2;max-height:130px;overflow-y:scroll;
  971. }
  972. .btn-cont {
  973. text-align: center;
  974. margin: 20px 0 10px;
  975. }
  976. .flex{
  977. display:flex;
  978. align-items:center;
  979. justify-content:space-between;
  980. }
  981. }
  982. /deep/.ve-table{
  983. border-radius:5px;
  984. }
  985. </style>