specialOfferModal.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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">
  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. quotaAmount: undefined,
  256. discountType: '0', // 特价规则
  257. gateInfo: undefined,
  258. ruleInfo: undefined
  259. },
  260. rules: {
  261. description: [ { required: true, message: '请输入规则简称', trigger: 'blur' } ],
  262. gateFlag: [ { required: true, message: '请选择规则门槛', trigger: 'change' } ],
  263. discountType: [{ required: true, message: '请选择特价规则', trigger: 'change' }]
  264. },
  265. setTableData: null,
  266. chooseVal: 'a',
  267. openProductsModal: false,
  268. chooseProducts: [],
  269. openGuideModal: false, // 导入弹窗
  270. code: 'SCOPE_UNIT_TYPE', // 起订类型数据字典
  271. unitTypeDataList: []
  272. }
  273. },
  274. computed: {
  275. setColumns () {
  276. const _this = this
  277. var arr = []
  278. if (_this.form.discountType === '1') {
  279. arr = [
  280. { title: '省价折扣', scopedSlots: { customRender: 'provinceDiscount' }, width: '33%', align: 'center' },
  281. { title: '市价折扣', scopedSlots: { customRender: 'cityDiscount' }, width: '33%', align: 'center' },
  282. { title: '特约折扣', scopedSlots: { customRender: 'specialDiscount' }, width: '33%', align: 'center' }
  283. ]
  284. } else if (_this.form.discountType === '2') {
  285. arr = [
  286. { title: '省价直降', scopedSlots: { customRender: 'provincePrice' }, width: '33%', align: 'center' },
  287. { title: '市价直降', scopedSlots: { customRender: 'cityPrice' }, width: '33%', align: 'center' },
  288. { title: '特约直降', scopedSlots: { customRender: 'specialPrice' }, width: '33%', align: 'center' }
  289. ]
  290. }
  291. return arr
  292. }
  293. },
  294. methods: {
  295. // 单位切换时,满赠规则数据清空
  296. handleUnit (val) {
  297. this.form.gateUnit = val
  298. this.form.gateValue = undefined
  299. },
  300. handleProvincePrice (e) {
  301. this.setTableData[0].provinceValue = Number(e.target.value)
  302. },
  303. handleCityPrice (e) {
  304. this.setTableData[0].cityValue = Number(e.target.value)
  305. },
  306. handleSpecialPrice (e) {
  307. this.setTableData[0].specialValue = Number(e.target.value)
  308. },
  309. // 特价规则切换时清空数据
  310. handleDiscountType (val) {
  311. this.form.discountType = val
  312. this.$refs.specialProduct.reSetTableData()
  313. this.setTableData = [{
  314. provinceValue: undefined,
  315. cityValue: undefined,
  316. specialValue: undefined
  317. }]
  318. },
  319. // 导入
  320. closeGuideModel () {
  321. this.openGuideModal = false
  322. },
  323. // 门槛产品
  324. handleChange (e) {
  325. if (e.target.value == '1') {
  326. this.chooseVal = 'a'
  327. } else {
  328. this.chooseVal = 'd'
  329. this.form.gateType = undefined
  330. this.form.gateValue = undefined
  331. this.form.quotaAmount = undefined
  332. }
  333. },
  334. changeGateTypeFlag (val) {
  335. this.form.gateType = val
  336. this.form.gateValue = undefined
  337. this.form.quotaAmount = undefined
  338. },
  339. // 保存
  340. handleSave () {
  341. const _this = this
  342. this.$refs.ruleForm.validate(valid => {
  343. if (valid) {
  344. // 验证必填
  345. if (_this.form.gateFlag === '1') {
  346. if (!_this.form.gateType) {
  347. _this.$message.warning('请选择规则门槛设置类型!')
  348. return
  349. }
  350. if (!_this.form.gateValue) {
  351. _this.$message.warning('规则门槛条件不能为空!')
  352. return
  353. }
  354. if (_this.form.gateType === 'FIXED_AMOUNT' && !_this.form.quotaAmount) {
  355. _this.$message.warning('规则门槛条件不能为空!')
  356. return
  357. }
  358. }
  359. // 判断特价规则必填
  360. if (_this.form.discountType != '0' && _this.setTableData) {
  361. if (_this.setTableData[0].provinceValue == undefined || _this.setTableData[0].cityValue == undefined || _this.setTableData[0].specialValue == undefined) {
  362. _this.$message.warning('特价规则条件不能为空!')
  363. return
  364. }
  365. }
  366. const form = JSON.parse(JSON.stringify(_this.form))
  367. if (form.gateFlag === '1') {
  368. form.gateProductList = _this.$refs.cillProduct.getResultVal()
  369. form.gateValue = form.gateType === 'RATIO_AMOUNT' ? form.gateValue / 100 : form.gateValue
  370. if (form.gateProductList.length == 0) {
  371. _this.$message.warning('请添加门槛产品!')
  372. return
  373. } else {
  374. const qtyFlag = form.gateProductList.some(newCon => { return (!newCon.unitType || !newCon.unitQty) })
  375. if (qtyFlag) {
  376. _this.$message.warning('订单起订量设置不能为空!')
  377. return
  378. }
  379. const rowFlag = _this.isJudge(form.gateProductList)
  380. if (rowFlag) {
  381. _this.$message.warning('请选择产品分类、品牌或产品!')
  382. return
  383. }
  384. }
  385. } else {
  386. form.gateProductList = []
  387. form.gateValue = ''
  388. form.quotaAmount = ''
  389. form.gateType = undefined
  390. }
  391. form.specialProductList = _this.$refs.specialProduct.getResultVal()
  392. if (form.specialProductList.length == 0) {
  393. _this.$message.warning('请添加特价产品!')
  394. return
  395. } else {
  396. // 为空判断
  397. const isTypeEmpty = form.specialProductList.some(item => (item.productTypeList && item.productTypeList.length == 0) && (item.productBrandList && item.productBrandList.length == 0))
  398. if (isTypeEmpty) {
  399. _this.$message.warning('产品分类或品牌不能为空!')
  400. return
  401. }
  402. const isNumEmpty = form.specialProductList.some(item => (!item.unitType || !item.unitQty))
  403. if (isNumEmpty) {
  404. _this.$message.warning('订单起订量设置不能为空!')
  405. return
  406. }
  407. }
  408. if (form.discountType === '0') { // 手动输入
  409. const isCountEmpty = _this.isNumEmpty(form.specialProductList)
  410. if (isCountEmpty.flag) {
  411. _this.$message.warning('折扣不能为空!')
  412. return
  413. }
  414. if (isCountEmpty.flag1) {
  415. _this.$message.warning('折扣金额不能为空!')
  416. return
  417. }
  418. } else {
  419. // if (form.discountType === '2') { // 直降价格为负判断
  420. // const hasNegativePrice = form.specialProductList.some((item) => (item.provinceDiscountPrice < 0 || item.cityDiscountPrice < 0 || item.specialDiscountPrice < 0))
  421. // if (hasNegativePrice) {
  422. // _this.$message.warning('直降后价格不能为负值!')
  423. // return
  424. // }
  425. // }
  426. form.provinceValue = _this.setTableData[0].provinceValue
  427. form.cityValue = _this.setTableData[0].cityValue
  428. form.specialValue = _this.setTableData[0].specialValue
  429. }
  430. form.promotionSn = _this.promotionSn
  431. if (form.gateFlag == '1') {
  432. if (form.gateType === 'RATIO_AMOUNT') {
  433. form.gateInfo = '购买门槛产品金额' + form.gateValue + '作为配额'
  434. } else if (form.gateType === 'MIN_AMOUNT') {
  435. form.gateInfo = '购买门槛产品满最低金额' + form.gateValue + '不限制配额'
  436. } else {
  437. form.gateInfo = '购买每满' + form.gateValue + form.gateUnit == 'YUAN' ? '元' : '个' + '门槛产品,可采购' + form.quotaAmount + '个特价产品(配额算销售额)'
  438. }
  439. }
  440. if (form.discountType == '0') {
  441. form.ruleInfo = '手动输入特价'
  442. } else if (form.discountType == '1') {
  443. form.ruleInfo = '各级别价打折;省级折扣' + form.provinceValue + '%,市级折扣' + form.cityValue + '%,特约折扣' + form.specialValue + '%'
  444. } else {
  445. form.ruleInfo = '各级别价直降;省级直降' + form.provinceValue + ',市级直降' + form.cityValue + ',特约直降' + form.specialValue
  446. }
  447. _this.spinning = true
  448. promotionSave(form).then(res => {
  449. if (res.status == 200) {
  450. _this.$message.success(res.message)
  451. setTimeout(() => {
  452. _this.isShow = false
  453. _this.$emit('ok')
  454. _this.spinning = false
  455. }, 1000)
  456. } else {
  457. _this.spinning = false
  458. }
  459. })
  460. } else {
  461. return false
  462. }
  463. })
  464. },
  465. isNumEmpty (dataList) {
  466. const arr = []
  467. const arr1 = []
  468. dataList.forEach(item => {
  469. if (item.dataSourceOrigin === '0') { // 判断分类品牌
  470. if (!item.provinceDiscountRate || !item.cityDiscountRate || !item.specialDiscountRate) {
  471. arr.push(item.productScopeSn)
  472. }
  473. } else {
  474. if (!item.cityDiscountPrice || !item.provinceDiscountPrice || !item.specialDiscountPrice) {
  475. arr1.push(item.productScopeSn)
  476. }
  477. }
  478. })
  479. return { flag: arr.length > 0, flag1: arr1.length > 0 }
  480. },
  481. // 判断门槛产品中品牌,分类,产品其中一个必填
  482. isJudge (list) {
  483. const flag = list.some(con => {
  484. if (con.productThisList) {
  485. if (con.productThisList.length > 0) {
  486. return false
  487. } else {
  488. if ((con.productTypeList && con.productTypeList.length > 0) || (con.productBrandList && con.productBrandList.length > 0)) {
  489. return false
  490. } else {
  491. return true
  492. }
  493. }
  494. } else {
  495. if ((con.productTypeList && con.productTypeList.length > 0) || (con.productBrandList && con.productBrandList.length > 0)) {
  496. return false
  497. } else {
  498. return true
  499. }
  500. }
  501. })
  502. return flag
  503. },
  504. // 重置表格
  505. resetSearchForm () {
  506. this.form = {
  507. promotionRuleType: 'PROMO_PROD', // 特价产品
  508. description: '', // 规则简称
  509. gateFlag: '0', // 门槛
  510. gateType: undefined,
  511. gateValue: undefined,
  512. gateUnit: 'GE',
  513. quotaAmount: undefined,
  514. discountType: '0', // 特价规则
  515. gateProductList: undefined,
  516. specialProductList: undefined
  517. }
  518. this.$nextTick(() => {
  519. this.$refs.ruleForm.resetFields()
  520. this.$refs.cillProduct.reSetTableData()
  521. this.$refs.specialProduct.reSetTableData()
  522. })
  523. if (this.form.discountType != '0') {
  524. this.$refs[0].setTable.clearTable()
  525. }
  526. this.setTableData = []
  527. },
  528. // 获取编辑详情
  529. getDetail () {
  530. const _this = this
  531. getRuleDetail({ sn: this.itemSn }).then(res => {
  532. if (res.status == 200) {
  533. this.chooseVal = res.data.gateFlag == '0' ? 'd' : 'a'
  534. const resultObj = res.data
  535. if (resultObj.gateFlag === '1') {
  536. resultObj.gateValue = resultObj.gateType === 'RATIO_AMOUNT' ? resultObj.gateValue * 100 : resultObj.gateValue
  537. }
  538. if (resultObj.discountType != '0') {
  539. _this.setTableData = [{
  540. provinceValue: resultObj.provinceValue,
  541. cityValue: resultObj.cityValue,
  542. specialValue: resultObj.specialValue
  543. }]
  544. }
  545. // 重新组成保存数据
  546. if (resultObj.gateProductList && resultObj.gateProductList.length > 0) {
  547. resultObj.gateProductList = _this.newData(resultObj.gateProductList)
  548. this.$refs.cillProduct.setTabVal(resultObj.gateProductList)
  549. }
  550. if (resultObj.specialProductList && resultObj.specialProductList.length > 0) {
  551. resultObj.specialProductList = _this.newData(resultObj.specialProductList)
  552. this.$refs.specialProduct.setSourceData(resultObj.specialProductList)
  553. }
  554. this.form = { ...this.form, ...resultObj }
  555. }
  556. })
  557. },
  558. newData (list) {
  559. list.forEach(con => {
  560. // 品牌
  561. if (con.productBrandList) {
  562. const brandList = []
  563. con.productBrandList.forEach(item => {
  564. item.brandName = item.productBrandName
  565. const brandObj = {
  566. productBrandSn: item.productBrandSn
  567. }
  568. brandList.push(brandObj)
  569. })
  570. con.productBrandArr = con.productBrandList
  571. con.productBrandList = brandList
  572. }
  573. // 分类
  574. if (con.productTypeList) {
  575. const typeList = []
  576. con.productTypeList.forEach(item => {
  577. const typeObj = {}
  578. item.title = ''
  579. const num = 3
  580. for (var i = 0; i < num; i++) {
  581. if (item['productTypeName' + (i + 1)]) {
  582. typeObj['productTypeSn' + (i + 1)] = item['productTypeSn' + (i + 1)] ? item['productTypeSn' + (i + 1)] : ''
  583. }
  584. }
  585. if (item.productTypeName3) {
  586. item.title = item.productTypeName2 + '/' + item.productTypeName3
  587. } else if (!item.productTypeName3 && item.productTypeName2) {
  588. item.title = item.productTypeName2
  589. } else {
  590. item.title = item.productTypeName1
  591. }
  592. item.id = item.productTypeSn3 ? item.productTypeSn3 : item.productTypeSn2 ? item.productTypeSn2 : item.productTypeSn1
  593. typeList.push(typeObj)
  594. })
  595. con.productTypeArr = con.productTypeList
  596. con.productTypeList = typeList
  597. }
  598. // 产品
  599. if (con.productThisList) {
  600. const productList = []
  601. con.productThisList.forEach(item => {
  602. const productObj = {
  603. productCode: item.productCode,
  604. productSn: item.productSn
  605. }
  606. productList.push(productObj)
  607. })
  608. con.productThisList = productList
  609. }
  610. })
  611. return list
  612. },
  613. // 导入
  614. hanldeOk (arr) {
  615. // 门槛产品导入
  616. const resultArr = []
  617. if (this.chooseVal == 'a') {
  618. const name = this.chooseVal == 'a' ? 'cill' : this.chooseVal == 'b' ? 'normalPrice' : 'offer'
  619. this.$refs[name + 'Product'].importRow(arr)
  620. } else {
  621. // 特价产品导入
  622. const dataList = this.setShowData('This')
  623. arr.forEach(item => {
  624. item = { ...item, ...item.product }
  625. item.code = item.productCode
  626. if (this.form.discountType == '0') {
  627. if (item.provincePrice) {
  628. item.provinceDiscountRate = Math.floor(((item.provinceDiscountPriceText / item.provincePrice) * 100).toFixed(2))
  629. }
  630. if (item.cityPrice) {
  631. item.cityDiscountRate = Math.floor(((item.cityDiscountPriceText / item.cityPrice) * 100).toFixed(2))
  632. }
  633. if (item.specialPrice) {
  634. item.specialDiscountRate = Math.floor(((item.specialDiscountPriceText / item.specialPrice) * 100).toFixed(2))
  635. }
  636. } else if (this.form.discountType == '1') {
  637. if (item.provincePrice) {
  638. item.provinceDiscountRate = this.form.provinceValue
  639. item.provinceDiscountPriceText = (item.provincePrice * this.form.provinceValue / 100).toFixed(2)
  640. }
  641. if (item.cityPrice) {
  642. item.cityDiscountRate = this.form.cityValue
  643. item.cityDiscountPriceText = (item.cityPrice * this.form.cityValue / 100).toFixed(2)
  644. }
  645. if (item.specialPrice) {
  646. item.specialDiscountRate = this.form.specialValue
  647. item.specialDiscountPriceText = (item.specialPrice * this.form.specialValue / 100).toFixed(2)
  648. }
  649. } else {
  650. if (item.provincePrice) {
  651. item.provinceSubtract = item.provincePrice - this.form.provinceValue
  652. }
  653. if (item.cityPrice) {
  654. item.citySubtract = item.cityPrice - this.form.cityValue
  655. }
  656. if (item.specialPrice) {
  657. item.specialSubtract = item.specialPrice - this.form.specialValue
  658. }
  659. }
  660. const flag = dataList.includes(item.productSn)
  661. if (!flag) {
  662. resultArr.push(item)
  663. }
  664. })
  665. if (resultArr.length > 0) {
  666. this.handleProductsOk(resultArr)
  667. } else {
  668. this.$message.warning('请勿添加重复数据!')
  669. }
  670. }
  671. },
  672. // 打开新增产品弹窗(禁用已选)
  673. addProducts () {
  674. this.chooseProducts = []
  675. this.openProductsModal = true
  676. const dataList = this.setShowData('This')
  677. this.$refs.productBox.handleDisabled(dataList)
  678. },
  679. // 获取回显禁用数据
  680. setShowData (name) {
  681. const _this = this
  682. const snArr = []
  683. const valList = _this.$refs.specialProduct.getResultVal()
  684. valList.forEach(item => {
  685. if (item['product' + name + 'List'] && item['product' + name + 'List'].length > 0) {
  686. item['product' + name + 'List'].forEach(con => {
  687. const newName = name === 'This' ? '' : name
  688. snArr.push(con['product' + newName + 'Sn'])
  689. })
  690. }
  691. })
  692. return snArr
  693. },
  694. handleProductsAdd (con) {
  695. const newArr = []
  696. const newConArr = []
  697. con.forEach(newCon => {
  698. if (!newCon.provincePrice || !newCon.cityPrice || !newCon.specialPrice) {
  699. newArr.push(newCon.code)
  700. }
  701. })
  702. con.forEach((list, pos) => {
  703. if (list.provincePrice && list.cityPrice && list.specialPrice) {
  704. newConArr.push(list)
  705. }
  706. })
  707. const _this = this
  708. if (newArr && newArr.length > 0) {
  709. _this.$info({
  710. title: '提示',
  711. content: newArr.toString() + '(产品编码),没有定价,不可添加',
  712. closable: true,
  713. centered: true,
  714. onOk () {
  715. _this.handleProductsOk(newConArr)
  716. }
  717. })
  718. } else {
  719. _this.handleProductsOk(newConArr)
  720. }
  721. },
  722. // 生成随机数
  723. generateUniqueRandomNumber () {
  724. const timestamp = new Date().getTime()
  725. const randomNumber = Math.floor(Math.random() * 1e5).toString().padStart(5, '0')
  726. const uniqueRandomNumber = timestamp + randomNumber
  727. return uniqueRandomNumber
  728. },
  729. // +新增产品
  730. handleProductsOk (con) {
  731. const _this = this
  732. con.forEach(async (item) => {
  733. const chooseProductsList = []
  734. const getSn = this.generateUniqueRandomNumber()
  735. if (getSn) {
  736. const newData = {
  737. productScopeSn: getSn,
  738. dataSourceOrigin: '1',
  739. productTypeArr: [],
  740. productTypeList: [],
  741. productBrandArr: [{ productBrandSn: item.productBrandSn, brandName: item.productBrandName }],
  742. productBrandList: [{ productBrandSn: item.productBrandSn }],
  743. productThisList: [{
  744. productSn: item.productSn,
  745. productCode: item.code
  746. }],
  747. provincePrice: item.provincePrice,
  748. cityPrice: item.cityPrice,
  749. specialPrice: item.specialPrice,
  750. provinceDiscountPrice: item.provinceDiscountPriceText,
  751. cityDiscountPrice: item.cityDiscountPriceText,
  752. specialDiscountPrice: item.specialDiscountPriceText,
  753. unitType: item.unitType || 'SL',
  754. unitQty: item.unitQty || '1',
  755. provinceDiscountRate: item.provinceDiscountRate ? item.provinceDiscountRate : undefined,
  756. cityDiscountRate: item.cityDiscountRate ? item.cityDiscountRate : undefined,
  757. specialDiscountRate: item.specialDiscountRate ? item.specialDiscountRate : undefined
  758. }
  759. const obj = {}
  760. if (item.productTypeSn1) {
  761. obj.productTypeSn1 = item.productTypeSn1
  762. }
  763. if (item.productTypeSn2) {
  764. obj.productTypeSn2 = item.productTypeSn2
  765. }
  766. if (item.productTypeSn3) {
  767. obj.productTypeSn3 = item.productTypeSn3
  768. }
  769. const newObj = { ...obj, ...{} }
  770. if (Object.keys(obj).length == 1) {
  771. newObj.title = item.productTypeName1
  772. newObj.id = item.productTypeSn1
  773. } else if (Object.keys(obj).length == 2) {
  774. newObj.title = item.productTypeName2
  775. newObj.id = item.productTypeSn2
  776. } else {
  777. newObj.title = item.productTypeName2 + '/' + item.productTypeName3
  778. newObj.id = item.productTypeSn3
  779. }
  780. newData.productTypeList[0] = obj
  781. newData.productTypeArr[0] = newObj
  782. chooseProductsList.push(newData)
  783. }
  784. _this.$refs.specialProduct.setSourceData(chooseProductsList)
  785. })
  786. },
  787. getUnitTypeList () {
  788. const _this = this
  789. getLookUpData({
  790. pageNo: 1,
  791. pageSize: 1000,
  792. lookupCode: _this.code
  793. }).then(res => {
  794. if (res.status == 200) {
  795. _this.unitTypeDataList = res.data.list
  796. }
  797. })
  798. }
  799. },
  800. watch: {
  801. // 父页面传过来的弹框状态
  802. openModal (newValue, oldValue) {
  803. this.isShow = newValue
  804. },
  805. // 重定义的弹框状态
  806. isShow (newValue, oldValue) {
  807. if (!newValue) {
  808. this.$emit('close')
  809. this.resetSearchForm()
  810. } else {
  811. // 获取起订类型数据字典
  812. this.getUnitTypeList()
  813. if (this.itemSn) {
  814. this.getDetail()
  815. } else {
  816. this.chooseVal = this.form.gateFlag == '0' ? 'd' : 'a'
  817. }
  818. }
  819. }
  820. }
  821. }
  822. </script>
  823. <style lang="less" scoped>
  824. .promotionList-basicInfo-modal{
  825. /deep/.ant-modal-body {
  826. padding: 20px 30px;
  827. max-height: 745px !important;
  828. overflow-y: scroll !important;
  829. }
  830. .ant-radio-button-wrapper{
  831. width:80px;
  832. text-align: center;
  833. }
  834. .ant-form-item{
  835. margin-bottom:5px;
  836. }
  837. .buyerBox{
  838. border:1px solid #d9d9d9;margin-top:10px;border-radius:4px;padding:4px 10px;background:#f2f2f2;max-height:130px;overflow-y:scroll;
  839. }
  840. .btn-cont {
  841. text-align: center;
  842. margin: 35px 0 10px;
  843. }
  844. .flex{
  845. display:flex;
  846. align-items:center;
  847. justify-content:space-between;
  848. }
  849. }
  850. </style>