index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <zj-tab-page ref="tabPage" :defaultActives="[{ key: 'list', label: $route.meta.title + '-列表', essential: true }]">
  3. <template slot-scope="{ activeKey, data }">
  4. <template-page
  5. v-if="activeKey == 'list'"
  6. ref="pageRef"
  7. :get-list="getList"
  8. :table-attributes="tableAttributes"
  9. :table-events="tableEvents"
  10. :options-evens-group="optionsEvensGroup"
  11. :moreParameters="moreParameters"
  12. :column-parsing="columnParsing"
  13. :operation="operation()"
  14. :exportList="exportList"
  15. >
  16. </template-page>
  17. <div v-if="~['add', 'edit'].indexOf(activeKey)">
  18. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  19. <zj-form-module
  20. title=""
  21. label-width="100px"
  22. :showPackUp="false"
  23. :form-data="formData"
  24. :form-items="formItems"
  25. >
  26. </zj-form-module>
  27. </zj-form-container>
  28. <div slot="footer" class="dialog-footer">
  29. <el-button size="mini" @click="data.removeTab()">取 消</el-button>
  30. <el-button size="mini" @click="formConfirm(data.removeTab)" type="primary">确 定</el-button>
  31. </div>
  32. </div>
  33. </template>
  34. </zj-tab-page>
  35. </template>
  36. <script>
  37. import TemplatePage from '@/components/template/template-page-1.vue'
  38. import import_mixin from '@/components/template/import_mixin.js'
  39. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  40. import {
  41. carouselMapListPageV2,
  42. carouselMapPageExport,
  43. changeBannerStatus,
  44. addBanner,
  45. editBanner,
  46. getBannerDetail,
  47. deleteBanner,
  48. getGoodsList,
  49. batchDeleteBanner
  50. } from '@/api/setting'
  51. import ImageUpload from '@/components/file-upload'
  52. import operation_mixin from '@/components/template/operation_mixin.js'
  53. export default {
  54. components: { TemplatePage, ImageUpload },
  55. mixins: [import_mixin, operation_mixin],
  56. data() {
  57. return {
  58. // 表格属性
  59. tableAttributes: {
  60. // 启用勾选列
  61. selectColumn: true
  62. },
  63. // 表格事件
  64. tableEvents: {
  65. 'selection-change': this.selectionChange
  66. },
  67. // 勾选选中行
  68. recordSelected: [],
  69. /** 表单变量 */
  70. formDialogType: 0,
  71. formDialogTitles: ['新增', '编辑'],
  72. formDialog: false,
  73. formData: {
  74. carouselName: '',
  75. imgSrc: [],
  76. state: true,
  77. sortNum: '',
  78. port: '',
  79. type: '',
  80. goodsId: '',
  81. appId: '',
  82. linkUrl: ''
  83. },
  84. goodsList: [],
  85. formType: 'add',
  86. formVisible: false
  87. }
  88. },
  89. computed: {
  90. // 事件组合
  91. optionsEvensGroup() {
  92. return [
  93. [
  94. [
  95. this.optionsEvensAuth('add', {
  96. click: () => {
  97. this.openForm('add')
  98. }
  99. })
  100. ]
  101. ],
  102. [
  103. [
  104. this.optionsEvensAuth('del', {
  105. name: '批量删除',
  106. click: () => {
  107. this.batchDelete()
  108. }
  109. })
  110. ]
  111. ]
  112. ]
  113. },
  114. // 更多参数
  115. moreParameters() {
  116. return []
  117. },
  118. formItems() {
  119. return [
  120. {
  121. md: 6,
  122. isShow: true,
  123. name: 'el-input',
  124. attributes: { placeholder: '请输入' },
  125. formItemAttributes: {
  126. label: '轮播图名称',
  127. prop: 'carouselName',
  128. rules: [...required]
  129. }
  130. },
  131. {
  132. md: 6,
  133. isShow: true,
  134. name: 'el-input',
  135. attributes: { placeholder: '请输入' },
  136. formItemAttributes: {
  137. label: '排序',
  138. prop: 'sortNum',
  139. rules: []
  140. }
  141. },
  142. {
  143. md: 8,
  144. isShow: true,
  145. name: 'el-radio',
  146. options: [
  147. { label: '轮播图', value: 'SHOP' },
  148. { label: '以旧换新入口', value: 'YJHX' },
  149. { label: '二手商城', value: 'ESHOP' }
  150. ],
  151. attributes: { filterable: true, placeholder: '请选择' },
  152. formItemAttributes: {
  153. label: '类型',
  154. prop: 'port',
  155. rules: []
  156. },
  157. events: {
  158. change: e=>{
  159. if(e=='YJHX'){
  160. this.formData.type = 4
  161. }else{
  162. this.formData.type = 1
  163. }
  164. }
  165. }
  166. },
  167. {
  168. md: 8,
  169. isShow: true,
  170. name: 'slot-component',
  171. // options: [
  172. // { label: '分类列表', value: 1 },
  173. // { label: '商品链接', value: 1 },
  174. // // { label: '凡科活动链接', value: 2 },
  175. // { label: '专区活动链接', value: 3 }
  176. // ],
  177. formItemAttributes: {
  178. label: '链接类型',
  179. prop: 'type',
  180. rules: []
  181. },render: (h, { props, onInput }) => {
  182. var { value } = props
  183. return <el-radio-group v-model={this.formData.type}>
  184. {this.formData.port == 'YJHX'?<el-radio label={4}>分类列表</el-radio>:null}
  185. <el-radio label={3}>专区活动</el-radio>
  186. <el-radio label={1}>商品链接</el-radio>
  187. </el-radio-group>
  188. }
  189. },
  190. ...(() => {
  191. if (this.formData.type == 1) {
  192. this.formData.appid = ''
  193. this.formData.linkUrl = ''
  194. // this.formData.goodsId = ""
  195. return [
  196. {
  197. md: 6,
  198. isShow: true,
  199. name: 'el-select',
  200. options: this.goodsList,
  201. attributes: { filterable: true, placeholder: '请选择' },
  202. formItemAttributes: {
  203. label: '选择活动',
  204. prop: 'goodsId',
  205. rules: []
  206. }
  207. }
  208. ]
  209. } else if (this.formData.type == 2) {
  210. this.formData.goodsId = ''
  211. return [
  212. {
  213. md: 6,
  214. isShow: true,
  215. name: 'el-input',
  216. attributes: { placeholder: '请输入' },
  217. formItemAttributes: {
  218. label: '活动APPID',
  219. prop: 'appid',
  220. rules: []
  221. }
  222. },
  223. {
  224. md: 6,
  225. isShow: true,
  226. name: 'el-input',
  227. attributes: { placeholder: '请输入' },
  228. formItemAttributes: {
  229. label: '活动路径',
  230. prop: 'linkUrl',
  231. rules: []
  232. }
  233. }
  234. ]
  235. } else if (this.formData.type == 3) {
  236. this.formData.appid = ''
  237. this.formData.linkUrl = ''
  238. // this.formData.goodsId = ""
  239. return [
  240. {
  241. md: 6,
  242. isShow: true,
  243. name: 'el-select',
  244. options: [
  245. { value: 2, label: '首页弹窗' },
  246. { value: 3, label: '胶囊图' },
  247. { value: 4, label: '活动专区2-左侧专区' },
  248. { value: 5, label: '活动专区2-右侧专区' },
  249. { value: 6, label: '专场专区-01' },
  250. { value: 7, label: '专场专区-02' },
  251. { value: 8, label: '专场专区-03' },
  252. { value: 9, label: '专场专区-04' },
  253. { value: 10, label: '专题精选-01' },
  254. { value: 11, label: '专题精选-02' },
  255. { value: 12, label: '专题精选-03' },
  256. { value: 13, label: '底部广告图' }
  257. ],
  258. attributes: { filterable: true, placeholder: '请选择' },
  259. formItemAttributes: {
  260. label: '选择活动',
  261. prop: 'goodsId',
  262. rules: []
  263. }
  264. }
  265. ]
  266. }
  267. return []
  268. })(),
  269. {
  270. md: 24,
  271. isShow: true,
  272. name: 'slot-component',
  273. formItemAttributes: {
  274. label: '封面图片',
  275. prop: 'imgSrc',
  276. rules: [...required]
  277. },
  278. render: (h, { props, onInput }) => {
  279. var { value } = props
  280. return <ImageUpload fileList={this.formData.imgSrc} uid="imgSrc_materials_drawing_images" limit={1} />
  281. }
  282. }
  283. ]
  284. }
  285. },
  286. methods: {
  287. // 列表请求函数
  288. getList: carouselMapListPageV2,
  289. // 列表导出函数
  290. exportList: carouselMapPageExport,
  291. // 表格列解析渲染数据更改
  292. columnParsing(item, defaultData) {
  293. return defaultData
  294. },
  295. // 监听勾选变化
  296. selectionChange(data) {
  297. this.recordSelected = data
  298. },
  299. // 表格操作列
  300. operation() {
  301. return this.operationBtn({
  302. edit: {
  303. btnType: 'text',
  304. click: ({ row, index, column }) => {
  305. this.openForm('edit', row.id)
  306. }
  307. },
  308. del: {
  309. btnType: 'text',
  310. prompt: '确定删除吗?',
  311. click: ({ row, index, column }) => {
  312. deleteBanner({ carouselMapId: row.id }).then(() => {
  313. this.$message({ type: 'success', message: '删除成功!' })
  314. this.$refs.pageRef.refreshList()
  315. })
  316. }
  317. },
  318. status: {
  319. btnType: 'text',
  320. name: ({ row, index, column }) => {
  321. return row.state ? '隐藏' : '显示'
  322. },
  323. prompt: ({ row, index, column }) => {
  324. return `确定${row.state ? '隐藏' : '显示'}吗?`
  325. },
  326. click: ({ row, index, column }) => {
  327. changeBannerStatus({ carouselMapId: row.id, state: !row.state }).then(() => {
  328. this.$message({ type: 'success', message: `${row.state ? '隐藏' : '显示'}成功!` })
  329. this.$refs.pageRef.refreshList()
  330. })
  331. }
  332. }
  333. })
  334. },
  335. // 取消 新增编辑
  336. formCancel() {
  337. this.formVisible = false
  338. this.$refs?.formRef?.resetFields()
  339. this.$data.formData = this.$options.data().formData
  340. },
  341. // 打开 新增编辑 网点表单
  342. openForm(type, id) {
  343. this.$refs.tabPage.addTab({
  344. // 对应显示的模块
  345. activeKey: type,
  346. // 唯一标识
  347. key: type,
  348. // 页签名称
  349. label: { edit: '编辑', add: '新增' }[type],
  350. // 打开时事件
  351. triggerEvent: () => {
  352. this.formCancel()
  353. this.$nextTick(() => {
  354. this.formType = type
  355. this.formVisible = true
  356. if (type == 'add') {
  357. this.formDialogType = 0
  358. } else {
  359. this.formDialogType = 1
  360. getBannerDetail({ id }).then(res => {
  361. Object.assign(this.formData, res.data, {
  362. imgSrc: res.data.imgSrc ? [{ url: res.data.imgSrc }] : []
  363. })
  364. getGoodsList({
  365. pageNum: 1,
  366. pageSize: -1
  367. }).then(res => {
  368. this.goodsList = res.data.records.map(item => ({
  369. value: item.goodsId,
  370. label: item.goodsName
  371. }))
  372. })
  373. })
  374. }
  375. })
  376. },
  377. // 关闭时事件
  378. closeEvent: () => {
  379. this.formCancel()
  380. }
  381. })
  382. },
  383. formConfirm(cancel) {
  384. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  385. if (valid) {
  386. ;[addBanner, editBanner]
  387. [this.formDialogType]({
  388. ...this.formData,
  389. imgSrc: this.formData.imgSrc.map(item => item.url).join(',')
  390. })
  391. .then(res => {
  392. this.$message({ type: 'success', message: `${{ edit: '编辑', add: '新增' }[this.formType]}成功!` })
  393. cancel('list')
  394. this.$refs.pageRef.refreshList()
  395. })
  396. }
  397. })
  398. },
  399. batchDelete() {
  400. if (this.recordSelected && this.recordSelected.length > 0) {
  401. this.$confirm('此操作将删除选中轮播图, 是否继续?', '提示', {
  402. confirmButtonText: '确定',
  403. cancelButtonText: '取消',
  404. type: 'warning'
  405. })
  406. .then(() => {
  407. let ids = []
  408. this.recordSelected.forEach(value => {
  409. ids.push(value.id)
  410. })
  411. batchDeleteBanner(ids).then(() => {
  412. this.$message({ type: 'success', message: '删除成功!' })
  413. this.$refs.pageRef.refreshList()
  414. })
  415. })
  416. .catch(() => {})
  417. } else {
  418. this.$errorMsg('请选择要删除的轮播图')
  419. }
  420. }
  421. }
  422. }
  423. </script>
  424. <style lang="scss" scoped></style>
  425. <style>
  426. .dialog-footer {
  427. padding: 0 30px;
  428. display: flex;
  429. justify-content: flex-end;
  430. }
  431. </style>