index.vue 6.0KB

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