edit.vue 17 KB

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