edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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. 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="!isDisabled"
  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="isDisabled" 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" :chooseInfo="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. contentLink: [{ required: true, message: '请输入对应内容', trigger: ['blur', 'change'] }]
  223. }
  224. }
  225. },
  226. methods: {
  227. // 部分经销商 选择经销商成功
  228. addDealerOk (list) {
  229. this.chooseDealerList = list
  230. this.openDealerModal = false
  231. },
  232. // 禁用日期时间
  233. disabledDate (current) {
  234. return current && current < moment().startOf('day')
  235. },
  236. // 轮播时间
  237. dateChange (date, dateString) {
  238. this.form.time = date
  239. if (dateString[0] != '' && dateString[1] != '') {
  240. this.form.bannerStartDate = dateString[0] + ' 00:00:00'
  241. this.form.bannerEndDate = dateString[1] + ' 23:59:59'
  242. }
  243. },
  244. // 打开 选择经销商弹窗
  245. handleDealerModal () {
  246. this.chooseSnList = this.chooseDealerList.map(item => item.dealerSn)
  247. this.openDealerModal = true
  248. },
  249. // 关闭 选择经销商弹窗
  250. closeDealerModal () {
  251. this.chooseSnList = []
  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. // 参与经销商 change
  262. changeDealerScope (val) {
  263. this.form.allDealerFlag = val
  264. if (val == '1') {
  265. this.chooseDealerList = []
  266. }
  267. },
  268. // 返回列表
  269. handleBack () {
  270. this.$router.push({ name: 'carouselImageList', query: { closeLastOldTab: true } })
  271. },
  272. // 详情
  273. getDetail () {
  274. const _this = this
  275. shopBannerDetail({ bannerSn: this.$route.params.sn }).then(res => {
  276. if (res.status == 200) {
  277. if (res.data.bizType && res.data.bizType === 'SHOP_PROMO') {
  278. _this.isDisabled = true
  279. }
  280. if (res.data.contentType == 'IMAGE_CONTENT') {
  281. _this.$refs.editor.setHtml(res.data.content)
  282. } else if (res.data.contentType == 'VIDEO') {
  283. _this.$refs.videoSet.setFileList(res.data.content)
  284. } else if (res.data.contentType == 'LINK') {
  285. res.data.contentLink = res.data.content
  286. }
  287. if (res.data.allDealerFlag == '0') {
  288. this.chooseDealerList = res.data.dealerList
  289. }
  290. _this.$refs.imageSet.setFileList(res.data.imageUrl)
  291. _this.form = res.data
  292. _this.form.time = [res.data.bannerStartDate, res.data.bannerEndDate]
  293. }
  294. })
  295. },
  296. // 确定保存 验证必填
  297. handleSave (type) {
  298. const _this = this
  299. if (_this.form.contentType === 'LINK') {
  300. _this.form.content = _this.form.contentLink
  301. }
  302. // 验证组件必填项
  303. _this.$refs.ruleForm.validate(valid => {
  304. if (valid) {
  305. _this.savePartInfo(type)
  306. }
  307. })
  308. },
  309. // 保存
  310. savePartInfo (type) {
  311. const _this = this
  312. if (_this.form.allDealerFlag == '0') {
  313. if (_this.chooseDealerList && _this.chooseDealerList.length == 0) {
  314. _this.$message.warning('请选择参与经销商!')
  315. return
  316. }
  317. _this.form.dealerSnList = _this.chooseDealerList.map(con => con.dealerSn)
  318. }
  319. _this.form.bannerSn = _this.$route.params.sn || undefined
  320. var formData = JSON.parse(JSON.stringify(_this.form))
  321. delete formData.time
  322. delete formData.contentLink
  323. _this.spinning = true
  324. saveShopBanner(formData).then(res => {
  325. if (res.status == 200) {
  326. _this.$message.success(res.message)
  327. _this.$nextTick(() => {
  328. _this.handleBack()
  329. _this.resetSearchForm()
  330. })
  331. _this.spinning = false
  332. } else {
  333. _this.spinning = false
  334. }
  335. })
  336. },
  337. // 图片上传
  338. changeImage (file) {
  339. this.form.imageUrl = file
  340. },
  341. // 视频上传
  342. changeVideo (file) {
  343. this.form.content = file
  344. },
  345. // 文本编辑器
  346. editorChange (html, text) {
  347. this.form.content = html
  348. if (html) {
  349. this.$refs.ruleForm.clearValidate('content')
  350. }
  351. },
  352. // 重置
  353. resetSearchForm () {
  354. this.$refs.imageSet.setFileList('')
  355. if (this.contentType === 'VIDEO') {
  356. this.$refs.videoSet.setFileList('')
  357. }
  358. if (this.contentType === 'IMAGE_CONTENT') {
  359. this.$refs.editor.setHtml('')
  360. }
  361. this.form = {
  362. bannerSn: undefined, // 轮播图sn
  363. bannerName: '', // 轮播图名称
  364. time: [], // 轮播时间
  365. bannerStartDate: undefined, // 轮播图活动开始时间
  366. bannerEndDate: undefined, // 轮播图活动结束时间
  367. sort: undefined, // 排序
  368. allDealerFlag: '1', // 参与经销商 0 部分 1全部
  369. dealerSnList: [], // 已选经销商sn列表
  370. imageUrl: '', // 图片
  371. contentType: 'LINK', // 内容类型
  372. content: '', // 内容
  373. contentLink: '',
  374. state: 'UNPUBLISH'
  375. }
  376. this.isDisabled = false
  377. if (this.$refs.ruleForm) {
  378. this.$refs.ruleForm.resetFields()
  379. }
  380. },
  381. // 初始化
  382. pageInit () {
  383. if (this.$route.params.sn) {
  384. this.getDetail()
  385. if (this.$route.params.bizType && this.$route.params.bizType === 'SHOP_PROMO') {
  386. this.notShowSel.splice(0, 1)
  387. }
  388. }
  389. }
  390. },
  391. mounted () {
  392. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  393. this.pageInit()
  394. }
  395. },
  396. activated () {
  397. // 如果是新页签打开,则重置当前页面
  398. if (this.$store.state.app.isNewTab) {
  399. this.pageInit()
  400. }
  401. // 仅刷新列表,不重置页面
  402. if (this.$store.state.app.updateList) {
  403. this.pageInit()
  404. }
  405. },
  406. beforeRouteEnter (to, from, next) {
  407. next(vm => {})
  408. }
  409. }
  410. </script>
  411. <style lang="less" scoped>
  412. .carouselImageEdit-wrap{
  413. position: relative;
  414. height: 100%;
  415. box-sizing: border-box;
  416. padding-bottom:51px;
  417. >.ant-spin-nested-loading{
  418. overflow-y: scroll;
  419. height: 100%;
  420. }
  421. /deep/.ant-form-item{
  422. margin-bottom:8px;
  423. }
  424. .carouselImageEdit-cont{
  425. margin-bottom: 10px;
  426. }
  427. .upload{
  428. width: 100%!important;
  429. }
  430. // 文本编辑器 工具栏样式换行
  431. .carouselImageEdit-editor{
  432. .w-e-toolbar{
  433. flex-wrap: wrap;
  434. z-index: 0;
  435. }
  436. }
  437. .buyerBox{
  438. border:1px solid #d9d9d9;
  439. margin-top:10px;
  440. border-radius:4px;padding:4px 10px;
  441. background:#f2f2f2;max-height:130px;
  442. overflow-y:scroll;
  443. }
  444. // 商品图片描述
  445. .upload-desc{
  446. font-size: 12px;
  447. color: #808695;
  448. }
  449. #carouselImageEdit-attachList{
  450. height: auto;
  451. }
  452. .box{
  453. border:1px solid #d9d9d9;
  454. border-radius:4px;
  455. padding:4px 11px;
  456. color:rgba(0, 0, 0, 0.25);
  457. cursor: not-allowed;
  458. background:#fdfdfd;
  459. }
  460. .affix{
  461. .ant-affix{
  462. z-index: 101;
  463. display:inline-block
  464. }
  465. }
  466. /deep/.ant-radio-disabled + span{
  467. color:#000!important;
  468. }
  469. .tip{
  470. margin-left:10px;
  471. }
  472. .productInfo{
  473. display:flex;
  474. justify-content: space-between;
  475. }
  476. #setPromotion-productRange{
  477. /deep/.ant-select-dropdown{
  478. max-height:30vh !important;
  479. }
  480. }
  481. }
  482. </style>