GoodsManager.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-col :span="3">
  5. <el-input v-model="search" placeholder="请输入商品名称"></el-input>
  6. </el-col>
  7. <el-col :span="1">
  8. &nbsp;
  9. </el-col>
  10. <el-col :span="3">
  11. <el-select v-model="status">
  12. <el-option value="-1" label="全部"></el-option>
  13. <el-option value="1" label="在线"></el-option>
  14. <el-option value="0" label="离线"></el-option>
  15. </el-select>
  16. </el-col>
  17. <el-col :span="1">
  18. &nbsp;
  19. </el-col>
  20. <el-col :span="4">
  21. <el-button type="primary" @click="getItems">查询</el-button>
  22. <el-button type="primary" @click="goAdd">添加</el-button>
  23. </el-col>
  24. </el-row>
  25. <el-table :data="items">
  26. <el-table-column label="商品ID" prop="gid"></el-table-column>
  27. <el-table-column label="商品图标" width="110px">图标
  28. <template slot-scope="scope">
  29. <img :src="scope.row.icon" style="width:100px;" />
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="商品名称" prop="name"></el-table-column>
  33. <el-table-column label="简介" prop="describe"></el-table-column>
  34. <el-table-column label="原价" prop="price.price"></el-table-column>
  35. <el-table-column label="折扣价" prop="price.discountPrice"></el-table-column>
  36. <el-table-column label="详细">
  37. <template slot-scope="scope">
  38. <el-button type="text" size="small" @click="goEditGoodsDescribe(scope.row)">编辑详细</el-button>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="状态">
  42. <template slot-scope="scope">
  43. <template v-if="scope.row.status === 1">
  44. <p class="online">启用</p>
  45. </template>
  46. <template v-else>
  47. <p class="offline">禁用</p>
  48. </template>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="绑定套餐" prop="packageName">
  52. <template slot-scope="scope">
  53. <template v-if="scope.row.packageid === '0'">
  54. <el-button type="text" size="small" @click="goBindPackage(scope.row)">去绑定</el-button>
  55. </template>
  56. <template v-else>
  57. <el-button type="text" size="small" @click="goBindPackage(scope.row)">{{scope.row.packageName}}</el-button>
  58. </template>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="推荐商品">
  62. <template slot-scope="scope">
  63. <template v-if="scope.row.isRecommend">
  64. <p v-on:click="setRecommand(scope.row)" class="online">是</p>
  65. </template>
  66. <template v-else>
  67. <p v-on:click="setRecommand(scope.row)" class="offline">否</p>
  68. </template>
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="操作" width="250px">
  72. <template slot-scope="scope">
  73. <template v-if="scope.row.status == 0">
  74. <el-button type="success" @click="setStatus(scope.row)">启用</el-button>
  75. </template>
  76. <template v-else>
  77. <el-button type="danger" @click="setStatus(scope.row)">禁用</el-button>
  78. </template>
  79. <el-button type="text" size="small" @click="goEdit(scope.row)">编辑</el-button>
  80. <el-button type="text" size="small" @click="goEditLabel(scope.row)">标签</el-button>
  81. <el-button type="text" size="small" @click="goExchangeCode(scope.row)">兑换码</el-button>
  82. <a :href="serverPath + 'good/detail/' + scope.row.gid" target="_black">
  83. <el-button type="text" size="small">预览</el-button>
  84. </a>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. <div class="page">
  89. <el-pagination background layout="total, prev, pager, next,jumper" @current-change="nextPage" :page-size="pageSize" :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({ path: '/editGoodsDescribe', query: { gid: row.gid } })
  169. },
  170. goEditLabel: function(row) {
  171. this.$router.push({ path: '/goodLabelManage', query: { gid: row.gid } })
  172. },
  173. goBindPackage: function(row) {
  174. this.$router.push({ path: '/bindPackage', query: { gid: row.gid } })
  175. },
  176. goAdd: function(){
  177. this.$router.push({ path: '/editGoods', query: { gid: 0 } })
  178. },
  179. goExchangeCode:function(row){
  180. this.$router.push({ path: '/exchangeCodeList', query: { gid: row.gid } })
  181. },
  182. setRecommand: function(row) {
  183. var msg = row.isRecommend
  184. ? '您是否要停止推荐此商品吗?'
  185. : '您是否要推荐此商品?'
  186. this.$confirm(msg, '提示', {
  187. confirmButtonText: '确定',
  188. cancelButtonText: '取消',
  189. type: 'warning'
  190. }).then(res => {
  191. this.$http
  192. .setRecommand(
  193. { gid: row.gid, isrecommand: row.isRecommend ? false : true },
  194. this
  195. )
  196. .then(res => {
  197. row.isRecommend = !row.isRecommend
  198. })
  199. })
  200. }
  201. },
  202. mounted: function() {
  203. this.getItems()
  204. }
  205. }
  206. </script>
  207. <style>
  208. .page {
  209. margin-top: 10px;
  210. text-align: center;
  211. }
  212. .online {
  213. color: #67c23a;
  214. }
  215. .offline {
  216. color: #f56c6c;
  217. }
  218. </style>