list-commonly.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div class="app-container" style="padding: 0 20px;padding-bottom: 0;">
  3. <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal">
  4. <el-menu-item index="0"><router-link to="/goods/list">全部商品</router-link></el-menu-item>
  5. <el-menu-item v-if="modules && modules.firstModulesName" index="1"><router-link to="/goods/list/preferred">{{ modules.firstModulesName }}</router-link></el-menu-item>
  6. <el-menu-item v-if="modules && modules.secondModulesName" index="2"><router-link to="/goods/list/preferential">{{ modules.secondModulesName }}</router-link></el-menu-item>
  7. <el-menu-item v-if="modules && modules.thirdModulesName" index="3"><router-link to="/goods/list/commonly">{{ modules.thirdModulesName }}</router-link></el-menu-item>
  8. </el-menu>
  9. <div class="filter-container">
  10. <el-form class="demo-form-inline goods-list">
  11. <el-form-item label="商品ID:" style="width:225px;float: left;margin-bottom: 8px;">
  12. <el-input v-model="listQuery.id" placeholder="请输入商品ID" maxlength="30" style="width: 150px;" class="filter-item" @keyup.enter.native="handleFilter" />
  13. </el-form-item>
  14. <el-form-item label="商品名称:" style="width:240px;float: left;">
  15. <el-input v-model="listQuery.productName" placeholder="请输入商品名称" style="width: 150px;" class="filter-item" @keyup.enter.native="handleFilter" />
  16. </el-form-item>
  17. <el-form-item label="供应商名称:" style="width:250px;float: left;">
  18. <el-input v-model="listQuery.shopName" placeholder="请输入供应商名称" style="width: 150px;" class="filter-item" @keyup.enter.native="handleFilter" />
  19. </el-form-item>
  20. <el-form-item label="商品分类:" style="width:200px;float: left;">
  21. <el-select v-model="listQuery.classifyID" placeholder="商品分类" clearable style="width: 110px" class="filter-item" value="" @change="handleFilter">
  22. <template v-for="item in classify">
  23. <el-option v-if="item.status*1 === 1" :key="item.id" :label="item.classifyName" :value="item.id" />
  24. </template>
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item style="width:95px;float: left;">
  28. <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
  29. </el-form-item>
  30. <el-form-item style="width:150px;float: left;">
  31. <el-button class="filter-item" type="primary" icon="el-icon-sort" @click="batchSaveSort">批量更新排序</el-button>
  32. </el-form-item>
  33. <el-form-item style="width:120px;float: left;">
  34. <el-button class="filter-item" type="primary" icon="el-icon-circle-plus-outline">
  35. <router-link :to="'/goods/list/select/'+ activeIndex">添加商品</router-link>
  36. </el-button>
  37. </el-form-item>
  38. </el-form>
  39. </div>
  40. <div class="filter-title">
  41. <p>排序值是指本页面和商城小程序对应商品列表的排列顺序,数值越小排序越靠前,排序值允许重复。</p>
  42. </div>
  43. <el-table
  44. v-loading="listLoading"
  45. :data="list"
  46. element-loading-text="Loading"
  47. border
  48. fit
  49. highlight-current-row
  50. :header-cell-style="{background:'#eef1f6',color:'#606266'}"
  51. style="width:100%;margin-top:20px;"
  52. >
  53. <el-table-column align="center" label="序号" width="50px">
  54. <template slot-scope="scope">
  55. {{ scope.$index+1 }}
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="商品ID" align="center" prop="id" width="70px" />
  59. <el-table-column label="商品图片" align="center" prop="mainImage">
  60. <template slot-scope="{row}">
  61. <img :src="row.mainImage" alt="" width="50">
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="商品名称" align="center" prop="productName" min-width="200px" />
  65. <el-table-column label="供应商" align="center" prop="shopName" min-width="120px" />
  66. <el-table-column label="市场价" align="center" prop="normalPrice" />
  67. <el-table-column label="成本价" align="center" prop="costPrice" />
  68. <el-table-column label="售价" align="center" prop="retailPrice" />
  69. <el-table-column label="起订量" align="center" prop="minBuyNumber" />
  70. <el-table-column label="商品分类" align="center" prop="productClassifyName" />
  71. <el-table-column align="center" label="添加时间" prop="addTime">
  72. <template v-if="row.addTime" slot-scope="{row}">
  73. <span>{{ row.addTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="排序值" align="center" prop="commonlyProductSort">
  77. <template slot-scope="{row}">
  78. <el-input v-model="row.commonlyProductSort" size="small" type="number" min="1" />
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  82. <template slot-scope="{row}">
  83. <el-button type="primary" size="mini" style="width: 80px;margin:5px 0 0 0;" @click="cancelGoods(row.id)">取消</el-button>
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. <pagination v-show="total>20" :total="total" :page.sync="listQuery.index" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
  88. <template>
  89. <el-backtop style="right: 40px; bottom: 40px;">
  90. <i class="el-icon-upload2" />
  91. </el-backtop>
  92. </template>
  93. </div>
  94. </template>
  95. <script>
  96. import { getList, getModule, saveGoodsSort, canncelProduct } from '@/api/goods'
  97. import Pagination from '@/components/Pagination'
  98. export default {
  99. components: { Pagination },
  100. data() {
  101. return {
  102. activeIndex: '3', // 模块3
  103. list: null,
  104. classify: null,
  105. modules: null,
  106. listLoading: true,
  107. total: 0,
  108. listQuery: {
  109. index: 1,
  110. pageSize: 20,
  111. organizeID: this.$store.getters.organizeID,
  112. commonlyProduct: '1', // 常用商品
  113. id: '',
  114. productName: '',
  115. shopName: '',
  116. classifyID: ''
  117. }
  118. }
  119. },
  120. computed: {
  121. organizeID() {
  122. return this.$store.getters.organizeID
  123. }
  124. },
  125. created() {
  126. this.getModuleType()
  127. this.fetchData()
  128. },
  129. methods: {
  130. getModuleType() {
  131. getModule({ organizeID: this.$store.getters.organizeID }).then(response => {
  132. this.modules = response.data[0]
  133. })
  134. },
  135. fetchData() {
  136. this.listLoading = true
  137. getList(this.listQuery).then(response => {
  138. const { organizeProductsPage, listByEffective } = response.data
  139. this.list = organizeProductsPage.results
  140. this.total = organizeProductsPage.totalRecord
  141. this.classify = listByEffective
  142. this.listLoading = false
  143. })
  144. },
  145. handleFilter() {
  146. this.fetchData()
  147. },
  148. batchSaveSort() {
  149. const sorts = []
  150. this.list.map(item => {
  151. if (item.commonlyProductSort) {
  152. sorts.push(item.id + '-' + item.commonlyProductSort)
  153. }
  154. })
  155. saveGoodsSort({ newProducSorttList: sorts.join(','), modules: this.activeIndex }).then(response => {
  156. this.$notify({
  157. title: response.code * 1 === 1 ? 'Success' : 'Error',
  158. message: response.msg,
  159. type: response.code * 1 === 1 ? 'success' : 'error',
  160. duration: 2000
  161. })
  162. this.fetchData()
  163. }).catch(() => {
  164. this.fetchData()
  165. })
  166. },
  167. cancelGoods(id) {
  168. canncelProduct({ id: id, modules: this.activeIndex }).then(() => {
  169. this.fetchData()
  170. }).catch(() => {
  171. this.fetchData()
  172. })
  173. }
  174. }
  175. }
  176. </script>
  177. <style scoped>
  178. .filter-container{
  179. width: 100%;
  180. float: left;
  181. margin-top:20px;
  182. padding-bottom: 0;
  183. }
  184. .filter-title{
  185. float: left;
  186. font-size: 12px;
  187. line-height: 18px;
  188. text-align: left;
  189. color: #2E3748;
  190. }
  191. .filter-title p{
  192. margin:5px 0;
  193. }
  194. .goods-list .el-form-item{
  195. margin-bottom: 8px;
  196. }
  197. </style>