| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- <template>
- <div>
- <Card :bordered="false" dis-hover class="ivu-mt">
- <Form
- ref="artFrom"
- :model="artFrom"
- :label-width="labelWidth"
- :label-position="labelPosition"
- @submit.native.prevent
- >
- <Row type="flex" :gutter="24">
- <Col v-bind="grid">
- <FormItem label="文章分类:" label-for="pid">
- <i-select :value="artFrom.pid" placeholder="请选择" style="width: 80%" class="treeSel">
- <i-option v-for="(item, index) of list" :value="item.value" :key="index" style="display: none">
- {{ item.title }}
- </i-option>
- <Tree :data="treeData" @on-select-change="handleCheckChange"></Tree>
- </i-select>
- </FormItem>
- </Col>
- <Col v-bind="grid">
- <FormItem label="文章搜索:" label-for="title">
- <Input
- search
- enter-button
- placeholder="请输入"
- v-model="artFrom.title"
- style="width: 80%"
- @on-search="userSearchs"
- />
- </FormItem>
- </Col>
- </Row>
- <Row type="flex">
- <Col v-bind="grid">
- <router-link :to="$routeProStr + '/cms/article/add_article'" v-auth="['cms-article-creat']"
- ><Button type="primary" class="bnt" icon="md-add">添加文章</Button></router-link
- >
- </Col>
- </Row>
- </Form>
- <Table
- :columns="columns1"
- :data="cmsList"
- ref="table"
- class="mt25"
- :loading="loading"
- highlight-row
- no-userFrom-text="暂无数据"
- no-filtered-userFrom-text="暂无筛选结果"
- >
- <template slot-scope="{ row, index }" slot="titles">
- <span>{{ ' [ ' + row.catename + ' ] ' + row.title }}</span>
- </template>
- <template slot-scope="{ row, index }" slot="image_inputs">
- <div v-if="row.image_input.length !== 0" v-viewer>
- <div class="tabBox_img" v-for="(item, index) in row.image_input" :key="index">
- <img v-lazy="item" />
- </div>
- </div>
- </template>
- <template slot-scope="{ row, index }" slot="action">
- <a @click="edit(row)">编辑</a>
- <Divider type="vertical" />
- <a @click="artRelation(row, '取消关联', index)">{{ row.product_id === 0 ? '关联' : '取消关联' }}</a>
- <Divider type="vertical" />
- <a @click="del(row, '删除文章', index)">删除</a>
- </template>
- </Table>
- <div class="acea-row row-right page">
- <Page
- :total="total"
- :current="artFrom.page"
- show-elevator
- show-total
- @on-change="pageChange"
- :page-size="artFrom.limit"
- />
- </div>
- </Card>
- <!--关联-->
- <Modal
- v-model="modals"
- title="商品列表"
- footerHide
- class="paymentFooter"
- scrollable
- width="900"
- @on-cancel="cancel"
- >
- <goods-list ref="goodslist" @getProductId="getProductId" v-if="modals"></goods-list>
- </Modal>
- </div>
- </template>
- <script>
- import { mapState } from 'vuex';
- import { cmsListApi, categoryListApi, relationApi } from '@/api/cms';
- import relationList from './relation';
- import { formatDate } from '@/utils/validate';
- import goodsList from '@/components/goodsList/index';
- export default {
- name: 'cms_article',
- data() {
- return {
- modalTitleSs: '',
- currentTab: '',
- grid: {
- xl: 8,
- lg: 8,
- md: 12,
- sm: 24,
- xs: 24,
- },
- loading: false,
- artFrom: {
- pid: 0,
- title: '',
- page: 1,
- limit: 20,
- },
- total: 0,
- columns1: [
- {
- title: 'ID',
- key: 'id',
- width: 80,
- },
- {
- title: '文章图片',
- slot: 'image_inputs',
- minWidth: 90,
- },
- {
- title: '文章名称',
- slot: 'titles',
- minWidth: 130,
- },
- {
- title: '关联商品',
- key: 'store_name',
- minWidth: 130,
- },
- // {
- // title: '排序',
- // key: 'sort',
- // minWidth: 60
- // },
- {
- title: '浏览量',
- key: 'visit',
- minWidth: 80,
- },
- {
- title: '时间',
- key: 'add_time',
- sortable: true,
- render: (h, params) => {
- return h('div', formatDate(new Date(Number(params.row.add_time) * 1000), 'yyyy-MM-dd hh:mm'));
- },
- minWidth: 120,
- },
- {
- title: '操作',
- slot: 'action',
- fixed: 'right',
- minWidth: 150,
- },
- ],
- cmsList: [],
- treeData: [],
- list: [],
- cid: 0, // 移动分类id
- cmsId: 0,
- formValidate: {
- type: 1,
- },
- rows: {},
- modal_loading: false,
- modals: false,
- };
- },
- components: {
- relationList,
- goodsList,
- },
- computed: {
- ...mapState('media', ['isMobile']),
- labelWidth() {
- return this.isMobile ? undefined : 75;
- },
- labelPosition() {
- return this.isMobile ? 'top' : 'right';
- },
- },
- created() {},
- activated() {
- this.artFrom.pid = this.$route.query.id ? this.$route.query.id : 0;
- this.getList();
- this.getClass();
- },
- methods: {
- // 关联成功
- getProductId(row) {
- let data = {
- product_id: row.id,
- };
- relationApi(data, this.rows.id)
- .then(async (res) => {
- this.$Message.success(res.msg);
- row.id = 0;
- this.modal_loading = false;
- this.modals = false;
- setTimeout(() => {
- this.getList();
- }, 500);
- })
- .catch((res) => {
- this.modal_loading = false;
- this.loading = false;
- this.$Message.error(res.msg);
- });
- },
- cancel() {
- this.modals = false;
- },
- // 等级列表
- getList() {
- this.loading = true;
- cmsListApi(this.artFrom)
- .then(async (res) => {
- let data = res.data;
- this.cmsList = data.list;
- this.total = data.count;
- this.loading = false;
- })
- .catch((res) => {
- this.loading = false;
- this.$Message.error(res.msg);
- });
- },
- // 分类
- getClass() {
- categoryListApi(this.formValidate)
- .then(async (res) => {
- let data = res.data;
- this.treeData = data;
- let obj = {
- id: 0,
- title: '全部',
- };
- this.treeData.unshift(obj);
- })
- .catch((res) => {
- this.$Message.error(res.msg);
- });
- },
- pageChange(index) {
- this.artFrom.page = index;
- this.getList();
- },
- // 下拉树
- handleCheckChange(data) {
- let value = '';
- let title = '';
- this.list = [];
- this.artFrom.pid = 0;
- data.forEach((item, index) => {
- value += `${item.id},`;
- title += `${item.title},`;
- });
- value = value.substring(0, value.length - 1);
- title = title.substring(0, title.length - 1);
- this.list.push({
- value,
- title,
- });
- this.artFrom.pid = value;
- this.artFrom.page = 1;
- this.getList();
- },
- // 编辑
- edit(row) {
- this.$router.push({ path: this.$routeProStr + '/cms/article/add_article/' + row.id });
- },
- // 关联
- artRelation(row, tit, num) {
- this.rows = row;
- if (row.product_id === 0) {
- this.modals = true;
- } else {
- let delfromData = {
- title: tit,
- num: num,
- url: `/cms/cms/unrelation/${row.id}`,
- method: 'PUT',
- ids: '',
- };
- this.$modalSure(delfromData)
- .then((res) => {
- this.$Message.success(res.msg);
- this.getList();
- })
- .catch((res) => {
- this.$Message.error(res.msg);
- });
- }
- },
- // 删除
- del(row, tit, num) {
- let delfromData = {
- title: tit,
- num: num,
- url: `cms/cms/${row.id}`,
- method: 'DELETE',
- ids: '',
- };
- this.$modalSure(delfromData)
- .then((res) => {
- this.$Message.success(res.msg);
- this.cmsList.splice(num, 1);
- })
- .catch((res) => {
- this.$Message.error(res.msg);
- });
- },
- // 表格搜索
- userSearchs() {
- this.artFrom.page = 1;
- this.getList();
- },
- },
- };
- </script>
- <style scoped lang="stylus">
- .treeSel >>>.ivu-select-dropdown-list {
- padding: 0 10px !important;
- box-sizing: border-box;
- }
- .tabBox_img {
- width: 36px;
- height: 36px;
- border-radius: 4px;
- cursor: pointer;
- img {
- width: 100%;
- height: 100%;
- }
- }
- </style>
|