index.vue 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <div class="subPage">
  3. <div class="system-table-search">
  4. <div class="flex-h">
  5. <div class="flex-item flex-h">
  6. <el-button size="mini" type="success" @click='addRole'>新增商品</el-button>
  7. </div>
  8. <ul>
  9. <li>
  10. <!-- <span>选择案场:</span> -->
  11. <el-select v-model="CaseId" placeholder="请选择">
  12. <el-option
  13. v-for="item in cases"
  14. :key="item.CaseId"
  15. :label="item.CaseName"
  16. :value="item.CaseId">
  17. </el-option>
  18. </el-select>
  19. </li>
  20. <li>
  21. <el-input
  22. placeholder="请输入商品名称"
  23. v-model="postData.name"
  24. >
  25. </el-input>
  26. </li>
  27. <li>
  28. <span>商品类型:</span>
  29. <el-select v-model="postData.type" placeholder="请选择">
  30. <el-option
  31. v-for="item in types.list"
  32. :key="item.TypeId"
  33. :label="item.TypeName"
  34. :value="item.TypeId">
  35. </el-option>
  36. </el-select>
  37. </li>
  38. </ul>
  39. <el-button
  40. size="mini"
  41. type="primary" @click="search">搜索</el-button>
  42. </div>
  43. <div class="moreFilter"></div>
  44. </div>
  45. <div class="system-table-box">
  46. <el-table :data="goods.list" stripe style="width: 100%">
  47. <el-table-column prop="GoodsName" label="商品名称">
  48. </el-table-column>
  49. <el-table-column label="图片" width="300">
  50. <template slot-scope="scope">
  51. <img :src="(scope.row.Images[0] || {}).ImgUrl" style="width:200px;" />
  52. </template>
  53. </el-table-column>
  54. <el-table-column prop="Price" label="价格">
  55. </el-table-column>
  56. <el-table-column label="类型">
  57. <template slot-scope="scope">
  58. <label>{{getTypeName(scope.row.TypeId)}}</label>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="规格">
  62. <template slot-scope="scope">
  63. <label>{{getSpecNames(scope.row.Specs)}}</label>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="案场">
  67. <template slot-scope="scope">
  68. <label>{{getCaseName(scope.row.CaseId)}}</label>
  69. </template>
  70. </el-table-column>
  71. <el-table-column fixed='right' label="操作" width="300">
  72. <template slot-scope="scope">
  73. <el-button size="mini" type="warning" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
  74. <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
  75. </template>
  76. </el-table-column>
  77. </el-table>
  78. </div>
  79. <el-pagination
  80. @size-change="handleSizeChange"
  81. @current-change="handleCurrentChange"
  82. :current-page.sync="currentPage"
  83. :page-size="postData.pagesize"
  84. layout="prev, pager, next, jumper"
  85. :total="goods.pagenum">
  86. </el-pagination>
  87. </div>
  88. </template>
  89. <script>
  90. import { createNamespacedHelpers, mapState } from 'vuex'
  91. import tableSearch from '@/components/tableSearch/index'
  92. const { mapState: mapGoodsState, mapActions: mapGoodsActions } = createNamespacedHelpers('goods')
  93. export default {
  94. name: '',
  95. data () {
  96. return {
  97. currentPage: 0, // 当前页码
  98. key: '',
  99. postData: {
  100. caseid: '',
  101. name: '',
  102. type: '',
  103. page: 1,
  104. pagesize: 10,
  105. },
  106. }
  107. },
  108. computed: {
  109. ...mapState({
  110. cases: x => x.app.cases.list,
  111. defaultCaseId: x => x.app.cases.default
  112. }),
  113. ...mapGoodsState({
  114. goods: x => x.goodsList,
  115. types: x => x.goodsTypes,
  116. }),
  117. CaseId: {
  118. get () {
  119. return this.postData.caseid || this.defaultCaseId
  120. },
  121. set (val) {
  122. this.postData.caseid = val
  123. this.GetGoodTypes({ pagesize: 1000, caseid: this.CaseId })
  124. }
  125. }
  126. },
  127. components: {
  128. tableSearch
  129. },
  130. methods: {
  131. ...mapGoodsActions([
  132. 'GetGoodsList',
  133. 'GetGoodTypes',
  134. 'DelGoods',
  135. ]),
  136. getTypeName (typeid) {
  137. return (this.types.list.filter(x => x.TypeId === typeid)[0] || {}).TypeName
  138. },
  139. getSpecNames (specs) {
  140. return (specs || []).map(x => x.SpecName).join(',')
  141. },
  142. getCaseName (caseid) {
  143. return (this.cases.filter(x => x.CaseId === caseid)[0] || {}).CaseName
  144. },
  145. search () { // 搜索
  146. this.postData.page = 1
  147. this.currentList = []
  148. this.getList()
  149. },
  150. getList () {
  151. this.GetGoodsList({...this.postData, caseid: this.CaseId})
  152. },
  153. handleSizeChange (val) {
  154. console.log(`每页 ${val} 条`)
  155. },
  156. handleCurrentChange (val) {
  157. this.postData.page = this.currentPage
  158. this.getList()
  159. },
  160. handleEdit (index, row) {
  161. // 编辑
  162. this.$router.push({ name: 'editGoods', query: { id: row.GoodsId } })
  163. },
  164. handleDelete (index, row) {
  165. // 删除
  166. this.$confirm('确认删除此商品?', '提示', {
  167. confirmButtonText: '确定',
  168. cancelButtonText: '取消',
  169. type: 'warning'
  170. })
  171. .then(() => {
  172. this.DelGoods({id: row.GoodsId, callback: this.delCallBack})
  173. })
  174. .catch(() => {
  175. this.$message({
  176. type: 'info',
  177. message: '已取消删除'
  178. })
  179. })
  180. },
  181. delCallBack () {
  182. this.$message({
  183. type: 'success',
  184. message: '删除成功!'
  185. })
  186. this.getList()
  187. },
  188. addRole () {
  189. this.$router.push({ name: 'editGoods' })
  190. },
  191. },
  192. created () {
  193. this.GetGoodTypes({ pagesize: 1000, caseid: this.CaseId })
  194. this.$nextTick(function () {
  195. this.getList()
  196. })
  197. },
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. </style>