specialOfferModal.vue 32 KB

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