GoodsManager.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <div>
  3. <div class="operation">
  4. <el-input v-model="search" placeholder="请输入商品名称" size="mini"></el-input>
  5. <el-select v-model="status" size="mini">
  6. <el-option value="-1" label="全部"></el-option>
  7. <el-option value="1" label="在线"></el-option>
  8. <el-option value="0" label="离线"></el-option>
  9. </el-select>
  10. <div class="btn">
  11. <el-button type="primary" @click="getItems" size="mini">查询</el-button>
  12. <el-button type="primary" @click="goAdd" size="mini">添加</el-button>
  13. </div>
  14. </div>
  15. <el-table :data="items">
  16. <el-table-column label="商品ID" prop="gid"></el-table-column>
  17. <el-table-column label="商品图标" width="110px">
  18. 图标
  19. <template slot-scope="scope">
  20. <img :src="scope.row.icon" style="width:100px;" />
  21. </template>
  22. </el-table-column>
  23. <el-table-column label="商品名称" prop="name"></el-table-column>
  24. <el-table-column label="简介" prop="describe" width="300px"></el-table-column>
  25. <el-table-column label="原价" prop="price.price"></el-table-column>
  26. <el-table-column label="折扣价" prop="price.discountPrice"></el-table-column>
  27. <el-table-column label="详细">
  28. <template slot-scope="scope">
  29. <el-button type="text" size="small" @click="goEditGoodsDescribe(scope.row)">编辑详细</el-button>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="状态">
  33. <template slot-scope="scope">
  34. <template v-if="scope.row.status === 1">
  35. <p class="online">启用</p>
  36. </template>
  37. <template v-else>
  38. <p class="offline">禁用</p>
  39. </template>
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="绑定套餐" prop="packageName">
  43. <template slot-scope="scope">
  44. <template v-if="scope.row.packageid === '0'">
  45. <el-button type="text" size="small" @click="goBindPackage(scope.row)">去绑定</el-button>
  46. </template>
  47. <template v-else>
  48. <el-button
  49. type="text"
  50. size="small"
  51. @click="goBindPackage(scope.row)"
  52. >{{scope.row.packageName}}</el-button>
  53. </template>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="推荐商品">
  57. <template slot-scope="scope">
  58. <template v-if="scope.row.isRecommend">
  59. <p v-on:click="setRecommand(scope.row)" class="online">是</p>
  60. </template>
  61. <template v-else>
  62. <p v-on:click="setRecommand(scope.row)" class="offline">否</p>
  63. </template>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="操作" width="250px" fixed="right">
  67. <template slot-scope="scope">
  68. <template v-if="scope.row.status == 0">
  69. <el-button type="success" @click="setStatus(scope.row)" size="mini">启用</el-button>
  70. </template>
  71. <template v-else>
  72. <el-button type="danger" @click="setStatus(scope.row)" size="mini">禁用</el-button>
  73. </template>
  74. <el-button type="text" size="small" @click="goEdit(scope.row)">编辑</el-button>
  75. <el-button type="text" size="small" @click="goEditLabel(scope.row)">标签</el-button>
  76. <el-button type="text" size="small" @click="goExchangeCode(scope.row)">兑换码</el-button>
  77. <a :href="serverPath + 'good/detail/' + scope.row.gid" target="_black">
  78. <el-button type="text" size="small">预览</el-button>
  79. </a>
  80. </template>
  81. </el-table-column>
  82. </el-table>
  83. <div class="page">
  84. <el-pagination
  85. background
  86. layout="total, prev, pager, next,jumper"
  87. @current-change="nextPage"
  88. :page-size="pageSize"
  89. :total="totalCount"
  90. ></el-pagination>
  91. </div>
  92. </div>
  93. </template>
  94. <script>
  95. export default {
  96. data() {
  97. return {
  98. page: 1,
  99. pageSize: 20,
  100. items: [],
  101. totalCount: 0,
  102. status: "-1",
  103. search: "",
  104. serverPath: process.env.SERVER_PATH
  105. };
  106. },
  107. methods: {
  108. getItems: function() {
  109. this.$http
  110. .getGoods(
  111. {
  112. page: this.page,
  113. pageSize: this.pageSize,
  114. status: this.status,
  115. search: this.search
  116. },
  117. this
  118. )
  119. .then(data => {
  120. this.items = data.obj.list;
  121. this.totalCount = data.obj.totalCount;
  122. });
  123. },
  124. nextPage: function(currentPage) {
  125. this.page = currentPage;
  126. this.getItems();
  127. },
  128. statusFormater: function(row) {
  129. if (row.status === 1) {
  130. return "在线";
  131. } else {
  132. return "离线";
  133. }
  134. },
  135. setStatus: function(row) {
  136. let msg = row.status === 1 ? "禁用" : "启用";
  137. this.$confirm(
  138. '您确定要将此商品设置为 "' + msg + '" , 是否继续?',
  139. "提示",
  140. {
  141. confirmButtonText: "确定",
  142. cancelButtonText: "取消",
  143. type: "warning"
  144. }
  145. )
  146. .then(() => {
  147. this.$http
  148. .setGoodStatus(
  149. { gid: row.gid, status: row.status === 1 ? false : true },
  150. this
  151. )
  152. .then(res => {
  153. if (res.code === 0) {
  154. row.status = row.status === 1 ? 0 : 1;
  155. this.$message({
  156. message: "操作成功",
  157. type: "success"
  158. });
  159. }
  160. });
  161. })
  162. .catch(() => {});
  163. },
  164. goEdit: function(row) {
  165. this.$router.push({ path: "/editGoods", query: { gid: row.gid } });
  166. },
  167. goEditGoodsDescribe: function(row) {
  168. this.$router.push({
  169. path: "/editGoodsDescribe",
  170. query: { gid: row.gid }
  171. });
  172. },
  173. goEditLabel: function(row) {
  174. this.$router.push({ path: "/goodLabelManage", query: { gid: row.gid } });
  175. },
  176. goBindPackage: function(row) {
  177. this.$router.push({ path: "/bindPackage", query: { gid: row.gid } });
  178. },
  179. goAdd: function() {
  180. this.$router.push({ path: "/editGoods", query: { gid: 0 } });
  181. },
  182. goExchangeCode: function(row) {
  183. this.$router.push({ path: "/exchangeCodeList", query: { gid: row.gid } });
  184. },
  185. setRecommand: function(row) {
  186. var msg = row.isRecommend
  187. ? "您是否要停止推荐此商品吗?"
  188. : "您是否要推荐此商品?";
  189. this.$confirm(msg, "提示", {
  190. confirmButtonText: "确定",
  191. cancelButtonText: "取消",
  192. type: "warning"
  193. }).then(res => {
  194. this.$http
  195. .setRecommand(
  196. { gid: row.gid, isrecommand: row.isRecommend ? false : true },
  197. this
  198. )
  199. .then(res => {
  200. row.isRecommend = !row.isRecommend;
  201. });
  202. });
  203. }
  204. },
  205. mounted: function() {
  206. this.getItems();
  207. }
  208. };
  209. </script>
  210. <style scoped>
  211. .page {
  212. margin-top: 10px;
  213. }
  214. .online {
  215. color: #67c23a;
  216. }
  217. .offline {
  218. color: #f56c6c;
  219. }
  220. .operation {
  221. display: flex;
  222. height: 50px;
  223. border-bottom: 1px solid #e6e6e6;
  224. margin-bottom: 10px;
  225. }
  226. .operation .btn {
  227. display: flex;
  228. height: 28px;
  229. }
  230. .operation .btn,
  231. .operation .el-input,
  232. .operation .el-select {
  233. width: 150px;
  234. margin-right: 8px;
  235. }
  236. </style>