index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. <el-dialog
  34. width="50%"
  35. title="商品列表"
  36. :visible.sync="innerVisible"
  37. append-to-body>
  38. <el-input v-model="search" placeholder="输入名称搜索">
  39. <el-button slot="append" icon="el-icon-search" @click="searchGoods()"></el-button>
  40. </el-input>
  41. <div class="table" style="margin-top: 10px">
  42. <el-table
  43. :data="goodsList"
  44. height="400px"
  45. style="width: 100%">
  46. <el-table-column align="center">
  47. <template slot="header"></template>
  48. <template slot-scope="scope">
  49. <el-button type="primary" size="small" @click="selGoods(scope.row)" :disabled="scope.row.promotionGroup" >选择</el-button>
  50. </template>
  51. </el-table-column>
  52. <el-table-column label="商品名称" prop="goodsName"></el-table-column>
  53. <el-table-column label="商品图片" prop="imgUrl" align="center">
  54. <template slot-scope="scope">
  55. <div class="demo-image__preview">
  56. <el-image style="width: 40px; height: 40px" :src="scope.row.imgUrl" :preview-src-list="[scope.row.imgUrl]">
  57. <div slot="error" class="image-slot">
  58. <i class="el-icon-picture-outline"></i>
  59. </div>
  60. </el-image>
  61. </div>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. </div>
  66. <div class="pagination clearfix">
  67. <div class="fr">
  68. <el-pagination
  69. @size-change="innerHandleSizeChange"
  70. @current-change="innerHandleCurrentChange"
  71. :current-page="innerCurrentPage"
  72. :page-sizes="[10, 20, 30, 50]"
  73. :page-size="10"
  74. layout="total, sizes, prev, pager, next, jumper"
  75. :total="innerListTotal">
  76. </el-pagination>
  77. </div>
  78. </div>
  79. <div slot="footer" class="dialog-footer">
  80. <el-button @click="innerVisible = false">取 消</el-button>
  81. </div>
  82. </el-dialog>
  83. </template>
  84. </zj-tab-page>
  85. </template>
  86. <script>
  87. import TemplatePage from '@/components/template/template-page-1.vue'
  88. import import_mixin from '@/components/template/import_mixin.js'
  89. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  90. import {
  91. carouselMapListPageV2,
  92. carouselMapPageExport,
  93. changeBannerStatus,
  94. addBanner,
  95. editBanner,
  96. getBannerDetail,
  97. deleteBanner,
  98. getGoodsList,
  99. batchDeleteBanner
  100. } from '@/api/setting'
  101. import ImageUpload from '@/components/file-upload'
  102. import operation_mixin from '@/components/template/operation_mixin.js'
  103. export default {
  104. components: { TemplatePage, ImageUpload },
  105. mixins: [import_mixin, operation_mixin],
  106. data() {
  107. return {
  108. // 表格属性
  109. tableAttributes: {
  110. // 启用勾选列
  111. selectColumn: true
  112. },
  113. // 表格事件
  114. tableEvents: {
  115. 'selection-change': this.selectionChange
  116. },
  117. // 勾选选中行
  118. recordSelected: [],
  119. /** 表单变量 */
  120. formDialogType: 0,
  121. formDialogTitles: ['新增', '编辑'],
  122. formDialog: false,
  123. formData: {
  124. carouselName: '',
  125. imgSrc: [],
  126. state: true,
  127. sortNum: '',
  128. port: 'SHOP',
  129. type: '',
  130. goodsId: '',
  131. appId: '',
  132. linkUrl: '',
  133. selGoodsName: '',
  134. goodsId: ''
  135. },
  136. goodsList: [],
  137. formType: 'add',
  138. formVisible: false,
  139. innerCurrentPage: 1, // 内联当前页码
  140. innerPageSize: 10, // 内联每页数量
  141. innerListTotal: 0, // 内联列表总数
  142. innerVisible: false,
  143. goodsList: [],
  144. search: '',
  145. }
  146. },
  147. computed: {
  148. // 事件组合
  149. optionsEvensGroup() {
  150. return [
  151. [
  152. [
  153. this.optionsEvensAuth('add', {
  154. click: () => {
  155. this.openForm('add')
  156. }
  157. })
  158. ]
  159. ],
  160. [
  161. [
  162. this.optionsEvensAuth('del', {
  163. name: '批量删除',
  164. click: () => {
  165. this.batchDelete()
  166. }
  167. })
  168. ]
  169. ]
  170. ]
  171. },
  172. // 更多参数
  173. moreParameters() {
  174. return []
  175. },
  176. formItems() {
  177. return [
  178. {
  179. md: 6,
  180. isShow: true,
  181. name: 'el-input',
  182. attributes: { placeholder: '请输入' },
  183. formItemAttributes: {
  184. label: '轮播图名称',
  185. prop: 'carouselName',
  186. rules: [...required]
  187. }
  188. },
  189. {
  190. md: 6,
  191. isShow: true,
  192. name: 'el-input',
  193. attributes: { placeholder: '请输入' },
  194. formItemAttributes: {
  195. label: '排序',
  196. prop: 'sortNum',
  197. rules: []
  198. }
  199. },
  200. {
  201. md: 8,
  202. isShow: true,
  203. name: 'el-radio',
  204. options: [
  205. { label: '轮播图', value: 'SHOP' },
  206. { label: '以旧换新入口', value: 'YJHX' },
  207. { label: '二手商城', value: 'ESHOP' }
  208. ],
  209. attributes: { filterable: true, placeholder: '请选择' },
  210. formItemAttributes: {
  211. label: '类型',
  212. prop: 'port',
  213. rules: []
  214. },
  215. events: {
  216. change: e=>{
  217. this.clearGoodsId()
  218. if(e=='YJHX'){
  219. this.formData.type = 4
  220. }else{
  221. this.formData.type = 1
  222. }
  223. }
  224. }
  225. },
  226. {
  227. md: 8,
  228. isShow: true,
  229. name: 'slot-component',
  230. // options: [
  231. // { label: '分类列表', value: 1 },
  232. // { label: '商品链接', value: 1 },
  233. // // { label: '凡科活动链接', value: 2 },
  234. // { label: '专区活动链接', value: 3 }
  235. // ],
  236. formItemAttributes: {
  237. label: '链接类型',
  238. prop: 'type',
  239. rules: []
  240. },render: (h, { props, onInput }) => {
  241. var { value } = props
  242. return <el-radio-group v-model={this.formData.type}>
  243. {this.formData.port == 'YJHX'?<el-radio label={4}>分类列表</el-radio>:null}
  244. <el-radio label={3}>专区活动</el-radio>
  245. <el-radio label={1}>商品链接</el-radio>
  246. </el-radio-group>
  247. }
  248. },
  249. ...(() => {
  250. if (this.formData.type == 1) {
  251. this.formData.appid = ''
  252. this.formData.linkUrl = ''
  253. // this.formData.goodsId = ""
  254. return [
  255. {
  256. md: 6,
  257. isShow: true,
  258. name: 'slot-component',
  259. options: this.goodsList,
  260. attributes: { },
  261. formItemAttributes: {
  262. label: '链接商品',
  263. prop: 'goodsId',
  264. rules: []
  265. },
  266. render: (h, { props, onInput }) => {
  267. var { value } = props
  268. return (
  269. <div>
  270. <el-button onClick={()=>{
  271. console.log(11)
  272. this.showGoods()
  273. }} size="small">查找商品</el-button>
  274. <el-button onClick={()=>{
  275. this.clearGoodsId()
  276. }} size="small">清除</el-button>
  277. </div>
  278. )
  279. }
  280. },
  281. {
  282. md: 6,
  283. isShow: true,
  284. name: 'el-input',
  285. attributes: { placeholder: '请输入',disabled: true },
  286. formItemAttributes: {
  287. label: '链接商品名称',
  288. prop: 'goodsName',
  289. rules: []
  290. }
  291. },
  292. ]
  293. } else if (this.formData.type == 2) {
  294. this.formData.goodsId = ''
  295. return [
  296. {
  297. md: 6,
  298. isShow: true,
  299. name: 'el-input',
  300. attributes: { placeholder: '请输入' },
  301. formItemAttributes: {
  302. label: '活动APPID',
  303. prop: 'appid',
  304. rules: []
  305. }
  306. },
  307. {
  308. md: 6,
  309. isShow: true,
  310. name: 'el-input',
  311. attributes: { placeholder: '请输入' },
  312. formItemAttributes: {
  313. label: '活动路径',
  314. prop: 'linkUrl',
  315. rules: []
  316. }
  317. }
  318. ]
  319. } else if (this.formData.type == 3) {
  320. this.formData.appid = ''
  321. this.formData.linkUrl = ''
  322. // this.formData.goodsId = ""
  323. return [
  324. {
  325. md: 6,
  326. isShow: true,
  327. name: 'el-select',
  328. options: [
  329. { value: 2, label: '首页弹窗' },
  330. { value: 3, label: '胶囊图' },
  331. { value: 4, label: '活动专区2-左侧专区' },
  332. { value: 5, label: '活动专区2-右侧专区' },
  333. { value: 6, label: '专场专区-01' },
  334. { value: 7, label: '专场专区-02' },
  335. { value: 8, label: '专场专区-03' },
  336. { value: 9, label: '专场专区-04' },
  337. { value: 10, label: '专题精选-01' },
  338. { value: 11, label: '专题精选-02' },
  339. { value: 12, label: '专题精选-03' },
  340. { value: 13, label: '底部广告图' }
  341. ],
  342. attributes: { filterable: true, placeholder: '请选择' },
  343. formItemAttributes: {
  344. label: '选择活动',
  345. prop: 'goodsId',
  346. rules: []
  347. }
  348. }
  349. ]
  350. }
  351. return []
  352. })(),
  353. {
  354. md: 24,
  355. isShow: true,
  356. name: 'slot-component',
  357. formItemAttributes: {
  358. label: '封面图片',
  359. prop: 'imgSrc',
  360. rules: [...required]
  361. },
  362. render: (h, { props, onInput }) => {
  363. var { value } = props
  364. return <ImageUpload fileList={this.formData.imgSrc} uid="imgSrc_materials_drawing_images" limit={1} />
  365. }
  366. }
  367. ]
  368. }
  369. },
  370. methods: {
  371. // 列表请求函数
  372. getList: carouselMapListPageV2,
  373. // 列表导出函数
  374. exportList: carouselMapPageExport,
  375. // 表格列解析渲染数据更改
  376. columnParsing(item, defaultData) {
  377. return defaultData
  378. },
  379. // 监听勾选变化
  380. selectionChange(data) {
  381. this.recordSelected = data
  382. },
  383. // 表格操作列
  384. operation() {
  385. return this.operationBtn({
  386. edit: {
  387. btnType: 'text',
  388. click: ({ row, index, column }) => {
  389. this.openForm('edit', row.id)
  390. }
  391. },
  392. del: {
  393. btnType: 'text',
  394. prompt: '确定删除吗?',
  395. click: ({ row, index, column }) => {
  396. deleteBanner({ carouselMapId: row.id }).then(() => {
  397. this.$message({ type: 'success', message: '删除成功!' })
  398. this.$refs.pageRef.refreshList()
  399. })
  400. }
  401. },
  402. status: {
  403. btnType: 'text',
  404. name: ({ row, index, column }) => {
  405. return row.state ? '隐藏' : '显示'
  406. },
  407. prompt: ({ row, index, column }) => {
  408. return `确定${row.state ? '隐藏' : '显示'}吗?`
  409. },
  410. click: ({ row, index, column }) => {
  411. changeBannerStatus({ carouselMapId: row.id, state: !row.state }).then(() => {
  412. this.$message({ type: 'success', message: `${row.state ? '隐藏' : '显示'}成功!` })
  413. this.$refs.pageRef.refreshList()
  414. })
  415. }
  416. }
  417. })
  418. },
  419. // 取消 新增编辑
  420. formCancel() {
  421. this.formVisible = false
  422. this.$refs?.formRef?.resetFields()
  423. this.$data.formData = this.$options.data().formData
  424. },
  425. // 打开 新增编辑 网点表单
  426. openForm(type, id) {
  427. this.$refs.tabPage.addTab({
  428. // 对应显示的模块
  429. activeKey: type,
  430. // 唯一标识
  431. key: type,
  432. // 页签名称
  433. label: { edit: '编辑', add: '新增' }[type],
  434. // 打开时事件
  435. triggerEvent: () => {
  436. this.formCancel()
  437. this.$nextTick(() => {
  438. this.formType = type
  439. this.formVisible = true
  440. if (type == 'add') {
  441. this.formDialogType = 0
  442. } else {
  443. this.formDialogType = 1
  444. getBannerDetail({ id }).then(res => {
  445. Object.assign(this.formData, res.data, {
  446. imgSrc: res.data.imgSrc ? [{ url: res.data.imgSrc }] : []
  447. })
  448. getGoodsList({
  449. pageNum: 1,
  450. pageSize: -1,
  451. goodsId: res.data.goodsId,
  452. }).then(res => {
  453. // this.goodsList = res.data.records.map(item => ({
  454. // value: item.goodsId,
  455. // label: item.goodsName
  456. // }))
  457. this.formData.goodsId = res.data.records[0].goodsId
  458. this.formData.goodsName = res.data.records[0].goodsName
  459. })
  460. })
  461. }
  462. })
  463. },
  464. // 关闭时事件
  465. closeEvent: () => {
  466. this.formCancel()
  467. }
  468. })
  469. },
  470. formConfirm(cancel) {
  471. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  472. if (valid) {
  473. ;[addBanner, editBanner]
  474. [this.formDialogType]({
  475. ...this.formData,
  476. imgSrc: this.formData.imgSrc.map(item => item.url).join(',')
  477. })
  478. .then(res => {
  479. this.$message({ type: 'success', message: `${{ edit: '编辑', add: '新增' }[this.formType]}成功!` })
  480. cancel('list')
  481. this.$refs.pageRef.refreshList()
  482. })
  483. }
  484. })
  485. },
  486. batchDelete() {
  487. if (this.recordSelected && this.recordSelected.length > 0) {
  488. this.$confirm('此操作将删除选中轮播图, 是否继续?', '提示', {
  489. confirmButtonText: '确定',
  490. cancelButtonText: '取消',
  491. type: 'warning'
  492. })
  493. .then(() => {
  494. let ids = []
  495. this.recordSelected.forEach(value => {
  496. ids.push(value.id)
  497. })
  498. batchDeleteBanner(ids).then(() => {
  499. this.$message({ type: 'success', message: '删除成功!' })
  500. this.$refs.pageRef.refreshList()
  501. })
  502. })
  503. .catch(() => {})
  504. } else {
  505. this.$errorMsg('请选择要删除的轮播图')
  506. }
  507. },
  508. showGoods() {
  509. this.search = '';
  510. this.innerVisible = true
  511. this.showGoodsList()
  512. },
  513. clearGoodsId() {
  514. this.formData.goodsId = ''
  515. this.formData.goodsName = ''
  516. },
  517. searchGoods() {
  518. this.innerCurrentPage = 1;
  519. this.showGoodsList()
  520. },
  521. selGoods(row) {
  522. this.innerVisible = false
  523. this.search = ''
  524. this.formData.goodsId = row.goodsId
  525. this.formData.goodsName = row.goodsName
  526. },
  527. showGoodsList() {
  528. let params = {
  529. goodsName: this.search,
  530. pageNum: this.innerCurrentPage,
  531. pageSize: this.innerPageSize
  532. };
  533. getGoodsList(params).then(res => {
  534. this.goodsList = res.data.records;
  535. this.innerListTotal = res.data.total;
  536. })
  537. },
  538. // 更改内嵌每页数量
  539. innerHandleSizeChange(val) {
  540. this.innerPageSize = val;
  541. this.innerCurrentPage = 1;
  542. this.showGoodsList();
  543. },
  544. // 更改内嵌当前页
  545. innerHandleCurrentChange(val) {
  546. this.innerCurrentPage = val;
  547. this.showGoodsList();
  548. },
  549. }
  550. }
  551. </script>
  552. <style lang="scss" scoped></style>
  553. <style>
  554. .dialog-footer {
  555. padding: 0 30px;
  556. display: flex;
  557. justify-content: flex-end;
  558. }
  559. </style>