list-select.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div class="app-container" style="padding: 0 20px 20px 20px;">
  3. <el-menu :default-active="moduleId+''" class="el-menu-demo" mode="horizontal">
  4. <el-menu-item v-if="moduleId===1 && modules && modules.firstModulesName" index="1">添加【{{ modules.firstModulesName }}】</el-menu-item>
  5. <el-menu-item v-if="moduleId===2 && modules && modules.secondModulesName" index="2">添加【{{ modules.secondModulesName }}】</el-menu-item>
  6. <el-menu-item v-if="moduleId===3 && modules && modules.thirdModulesName" index="3">添加【{{ modules.thirdModulesName }}】</el-menu-item>
  7. </el-menu>
  8. <div class="filter-container" style="margin-top:20px;">
  9. <el-form class="demo-form-inline goods-list">
  10. <el-form-item label="商品ID:" style="width:225px;float: left;margin-bottom: 8px;">
  11. <el-input v-model="listQuery.id" type="number" placeholder="请输入商品ID" maxlength="30" style="width: 150px;" class="filter-item" @keyup.enter.native="handleFilter" />
  12. </el-form-item>
  13. <el-form-item label="商品名称:" style="width:240px;float: left;">
  14. <el-input v-model="listQuery.productName" placeholder="请输入商品名称" style="width: 150px;" class="filter-item" @keyup.enter.native="handleFilter" />
  15. </el-form-item>
  16. <el-form-item label="供应商名称:" style="width:250px;float: left;">
  17. <el-input v-model="listQuery.shopName" placeholder="请输入供应商名称" style="width: 150px;" class="filter-item" @keyup.enter.native="handleFilter" />
  18. </el-form-item>
  19. <el-form-item label="商品分类:" style="width:200px;float: left;">
  20. <el-select v-model="listQuery.classifyID" placeholder="商品分类" clearable style="width: 110px" class="filter-item" value="" @change="handleFilter">
  21. <template v-for="item in classify">
  22. <el-option v-if="item.status*1 === 1" :key="item.id" :label="item.classifyName" :value="item.id" />
  23. </template>
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item style="width:100px;float: left;">
  27. <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
  28. </el-form-item>
  29. <el-form-item style="width:130px;float: left;">
  30. <el-button class="filter-item" type="primary" icon="el-icon-check" @click="confirmChoose()">确定选择</el-button>
  31. </el-form-item>
  32. <el-form-item style="width:130px;float: left;">
  33. <el-button class="filter-item" type="primary" icon="el-icon-close" @click="toggleSelection()">取消选择</el-button>
  34. </el-form-item>
  35. </el-form>
  36. </div>
  37. <el-table
  38. ref="multipleTable"
  39. v-loading="listLoading"
  40. :data="list"
  41. element-loading-text="Loading"
  42. border
  43. fit
  44. highlight-current-row
  45. :header-cell-style="{background:'#eef1f6',color:'#606266'}"
  46. style="width:100%;margin-top:20px;"
  47. @selection-change="handleSelectionChange"
  48. >
  49. <el-table-column align="center" type="selection" width="55" />
  50. <el-table-column label="商品ID" align="center" prop="id" width="70px" />
  51. <el-table-column label="商品图片" align="center" prop="mainImage">
  52. <template slot-scope="{row}">
  53. <img :src="row.mainImage" alt="" width="50">
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="商品名称" align="center" prop="productName" min-width="200px" />
  57. <el-table-column label="供应商" align="center" prop="shopName" min-width="120px" />
  58. <el-table-column label="市场价" align="center" prop="normalPrice" />
  59. <el-table-column label="成本价" align="center" prop="costPrice" />
  60. <el-table-column label="售价" align="center" prop="retailPrice" />
  61. <el-table-column label="起订量" align="center" prop="minBuyNumber" />
  62. <el-table-column label="商品分类" align="center" prop="productClassifyName" />
  63. </el-table>
  64. <pagination v-show="total>20" :total="total" :page.sync="listQuery.index" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
  65. <template>
  66. <el-backtop style="right: 40px; bottom: 40px;">
  67. <i class="el-icon-upload2" />
  68. </el-backtop>
  69. </template>
  70. </div>
  71. </template>
  72. <script>
  73. import { getAddList, getModule, saveAddList } from '@/api/goods'
  74. import Pagination from '@/components/Pagination'
  75. export default {
  76. components: { Pagination },
  77. filters: {
  78. statusFilter(status) {
  79. const statusMap = {
  80. 1: 'success',
  81. 0: 'danger'
  82. }
  83. return statusMap[status]
  84. }
  85. },
  86. data() {
  87. return {
  88. list: null,
  89. modules: null,
  90. classify: null,
  91. listLoading: true,
  92. total: 0,
  93. listQuery: {
  94. index: 1,
  95. pageSize: 20,
  96. organizeID: this.$store.getters.organizeID,
  97. id: '',
  98. productName: '',
  99. shopName: '',
  100. classifyID: ''
  101. },
  102. multipleSelection: []
  103. }
  104. },
  105. computed: {
  106. moduleId: function() {
  107. return window.location.href.split('/').reverse()[0] * 1
  108. },
  109. organizeID() {
  110. return this.$store.getters.organizeID
  111. }
  112. },
  113. created() {
  114. this.getModuleType()
  115. this.fetchData()
  116. },
  117. methods: {
  118. getModuleType() {
  119. getModule({ organizeID: this.$store.getters.organizeID }).then(response => {
  120. this.modules = response.data[0]
  121. })
  122. },
  123. fetchData() {
  124. this.listLoading = true
  125. let params = {}
  126. switch (this.moduleId) {
  127. case 1:
  128. params = Object.assign({ preferredProduct: 1 }, this.listQuery)
  129. break
  130. case 2:
  131. params = Object.assign({ preferentialProduct: 1 }, this.listQuery)
  132. break
  133. case 3:
  134. params = Object.assign({ commonlyProduct: 1 }, this.listQuery)
  135. break
  136. }
  137. getAddList(params).then(response => {
  138. const { productsPage, listByEffective } = response.data
  139. this.list = productsPage.results
  140. this.total = productsPage.totalRecord
  141. this.classify = listByEffective
  142. this.listLoading = false
  143. })
  144. },
  145. handleFilter() {
  146. this.fetchData()
  147. },
  148. toggleSelection(rows) {
  149. if (rows) {
  150. rows.forEach(row => {
  151. this.$refs.multipleTable.toggleRowSelection(row)
  152. })
  153. } else {
  154. this.$refs.multipleTable.clearSelection()
  155. this.backToParentPath()
  156. }
  157. },
  158. handleSelectionChange(val) {
  159. this.multipleSelection = val
  160. },
  161. confirmChoose() {
  162. console.log(this.multipleSelection)
  163. if (this.multipleSelection.length === 0) {
  164. this.$message({ message: '没有选择商品哦,请选择商品!', type: 'warning', center: true })
  165. return
  166. }
  167. const itemsList = []
  168. this.multipleSelection.map(item => {
  169. itemsList.push(item.id)
  170. })
  171. saveAddList({ itemsList: JSON.stringify(itemsList), organizeID: this.$store.getters.organizeID, modules: this.moduleId }).then(response => {
  172. this.$notify({
  173. title: response.code * 1 === 1 ? 'Success' : 'Error',
  174. message: response.code * 1 === 1 ? '添加成功' : response.msg,
  175. type: response.code * 1 === 1 ? 'success' : 'error',
  176. duration: 2000
  177. })
  178. this.backToParentPath()
  179. }).catch(() => {
  180. this.fetchData()
  181. })
  182. },
  183. backToParentPath() {
  184. this.$store.dispatch('tagsView/delView', this.$route).then(() => {
  185. let parentPath = ''
  186. switch (this.moduleId) {
  187. case 1:
  188. parentPath = '/goods/list/preferred'
  189. break
  190. case 2:
  191. parentPath = '/goods/list/preferential'
  192. break
  193. case 3:
  194. parentPath = '/goods/list/commonly'
  195. break
  196. }
  197. if (parentPath) {
  198. this.$nextTick(() => {
  199. this.$router.replace({ path: parentPath })
  200. })
  201. }
  202. })
  203. }
  204. }
  205. }
  206. </script>
  207. <style scoped>
  208. i[type=success]{
  209. color:#67C23A;
  210. }
  211. .goods-list .el-form-item{
  212. margin-bottom: 8px;
  213. }
  214. </style>