GoodList.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div class="mainBox">
  3. <!--搜索功能 start------------------------------------------------------------>
  4. <div class="layerBox_search">
  5. <div class="layerBoxLine">
  6. <el-row>
  7. <el-col :span="8">
  8. <div class="searchBox">
  9. <div class="searchTitle">发布类型:</div>
  10. <el-select v-model="getApiData.type_id" placeholder="请选择..">
  11. <el-option label="供应商品" value="1"></el-option>
  12. <el-option label="求购商品" value="2"></el-option>
  13. </el-select>
  14. </div>
  15. </el-col>
  16. <el-col :span="8">
  17. <div class="searchBox">
  18. <div class="searchTitle">名称:</div>
  19. <el-input placeholder="请输入名称" autocomplete="off" v-model="getApiData.name" />
  20. </div>
  21. </el-col>
  22. <el-col :span="8">
  23. <div class="searchBox">
  24. <div class="searchTitle">网站名称:</div>
  25. <el-input placeholder="请输入网站名称" autocomplete="off" v-model="getApiData.website_name" />
  26. </div>
  27. </el-col>
  28. </el-row>
  29. </div>
  30. <div class="layerBoxLineTwo">
  31. <el-row>
  32. <el-col :span="8">
  33. <div class="searchBox">
  34. <div class="searchTitle">导航名称:</div>
  35. <el-input placeholder="请输入网站名称" autocomplete="off" v-model="getApiData.category_name" />
  36. </div>
  37. </el-col>
  38. </el-row>
  39. </div>
  40. </div>
  41. <div class="layerBoxNoBg">
  42. <div>
  43. <el-button type="primary" @click="goCreat">发布商品</el-button>
  44. </div>
  45. <div>
  46. <el-button @click="clearSearchList">重置</el-button>
  47. <el-button type="primary" @click="getData('search')">搜索</el-button>
  48. </div>
  49. </div>
  50. <!--搜索功能 end------------------------------------------------------------>
  51. <!--表格内容 start------------------------------------------------------------>
  52. <div class="layerBox">
  53. <tableTitle :name="tableDivTitle" />
  54. <el-row>
  55. <template>
  56. <el-table :data="tableData" style="width: 100%">
  57. <el-table-column fixed prop="id" label="编号" width="50"></el-table-column>
  58. <el-table-column prop="type_id" label="发布类型" width="">
  59. <template slot-scope="scope">
  60. <span v-if="scope.row.type_id == 1">
  61. 供应商品
  62. </span>
  63. <span v-if="scope.row.type_id == 2">
  64. 求购商品
  65. </span>
  66. </template>
  67. </el-table-column>
  68. <el-table-column prop="name" label="名称" width=""></el-table-column>
  69. <el-table-column prop="cityname" label="发布地点" width=""></el-table-column>
  70. <el-table-column prop="website_name" label="网站名称" width="">
  71. </el-table-column>
  72. <el-table-column prop="category_name" label="导航池名称" width=""></el-table-column>
  73. <el-table-column prop="created_at" label="创建时间" width=""></el-table-column>
  74. <el-table-column prop="updated_at" label="修改时间" width=""></el-table-column>
  75. <el-table-column fixed="right" label="操作" width="200" header-align="center">
  76. <template slot-scope="scope">
  77. <div class="listBtnBox">
  78. <div class="listDeleteBtn" @click="deleteRow(scope.row.id, tableData)"><i
  79. class="el-icon-delete"></i>移除</div>
  80. <div class="listEditBtn" @click="goEdit(scope.row.id, tableData)"><i
  81. class="el-icon-edit-outline"></i>编辑</div>
  82. </div>
  83. </template>
  84. </el-table-column>
  85. </el-table>
  86. </template>
  87. </el-row>
  88. </div>
  89. <!--分页 start------------------------------------------------------------>
  90. <div class="alignBox">
  91. <el-row>
  92. <el-col :span="24">
  93. <el-pagination @size-change="handleSizeChange" :current-page="getApiData.page"
  94. @current-change="handleCurrentChange" :page-size="10" layout="total, prev, pager, next, jumper"
  95. :total="allCount"></el-pagination>
  96. </el-col>
  97. </el-row>
  98. </div>
  99. <!--分页 end------------------------------------------------------------>
  100. <!--表格内容 end------------------------------------------------------------>
  101. </div>
  102. </template>
  103. <script>
  104. //表格标题
  105. import tableTitle from './components/tableTitle';
  106. //引入公用样式
  107. import '@/styles/global.less';
  108. export default {
  109. components: {
  110. tableTitle,//表格标题
  111. },
  112. data() {
  113. return {
  114. //1.列表和分页相关 start ------------------------------------------------------------>
  115. tableDivTitle: "商品列表",
  116. tableData: [],//内容
  117. editId: 0,//要修改的网站id
  118. getApiData: {
  119. name: "",//标题
  120. category_name: "",//导航池id
  121. website_name: "",//网站名称
  122. type_id: "",//发布类型
  123. page: 1,//当前是第几页
  124. page_size: 10,//一共多少条
  125. },
  126. allCount: 0,//总条数
  127. //分页相关 end ------------------------------------------------------------>
  128. }
  129. },
  130. methods: {
  131. //1.列表和分页相关 start ------------------------------------------------------------>
  132. //1.1 开始请求列表信息方法
  133. getData(type) {
  134. if (type == "search") {
  135. this.getApiData.page = 1;
  136. }
  137. console.log(this.getApiData, '---1--')
  138. this.$store.dispatch('news/getGoodList', this.getApiData).then(res => {
  139. //格式化:islink=0为不使用外面 islink=1为使用外链
  140. //status=1为显示 status=2为不显示
  141. console.log(this.getApiData, '---2-')
  142. let data = [];
  143. for (let item of res.data.rows) {
  144. // if(item.status==0){item.status="隐藏"}
  145. // if(item.status==1){item.status="显示"}
  146. // if(item.status==404){item.status="已删除"}
  147. // if (item.islink == 0) { item.islink = "否" }
  148. // if (item.islink == 1) { item.islink = "是" }
  149. data.push(item)
  150. }
  151. this.tableData = res.data.rows; //给与内容
  152. this.allCount = res.data.count; //给与总条数
  153. }).catch(() => {
  154. this.$message({
  155. type: 'warning',
  156. message: '网络错误,请重试!'
  157. });
  158. })
  159. },
  160. //1.2 删除内容
  161. deleteRow(id) {
  162. this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
  163. confirmButtonText: '确定',
  164. cancelButtonText: '取消',
  165. type: 'warning'
  166. }).then(() => {
  167. console.log("当前删除:" + id)
  168. this.$store.dispatch('news/delGood', { id: id }).then(res => {
  169. this.getData();
  170. this.$message({
  171. type: 'success',
  172. message: '删除成功!'
  173. });
  174. }).catch(() => {
  175. this.$message({
  176. type: 'warning',
  177. message: '网络错误,请重试!'
  178. });
  179. })
  180. }).catch(() => {
  181. this.$message({
  182. type: 'warning',
  183. message: '已取消删除'
  184. });
  185. });
  186. },
  187. //1.3 修改网站状态
  188. upRow(id, status) {
  189. let data = {
  190. id: id,
  191. status: status
  192. }
  193. this.$store.dispatch('news/upArticleStatus', data).then(res => {
  194. if (res.code == 200) {
  195. this.$message({
  196. type: 'success',
  197. message: '商品状态已修改!'
  198. });
  199. }
  200. }).catch(() => {
  201. this.$message({
  202. type: 'warning',
  203. message: '已取消删除'
  204. });
  205. });
  206. },
  207. //1.4 列表内容分页
  208. //直接跳转
  209. handleSizeChange(val) {
  210. this.getApiData.page = val;
  211. this.getData();
  212. },
  213. //1.5 点击分页
  214. handleCurrentChange(val) {
  215. this.getApiData.page = val;
  216. this.getData();
  217. },
  218. //1.6 重置按钮
  219. clearSearchList() {
  220. this.tableData = [];
  221. this.getApiData.name = "";
  222. this.getApiData.category_name = "";
  223. this.getApiData.type_id = "";
  224. this.getApiData.website_name = "";
  225. this.getApiData.page = 1;
  226. this.getApiData.pageSize = 10;
  227. this.getData();
  228. },
  229. //列表和分页相关 end ------------------------------------------------------------>
  230. //2.添加新闻 start ------------------------------------------------------------>
  231. //跳转到商品发布页面
  232. goCreat() {
  233. this.$router.push({
  234. path: '/addGood',
  235. });
  236. },
  237. goEdit(id) {
  238. let data = {
  239. id: id
  240. }
  241. this.$router.push({
  242. path: '/addGood',
  243. query: data
  244. });
  245. }
  246. //添加新闻 end ------------------------------------------------------------>
  247. },
  248. mounted() {
  249. //1.获得初始数据
  250. this.getData();
  251. }
  252. }
  253. </script>
  254. <style scoped lang="less"></style>