edit.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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.stop="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. @change="changeContentType"
  114. allowClear></v-select>
  115. </a-form-model-item>
  116. </a-col>
  117. <a-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  118. <a-form-model-item label="内容" class="contentBox" v-show="form.contentType =='IMAGE_CONTENT'">
  119. <editor
  120. v-show="!isDisabled"
  121. id="carouselImageEdit-editor"
  122. ref="editor"
  123. class="carouselImageEdit-editor"
  124. @on-change="editorChange"
  125. :cache="false"></editor>
  126. <div style="border:1px solid #efefef;border-radius:8px;padding:10px 20px;" v-if="isDisabled" v-html="form.content"></div>
  127. </a-form-model-item>
  128. <a-form-model-item label="上传视频" prop="content" v-if="form.contentType =='VIDEO'">
  129. <Upload
  130. class="upload"
  131. id="carouselImageEdit-videoSet"
  132. v-model="form.content"
  133. fileType="video/mp4"
  134. ref="videoSet"
  135. :disabled="isDisabled"
  136. :fileSize="100"
  137. :maxNums="1"
  138. @change="changeVideo"
  139. ></Upload>
  140. <span class="upload-desc">说明:文件最大100M;视频:mp4.avi.flv</span>
  141. </a-form-model-item>
  142. <a-form-model-item label="跳转链接" prop="contentLink" v-if="form.contentType =='LINK'">
  143. <a-input
  144. style="width:50%;"
  145. :disabled="isDisabled"
  146. id="carouselImageEdit-contentLink"
  147. :maxLength="100"
  148. v-model.trim="form.contentLink"
  149. placeholder="请输入跳转链接"
  150. allowClear />
  151. </a-form-model-item>
  152. </a-col>
  153. </a-row>
  154. </a-form-model>
  155. </a-card>
  156. </a-spin>
  157. <div class="affix-cont">
  158. <a-button
  159. type="primary"
  160. class="button-primary"
  161. :disabled="spinning"
  162. id="carouselImageEdit-submit-btn"
  163. size="large"
  164. @click="handleSave('all')"
  165. style="padding: 0 60px;">保存</a-button>
  166. </div>
  167. <!-- 选择经销商 -->
  168. <chooseDealer :openModal="openDealerModal" :chooseInfo="chooseSnList" @close="closeDealerModal" @ok="addDealerOk"></chooseDealer>
  169. </div>
  170. </template>
  171. <script>
  172. import { commonMixin } from '@/utils/mixin'
  173. import moment from 'moment'
  174. // 组件
  175. import { VSelect, Upload } from '@/components'
  176. import Editor from '@/components/WEeditor'
  177. import chooseDealer from './chooseDealer'
  178. // 接口
  179. import { saveShopBanner, shopBannerDetail } from '@/api/shopBanner'
  180. export default {
  181. name: 'CarouselImageEdit',
  182. mixins: [commonMixin],
  183. components: { VSelect, Upload, Editor, chooseDealer },
  184. data () {
  185. return {
  186. spinning: false,
  187. // 表单 label 设置
  188. formItemLayout: {
  189. labelCol: { span: 2 },
  190. wrapperCol: { span: 20 }
  191. },
  192. chooseDealerList: [], // 已选经销商数据
  193. openDealerModal: false, // 打开选择经销商弹窗
  194. isDisabled: false,
  195. // 链接配置内容
  196. form: {
  197. bannerSn: undefined, // 轮播图sn
  198. bannerName: '', // 轮播图名称
  199. time: [], // 轮播时间
  200. bannerStartDate: undefined,
  201. bannerEndDate: undefined,
  202. sort: undefined, // 排序
  203. allDealerFlag: '1', // 参与经销商 0 部分 1全部
  204. dealerSnList: [], // 已选经销商sn列表
  205. imageUrl: '', // 图片
  206. contentType: 'LINK', // 内容类型
  207. content: '', // 内容
  208. contentLink: '', // 内容链接
  209. state: 'UNPUBLISH', // 发布状态
  210. contentEditor: ''
  211. },
  212. chooseSnList: [],
  213. dateFormat: 'YYYY-MM-DD', // 有效期时间格式
  214. notShowSel: ['PROMO_LINK'], // 是否显示促销活动选择按钮
  215. // 表单验证规则
  216. rules: {
  217. bannerName: [{ required: true, message: '请输入轮播图名称', trigger: 'blur' }],
  218. time: [{ required: true, message: '请选择轮播时间', trigger: 'change' }],
  219. sort: [{ required: true, message: '请输入排序数字', trigger: 'blur' }],
  220. allDealerFlag: [{ required: true, message: '请选择参与经销商', trigger: 'change' }],
  221. imageUrl: [{ required: true, message: '请选择要上传的封面图片', trigger: 'change' }],
  222. contentType: [{ required: true, message: '请选择内容类型', trigger: 'change' }],
  223. content: [{ required: true, message: '请选择视频展示', trigger: ['blur', 'change'] }],
  224. contentLink: [{ required: true, message: '请输入跳转链接', trigger: ['blur', 'change'] }]
  225. }
  226. }
  227. },
  228. methods: {
  229. // 部分经销商 选择经销商成功
  230. addDealerOk (list) {
  231. this.chooseDealerList = list
  232. this.openDealerModal = false
  233. },
  234. // 禁用日期时间
  235. disabledDate (current) {
  236. return current && current < moment().startOf('day')
  237. },
  238. // 轮播时间
  239. dateChange (date, dateString) {
  240. this.form.time = date
  241. if (dateString[0] != '' && dateString[1] != '') {
  242. this.form.bannerStartDate = dateString[0] + ' 00:00:00'
  243. this.form.bannerEndDate = dateString[1] + ' 23:59:59'
  244. }
  245. },
  246. // 打开 选择经销商弹窗
  247. handleDealerModal () {
  248. this.chooseSnList = this.chooseDealerList.map(item => item.dealerSn)
  249. this.openDealerModal = true
  250. },
  251. // 关闭 选择经销商弹窗
  252. closeDealerModal () {
  253. this.chooseSnList = []
  254. this.openDealerModal = false
  255. },
  256. // 切换类型 清空内容显示
  257. changeContentType (val) {
  258. this.form.content = ''
  259. this.form.contentLink = ''
  260. },
  261. // 部分经销商 删除
  262. delBuyerName (row) {
  263. const pos = this.chooseDealerList.findIndex(item => item.dealerSn == row.dealerSn)
  264. if (pos >= 0) {
  265. this.chooseDealerList.splice(pos, 1)
  266. }
  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. if (res.data.bizType && res.data.bizType === 'SHOP_PROMO') {
  285. _this.isDisabled = true
  286. }
  287. _this.form = { ..._this.form, ...res.data }
  288. _this.$nextTick(() => {
  289. if (res.data.contentType == 'IMAGE_CONTENT') {
  290. _this.$refs.editor.setHtml(res.data.content)
  291. } else if (res.data.contentType == 'VIDEO') {
  292. _this.$refs.videoSet.setFileList(res.data.content)
  293. } else if (res.data.contentType == 'LINK') {
  294. res.data.contentLink = res.data.content
  295. }
  296. if (res.data.allDealerFlag == '0') {
  297. this.chooseDealerList = res.data.dealerList
  298. }
  299. _this.$refs.imageSet.setFileList(res.data.imageUrl)
  300. _this.form.contentEditor = res.data.content
  301. _this.form.time = [res.data.bannerStartDate, res.data.bannerEndDate]
  302. })
  303. }
  304. })
  305. },
  306. // 确定保存 验证必填
  307. handleSave (type) {
  308. const _this = this
  309. if (_this.form.contentType === 'LINK') {
  310. _this.form.content = _this.form.contentLink
  311. }
  312. if (_this.form.contentType === 'IMAGE_CONTENT') {
  313. _this.form.content = _this.form.contentEditor ? _this.form.contentEditor : _this.form.content
  314. }
  315. // 验证组件必填项
  316. _this.$refs.ruleForm.validate(valid => {
  317. if (valid) {
  318. _this.savePartInfo(type)
  319. }
  320. })
  321. },
  322. // 保存
  323. savePartInfo (type) {
  324. const _this = this
  325. if (_this.form.allDealerFlag == '0') {
  326. if (_this.chooseDealerList && _this.chooseDealerList.length == 0) {
  327. _this.$message.warning('请选择参与经销商!')
  328. return
  329. }
  330. _this.form.dealerSnList = _this.chooseDealerList.map(con => con.dealerSn)
  331. }
  332. if (_this.form.contentType === 'IMAGE_CONTENT' && !_this.form.contentEditor) {
  333. _this.$message.warning('请输入图文内容!')
  334. return
  335. }
  336. _this.form.bannerSn = _this.$route.params.sn || undefined
  337. var formData = JSON.parse(JSON.stringify(_this.form))
  338. delete formData.time
  339. delete formData.contentLink
  340. delete formData.contentEditor
  341. _this.spinning = true
  342. saveShopBanner(formData).then(res => {
  343. if (res.status == 200) {
  344. _this.$message.success(res.message)
  345. _this.$nextTick(() => {
  346. _this.handleBack()
  347. })
  348. _this.resetSearchForm()
  349. _this.spinning = false
  350. } else {
  351. _this.spinning = false
  352. }
  353. })
  354. },
  355. // 图片上传
  356. changeImage (file) {
  357. this.form.imageUrl = file
  358. },
  359. // 视频上传
  360. changeVideo (file) {
  361. this.form.content = file
  362. },
  363. // 文本编辑器
  364. editorChange (html, text) {
  365. this.form.contentEditor = html
  366. },
  367. // 重置
  368. resetSearchForm () {
  369. this.form = {
  370. bannerSn: undefined, // 轮播图sn
  371. bannerName: '', // 轮播图名称
  372. time: [], // 轮播时间
  373. bannerStartDate: undefined, // 轮播图活动开始时间
  374. bannerEndDate: undefined, // 轮播图活动结束时间
  375. sort: undefined, // 排序
  376. allDealerFlag: '1', // 参与经销商 0 部分 1全部
  377. dealerSnList: [], // 已选经销商sn列表
  378. imageUrl: '', // 图片
  379. contentType: 'LINK', // 内容类型
  380. content: '', // 内容
  381. contentLink: '',
  382. state: 'UNPUBLISH',
  383. contentEditor: ''
  384. }
  385. if (this.$refs.imageSet) {
  386. this.$refs.imageSet.setFileList('')
  387. }
  388. if (this.form.contentType === 'VIDEO' && this.$refs.videoSet) {
  389. this.$refs.videoSet.setFileList('')
  390. }
  391. if (this.form.contentType === 'IMAGE_CONTENT') {
  392. this.$refs.editor.setHtml('')
  393. }
  394. this.isDisabled = false
  395. if (this.$refs.ruleForm) {
  396. this.$refs.ruleForm.resetFields()
  397. }
  398. },
  399. // 初始化
  400. pageInit () {
  401. if (this.$route.params.sn) {
  402. this.getDetail()
  403. if (this.$route.params.bizType && this.$route.params.bizType === 'SHOP_PROMO') {
  404. this.notShowSel.splice(0, 1)
  405. }
  406. }
  407. }
  408. },
  409. mounted () {
  410. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  411. this.pageInit()
  412. }
  413. },
  414. activated () {
  415. // 如果是新页签打开,则重置当前页面
  416. if (this.$store.state.app.isNewTab) {
  417. this.pageInit()
  418. }
  419. // 仅刷新列表,不重置页面
  420. if (this.$store.state.app.updateList) {
  421. this.pageInit()
  422. }
  423. },
  424. beforeRouteEnter (to, from, next) {
  425. next(vm => {})
  426. }
  427. }
  428. </script>
  429. <style lang="less" scoped>
  430. .carouselImageEdit-wrap{
  431. position: relative;
  432. height: 100%;
  433. box-sizing: border-box;
  434. padding-bottom:51px;
  435. >.ant-spin-nested-loading{
  436. overflow-y: scroll;
  437. height: 100%;
  438. }
  439. /deep/.ant-form-item{
  440. margin-bottom:8px;
  441. }
  442. .carouselImageEdit-cont{
  443. margin-bottom: 10px;
  444. }
  445. .upload{
  446. width: 100%!important;
  447. }
  448. // 文本编辑器 工具栏样式换行
  449. .carouselImageEdit-editor{
  450. .w-e-toolbar{
  451. flex-wrap: wrap;
  452. z-index: 0;
  453. }
  454. }
  455. //图文必填标志显示
  456. .contentBox {
  457. /deep/.ant-form-item-label label::before{
  458. display:inline-block;
  459. margin-right: 4px;
  460. color: #f5222d !important;
  461. font-size: 12px;
  462. font-family: SimSun, sans-serif;
  463. line-height: 1;
  464. content: '*';
  465. }
  466. }
  467. .buyerBox{
  468. border:1px solid #d9d9d9;
  469. margin-top:10px;
  470. border-radius:4px;padding:4px 10px;
  471. background:#f2f2f2;max-height:130px;
  472. overflow-y:scroll;
  473. }
  474. // 商品图片描述
  475. .upload-desc{
  476. font-size: 12px;
  477. color: #808695;
  478. }
  479. #carouselImageEdit-attachList{
  480. height: auto;
  481. }
  482. .box{
  483. border:1px solid #d9d9d9;
  484. border-radius:4px;
  485. padding:4px 11px;
  486. color:rgba(0, 0, 0, 0.25);
  487. cursor: not-allowed;
  488. background:#fdfdfd;
  489. }
  490. .affix{
  491. .ant-affix{
  492. z-index: 101;
  493. display:inline-block
  494. }
  495. }
  496. /deep/.ant-radio-disabled + span{
  497. color:#000!important;
  498. }
  499. .tip{
  500. margin-left:10px;
  501. }
  502. .productInfo{
  503. display:flex;
  504. justify-content: space-between;
  505. }
  506. #setPromotion-productRange{
  507. /deep/.ant-select-dropdown{
  508. max-height:30vh !important;
  509. }
  510. }
  511. }
  512. </style>