index.vue 10 KB

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