index.vue 10.0 KB

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