addPromotionModal.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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. isAllDealerFlag: null, // 是否是全部经销商
  187. form: {
  188. promoType: undefined, // 促销类型
  189. promoName: '', // '促销名称'
  190. time: [], // 促销时间
  191. promoStartDate: undefined, // 促销时间-开始
  192. promoEndDate: undefined, // 促销时间-结束
  193. sort: undefined, // 排序
  194. allDealerFlag: '1', // 全部经销商 1 部分经销商0'
  195. imageUrl: undefined, // 促销封面图
  196. description: '', // '促销描述'
  197. dealerEditFlag: '0', // 加盟商编辑 0否 1是
  198. dealerOpenFlag: '0' // 加盟商开关权限 0否 1是
  199. },
  200. // 表单验证规则
  201. rules: {
  202. promoName: [{ required: true, message: '请输入促销名称', trigger: 'blur' }],
  203. time: [{ required: true, message: '请选择促销时间', trigger: 'change' }],
  204. sort: [{ required: true, message: '请输入排序数字', trigger: 'blur' }],
  205. allDealerFlag: [{ required: true, message: '请选择参与经销商', trigger: 'change' }],
  206. imageUrl: [{ required: true, message: '请选择要上传的封面图片', trigger: 'change' }],
  207. description: [{ required: true, message: '请输入促销描述内容', trigger: 'blur' }],
  208. dealerOpenFlag: [{ required: true, message: '请选择加盟商开关权限', trigger: 'change' }]
  209. }
  210. }
  211. },
  212. methods: {
  213. // 封面图片上传
  214. changeImage (file) {
  215. this.form.imageUrl = file
  216. },
  217. // 参与经销商 change
  218. changeDealerScope (val) {
  219. const _this = this
  220. _this.form.allDealerFlag = val
  221. if (val == '1' || !val) {
  222. _this.chooseDealerList = []
  223. }
  224. },
  225. // 部分 打开选择经销商弹窗
  226. handleDealerModal () {
  227. this.chooseSnList = this.chooseDealerList.map(item => item.dealerSn)
  228. this.openDealerModal = true
  229. },
  230. // 关闭 选择经销商弹窗
  231. closeDealerModal () {
  232. this.chooseSnList = []
  233. this.openDealerModal = false
  234. },
  235. // 部分经销商 选择经销商成功
  236. addDealerOk (list) {
  237. const _this = this
  238. _this.chooseDealerList = list
  239. _this.openDealerModal = false
  240. },
  241. // 部分经销商 删除
  242. delBuyerName (row) {
  243. const pos = this.chooseDealerList.findIndex(item => item.dealerSn == row.dealerSn)
  244. if (pos >= 0) {
  245. this.chooseDealerList.splice(pos, 1)
  246. }
  247. },
  248. // 禁用日期时间
  249. disabledDate (current) {
  250. return current && current < moment().startOf('day')
  251. },
  252. // 促销时间 change
  253. dateChange (date, dateStrings) {
  254. if (dateStrings && dateStrings[0]) {
  255. this.form.time = dateStrings
  256. this.form.promoStartDate = date.length ? dateStrings[0] + ' 00:00:00' : ''
  257. this.form.promoEndDate = date.length ? dateStrings[1] + ' 23:59:59' : ''
  258. } else {
  259. this.form.time = []
  260. }
  261. },
  262. // 保存
  263. handleSave () {
  264. const _this = this
  265. // 验证组件必填项
  266. _this.$refs.ruleForm.validate(valid => {
  267. if (valid) {
  268. _this.form.promoType = _this.typeVal
  269. var formData = JSON.parse(JSON.stringify(_this.form))
  270. // 部分经销商
  271. if (formData.allDealerFlag == '0') {
  272. if (_this.chooseDealerList && _this.chooseDealerList.length == 0) {
  273. _this.$message.warning('请选择参与经销商!')
  274. return
  275. }
  276. formData.dealerSnList = _this.chooseDealerList.map(con => con.dealerSn)
  277. }
  278. if (_this.itemSn && _this.itemSn.length > 0) {
  279. const hasEq = _this.chooseDealerList.filter(item => !formData.shopPromoDealerList.map(k => k.dealerSn).includes(item.dealerSn)) // 经销商是否变更
  280. const hasEq1 = _this.isAllDealerFlag == 0 && formData.allDealerFlag == 1 // 部分变全部
  281. const hasChange = _this.isAllDealerFlag == 0 && _this.isAllDealerFlag == formData.allDealerFlag // 是否部分经销商未变更
  282. console.log(hasEq, hasEq1)
  283. if (_this.chooseProductNum > 0 && (hasChange && hasEq && hasEq.length > 0 || hasEq1)) {
  284. _this.$confirm({
  285. title: '提示',
  286. content: <div>变更【参与经销商】后将会【<span style="color:red">清空</span>】已选产品列表,确定变更吗?</div>,
  287. centered: true,
  288. onOk () {
  289. _this.saveSuccess(formData, '1')
  290. }
  291. })
  292. } else {
  293. _this.saveSuccess(formData, '0')
  294. }
  295. } else {
  296. _this.saveSuccess(formData, '0')
  297. }
  298. }
  299. })
  300. },
  301. saveSuccess (ajaxData, type) {
  302. const _this = this
  303. _this.spinning = true
  304. delete ajaxData.time
  305. delete ajaxData.shopPromoDealerList
  306. ajaxData.saveType = 'alone'
  307. saveShopPromo(ajaxData).then(res => {
  308. if (res.status == 200) {
  309. _this.spinning = false
  310. if (res.data.errorMsg && res.data.errorMsg.length > 0) {
  311. this.$confirm({
  312. title: '提示',
  313. content: res.data.errorMsg.map((item, i) => { return <p>{i * 1 + 1}、{item}</p> }),
  314. centered: true,
  315. okText: '知道了',
  316. cancelText: '取消', // 将cancelText设置为空字符串或去掉该属性可以隐藏取消按钮
  317. cancelButtonProps: {
  318. style: {
  319. display: 'none' // 通过设置样式隐藏取消按钮
  320. }
  321. },
  322. onOk () {
  323. console.log('知道了')
  324. }
  325. })
  326. return
  327. }
  328. _this.$message.success(res.message)
  329. _this.$nextTick(() => {
  330. _this.isShow = false
  331. _this.$emit('ok', type)
  332. })
  333. } else {
  334. _this.spinning = false
  335. }
  336. })
  337. },
  338. // 重置
  339. resetSearchForm () {
  340. this.form = {
  341. promoType: undefined, // 促销类型
  342. promoName: '', // '促销名称'
  343. time: [], // 促销时间
  344. promoStartDate: undefined, // 促销时间-开始
  345. promoEndDate: undefined, // 促销时间-结束
  346. sort: undefined, // 排序
  347. allDealerFlag: '1', // 全部经销商 1 部分经销商0'
  348. imageUrl: undefined, // 促销封面图
  349. description: '', // '促销描述'
  350. dealerEditFlag: '0', // 加盟商编辑 0否 1是
  351. dealerOpenFlag: '0' // 加盟商开关权限 0否 1是
  352. }
  353. this.chooseDealerList = []
  354. if (this.$refs.imageSet) {
  355. this.$refs.imageSet.setFileList('')
  356. }
  357. if (this.$refs.ruleForm) {
  358. this.$refs.ruleForm.resetFields()
  359. }
  360. },
  361. // 详情
  362. async getDetail () {
  363. const _this = this
  364. const res = await shopPromoDetail({ sn: _this.itemSn })
  365. if (res.status == 200) {
  366. if (res.data.promoStartDate && res.data.promoEndDate) {
  367. const startTime = res.data.promoStartDate.split(' ')[0]
  368. const endTime = res.data.promoEndDate.split(' ')[0]
  369. res.data.time = [startTime, endTime]
  370. }
  371. if (res.data.imageUrl) {
  372. _this.$refs.imageSet.setFileList(res.data.imageUrl)
  373. }
  374. _this.form = res.data
  375. _this.isShowNextStep = true
  376. if (_this.$route.params.pageType === 'edit') {
  377. _this.pageType = res.data.promoType
  378. _this.promotionName = res.data.promoName
  379. }
  380. _this.isAllDealerFlag = _this.form.allDealerFlag // 存储是否是全部经销商
  381. // 部分经销商
  382. if (_this.form.allDealerFlag == 0) {
  383. _this.chooseDealerList = _this.form.shopPromoDealerList
  384. }
  385. }
  386. }
  387. },
  388. watch: {
  389. // 父页面传过来的弹框状态
  390. openModal (newValue, oldValue) {
  391. this.isShow = newValue
  392. },
  393. // 重定义的弹框状态
  394. isShow (newValue, oldValue) {
  395. if (!newValue) {
  396. this.$emit('close')
  397. this.resetSearchForm()
  398. }
  399. }
  400. }
  401. }
  402. </script>
  403. <style lang="less" scoped>
  404. .promotionAdd-modal{
  405. /deep/.imageUrl_box .ant-form-item-control{
  406. line-height:0 !important;
  407. }
  408. .upload-desc{// 商品图片描述
  409. padding-top:10px;
  410. font-size: 12px;
  411. color: #808695;
  412. }
  413. .buyerBox{
  414. border:1px solid #d9d9d9;
  415. margin-top:10px;
  416. border-radius:4px;
  417. padding:4px 10px;
  418. background:#f2f2f2;
  419. max-height:130px;
  420. overflow-y:scroll;
  421. scrollbar-width: none;
  422. }
  423. .btn-cont {
  424. text-align: center;
  425. margin: 35px 0 10px;
  426. }
  427. }
  428. </style>