addPromotionModal.vue 16 KB

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