index.vue 9.8 KB

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