edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <div class="carouselImageEdit-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <a-page-header :ghost="false" :backIcon="false" class="carouselImageEdit-cont" >
  5. <!-- 自定义的二级文字标题 -->
  6. <template slot="subTitle">
  7. <a id="carouselImageEdit-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;">促销名称:{{ form.bannerName||'--' }}</span>
  9. </template>
  10. </a-page-header>
  11. <!-- 表单 -->
  12. <a-card :bordered="false" class="carouselImageEdit-cont">
  13. <a-form-model
  14. id="carouselImageEdit-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="bannerName" :label-col="{span:4}" :wrapper-col="{span:16}">
  24. <a-input
  25. id="carouselImageEdit-bannerName"
  26. :maxLength="30"
  27. :disabled="isDisabled"
  28. v-model.trim="form.bannerName"
  29. placeholder="请输入轮播图名称(最多30个字符)"
  30. allowClear/>
  31. </a-form-model-item>
  32. </a-col>
  33. <a-col :xs="12" :sm="12" :md="12" :lg="12" :xl="12">
  34. <a-form-model-item label="轮播时间" prop="time" :label-col="{span:4}" :wrapper-col="{span:16}">
  35. <a-range-picker
  36. v-model="form.time"
  37. style="width:100%"
  38. :format="dateFormat"
  39. id="carouselImageEdit-time"
  40. @change="dateChange"
  41. :disabled="isDisabled"
  42. :disabled-date="disabledDate"
  43. :placeholder="['开始时间', '结束时间']" />
  44. </a-form-model-item>
  45. </a-col>
  46. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  47. <a-form-model-item label="轮播图排序" prop="sort">
  48. <a-input-number
  49. style="width:40%"
  50. id="carouselImageEdit-sort"
  51. allowClear
  52. placeholder="请输入轮播图排序数字(数字越大越靠后)"
  53. v-model="form.sort"
  54. :min="0"
  55. :max="99999999"/>
  56. </a-form-model-item>
  57. </a-col>
  58. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  59. <a-form-model-item label="参与经销商" prop="allDealerFlag">
  60. <a-row :gutter="15">
  61. <a-col :md="10" :sm="24">
  62. <a-select
  63. style="width:98%;"
  64. id="carouselImageEdit-allDealerFlag"
  65. v-model="form.allDealerFlag"
  66. placeholder="请选择参与经销商"
  67. @change="changeDealerScope"
  68. :disabled="isDisabled"
  69. allowClear>
  70. <a-select-option id="promotionList-dealerScope-all" value="1">全部经销商</a-select-option>
  71. <a-select-option id="promotionList-dealerScope-some" value="0">部分经销商</a-select-option>
  72. </a-select>
  73. </a-col>
  74. <a-col :md="2" :sm="24" v-show="form.allDealerFlag && form.allDealerFlag!='1' ">
  75. <a-button id="promotionList-basicInfo-dealerScope" type="primary" :loading="spinning" :disabled="isDisabled" @click="handleDealerModal">选择</a-button>
  76. </a-col>
  77. <a-col :md="5" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  78. 已{{ chooseDealerList.length }}选项
  79. </a-col>
  80. <a-col :md="24" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  81. <div class="buyerBox">
  82. <a-tag :closable="!isDisabled" v-for="con in chooseDealerList" id="promotionList-dealerSn" :key="con.dealerSn" @close="delBuyerName(con)">
  83. {{ con.dealerName }}
  84. </a-tag>
  85. </div>
  86. </a-col>
  87. </a-row>
  88. </a-form-model-item>
  89. </a-col>
  90. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  91. <a-form-model-item label="封面图片" prop="imageUrl">
  92. <Upload
  93. class="upload"
  94. id="carouselImageEdit-imageUrl"
  95. v-model="form.imageUrl"
  96. ref="imageSet"
  97. :fileSize="10"
  98. :maxNums="1"
  99. @change="changeImage"
  100. listType="picture-card"></Upload>
  101. <span class="upload-desc">说明:单张大小小于10Mb;建议尺寸:宽(750px)*高(300px)</span>
  102. </a-form-model-item>
  103. </a-col>
  104. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  105. <a-form-model-item label="内容类型" prop="contentType">
  106. <v-select
  107. v-model="form.contentType"
  108. id="carouselImageEdit-contentType"
  109. code="PROMO_CONTENT_TYPE"
  110. showType="radio"
  111. :notIn="notShowSel"
  112. :disabled="isDisabled"
  113. allowClear></v-select>
  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="content" v-show="form.contentType =='IMAGE_CONTENT'">
  118. <editor
  119. v-show="!$route.params.sn"
  120. id="carouselImageEdit-editor"
  121. ref="editor"
  122. class="carouselImageEdit-editor"
  123. @on-change="editorChange"
  124. :cache="false"></editor>
  125. <div style="border:1px solid #efefef;border-radius:8px;padding:10px 20px;" v-if="$route.params.sn" v-html="form.content"></div>
  126. </a-form-model-item>
  127. <a-form-model-item label="上传视频" prop="content" v-show="form.contentType =='VIDEO'">
  128. <Upload
  129. class="upload"
  130. id="carouselImageEdit-videoSet"
  131. v-model="form.content"
  132. fileType="video/mp4"
  133. ref="videoSet"
  134. :disabled="isDisabled"
  135. :fileSize="100"
  136. :maxNums="1"
  137. @change="changeVideo"
  138. ></Upload>
  139. <span class="upload-desc">说明:文件最大100M;视频:mp4.avi.flv</span>
  140. </a-form-model-item>
  141. <a-form-model-item label="跳转链接" prop="contentLink" v-if="form.contentType =='LINK'">
  142. <a-input
  143. style="width:50%;"
  144. :disabled="isDisabled"
  145. id="carouselImageEdit-contentLink"
  146. :maxLength="100"
  147. v-model.trim="form.contentLink"
  148. placeholder="请输入跳转链接"
  149. allowClear />
  150. </a-form-model-item>
  151. </a-col>
  152. </a-row>
  153. </a-form-model>
  154. </a-card>
  155. </a-spin>
  156. <div class="affix-cont">
  157. <a-button
  158. type="primary"
  159. class="button-primary"
  160. :disabled="spinning"
  161. id="carouselImageEdit-submit-btn"
  162. size="large"
  163. @click="handleSave('all')"
  164. style="padding: 0 60px;">保存</a-button>
  165. </div>
  166. <!-- 选择经销商 -->
  167. <chooseDealer :openModal="openDealerModal" :disabledList="chooseSnList" @close="closeDealerModal" @ok="addDealerOk"></chooseDealer>
  168. </div>
  169. </template>
  170. <script>
  171. import { commonMixin } from '@/utils/mixin'
  172. import moment from 'moment'
  173. // 组件
  174. import { VSelect, Upload } from '@/components'
  175. import Editor from '@/components/WEeditor'
  176. import chooseDealer from './chooseDealer'
  177. // 接口
  178. import { saveShopBanner, shopBannerDetail } from '@/api/shopBanner'
  179. export default {
  180. name: 'CarouselImageEdit',
  181. mixins: [commonMixin],
  182. components: { VSelect, Upload, Editor, chooseDealer },
  183. data () {
  184. return {
  185. spinning: false,
  186. // 表单 label 设置
  187. formItemLayout: {
  188. labelCol: { span: 2 },
  189. wrapperCol: { span: 20 }
  190. },
  191. chooseDealerList: [], // 已选经销商数据
  192. openDealerModal: false, // 打开选择经销商弹窗
  193. isDisabled: false,
  194. // 链接配置内容
  195. form: {
  196. bannerSn: undefined, // 轮播图sn
  197. bannerName: '', // 轮播图名称
  198. time: [], // 轮播时间
  199. bannerStartDate: undefined,
  200. bannerEndDate: undefined,
  201. sort: undefined, // 排序
  202. allDealerFlag: '1', // 参与经销商 0 部分 1全部
  203. dealerSnList: [], // 已选经销商sn列表
  204. imageUrl: '', // 图片
  205. contentType: 'LINK', // 内容类型
  206. content: '', // 内容
  207. contentLink: '', // 内容链接
  208. state: 'UNPUBLISH'// 发布状态
  209. },
  210. chooseSnList: [],
  211. dateFormat: 'YYYY-MM-DD', // 有效期时间格式
  212. notShowSel: ['PROMO_LINK'], // 是否显示促销活动选择按钮
  213. // 表单验证规则
  214. rules: {
  215. bannerName: [{ required: true, message: '请输入轮播图名称', trigger: 'blur' }],
  216. time: [{ required: true, message: '请选择轮播时间', trigger: 'change' }],
  217. sort: [{ required: true, message: '请输入排序数字', trigger: 'blur' }],
  218. allDealerFlag: [{ required: true, message: '请选择参与经销商', trigger: 'change' }],
  219. imageUrl: [{ required: true, message: '请选择要上传的封面图片', trigger: 'change' }],
  220. contentType: [{ required: true, message: '请选择内容类型', trigger: 'change' }],
  221. content: [{ required: true, message: '请输入对应内容', trigger: ['blur', 'change'] }]
  222. }
  223. }
  224. },
  225. methods: {
  226. // 部分经销商 选择经销商成功
  227. addDealerOk (list) {
  228. const dealerArr = list.map(item => {
  229. return {
  230. dealerName: item.dealerName,
  231. dealerSn: item.dealerSn
  232. }
  233. })
  234. this.chooseDealerList = dealerArr
  235. this.openDealerModal = false
  236. },
  237. // 禁用日期时间
  238. disabledDate (current) {
  239. return current && current < moment().startOf('day')
  240. },
  241. // 轮播时间
  242. dateChange (date, dateString) {
  243. this.form.time = date
  244. if (dateString[0] != '' && dateString[1] != '') {
  245. this.form.bannerStartDate = dateString[0] + ' 00:00:00'
  246. this.form.bannerEndDate = dateString[1] + ' 23:59:59'
  247. }
  248. },
  249. // 打开 选择经销商弹窗
  250. handleDealerModal () {
  251. console.log('111111111111:', this.chooseDealerList)
  252. this.chooseSnList = this.chooseDealerList.map(item => item.dealerSn)
  253. this.openDealerModal = true
  254. },
  255. // 关闭 选择经销商弹窗
  256. closeDealerModal () {
  257. this.chooseSnList = []
  258. this.openDealerModal = false
  259. },
  260. // 部分经销商 删除
  261. delBuyerName (row) {
  262. const pos = this.chooseDealerList.findIndex(item => item.dealerSn == row.dealerSn)
  263. if (pos > 0) {
  264. this.chooseDealerList.splice(pos, 1)
  265. }
  266. console.log('222222:', pos, this.chooseDealerList)
  267. },
  268. // 参与经销商 change
  269. changeDealerScope (val) {
  270. this.form.allDealerFlag = val
  271. if (val == '1') {
  272. this.chooseDealerList = []
  273. }
  274. },
  275. // 返回列表
  276. handleBack () {
  277. this.$router.push({ name: 'carouselImageList', query: { closeLastOldTab: true } })
  278. },
  279. // 详情
  280. getDetail () {
  281. const _this = this
  282. shopBannerDetail({ bannerSn: this.$route.params.sn }).then(res => {
  283. if (res.status == 200) {
  284. _this.isDisabled = true
  285. if (res.data.contentType == 'IMAGE_CONTENT') {
  286. _this.$refs.editor.setHtml(res.data.content)
  287. } else if (res.data.contentType == 'VIDEO') {
  288. _this.$refs.videoSet.setFileList(res.data.content)
  289. } else if (res.data.contentType == 'LINK') {
  290. _this.form.contentLink = res.data.content
  291. }
  292. if (res.data.allDealerFlag == '0') {
  293. this.chooseDealerList = res.data.dealerList
  294. }
  295. _this.$refs.imageSet.setFileList(res.data.imageUrl)
  296. _this.form = res.data
  297. _this.form.time = [res.data.bannerStartDate, res.data.bannerEndDate]
  298. }
  299. })
  300. },
  301. // 确定保存 验证必填
  302. handleSave (type) {
  303. const _this = this
  304. if (_this.form.contentType === 'LINK') {
  305. _this.form.content = _this.form.contentLink
  306. }
  307. // 验证组件必填项
  308. _this.$refs.ruleForm.validate(valid => {
  309. if (valid) {
  310. _this.savePartInfo(type)
  311. }
  312. })
  313. },
  314. // 保存
  315. savePartInfo (type) {
  316. const _this = this
  317. if (_this.form.allDealerFlag == '0') {
  318. if (_this.chooseDealerList && _this.chooseDealerList.length == 0) {
  319. _this.$message.warning('请选择参与经销商!')
  320. return
  321. }
  322. _this.form.dealerSnList = _this.chooseDealerList.map(con => con.dealerSn)
  323. }
  324. _this.form.bannerSn = _this.$route.params.sn || undefined
  325. var formData = JSON.parse(JSON.stringify(_this.form))
  326. delete formData.time
  327. delete formData.contentLink
  328. _this.spinning = true
  329. saveShopBanner(formData).then(res => {
  330. if (res.status == 200) {
  331. _this.$message.success(res.message)
  332. _this.$nextTick(() => {
  333. _this.handleBack()
  334. _this.resetSearchForm()
  335. })
  336. _this.spinning = false
  337. } else {
  338. _this.spinning = false
  339. }
  340. })
  341. },
  342. // 图片上传
  343. changeImage (file) {
  344. this.form.imageUrl = file
  345. },
  346. // 视频上传
  347. changeVideo (file) {
  348. this.form.content = file
  349. },
  350. // 文本编辑器
  351. editorChange (html, text) {
  352. this.form.content = html
  353. },
  354. // 重置
  355. resetSearchForm () {
  356. this.$refs.imageSet.setFileList('')
  357. if (this.contentType === 'VIDEO') {
  358. this.$refs.videoSet.setFileList('')
  359. }
  360. if (this.contentType === 'IMAGE_CONTENT') {
  361. this.$refs.editor.setHtml('')
  362. }
  363. this.form = {
  364. bannerSn: undefined, // 轮播图sn
  365. bannerName: '', // 轮播图名称
  366. time: [], // 轮播时间
  367. bannerStartDate: undefined, // 轮播图活动开始时间
  368. bannerEndDate: undefined, // 轮播图活动结束时间
  369. sort: undefined, // 排序
  370. allDealerFlag: '1', // 参与经销商 0 部分 1全部
  371. dealerSnList: [], // 已选经销商sn列表
  372. imageUrl: '', // 图片
  373. contentType: 'LINK', // 内容类型
  374. content: '', // 内容
  375. contentLink: '',
  376. state: 'UNPUBLISH'
  377. }
  378. this.isDisabled = false
  379. if (this.$refs.ruleForm) {
  380. this.$refs.ruleForm.resetFields()
  381. }
  382. },
  383. // 初始化
  384. pageInit () {
  385. if (this.$route.params.sn) {
  386. this.getDetail()
  387. if (this.$route.params.bizType && this.$route.params.bizType === 'SHOP_PROMO') {
  388. this.notShowSel.splice(0, 1)
  389. }
  390. }
  391. }
  392. },
  393. mounted () {
  394. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  395. this.pageInit()
  396. }
  397. },
  398. activated () {
  399. // 如果是新页签打开,则重置当前页面
  400. if (this.$store.state.app.isNewTab) {
  401. this.pageInit()
  402. }
  403. // 仅刷新列表,不重置页面
  404. if (this.$store.state.app.updateList) {
  405. this.pageInit()
  406. }
  407. },
  408. beforeRouteEnter (to, from, next) {
  409. next(vm => {})
  410. }
  411. }
  412. </script>
  413. <style lang="less" scoped>
  414. .carouselImageEdit-wrap{
  415. position: relative;
  416. height: 100%;
  417. box-sizing: border-box;
  418. padding-bottom:51px;
  419. >.ant-spin-nested-loading{
  420. overflow-y: scroll;
  421. height: 100%;
  422. }
  423. /deep/.ant-form-item{
  424. margin-bottom:8px;
  425. }
  426. .carouselImageEdit-cont{
  427. margin-bottom: 10px;
  428. }
  429. .upload{
  430. width: 100%!important;
  431. }
  432. // 文本编辑器 工具栏样式换行
  433. .carouselImageEdit-editor{
  434. .w-e-toolbar{
  435. flex-wrap: wrap;
  436. z-index: 0;
  437. }
  438. }
  439. .buyerBox{
  440. border:1px solid #d9d9d9;
  441. margin-top:10px;
  442. border-radius:4px;padding:4px 10px;
  443. background:#f2f2f2;max-height:130px;
  444. overflow-y:scroll;
  445. }
  446. // 商品图片描述
  447. .upload-desc{
  448. font-size: 12px;
  449. color: #808695;
  450. }
  451. #carouselImageEdit-attachList{
  452. height: auto;
  453. }
  454. .box{
  455. border:1px solid #d9d9d9;
  456. border-radius:4px;
  457. padding:4px 11px;
  458. color:rgba(0, 0, 0, 0.25);
  459. cursor: not-allowed;
  460. background:#fdfdfd;
  461. }
  462. .affix{
  463. .ant-affix{
  464. z-index: 101;
  465. display:inline-block
  466. }
  467. }
  468. /deep/.ant-radio-disabled + span{
  469. color:#000!important;
  470. }
  471. .tip{
  472. margin-left:10px;
  473. }
  474. .productInfo{
  475. display:flex;
  476. justify-content: space-between;
  477. }
  478. #setPromotion-productRange{
  479. /deep/.ant-select-dropdown{
  480. max-height:30vh !important;
  481. }
  482. }
  483. }
  484. </style>