list-commonly.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <div class="app-container" style="padding: 0 20px;padding-bottom: 20px;">
  3. <el-menu :router="true" default-active="/goods/list/commonly" class="el-menu-demo" mode="horizontal">
  4. <el-menu-item index="/goods/list">全部商品</el-menu-item>
  5. <el-menu-item v-if="modules && modules.firstModulesName" index="/goods/list/preferred">{{ modules.firstModulesName }}</el-menu-item>
  6. <el-menu-item v-if="modules && modules.secondModulesName" index="/goods/list/preferential">{{ modules.secondModulesName }}</el-menu-item>
  7. <el-menu-item v-if="modules && modules.thirdModulesName" index="/goods/list/commonly">{{ modules.thirdModulesName }}</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:190px;float: left;">
  12. <el-input v-model="listQuery.id" placeholder="请输入商品ID" oninput="if(value.length>9)value=value.slice(0,9)" type="number" style="width: 120px;" 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. <router-link :to="'/goods/list/select/'+ modulesId">
  35. <el-button class="filter-item" type="primary" icon="el-icon-circle-plus-outline">添加商品</el-button>
  36. </router-link>
  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="40px">
  54. <template slot-scope="scope">
  55. {{ ((pageNum-1)*listQuery.pageSize)+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">
  67. <template slot-scope="{row}">
  68. ¥{{ row.normalPrice | toThousandFloatFilter }}
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="成本价" align="center">
  72. <template slot-scope="{row}">
  73. ¥{{ row.costPrice | toThousandFloatFilter }}
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="售价" align="center">
  77. <template slot-scope="{row}">
  78. <template v-if="row.ladderPriceFlag*1===1">
  79. <div v-for="(item, index) in row.ladderShownList" :key="row.id+'list_ladder_pri'+index">
  80. ¥{{ item.price | toThousandFloatFilter }}</div>
  81. </template>
  82. <template v-else>¥{{ row.retailPrice | toThousandFloatFilter }}</template>
  83. </template>
  84. </el-table-column>
  85. <el-table-column label="起订量" align="center" width="70">
  86. <template slot-scope="{row}">
  87. <template v-if="row.ladderPriceFlag*1===1">
  88. <div v-for="(item, index) in row.ladderShownList" :key="row.id+'list_ladder_pri'+index">{{ item.number }}</div>
  89. </template>
  90. <template v-else>{{ row.minBuyNumber }}</template>
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="商品分类" align="center" prop="productClassifyName" />
  94. <el-table-column align="center" label="添加时间" prop="addTime">
  95. <template v-if="row.addTime" slot-scope="{row}">
  96. <span>{{ row.addTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
  97. </template>
  98. </el-table-column>
  99. <el-table-column label="排序值" align="center" prop="commonlyProductSort">
  100. <template slot-scope="{row}">
  101. <el-input-number v-model="row.commonlyProductSort" controls-position="right" :min="1" :max="999" :maxlength="3" size="mini" style="width:65px;" />
  102. </template>
  103. </el-table-column>
  104. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  105. <template slot-scope="{row}">
  106. <el-button type="primary" size="mini" style="width: 70px;margin:5px 0 0 0;" @click="cancelGoods(row)">取消</el-button>
  107. </template>
  108. </el-table-column>
  109. </el-table>
  110. <pagination v-show="total>20" :total="total" :page.sync="listQuery.index" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
  111. <template>
  112. <el-backtop style="right: 40px; bottom: 40px;">
  113. <i class="el-icon-upload2" />
  114. </el-backtop>
  115. </template>
  116. </div>
  117. </template>
  118. <script>
  119. import { getList, getModule, saveGoodsSort, canncelProduct } from '@/api/goods'
  120. import Pagination from '@/components/Pagination'
  121. export default {
  122. components: { Pagination },
  123. data() {
  124. return {
  125. modulesId: '3', // 模块
  126. pageNum: 0,
  127. list: null,
  128. classify: null,
  129. modules: null,
  130. listLoading: true,
  131. total: 0,
  132. listQuery: {
  133. index: 1,
  134. pageSize: 20,
  135. organizeID: this.$store.getters.organizeID,
  136. commonlyProduct: '1', // 常用商品
  137. id: '',
  138. productName: '',
  139. shopName: '',
  140. classifyID: ''
  141. }
  142. }
  143. },
  144. computed: {
  145. organizeID() {
  146. return this.$store.getters.organizeID
  147. },
  148. onKeypress() {
  149. return (/[\d]/.test(String.fromCharCode(event.keyCode)))
  150. }
  151. },
  152. created() {
  153. this.getModuleType()
  154. this.fetchData()
  155. },
  156. methods: {
  157. getModuleType() {
  158. getModule({ organizeID: this.$store.getters.organizeID }).then(response => {
  159. this.modules = response.data[0]
  160. })
  161. },
  162. fetchData() {
  163. this.listLoading = true
  164. getList(this.listQuery).then(response => {
  165. const { organizeProductsPage, listByEffective } = response.data
  166. this.list = organizeProductsPage.results
  167. this.total = organizeProductsPage.totalRecord
  168. this.pageNum = organizeProductsPage.index
  169. this.classify = listByEffective
  170. this.listLoading = false
  171. this.list.map(row => {
  172. row.ladderShownList = []
  173. if (row.ladderPriceFlag * 1 === 1 && row.ladderPriceList != null) {
  174. for (let i = 0; i < row.ladderPriceList.length; i++) {
  175. if (row.ladderPriceList[i] && row.ladderPriceList[i].delFlag * 1 === 0) {
  176. let str = ''
  177. if (row.ladderPriceList[i + 1] && row.ladderPriceList[i + 1].delFlag * 1 === 0) {
  178. str = row.ladderPriceList[i].buyNum + '-' + (row.ladderPriceList[i + 1].buyNum - 1)
  179. } else {
  180. str = '≥' + row.ladderPriceList[i].buyNum
  181. }
  182. row.ladderShownList.push({
  183. price: row.ladderPriceList[i].buyPrice,
  184. number: str
  185. })
  186. }
  187. }
  188. }
  189. })
  190. })
  191. },
  192. handleFilter() {
  193. this.fetchData()
  194. },
  195. batchSaveSort() {
  196. const sorts = []
  197. this.list.map(item => {
  198. if (item.commonlyProductSort) {
  199. sorts.push(item.id + '-' + Math.abs(item.commonlyProductSort))
  200. }
  201. })
  202. saveGoodsSort({ newProducSorttList: sorts.join(','), modules: this.modulesId }).then(response => {
  203. this.$message({ message: response.msg, type: 'success', center: true })
  204. this.clearListQuery()
  205. this.fetchData()
  206. }).catch(() => {
  207. this.clearListQuery()
  208. this.fetchData()
  209. })
  210. },
  211. cancelGoods(row) {
  212. this.$confirm('确定取消该商品吗?取消后该商品将不在出现在本页面', '系统提示', {
  213. confirmButtonText: '确定',
  214. cancelButtonText: '取消',
  215. type: 'warning'
  216. }).then(() => {
  217. canncelProduct({ id: row.id, modules: this.modulesId }).then(() => {
  218. this.clearListQuery()
  219. this.fetchData()
  220. }).catch(() => {
  221. this.clearListQuery()
  222. this.fetchData()
  223. })
  224. })
  225. },
  226. clearListQuery() {
  227. this.listQuery.id = ''
  228. this.listQuery.productName = ''
  229. this.listQuery.shopName = ''
  230. this.listQuery.classifyID = ''
  231. }
  232. }
  233. }
  234. </script>
  235. <style>
  236. .el-input-number.is-controls-right .el-input__inner {
  237. padding-left: 5px;
  238. padding-right: 30px;
  239. }
  240. </style>
  241. <style scoped>
  242. .filter-container .filter-item,.el-form-item{
  243. margin-bottom: 0;
  244. }
  245. .filter-container{
  246. width: 100%;
  247. float: left;
  248. height: auto;
  249. margin-top:20px;
  250. padding-bottom: 0;
  251. }
  252. .filter-title{
  253. float: left;
  254. font-size: 14px;
  255. line-height: 18px;
  256. text-align: left;
  257. color: #2E3748;
  258. }
  259. .filter-title p{
  260. margin:10px 0;
  261. }
  262. .goods-list .el-form-item{
  263. margin-bottom: 8px;
  264. }
  265. </style>