index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <div>
  3. <Card :bordered="false" dis-hover class="ivu-mt">
  4. <Form
  5. ref="artFrom"
  6. :model="artFrom"
  7. :label-width="labelWidth"
  8. :label-position="labelPosition"
  9. @submit.native.prevent
  10. >
  11. <Row type="flex" :gutter="24">
  12. <Col v-bind="grid">
  13. <FormItem label="文章分类:" label-for="pid">
  14. <i-select :value="artFrom.pid" placeholder="请选择" style="width: 80%" class="treeSel">
  15. <i-option v-for="(item, index) of list" :value="item.value" :key="index" style="display: none">
  16. {{ item.title }}
  17. </i-option>
  18. <Tree :data="treeData" @on-select-change="handleCheckChange"></Tree>
  19. </i-select>
  20. </FormItem>
  21. </Col>
  22. <Col v-bind="grid">
  23. <FormItem label="文章搜索:" label-for="title">
  24. <Input
  25. search
  26. enter-button
  27. placeholder="请输入"
  28. v-model="artFrom.title"
  29. style="width: 80%"
  30. @on-search="userSearchs"
  31. />
  32. </FormItem>
  33. </Col>
  34. </Row>
  35. <Row type="flex">
  36. <Col v-bind="grid">
  37. <router-link :to="$routeProStr + '/cms/article/add_article'" v-auth="['cms-article-creat']"
  38. ><Button type="primary" class="bnt" icon="md-add">添加文章</Button></router-link
  39. >
  40. </Col>
  41. </Row>
  42. </Form>
  43. <Table
  44. :columns="columns1"
  45. :data="cmsList"
  46. ref="table"
  47. class="mt25"
  48. :loading="loading"
  49. highlight-row
  50. no-userFrom-text="暂无数据"
  51. no-filtered-userFrom-text="暂无筛选结果"
  52. >
  53. <template slot-scope="{ row, index }" slot="titles">
  54. <span>{{ ' [ ' + row.catename + ' ] ' + row.title }}</span>
  55. </template>
  56. <template slot-scope="{ row, index }" slot="image_inputs">
  57. <div v-if="row.image_input.length !== 0" v-viewer>
  58. <div class="tabBox_img" v-for="(item, index) in row.image_input" :key="index">
  59. <img v-lazy="item" />
  60. </div>
  61. </div>
  62. </template>
  63. <template slot-scope="{ row, index }" slot="action">
  64. <a @click="edit(row)">编辑</a>
  65. <Divider type="vertical" />
  66. <a @click="artRelation(row, '取消关联', index)">{{ row.product_id === 0 ? '关联' : '取消关联' }}</a>
  67. <Divider type="vertical" />
  68. <a @click="del(row, '删除文章', index)">删除</a>
  69. </template>
  70. </Table>
  71. <div class="acea-row row-right page">
  72. <Page
  73. :total="total"
  74. :current="artFrom.page"
  75. show-elevator
  76. show-total
  77. @on-change="pageChange"
  78. :page-size="artFrom.limit"
  79. />
  80. </div>
  81. </Card>
  82. <!--关联-->
  83. <Modal
  84. v-model="modals"
  85. title="商品列表"
  86. footerHide
  87. class="paymentFooter"
  88. scrollable
  89. width="900"
  90. @on-cancel="cancel"
  91. >
  92. <goods-list ref="goodslist" @getProductId="getProductId" v-if="modals"></goods-list>
  93. </Modal>
  94. </div>
  95. </template>
  96. <script>
  97. import { mapState } from 'vuex';
  98. import { cmsListApi, categoryListApi, relationApi } from '@/api/cms';
  99. import relationList from './relation';
  100. import { formatDate } from '@/utils/validate';
  101. import goodsList from '@/components/goodsList/index';
  102. export default {
  103. name: 'cms_article',
  104. data() {
  105. return {
  106. modalTitleSs: '',
  107. currentTab: '',
  108. grid: {
  109. xl: 8,
  110. lg: 8,
  111. md: 12,
  112. sm: 24,
  113. xs: 24,
  114. },
  115. loading: false,
  116. artFrom: {
  117. pid: 0,
  118. title: '',
  119. page: 1,
  120. limit: 20,
  121. },
  122. total: 0,
  123. columns1: [
  124. {
  125. title: 'ID',
  126. key: 'id',
  127. width: 80,
  128. },
  129. {
  130. title: '文章图片',
  131. slot: 'image_inputs',
  132. minWidth: 90,
  133. },
  134. {
  135. title: '文章名称',
  136. slot: 'titles',
  137. minWidth: 130,
  138. },
  139. {
  140. title: '关联商品',
  141. key: 'store_name',
  142. minWidth: 130,
  143. },
  144. // {
  145. // title: '排序',
  146. // key: 'sort',
  147. // minWidth: 60
  148. // },
  149. {
  150. title: '浏览量',
  151. key: 'visit',
  152. minWidth: 80,
  153. },
  154. {
  155. title: '时间',
  156. key: 'add_time',
  157. sortable: true,
  158. render: (h, params) => {
  159. return h('div', formatDate(new Date(Number(params.row.add_time) * 1000), 'yyyy-MM-dd hh:mm'));
  160. },
  161. minWidth: 120,
  162. },
  163. {
  164. title: '操作',
  165. slot: 'action',
  166. fixed: 'right',
  167. minWidth: 150,
  168. },
  169. ],
  170. cmsList: [],
  171. treeData: [],
  172. list: [],
  173. cid: 0, // 移动分类id
  174. cmsId: 0,
  175. formValidate: {
  176. type: 1,
  177. },
  178. rows: {},
  179. modal_loading: false,
  180. modals: false,
  181. };
  182. },
  183. components: {
  184. relationList,
  185. goodsList,
  186. },
  187. computed: {
  188. ...mapState('media', ['isMobile']),
  189. labelWidth() {
  190. return this.isMobile ? undefined : 75;
  191. },
  192. labelPosition() {
  193. return this.isMobile ? 'top' : 'right';
  194. },
  195. },
  196. created() {},
  197. activated() {
  198. this.artFrom.pid = this.$route.query.id ? this.$route.query.id : 0;
  199. this.getList();
  200. this.getClass();
  201. },
  202. methods: {
  203. // 关联成功
  204. getProductId(row) {
  205. let data = {
  206. product_id: row.id,
  207. };
  208. relationApi(data, this.rows.id)
  209. .then(async (res) => {
  210. this.$Message.success(res.msg);
  211. row.id = 0;
  212. this.modal_loading = false;
  213. this.modals = false;
  214. setTimeout(() => {
  215. this.getList();
  216. }, 500);
  217. })
  218. .catch((res) => {
  219. this.modal_loading = false;
  220. this.loading = false;
  221. this.$Message.error(res.msg);
  222. });
  223. },
  224. cancel() {
  225. this.modals = false;
  226. },
  227. // 等级列表
  228. getList() {
  229. this.loading = true;
  230. cmsListApi(this.artFrom)
  231. .then(async (res) => {
  232. let data = res.data;
  233. this.cmsList = data.list;
  234. this.total = data.count;
  235. this.loading = false;
  236. })
  237. .catch((res) => {
  238. this.loading = false;
  239. this.$Message.error(res.msg);
  240. });
  241. },
  242. // 分类
  243. getClass() {
  244. categoryListApi(this.formValidate)
  245. .then(async (res) => {
  246. let data = res.data;
  247. this.treeData = data;
  248. let obj = {
  249. id: 0,
  250. title: '全部',
  251. };
  252. this.treeData.unshift(obj);
  253. })
  254. .catch((res) => {
  255. this.$Message.error(res.msg);
  256. });
  257. },
  258. pageChange(index) {
  259. this.artFrom.page = index;
  260. this.getList();
  261. },
  262. // 下拉树
  263. handleCheckChange(data) {
  264. let value = '';
  265. let title = '';
  266. this.list = [];
  267. this.artFrom.pid = 0;
  268. data.forEach((item, index) => {
  269. value += `${item.id},`;
  270. title += `${item.title},`;
  271. });
  272. value = value.substring(0, value.length - 1);
  273. title = title.substring(0, title.length - 1);
  274. this.list.push({
  275. value,
  276. title,
  277. });
  278. this.artFrom.pid = value;
  279. this.artFrom.page = 1;
  280. this.getList();
  281. },
  282. // 编辑
  283. edit(row) {
  284. this.$router.push({ path: this.$routeProStr + '/cms/article/add_article/' + row.id });
  285. },
  286. // 关联
  287. artRelation(row, tit, num) {
  288. this.rows = row;
  289. if (row.product_id === 0) {
  290. this.modals = true;
  291. } else {
  292. let delfromData = {
  293. title: tit,
  294. num: num,
  295. url: `/cms/cms/unrelation/${row.id}`,
  296. method: 'PUT',
  297. ids: '',
  298. };
  299. this.$modalSure(delfromData)
  300. .then((res) => {
  301. this.$Message.success(res.msg);
  302. this.getList();
  303. })
  304. .catch((res) => {
  305. this.$Message.error(res.msg);
  306. });
  307. }
  308. },
  309. // 删除
  310. del(row, tit, num) {
  311. let delfromData = {
  312. title: tit,
  313. num: num,
  314. url: `cms/cms/${row.id}`,
  315. method: 'DELETE',
  316. ids: '',
  317. };
  318. this.$modalSure(delfromData)
  319. .then((res) => {
  320. this.$Message.success(res.msg);
  321. this.cmsList.splice(num, 1);
  322. })
  323. .catch((res) => {
  324. this.$Message.error(res.msg);
  325. });
  326. },
  327. // 表格搜索
  328. userSearchs() {
  329. this.artFrom.page = 1;
  330. this.getList();
  331. },
  332. },
  333. };
  334. </script>
  335. <style scoped lang="stylus">
  336. .treeSel >>>.ivu-select-dropdown-list {
  337. padding: 0 10px !important;
  338. box-sizing: border-box;
  339. }
  340. .tabBox_img {
  341. width: 36px;
  342. height: 36px;
  343. border-radius: 4px;
  344. cursor: pointer;
  345. img {
  346. width: 100%;
  347. height: 100%;
  348. }
  349. }
  350. </style>