addPromotionModal.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <a-modal
  3. centered
  4. class="promotionAdd-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="itemSn?'编辑':'新增'"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. width="70%">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <div class="promotionAdd-con">
  13. <a-form-model
  14. id="promotionAdd-form"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. :label-col="formItemLayout.labelCol"
  19. :wrapper-col="formItemLayout.wrapperCol">
  20. <a-row>
  21. <a-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
  22. <a-form-model-item label="促销名称" prop="promoName" :label-col="{span:6}" :wrapper-col="{span:14}">
  23. <a-input
  24. id="promotionAdd-promoName"
  25. :maxLength="20"
  26. v-model.trim="form.promoName"
  27. placeholder="请输入促销名称(最多20个字符)"
  28. allowClear/>
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
  32. <a-form-model-item label="促销时间" prop="time" :label-col="{span:6}" :wrapper-col="{span:14}">
  33. <a-range-picker
  34. style="width:100%"
  35. id="promotionAdd-time"
  36. v-model="form.time"
  37. :format="dateFormat"
  38. :disabled-date="disabledDate"
  39. @change="dateChange"
  40. :placeholder="['开始时间', '结束时间']" />
  41. </a-form-model-item>
  42. </a-col>
  43. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  44. <a-form-model-item label="排序" prop="sort">
  45. <a-input-number
  46. style="width:37%"
  47. id="promotionAdd-sort"
  48. allowClear
  49. placeholder="请输入排序数字(数字越大越靠后)"
  50. v-model="form.sort"
  51. :min="0"
  52. :max="99999999"/>
  53. </a-form-model-item>
  54. </a-col>
  55. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  56. <a-form-model-item label="参与经销商" prop="allDealerFlag">
  57. <a-row :gutter="15">
  58. <a-col :md="10" :sm="24">
  59. <a-select
  60. style="width:90%;"
  61. id="promotionAdd-allDealerFlag"
  62. v-model="form.allDealerFlag"
  63. placeholder="请选择参与经销商"
  64. @change="changeDealerScope"
  65. allowClear>
  66. <a-select-option id="promotionAdd-dealerScope-all" value="1">全部经销商</a-select-option>
  67. <a-select-option id="promotionAdd-dealerScope-some" value="0">部分经销商</a-select-option>
  68. </a-select>
  69. </a-col>
  70. <a-col :md="3" :sm="24" v-show="form.allDealerFlag && form.allDealerFlag!='1' ">
  71. <a-button id="promotionAdd-dealerScope" type="primary" :loading="spinning" @click="handleDealerModal">选择</a-button>
  72. </a-col>
  73. <a-col :md="5" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  74. 已 {{ chooseDealerList.length }} 选项
  75. </a-col>
  76. <a-col :md="24" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  77. <div class="buyerBox">
  78. <a-tag closable v-for="con in chooseDealerList" id="promotionAdd-dealerSn" :key="con.dealerSn" @close="delBuyerName(con)">
  79. {{ con.dealerName }}
  80. </a-tag>
  81. </div>
  82. </a-col>
  83. </a-row>
  84. </a-form-model-item>
  85. </a-col>
  86. <a-col
  87. :xs="24"
  88. :sm="24"
  89. :md="24"
  90. :lg="24"
  91. :xl="24"
  92. class="imageUrl_box">
  93. <a-form-model-item label="封面图片" prop="imageUrl">
  94. <Upload
  95. class="upload"
  96. id="promotionAdd-imageUrl"
  97. v-model="form.imageUrl"
  98. ref="imageSet"
  99. :fileSize="10"
  100. :maxNums="1"
  101. @change="changeImage"
  102. listType="picture-card"></Upload>
  103. <div class="upload-desc">说明:单张大小小于10Mb;建议尺寸:宽(420px)*高(230px)</div>
  104. </a-form-model-item>
  105. </a-col>
  106. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  107. <a-form-model-item label="促销描述" prop="description">
  108. <a-input
  109. v-model="form.description"
  110. type="textarea"
  111. id="promotionAdd-description"
  112. placeholder="请输入促销描述(最多500个字符)"
  113. :maxLength="500" />
  114. </a-form-model-item>
  115. </a-col>
  116. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  117. <a-form-model-item label="加盟商开关权限" prop="dealerOpenFlag">
  118. <v-select
  119. v-model="form.dealerOpenFlag"
  120. id="promotionAdd-dealerOpenFlag"
  121. code="FLAG"
  122. showType="radio"
  123. allowClear></v-select>
  124. </a-form-model-item>
  125. </a-col>
  126. </a-row>
  127. </a-form-model>
  128. <div class="btn-cont">
  129. <a-button id="promotionAdd-close-btn" style="margin-right: 15px;" @click="isShow = false">取消</a-button>
  130. <a-button
  131. type="primary"
  132. class="button-primary"
  133. :disabled="spinning"
  134. id="promotionAdd-submit-btn"
  135. @click="handleSave()">保存</a-button>
  136. </div>
  137. </div>
  138. </a-spin>
  139. <!-- 选择经销商 -->
  140. <chooseDealer ref="chooseDearler" :openModal="openDealerModal" :chooseInfo="chooseSnList" @close="closeDealerModal" @ok="addDealerOk"></chooseDealer>
  141. </a-modal>
  142. </template>
  143. <script>
  144. import { commonMixin } from '@/utils/mixin'
  145. import moment from 'moment'
  146. // 组件
  147. import { STable, VSelect, Upload } from '@/components'
  148. import chooseDealer from '@/views/easyPassManagement/homepageCarouselImg/chooseDealer'
  149. // 接口
  150. import { shopPromoDetail, saveShopPromo } from '@/api/shopPromo'
  151. export default {
  152. name: 'AddPromotionModal',
  153. mixins: [commonMixin],
  154. components: { STable, VSelect, Upload, chooseDealer },
  155. props: {
  156. openModal: { // 弹框显示状态
  157. type: Boolean,
  158. default: false
  159. },
  160. itemSn: {// 活动sn
  161. type: String,
  162. default: ''
  163. },
  164. typeVal: {// 添加活动类型
  165. type: String,
  166. default: ''
  167. },
  168. chooseProductNum: {
  169. type: [String, Number],
  170. default: null
  171. }
  172. },
  173. data () {
  174. return {
  175. isShow: this.openModal, // 是否打开弹框
  176. spinning: false, // 页面加载状态
  177. // form表单label布局
  178. formItemLayout: {
  179. labelCol: { span: 3 },
  180. wrapperCol: { span: 19 }
  181. },
  182. dateFormat: 'YYYY-MM-DD', // 促销时间显示格式
  183. chooseDealerList: [], // 已选择的经销商列表
  184. chooseSnList: [], // 已选经销商sn集合
  185. openDealerModal: false, // 经销商弹窗
  186. hasEq: null, // 选择经销商数据是否发生变化
  187. oldDealerFlag: null, // 编辑页面,初始选择经销商值
  188. isAllDealerFlag: null, // 是否是全部经销商
  189. form: {
  190. promoType: undefined, // 促销类型
  191. promoName: '', // '促销名称'
  192. time: [], // 促销时间
  193. promoStartDate: undefined, // 促销时间-开始
  194. promoEndDate: undefined, // 促销时间-结束
  195. sort: undefined, // 排序
  196. allDealerFlag: '1', // 全部经销商 1 部分经销商0'
  197. imageUrl: undefined, // 促销封面图
  198. description: '', // '促销描述'
  199. dealerEditFlag: '0', // 加盟商编辑 0否 1是
  200. dealerOpenFlag: '0' // 加盟商开关权限 0否 1是
  201. },
  202. // 表单验证规则
  203. rules: {
  204. promoName: [{ required: true, message: '请输入促销名称', trigger: 'blur' }],
  205. time: [{ required: true, message: '请选择促销时间', trigger: 'change' }],
  206. sort: [{ required: true, message: '请输入排序数字', trigger: 'blur' }],
  207. allDealerFlag: [{ required: true, message: '请选择参与经销商', trigger: 'change' }],
  208. imageUrl: [{ required: true, message: '请选择要上传的封面图片', trigger: 'change' }],
  209. description: [{ required: true, message: '请输入促销描述内容', trigger: 'blur' }],
  210. dealerOpenFlag: [{ required: true, message: '请选择加盟商开关权限', trigger: 'change' }]
  211. }
  212. }
  213. },
  214. methods: {
  215. // 封面图片上传
  216. changeImage (file) {
  217. this.form.imageUrl = file
  218. },
  219. // 参与经销商 change
  220. changeDealerScope (val) {
  221. // 全部切部分
  222. if (this.isAllDealerFlag == '1' && this.isAllDealerFlag != val) {
  223. this.oldDealerFlag = '1'
  224. } else {
  225. this.oldDealerFlag = '0'
  226. }
  227. const _this = this
  228. _this.form.allDealerFlag = val
  229. if (val == '1' || !val) {
  230. _this.chooseDealerList = []
  231. }
  232. },
  233. // 部分 打开选择经销商弹窗
  234. handleDealerModal () {
  235. this.chooseSnList = this.chooseDealerList.map(item => item.dealerSn)
  236. this.openDealerModal = true
  237. },
  238. // 关闭 选择经销商弹窗
  239. closeDealerModal () {
  240. this.chooseSnList = []
  241. this.openDealerModal = false
  242. },
  243. // 部分经销商 选择经销商成功
  244. addDealerOk (list) {
  245. const _this = this
  246. if (this.chooseDealerList && this.chooseDealerList.length == 0 && this.oldDealerFlag === '1') {
  247. _this.hasEq = []
  248. } else {
  249. _this.hasEq = list.filter(item => !this.chooseDealerList.map(k => k.dealerSn).includes(item.dealerSn))
  250. }
  251. _this.chooseDealerList = list
  252. _this.openDealerModal = false
  253. },
  254. // 部分经销商 删除
  255. delBuyerName (row) {
  256. const pos = this.chooseDealerList.findIndex(item => item.dealerSn == row.dealerSn)
  257. if (pos >= 0) {
  258. this.chooseDealerList.splice(pos, 1)
  259. }
  260. },
  261. // 禁用日期时间
  262. disabledDate (current) {
  263. return current && current < moment().startOf('day')
  264. },
  265. // 促销时间 change
  266. dateChange (date, dateStrings) {
  267. if (dateStrings && dateStrings[0]) {
  268. this.form.time = dateStrings
  269. this.form.promoStartDate = date.length ? dateStrings[0] + ' 00:00:00' : ''
  270. this.form.promoEndDate = date.length ? dateStrings[1] + ' 23:59:59' : ''
  271. } else {
  272. this.form.time = []
  273. }
  274. },
  275. // 保存
  276. handleSave () {
  277. const _this = this
  278. // 验证组件必填项
  279. _this.$refs.ruleForm.validate(valid => {
  280. if (valid) {
  281. _this.form.promoType = _this.typeVal
  282. var formData = JSON.parse(JSON.stringify(_this.form))
  283. // 部分经销商
  284. if (formData.allDealerFlag == '0') {
  285. if (_this.chooseDealerList && _this.chooseDealerList.length == 0) {
  286. _this.$message.warning('请选择参与经销商!')
  287. return
  288. }
  289. formData.dealerSnList = _this.chooseDealerList.map(con => con.dealerSn)
  290. }
  291. delete formData.time
  292. delete formData.shopPromoDealerList
  293. if (_this.itemSn && _this.itemSn.length > 0) {
  294. if (_this.chooseProductNum > 0 && ((_this.hasEq && _this.hasEq.length > 0) || _this.oldDealerFlag != '1')) {
  295. _this.$confirm({
  296. title: '提示',
  297. content: <div>变更【参与经销商】后将会【<span style="color:red">清空</span>】已选产品列表,确定变更吗?</div>,
  298. centered: true,
  299. onOk () {
  300. _this.saveSuccess(formData, '1')
  301. },
  302. onCancel () {
  303. console.log('取消变更经销商')
  304. }
  305. })
  306. } else {
  307. _this.saveSuccess(formData, '0')
  308. }
  309. } else {
  310. _this.saveSuccess(formData, '0')
  311. }
  312. }
  313. })
  314. },
  315. saveSuccess (ajaxData, type) {
  316. const _this = this
  317. _this.spinning = true
  318. ajaxData.saveType = 'alone'
  319. saveShopPromo(ajaxData).then(res => {
  320. if (res.status == 200) {
  321. _this.spinning = false
  322. if (res.data.errorMsg && res.data.errorMsg.length > 0) {
  323. this.$confirm({
  324. title: '提示',
  325. content: res.data.errorMsg.map((item, i) => { return <p>{i * 1 + 1}、{item}</p> }),
  326. centered: true,
  327. okText: '知道了',
  328. cancelText: '取消', // 将cancelText设置为空字符串或去掉该属性可以隐藏取消按钮
  329. cancelButtonProps: {
  330. style: {
  331. display: 'none' // 通过设置样式隐藏取消按钮
  332. }
  333. },
  334. onOk () {
  335. console.log('知道了')
  336. }
  337. })
  338. return
  339. }
  340. _this.$message.success(res.message)
  341. _this.$nextTick(() => {
  342. _this.isShow = false
  343. _this.$emit('ok', type)
  344. })
  345. } else {
  346. _this.spinning = false
  347. }
  348. })
  349. },
  350. // 重置
  351. resetSearchForm () {
  352. this.form = {
  353. promoType: undefined, // 促销类型
  354. promoName: '', // '促销名称'
  355. time: [], // 促销时间
  356. promoStartDate: undefined, // 促销时间-开始
  357. promoEndDate: undefined, // 促销时间-结束
  358. sort: undefined, // 排序
  359. allDealerFlag: '1', // 全部经销商 1 部分经销商0'
  360. imageUrl: undefined, // 促销封面图
  361. description: '', // '促销描述'
  362. dealerEditFlag: '0', // 加盟商编辑 0否 1是
  363. dealerOpenFlag: '0' // 加盟商开关权限 0否 1是
  364. }
  365. this.chooseDealerList = []
  366. if (this.$refs.imageSet) {
  367. this.$refs.imageSet.setFileList('')
  368. }
  369. if (this.$refs.ruleForm) {
  370. this.$refs.ruleForm.resetFields()
  371. }
  372. },
  373. // 详情
  374. async getDetail () {
  375. const _this = this
  376. const res = await shopPromoDetail({ sn: _this.itemSn })
  377. if (res.status == 200) {
  378. if (res.data.promoStartDate && res.data.promoEndDate) {
  379. const startTime = res.data.promoStartDate.split(' ')[0]
  380. const endTime = res.data.promoEndDate.split(' ')[0]
  381. res.data.time = [startTime, endTime]
  382. }
  383. if (res.data.imageUrl) {
  384. _this.$refs.imageSet.setFileList(res.data.imageUrl)
  385. }
  386. _this.form = res.data
  387. _this.isShowNextStep = true
  388. if (_this.$route.params.pageType === 'edit') {
  389. _this.pageType = res.data.promoType
  390. _this.promotionName = res.data.promoName
  391. }
  392. _this.isAllDealerFlag = _this.form.allDealerFlag // 存储是否是全部经销商
  393. // 部分经销商
  394. if (_this.form.allDealerFlag == 0) {
  395. _this.chooseDealerList = _this.form.shopPromoDealerList
  396. }
  397. }
  398. }
  399. },
  400. watch: {
  401. // 父页面传过来的弹框状态
  402. openModal (newValue, oldValue) {
  403. this.isShow = newValue
  404. },
  405. // 重定义的弹框状态
  406. isShow (newValue, oldValue) {
  407. if (!newValue) {
  408. this.$emit('close')
  409. this.resetSearchForm()
  410. }
  411. }
  412. }
  413. }
  414. </script>
  415. <style lang="less" scoped>
  416. .promotionAdd-modal{
  417. /deep/.imageUrl_box .ant-form-item-control{
  418. line-height:0 !important;
  419. }
  420. .upload-desc{// 商品图片描述
  421. padding-top:10px;
  422. font-size: 12px;
  423. color: #808695;
  424. }
  425. .buyerBox{
  426. border:1px solid #d9d9d9;
  427. margin-top:10px;
  428. border-radius:4px;
  429. padding:4px 10px;
  430. background:#f2f2f2;
  431. max-height:130px;
  432. overflow-y:scroll;
  433. scrollbar-width: none;
  434. }
  435. .btn-cont {
  436. text-align: center;
  437. margin: 35px 0 10px;
  438. }
  439. }
  440. </style>