edit.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. <template>
  2. <div class="promotionEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="promotionEdit-cont" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="promotionEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" />返回列表</a>
  8. <span v-if="$route.params.sn" style="margin: 0 10px 0 20px;color: #666;font-size: 14px;font-weight: 600;">促销名称:{{ promotionName||'--' }}</span>
  9. </template>
  10. </a-page-header>
  11. <!-- 表单 -->
  12. <a-card :bordered="false" class="promotionEdit-cont">
  13. <a-form-model
  14. id="promotionEdit-form"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. :label-col="formItemLayout.labelCol"
  19. :wrapper-col="formItemLayout.wrapperCol"
  20. >
  21. <a-row>
  22. <a-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
  23. <a-form-model-item label="促销名称" prop="promoName" :label-col="{span:4}" :wrapper-col="{span:16}">
  24. <a-input
  25. id="promotionEdit-promoName"
  26. :maxLength="20"
  27. v-model.trim="form.promoName"
  28. placeholder="请输入促销名称(最多20个字符)"
  29. allowClear/>
  30. </a-form-model-item>
  31. </a-col>
  32. <a-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
  33. <a-form-model-item label="促销时间" prop="time" :label-col="{span:4}" :wrapper-col="{span:16}">
  34. <a-range-picker
  35. style="width:100%"
  36. id="promotionAdd-time"
  37. v-model="form.time"
  38. :format="dateFormat"
  39. :disabled-date="disabledDate"
  40. @change="dateChange"
  41. :placeholder="['开始时间', '结束时间']" />
  42. </a-form-model-item>
  43. </a-col>
  44. <a-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
  45. <a-form-model-item label="排序" prop="sort" :label-col="{span:4}" :wrapper-col="{span:16}">
  46. <a-input-number
  47. style="width:100%"
  48. id="promotionEdit-sort"
  49. :disabled="isDisabled"
  50. allowClear
  51. placeholder="请输入排序数字(数字越大越靠后)"
  52. v-model="form.sort"
  53. :min="0"
  54. :max="99999999"/>
  55. </a-form-model-item>
  56. </a-col>
  57. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  58. <a-form-model-item label="参与经销商" prop="allDealerFlag">
  59. <a-row :gutter="15">
  60. <a-col :md="10" :sm="24">
  61. <a-select
  62. style="width:98%;"
  63. id="promotionList-allDealerFlag"
  64. v-model="form.allDealerFlag"
  65. placeholder="请选择参与经销商"
  66. @change="changeDealerScope"
  67. :disabled="true"
  68. allowClear>
  69. <a-select-option id="promotionList-dealerScope-all" value="1">全部经销商</a-select-option>
  70. <a-select-option id="promotionList-dealerScope-some" value="0">部分经销商</a-select-option>
  71. </a-select>
  72. </a-col>
  73. <a-col :md="3" :sm="24" v-show="form.dealerScope && form.dealerScope!='ALL_DEALER' ">
  74. <a-button id="promotionList-basicInfo-dealerScope" type="primary" :loading="spinning" @click="handleDealerModal">选择</a-button>
  75. </a-col>
  76. <a-col :md="5" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  77. 已{{ chooseDealerList.length }}选项
  78. </a-col>
  79. <a-col :md="24" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  80. <div class="buyerBox">
  81. <a-tag closable v-for="con in chooseDealerList" id="promotionList-dealerSn" :key="con.dealerSn" @close="delBuyerName(con)">
  82. {{ con.dealerName }}
  83. </a-tag>
  84. </div>
  85. </a-col>
  86. </a-row>
  87. </a-form-model-item>
  88. </a-col>
  89. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  90. <a-form-model-item label="封面图片" prop="imageUrl" class="promotionEdit-img">
  91. <Upload
  92. class="upload"
  93. id="promotionEdit-imageUrl"
  94. v-model="form.imageUrl"
  95. ref="imageSet"
  96. :fileSize="10"
  97. :maxNums="1"
  98. @change="changeImage"
  99. listType="picture-card"></Upload>
  100. <span class="upload-desc">说明:单张大小小于10Mb;建议尺寸:宽(420px)*高(230px)</span>
  101. </a-form-model-item>
  102. </a-col>
  103. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  104. <a-form-model-item label="促销描述" prop="description">
  105. <a-input
  106. v-model="form.description"
  107. :disabled="isDisabled"
  108. type="textarea"
  109. id="promotionEdit-description"
  110. placeholder="请输入促销描述(最多500个字符)"
  111. :maxLength="500" />
  112. </a-form-model-item>
  113. </a-col>
  114. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  115. <a-form-model-item label="加盟商开关权限" prop="dealerOpenFlag">
  116. <v-select
  117. v-model="form.dealerOpenFlag"
  118. id="promotion-dealerOpenFlag"
  119. code="FLAG"
  120. showType="radio"
  121. :disabled="true"
  122. allowClear></v-select>
  123. </a-form-model-item>
  124. </a-col>
  125. <!-- 买产品送代金券 -->
  126. <div v-if="pageType=='BUY_PROD_GIVE_VALID'">
  127. <a-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
  128. <a-form-model-item label="券名称" :label-col="{span:4}" :wrapper-col="{span:16}" prop="validName">
  129. <a-input
  130. id="promotionEdit-validName"
  131. :maxLength="20"
  132. v-model.trim="form.validName"
  133. placeholder="请输入券名称(最多20个字符)"
  134. allowClear />
  135. </a-form-model-item>
  136. </a-col>
  137. <a-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
  138. <a-form-model-item label="券副标题" :label-col="{span:4}" :wrapper-col="{span:16}">
  139. <a-input
  140. id="promotionEdit-validTitle"
  141. :maxLength="20"
  142. v-model.trim="form.validTitle"
  143. placeholder="请输入券副标题(最多20个字符)"
  144. allowClear />
  145. </a-form-model-item>
  146. </a-col>
  147. <!-- <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  148. <a-form-model-item label="生成方式" prop="validBaseType">
  149. <v-select
  150. style="width:40%;"
  151. v-model="form.validBaseType"
  152. id="promotionEdit-ruleBaseType"
  153. code="SHOP_PROMO_VALID_BASE_TYPE"
  154. placeholder="请选择生成方式"
  155. allowClear></v-select>
  156. </a-form-model-item>
  157. </a-col> -->
  158. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  159. <a-form-model-item label="券有效期" prop="validType">
  160. <v-select
  161. style="width:40%;"
  162. v-model="form.validType"
  163. placeholder="请选择券有效期"
  164. id="promotionEdit-validType"
  165. code="SHOP_PROMO_VALID_TYPE"
  166. @change="handleValidType"
  167. allowClear></v-select>
  168. <a-range-picker
  169. v-show="form.validType==='FIXED'"
  170. style="width:40%;margin-left:10px;"
  171. v-model="timeLimit"
  172. :format="dateFormat"
  173. id="promotionEdit-time"
  174. @change="dateLimitChange"
  175. :disabled-date="disabledDate"
  176. :placeholder="['开始时间', '结束时间']" />
  177. <span style="width:40%;margin-left:10px;" v-show="form.validType==='LIMIT'">
  178. 有效期<a-input-number
  179. style="margin:0 5px;"
  180. v-model="form.validDays"
  181. :step="1"
  182. id="promotionEdit-validDays"
  183. :max="99999999"
  184. :min="1"
  185. :precision="0"/>天
  186. </span>
  187. </a-form-model-item>
  188. </a-col>
  189. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  190. <a-form-model-item class="productName" label="券适用范围" prop="validScope">
  191. 全部产品
  192. </a-form-model-item>
  193. </a-col>
  194. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  195. <a-form-model-item label="使用说明" prop="validInfo">
  196. <a-input
  197. v-model="form.validInfo"
  198. type="textarea"
  199. id="promotionEdit-validInfo"
  200. placeholder="请输入使用说明(最多50个字符)"
  201. :maxLength="50" />
  202. </a-form-model-item>
  203. </a-col>
  204. </div>
  205. <div v-if="isShowNextStep">
  206. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  207. <a-form-model-item prop="productNum" :label="pageType==='BUY_PROD_GIVE_PROD'?'满赠规则': pageType==='PROMO_PROD'?'优惠方式':'返券产品'">
  208. <div class="productInfo flex-center">
  209. <!-- 买产品送产品 -->
  210. <div v-if="pageType==='BUY_PROD_GIVE_PROD'">
  211. 同款产品买<a-input-number
  212. v-model="conditionValue"
  213. style="margin:0 5px;"
  214. :min="1"
  215. :step="1"
  216. :precision="0"
  217. :max="99999999"
  218. id="promotionEdit-conditionValue"
  219. size="small"/>赠
  220. <a-input-number
  221. v-model="resultValue"
  222. style="margin:0 5px;"
  223. :min="0"
  224. :step="1"
  225. :precision="0"
  226. :max="99999999"
  227. id="promotionEdit-resultValue"
  228. size="small"/>个(数量叠加)
  229. <a-button
  230. type="primary"
  231. id="promotionEdit-addSet-btn"
  232. class="button-primary"
  233. size="small"
  234. @click="handleBatchAdd">批量设置</a-button>
  235. </div>
  236. <!-- 特价产品 -->
  237. <div v-if="pageType==='PROMO_PROD'" style="width:80%;">
  238. <v-select
  239. v-model="form.discountType"
  240. ref="promoState"
  241. id="promotionList-discountType"
  242. code="SHOP_PROMO_DISCOUNT_TYPE"
  243. size="small"
  244. style="width:15%;margin-right:5px;"
  245. @change="handleDiscountType"
  246. placeholder="请选择"
  247. allowClear></v-select>
  248. <span>{{ form.discountType==='STRAIGHT_DOWN'? '直降':'折扣' }}</span>
  249. <a-input-number
  250. v-model="resultValue"
  251. style="width:15%;margin:0 5px;"
  252. :min="0"
  253. :step="1"
  254. :precision="2"
  255. :max="99999999"
  256. id="promotionEdit-resultValue"
  257. size="small"/>{{ form.discountType==='STRAIGHT_DOWN'? '元':'%' }}
  258. <a-button
  259. type="primary"
  260. id="promotionEdit-addSet-btn"
  261. class="button-primary"
  262. size="small"
  263. @click="handleBatchAdd">批量设置</a-button>
  264. </div>
  265. <!-- 买产品返代金券 -->
  266. <div v-if="pageType=='BUY_PROD_GIVE_VALID'">
  267. 返券金额
  268. <a-input-number
  269. v-model="resultValue"
  270. style="margin:0 5px;"
  271. :min="0"
  272. :step="1"
  273. :precision="2"
  274. :max="99999999"
  275. id="promotionEdit-resultValue"
  276. size="small"/>元
  277. <a-button
  278. type="primary"
  279. id="promotionEdit-addSet-btn"
  280. :disabled="isDisabled"
  281. class="button-primary"
  282. size="small"
  283. @click="handleBatchAdd">批量设置</a-button>
  284. </div>
  285. <a-button type="primary" id="promotionEdit-add-btn" :disabled="isDisabled" @click="handleAddProduct" size="small">选择产品</a-button>
  286. </div>
  287. </a-form-model-item>
  288. </a-col>
  289. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  290. <div style="width: 83%;margin:0 auto 10px;">
  291. <productTable ref="chooseProductList" :promoActiveSn="form.promoSn" :discountType="form.discountType" :activeType="pageType"></productTable>
  292. </div>
  293. </a-col>
  294. </div>
  295. </a-row>
  296. </a-form-model>
  297. </a-card>
  298. </a-spin>
  299. <div class="affix-cont">
  300. <a-button
  301. type="primary"
  302. class="button-primary"
  303. :disabled="spinning"
  304. id="productInfoEdit-submit-btn"
  305. size="large"
  306. @click="handleSave('all')"
  307. v-if="isShowNextStep"
  308. style="padding: 0 60px;">保存</a-button>
  309. <a-button
  310. type="primary"
  311. class="button-primary"
  312. style="padding: 0 30px;"
  313. size="large"
  314. v-if="!isShowNextStep"
  315. @click="handleSave('part')">保存后设置产品</a-button>
  316. </div>
  317. <!-- 添加产品 -->
  318. <chooseProduct
  319. ref="chooseProduct"
  320. :chooseType="chooseTypeList"
  321. :itemSn="$route.params.sn"
  322. :openModal="showProModal"
  323. @ok="addProductSuccess"
  324. @close="closeProductModal"></chooseProduct>
  325. <!-- 选择经销商 -->
  326. <chooseDealer :openModal="openDealerModal" @close="closeDealerModal" @ok="addDealerOk"></chooseDealer>
  327. </div>
  328. </template>
  329. <script>
  330. import { commonMixin } from '@/utils/mixin'
  331. import moment from 'moment'
  332. // 组件
  333. import { VSelect, Upload } from '@/components'
  334. import Editor from '@/components/WEeditor'
  335. import chooseDealer from '@/views/easyPassManagement/homepageCarouselImg/chooseDealer'
  336. import productTable from './productTable'
  337. import chooseProduct from './chooseProductsModal.vue'
  338. // 接口
  339. import { saveChooseProduct, saveShopPromo, shopPromoDetail, clearByPromoSn } from '@/api/shopPromo'
  340. export default {
  341. name: 'ProductBrandEditModal',
  342. mixins: [commonMixin],
  343. components: { VSelect, Upload, Editor, productTable, chooseDealer, chooseProduct },
  344. data () {
  345. return {
  346. spinning: false,
  347. // 表单 label 设置
  348. formItemLayout: {
  349. labelCol: { span: 2 },
  350. wrapperCol: { span: 20 }
  351. },
  352. productRangeList: [], // 产品范围列表
  353. dateFormat: 'YYYY-MM-DD', // 促销时间显示格式
  354. openDealerModal: false,
  355. pageType: undefined, // 促销类型
  356. // 链接配置内容
  357. form: {
  358. promoType: undefined, // 促销类型
  359. promoName: '', // '促销名称'
  360. time: [], // 促销时间
  361. promoStartDate: undefined, // 促销时间-开始
  362. promoEndDate: undefined, // 促销时间-结束
  363. sort: undefined, // 排序
  364. allDealerFlag: '1', // 全部经销商 1 部分经销商0'
  365. imageUrl: undefined, // 促销封面图
  366. description: '', // '促销描述'
  367. dealerEditFlag: '0', // 加盟商编辑 0否 1是
  368. dealerOpenFlag: '0', // 加盟商开关权限 0否 1是
  369. rangeList: [], // 选择产品列表
  370. discountType: 'STRAIGHT_DOWN', // 特价产品 - 优惠方式'
  371. validName: '', // 券名称
  372. validTitle: '', // 券副标题
  373. validBaseType: 'category', // 券生成方式
  374. validType: undefined, // 券有效期类型
  375. validStartDate: undefined, // 券生效时间
  376. validEndDate: undefined, // 券失效时间
  377. validDays: undefined, // 券有效期天数
  378. validScope: '1', // 券适用范围标记 1-全部 0-指定 死值 1
  379. validInfo: '', // 使用说明
  380. productNum: 0
  381. },
  382. conditionValue: undefined, // 买产品送产品 买
  383. resultValue: undefined, // 买产品送产品 赠 返券金额
  384. chooseDealerList: [], // 所选经销商数据
  385. timeLimit: [], // 有效期
  386. promotionName: '', // 促销名称
  387. showProModal: false, // 打开产品弹窗
  388. isShowNextStep: false, // 是否显示下一步 并提交一半配置产品
  389. isDisabled: false, // 控制页面是否能编辑
  390. chooseTypeList: [], // 已选中产品范围
  391. imageSet: [], // 回显显示图片数据
  392. productTypeList: [], // 产品范围 列表数据
  393. // 表单验证规则
  394. rules: {
  395. promoName: [{ required: true, message: '请输入促销名称', trigger: 'blur' }],
  396. time: [{ required: true, message: '请选择促销时间', trigger: 'change' }],
  397. sort: [{ required: true, message: '请输入排序数字', trigger: 'blur' }],
  398. allDealerFlag: [{ required: true, message: '请选择参与经销商', trigger: 'change' }],
  399. imageUrl: [{ required: true, message: '请选择要上传的封面图片', trigger: 'change' }],
  400. description: [{ required: true, message: '请输入促销描述内容', trigger: 'blur' }],
  401. dealerOpenFlag: [{ required: true, message: '请选择加盟商开关权限', trigger: 'change' }],
  402. rangeList: [{ required: true, message: '请选择促销产品', trigger: 'change' }],
  403. validName: [{ required: true, message: '请输入券名称', trigger: ['change', 'blur'] }],
  404. validBaseType: [{ required: true, message: '请选择生成方式', trigger: 'change' }],
  405. validType: [{ required: true, message: '请选择券有效期类型', trigger: 'change' }],
  406. validScope: [{ required: true, message: '请选择券适用范围', trigger: 'blur' }],
  407. productNum: [{ required: true, message: '选择产品不能为空', trigger: 'blur' }]
  408. }
  409. }
  410. },
  411. methods: {
  412. changeDealerScope () {},
  413. addDealerOk () {},
  414. // 选择经销商
  415. handleDealerModal () {
  416. this.openDealerModal = true
  417. },
  418. // 关闭经销商弹窗
  419. closeDealerModal () {
  420. this.openDealerModal = false
  421. },
  422. // 禁用日期时间
  423. disabledDate (current) {
  424. return current && current < moment().startOf('day')
  425. },
  426. // 促销时间 change
  427. dateChange (date, dateStrings) {
  428. if (dateStrings && dateStrings[0]) {
  429. this.form.time = dateStrings
  430. this.form.promoStartDate = date.length ? dateStrings[0] + ' 00:00:00' : ''
  431. this.form.promoEndDate = date.length ? dateStrings[1] + ' 23:59:59' : ''
  432. } else {
  433. this.form.time = []
  434. }
  435. },
  436. // 有效期
  437. dateLimitChange (date, dateStrings) {
  438. if (dateStrings && dateStrings[0]) {
  439. this.timeLimit = dateStrings
  440. this.form.validStartDate = date.length ? dateStrings[0] + ' 00:00:00' : ''
  441. this.form.validEndDate = date.length ? dateStrings[1] + ' 23:59:59' : ''
  442. } else {
  443. this.timeLimit = []
  444. }
  445. },
  446. // 打开产品弹窗
  447. insterProduct (obj) {
  448. if (obj && Object.keys(obj).length > 0) {
  449. this.chooseTypeList = obj.typeArr
  450. }
  451. this.showProModal = true
  452. },
  453. async handleDiscountType (val) {
  454. this.form.discountType = val
  455. this.resultValue = undefined
  456. const res = await clearByPromoSn({ promoSn: this.$route.params.sn })
  457. if (res.status == '200') {
  458. this.$refs.chooseProductList.pageInit()
  459. }
  460. },
  461. // 关闭产品弹窗
  462. closeProductModal () {
  463. this.showProModal = false
  464. },
  465. // 返回列表
  466. handleBack () {
  467. this.$router.push({ name: 'promotionalActivities', query: { closeLastOldTab: true } })
  468. },
  469. // 详情
  470. async getDetail (ajaxData) {
  471. const _this = this
  472. const res = await shopPromoDetail(ajaxData)
  473. if (res.status == 200) {
  474. if (res.data.promoStartDate && res.data.promoEndDate) {
  475. const startTime = res.data.promoStartDate.split(' ')[0]
  476. const endTime = res.data.promoEndDate.split(' ')[0]
  477. res.data.time = [startTime, endTime]
  478. }
  479. if (res.data.imageUrl) {
  480. _this.$refs.imageSet.setFileList(res.data.imageUrl)
  481. }
  482. _this.form = res.data
  483. _this.form.productNum = 0
  484. _this.isShowNextStep = true
  485. if (_this.$route.params.pageType === 'edit') {
  486. _this.pageType = res.data.promoType
  487. _this.promotionName = res.data.promoName
  488. }
  489. _this.$nextTick(() => {
  490. _this.$refs.chooseProductList.pageInit()
  491. })
  492. _this.form.productNum = _this.$refs.chooseProductList.getChooseProductNum()
  493. }
  494. },
  495. // 券有效期 change
  496. handleValidType (con) {
  497. this.form.validType = con
  498. if (con === 'FIXED') {
  499. this.form.validDays = undefined
  500. } else {
  501. this.timeLimit = []
  502. this.form.validStartDate = undefined
  503. this.form.validEndDate = undefined
  504. }
  505. },
  506. // 确定保存 验证必填
  507. handleSave (type) {
  508. const _this = this
  509. // 验证组件必填项
  510. console.log('_this.form.productNum ', _this.form.productNum)
  511. _this.$refs.ruleForm.validate(valid => {
  512. if (valid) {
  513. _this.savePartInfo(type)
  514. }
  515. })
  516. },
  517. // 保存
  518. savePartInfo (type) {
  519. const _this = this
  520. _this.form.promoType = _this.pageType
  521. var formData = JSON.parse(JSON.stringify(_this.form))
  522. if (type === 'all') {
  523. formData.productNum = _this.$refs.chooseProductList.getChooseProductNum()
  524. if (formData.productNum && formData.productNum == 0) {
  525. _this.$message.warning('请选择返券产品!')
  526. return
  527. }
  528. if (formData.promoType === 'BUY_PROD_GIVE_VALID') {
  529. if (formData.validType === 'FIXED') {
  530. if (!formData.validStartDate || !formData.validEndDate) {
  531. _this.$message.warning('请输入券有效期!')
  532. return false
  533. }
  534. } else {
  535. if (!formData.validDays) {
  536. _this.$message.warning('请输入券有效期!')
  537. return false
  538. }
  539. }
  540. }
  541. delete formData.productNum
  542. }
  543. delete formData.time
  544. _this.spinning = true
  545. saveShopPromo(formData).then(res => {
  546. if (res.status == 200) {
  547. _this.spinning = false
  548. if (res.data.errorMsg && res.data.errorMsg.length > 0) {
  549. this.$confirm({
  550. title: '提示',
  551. content: res.data.errorMsg.map((item, i) => { return <p>{i * 1 + 1}、{item}</p> }),
  552. centered: true,
  553. okText: '知道了',
  554. cancelText: '取消', // 将cancelText设置为空字符串或去掉该属性可以隐藏取消按钮
  555. cancelButtonProps: {
  556. style: {
  557. display: 'none' // 通过设置样式隐藏取消按钮
  558. }
  559. },
  560. onOk () {
  561. console.log('知道了')
  562. }
  563. })
  564. return
  565. }
  566. _this.$message.success(res.message)
  567. if (type === 'all') {
  568. _this.$nextTick(() => {
  569. _this.handleBack()
  570. _this.resetSearchForm()
  571. })
  572. } else {
  573. _this.isShowNextStep = true
  574. _this.getDetail({ sn: res.data.shopPromo.promoSn })
  575. }
  576. } else {
  577. _this.spinning = false
  578. }
  579. })
  580. },
  581. // 封面图片上传
  582. changeImage (file) {
  583. this.form.imageUrl = file
  584. },
  585. // 重置
  586. resetSearchForm () {
  587. if (this.pageType == 'add' || (this.pageType == 'edit' && !this.isDisabled)) {
  588. if (this.$refs.imageSet) {
  589. this.$refs.imageSet.setFileList('')
  590. }
  591. if (this.$refs.videoSet) {
  592. this.$refs.videoSet.setFileList('')
  593. }
  594. }
  595. if (this.$refs.editor) {
  596. this.$refs.editor.setHtml('')
  597. }
  598. this.form = {
  599. promoType: undefined, // 促销类型
  600. promoName: '', // '促销名称'
  601. time: [], // 促销时间
  602. promoStartDate: undefined, // 促销时间-开始
  603. promoEndDate: undefined, // 促销时间-结束
  604. sort: undefined, // 排序
  605. allDealerFlag: '1', // 全部经销商 1 部分经销商0'
  606. imageUrl: undefined, // 促销封面图
  607. description: '', // '促销描述'
  608. dealerEditFlag: '0', // 加盟商编辑 0否 1是
  609. dealerOpenFlag: '0', // 加盟商开关权限 0否 1是
  610. rangeList: [], // 选择产品列表
  611. discountType: 'STRAIGHT_DOWN', // 特价产品 - 优惠方式'
  612. validName: '', // 券名称
  613. validTitle: '', // 券副标题
  614. validBaseType: 'category', // 券生成方式
  615. validType: undefined, // 券有效期类型
  616. validStartDate: undefined, // 券生效时间
  617. validEndDate: undefined, // 券失效时间
  618. validDays: undefined, // 券有效期天数
  619. validScope: '1', // 券适用范围标记 1-全部 0-指定 死值 1
  620. validInfo: '', // 使用说明
  621. productNum: 0
  622. }
  623. this.isShowNextStep = false
  624. this.isDisabled = false
  625. if (this.$refs.ruleForm) {
  626. this.$refs.ruleForm.resetFields()
  627. }
  628. if (this.$refs.ruleForm) {
  629. this.$refs.ruleForm.resetFields()
  630. }
  631. },
  632. // 添加产品
  633. handleAddProduct () {
  634. this.chooseTypeList = this.productRangeList
  635. this.showProModal = true
  636. },
  637. // 批量设置
  638. handleBatchAdd () {
  639. if (!this.conditionValue && !this.resultValue) {
  640. this.$message.warning('请输入促销优惠规则!')
  641. return
  642. }
  643. this.$refs.chooseProductList.editMorePrice({ conditionValue: this.conditionValue, resultValue: this.resultValue })
  644. },
  645. // 添加产品成功
  646. addProductSuccess (list) {
  647. const productArr = list.map(item => {
  648. return {
  649. promoSn: this.form.promoSn,
  650. shopProductSn: item.shopProductSn,
  651. productSn: item.productSn,
  652. productCode: item.productCode
  653. }
  654. })
  655. saveChooseProduct(productArr).then(res => {
  656. if (res.status == 200) {
  657. this.showProModal = false
  658. // 获取产品列表 有分页
  659. this.$refs.chooseProductList.pageInit()
  660. }
  661. })
  662. },
  663. // 初始化
  664. pageInit () {
  665. if (this.$route.params.pageType === 'edit') {
  666. this.getDetail({ sn: this.$route.params.sn })
  667. } else {
  668. this.pageType = this.$route.params.pageType
  669. }
  670. }
  671. },
  672. mounted () {
  673. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  674. this.pageInit()
  675. }
  676. },
  677. activated () {
  678. // 如果是新页签打开,则重置当前页面
  679. if (this.$store.state.app.isNewTab) {
  680. this.pageInit()
  681. }
  682. // 仅刷新列表,不重置页面
  683. if (this.$store.state.app.updateList) {
  684. this.pageInit()
  685. }
  686. },
  687. beforeRouteEnter (to, from, next) {
  688. next(vm => {})
  689. }
  690. }
  691. </script>
  692. <style lang="less" scoped>
  693. .promotionEdit-wrap{
  694. position: relative;
  695. height: 100%;
  696. box-sizing: border-box;
  697. padding-bottom:51px;
  698. .buyerBox{
  699. border:1px solid #d9d9d9;
  700. margin-top:10px;
  701. border-radius:4px;
  702. padding:4px 10px;
  703. background:#f2f2f2;
  704. max-height:130px;
  705. overflow-y:scroll;
  706. scrollbar-width: none;
  707. }
  708. >.ant-spin-nested-loading{
  709. overflow-y: scroll;
  710. height: 100%;
  711. }
  712. /deep/.ant-form-item{
  713. margin-bottom:8px;
  714. }
  715. // .ant-form-item-control
  716. .promotionEdit-cont{
  717. margin-bottom: 10px;
  718. }
  719. .upload{
  720. width: 100%!important;
  721. }
  722. // 文本编辑器 工具栏样式换行
  723. .promotionEdit-editor{
  724. .w-e-toolbar{
  725. flex-wrap: wrap;
  726. z-index: 0;
  727. }
  728. }
  729. // 商品图片描述
  730. .upload-desc{
  731. font-size: 12px;
  732. color: #808695;
  733. }
  734. #promotionEdit-attachList{
  735. height: auto;
  736. }
  737. .box{
  738. border:1px solid #d9d9d9;
  739. border-radius:4px;
  740. padding:4px 11px;
  741. color:rgba(0, 0, 0, 0.25);
  742. cursor: not-allowed;
  743. background:#fdfdfd;
  744. }
  745. .affix{
  746. .ant-affix{
  747. z-index: 101;
  748. display:inline-block
  749. }
  750. }
  751. /deep/.ant-radio-disabled + span{
  752. color:#000!important;
  753. }
  754. .tip{
  755. margin-left:10px;
  756. }
  757. .productInfo{
  758. display:flex;
  759. justify-content: space-between;
  760. }
  761. #setPromotion-productRange{
  762. /deep/.ant-select-dropdown{
  763. max-height:30vh !important;
  764. }
  765. }
  766. }
  767. </style>