editModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <a-modal
  3. centered
  4. class="promotionEdit-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="modalTit"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. width="76%">
  11. <!-- 表单 -->
  12. <div>
  13. <a-spin :spinning="spinning" tip="Loading..." class="promotionEdit-content">
  14. <a-form-model
  15. id="promotionEdit-form"
  16. ref="ruleForm"
  17. :model="form"
  18. :rules="rules"
  19. :label-col="formItemLayout.labelCol"
  20. :wrapper-col="formItemLayout.wrapperCol"
  21. >
  22. <a-form-model-item label="标题名称" prop="title">
  23. <a-input
  24. id="promotionEdit-title"
  25. :maxLength="100"
  26. v-model.trim="form.title"
  27. placeholder="请输入标题名称(最多100个字符)"
  28. :disabled="pageType === 'edit'"
  29. allowClear/>
  30. </a-form-model-item>
  31. <a-form-model-item label="封面图片" prop="imageSet">
  32. <Upload
  33. v-if="pageType==='add'"
  34. class="upload"
  35. id="promotionEdit-imageSet"
  36. v-model="form.imageSet"
  37. ref="imageSet"
  38. :fileSize="10"
  39. :maxNums="10"
  40. @change="changeImage"
  41. listType="picture-card"></Upload>
  42. <div v-else>
  43. <img
  44. :src="con"
  45. alt="图片走丢了"
  46. width="80"
  47. height="80"
  48. v-for="(con,i) in images"
  49. style="margin-right:10px;"
  50. :key="i" />
  51. </div>
  52. <span class="upload-desc">说明:单张大小小于10Mb,最多10张;建议尺寸:宽(420px)*高(230px)</span>
  53. </a-form-model-item>
  54. <a-form-model-item label="排序" prop="sort">
  55. <a-input
  56. id="promotionEdit-sort"
  57. type="number"
  58. v-model.trim="form.sort"
  59. placeholder="请输入排序数字(数字越大越靠后)"
  60. :disabled="pageType === 'edit'"
  61. allowClear />
  62. </a-form-model-item>
  63. <a-form-model-item label="内容类型" prop="contentType">
  64. <v-select
  65. v-model="form.contentType"
  66. ref="saleStatus"
  67. id="promotion-saleStatus"
  68. code="PROMO_CONTENT_TYPE"
  69. showType="radio"
  70. :disabled="pageType === 'edit'"
  71. allowClear></v-select>
  72. </a-form-model-item>
  73. <a-form-model-item label="内容" prop="content" v-show="form.contentType =='IMAGE_CONTENT'">
  74. <editor
  75. v-show="pageType === 'add'"
  76. id="promotionEdit-editor"
  77. ref="editor"
  78. class="promotionEdit-editor"
  79. @on-change="editorChange"
  80. :cache="false"></editor>
  81. <div v-show="pageType === 'edit'" class="box" v-html="form.content"></div>
  82. </a-form-model-item>
  83. <a-form-model-item label="上传视频" prop="content" v-show="form.contentType =='VIDEO'">
  84. <Upload
  85. v-if="pageType==='add'"
  86. class="upload"
  87. id="promotionEdit-imageSet"
  88. v-model="videoPath"
  89. fileType="video/mp4"
  90. ref="imageSet"
  91. :fileSize="10"
  92. :maxNums="1"
  93. @change="changeVideo"
  94. listType="picture-card"></Upload>
  95. <div v-else>
  96. <video width="100" height="100">
  97. <source :src="videoPath" type="video/mp4"></source>
  98. </video>
  99. </div>
  100. <span class="upload-desc">说明:文件最大1G;视频:mp4.avi.flv</span>
  101. </a-form-model-item>
  102. <a-form-model-item label="跳转链接" prop="content" v-show="form.contentType =='LINK'">
  103. <a-input
  104. :disabled="pageType === 'edit'"
  105. id="promotionEdit-title"
  106. :maxLength="100"
  107. v-model.trim="form.content"
  108. placeholder="请输入跳转链接"
  109. allowClear />
  110. </a-form-model-item>
  111. <a-form-model-item label="是否发布" prop="enabledFlag">
  112. <a-radio-group button-style="solid" v-model="form.enabledFlag">
  113. <a-radio-button value="1">
  114. </a-radio-button>
  115. <a-radio-button value="0">
  116. </a-radio-button>
  117. </a-radio-group>
  118. </a-form-model-item>
  119. <a-form-model-item label="是否显示" prop="showFlag" v-show="form.enabledFlag == 1">
  120. <a-radio-group button-style="solid" v-model="form.showFlag">
  121. <a-radio-button value="1">
  122. 显示
  123. </a-radio-button>
  124. <a-radio-button value="0">
  125. 隐藏
  126. </a-radio-button>
  127. </a-radio-group>
  128. </a-form-model-item>
  129. </a-form-model>
  130. </a-spin>
  131. <div class="btn-cont">
  132. <a-button id="product-brand-edit-modal-back" @click="isShow = false" style="margin-right:15px;">取消</a-button>
  133. <a-button
  134. style="margin-right:15px;color: #fff;background-color: #39f;border-color: #39f;"
  135. @click="handleSee" v-if="form.contentType !='LINK'">预览</a-button>
  136. <a-button type="primary" id="product-brand-edit-modal-save" @click="handleSave">确定</a-button>
  137. </div>
  138. </div>
  139. <!-- 预览 -->
  140. <promotion-show-modal ref="showModal" :openModal="openShowModal" @close="openShowModal = false"></promotion-show-modal>
  141. </a-modal>
  142. </template>
  143. <script>
  144. import { commonMixin } from '@/utils/mixin'
  145. import moment from 'moment'
  146. import { VSelect, Upload } from '@/components'
  147. import Editor from '@/components/WEeditor'
  148. import { saveActive, promoTerminalDetail } from '@/api/promoTerminal'
  149. import promotionShowModal from './promotionShowModal'
  150. export default {
  151. name: 'ProductBrandEditModal',
  152. mixins: [commonMixin],
  153. components: { VSelect, Upload, Editor ,promotionShowModal},
  154. props: {
  155. openModal: { // 弹框显示状态
  156. type: Boolean,
  157. default: false
  158. },
  159. itemId: {
  160. type: [Number, String],
  161. default: ''
  162. },
  163. pageType: {
  164. type: String,
  165. default: 'add'
  166. }
  167. },
  168. computed: {
  169. modalTit () {
  170. return this.pageType != 'add' ? '发布修改' : '促销发布'
  171. }
  172. },
  173. data () {
  174. return {
  175. isShow: this.openModal, // 是否打开弹框
  176. spinning: false,
  177. formItemLayout: {
  178. labelCol: { span: 4 },
  179. wrapperCol: { span: 18 }
  180. },
  181. form: {
  182. promoActiveSn: undefined,
  183. title: '',
  184. contentType: 'IMAGE_CONTENT',
  185. imageSet: '',
  186. showFlag: undefined,
  187. content: '',
  188. enabledFlag: '1',
  189. sort: undefined
  190. },
  191. images: [],
  192. rules: {
  193. title: [
  194. { required: true, message: '请输入标题名称', trigger: 'blur' }
  195. ],
  196. imageSet: [
  197. { required: true, message: '请选择要上传的封面图片', trigger: 'change' }
  198. ],
  199. sort: [
  200. { required: true, message: '请输入排序数字', trigger: 'blur' }
  201. ],
  202. contentType: [
  203. { required: true, message: '请选择内容类型', trigger: 'change' }
  204. ],
  205. content: [
  206. { required: true, message: '请输入对应内容', trigger: ['blur', 'change'] }
  207. ],
  208. enabledFlag: [
  209. { required: true, message: '请选择是否发布', trigger: 'change' }
  210. ],
  211. showFlag: [
  212. { required: true, message: '请选择是否显示', trigger: 'change' }
  213. ]
  214. }
  215. }
  216. },
  217. methods: {
  218. // 预览
  219. handleSee () {
  220. this.$refs.showModal.pageInit({type:this.form.contentType,con:this.form.content})
  221. },
  222. onChange (e) {
  223. console.log('radio checked', e.target.value)
  224. },
  225. // 详情
  226. getDetail () {
  227. promoTerminalDetail({ sn: this.itemId }).then(res => {
  228. if (res.status == 200) {
  229. this.form.promoActiveSn = res.data.promoActiveSn
  230. this.form.title = res.data.title
  231. this.form.contentType = res.data.contentType
  232. this.form.showFlag = res.data.showFlag
  233. this.form.enabledFlag = res.data.enabledFlag
  234. this.form.sort = res.data.sort
  235. this.images = res.data.imageSet
  236. this.form.imageSet = res.data.imageSet
  237. this.form.content = res.data.content
  238. if (res.data.contentType == 'IMAGE_CONTENT') {
  239. this.$refs.editor.setHtml(res.data.content)
  240. } else if (res.data.contentType == 'VIDEO') {
  241. this.videoPath = res.data.content
  242. }
  243. }
  244. })
  245. },
  246. // 确定
  247. handleSave () {
  248. const _this = this
  249. _this.$refs.ruleForm.validate(valid => {
  250. if (valid) {
  251. _this.form.promoActiveSn = this.itemId
  252. const formData = JSON.parse(JSON.stringify(_this.form))
  253. formData.imageSet = formData.imageSet ? formData.imageSet.split(',') : []
  254. _this.spinning = true
  255. saveActive(formData).then(res => {
  256. if (res.status == 200) {
  257. _this.$message.success(res.message)
  258. _this.$emit('ok')
  259. _this.isShow = false
  260. _this.spinning = false
  261. } else {
  262. _this.spinning = false
  263. }
  264. })
  265. } else {
  266. return false
  267. }
  268. })
  269. },
  270. // 图片上传
  271. changeImage (file) {
  272. this.form.imageSet = file
  273. },
  274. // 视频上传
  275. changeVideo (file) {
  276. this.form.content = file
  277. },
  278. // 文本编辑器
  279. editorChange (html, text) {
  280. this.form.content = html
  281. }
  282. },
  283. watch: {
  284. // 父页面传过来的弹框状态
  285. openModal (newValue, oldValue) {
  286. this.isShow = newValue
  287. },
  288. // 重定义的弹框状态
  289. isShow (newValue, oldValue) {
  290. if (!newValue) {
  291. this.$emit('close')
  292. this.$refs.imageSet.setFileList('')
  293. this.$refs.editor.setHtml('')
  294. this.form = {
  295. promoActiveSn: undefined,
  296. title: '',
  297. contentType: 'IMAGE_CONTENT',
  298. imageSet: '',
  299. showFlag: undefined,
  300. content: '',
  301. enabledFlag: '1',
  302. sort: undefined
  303. }
  304. this.images = []
  305. this.$refs.ruleForm.resetFields()
  306. } else {
  307. if (this.pageType === 'edit') {
  308. this.getDetail()
  309. }
  310. }
  311. }
  312. }
  313. }
  314. </script>
  315. <style lang="less" scoped>
  316. .promotionEdit-modal{
  317. .promotionEdit-content{
  318. max-height:60vh;
  319. overflow-y: scroll;
  320. }
  321. .ant-modal-body {
  322. padding: 40px 40px 24px;
  323. }
  324. .upload{
  325. width: 100%!important;
  326. }
  327. /deep/.upload-file .ant-upload-list-item-info{
  328. padding:2px !important;
  329. }
  330. // 商品图片描述
  331. .upload-desc{
  332. font-size: 12px;
  333. color: #808695;
  334. }
  335. // 文本编辑器 工具栏样式换行
  336. .promotionEdit-editor{
  337. .w-e-toolbar{
  338. flex-wrap: wrap;
  339. }
  340. }
  341. .btn-cont {
  342. text-align: center;
  343. margin: 35px 0 10px;
  344. }
  345. #promotionEdit-attachList{
  346. height: auto;
  347. }
  348. a{
  349. color: inherit;
  350. }
  351. .box{
  352. border:1px solid #d9d9d9;
  353. border-radius:4px;
  354. padding:4px 11px;
  355. color:rgba(0, 0, 0, 0.25);
  356. cursor: not-allowed;
  357. background:#fdfdfd;
  358. }
  359. }
  360. </style>