specialOfferModal.vue 32 KB

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