index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <div v-loading="loading">
  3. <div class="white-box">
  4. <el-tabs v-model="goodsCategory" @tab-click="handleClick">
  5. <el-tab-pane v-for="(item, key) in goodsActive" :key="key" :label="item.label" :name="item.name">
  6. <el-table v-if="numList.length > 0" class="withdraw-table" :data="tableData" stripe style="width: 100%;" ref="multipleTable" @selection-change="handleSelectionChange">
  7. <el-table-column
  8. type="selection"
  9. width="55">
  10. </el-table-column>
  11. <!-- <el-table-column label="创建时间">
  12. <template slot-scope="scope">
  13. {{tool.formatDate(scope.row.CREATED_AT)}}
  14. </template>
  15. </el-table-column> -->
  16. <el-table-column label="Product Name" prop="GOODS_NAME"><!--商品名称-->
  17. </el-table-column>
  18. <el-table-column label="Product picture" ><!--图片-->
  19. <template slot-scope="scope">
  20. <img :src="scope.row.COVER" alt="" style="width:100px" >
  21. </template>
  22. </el-table-column>
  23. <el-table-column label="Product price" prop="SELL_PRICE"><!--商品价格-->
  24. <template slot-scope="scope">
  25. <span>{{ Math.round(scope.row.SELL_PRICE * 100) / 100 }}</span>
  26. </template>
  27. </el-table-column>
  28. <el-table-column label="Product BV" prop="PRICE_PV" v-if="goodsCategory === '1'"><!--价格PV-->
  29. <template slot-scope="scope">
  30. <span>{{ Math.round(scope.row.PRICE_PV * 100) / 100 }}</span>
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="Inventory" prop="STORE_NUMS"><!--库存-->
  34. </el-table-column>
  35. <el-table-column label="Quantity" width="155"><!--数量-->
  36. <template slot-scope="scope">
  37. <el-input-number size="mini" v-model="numList[scope.$index]" :min="0" :max="Number(scope.row.STORE_NUMS)" @change="(val)=>{handleInputNumber(val, scope.row)}"></el-input-number>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. </el-tab-pane>
  42. </el-tabs>
  43. <div class="white-box-footer">
  44. <el-button @click="goToAccounts()">Settle accounts</el-button><!--去结算-->
  45. <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import network from '@/utils/network'
  52. import baseInfo from '@/utils/baseInfo'
  53. import store from '@/utils/vuexStore'
  54. import tool from '@/utils/tool'
  55. import Pagination from '@/components/Pagination'
  56. export default {
  57. name: "index",
  58. components: {Pagination},
  59. mounted() {
  60. this.getGoodsActive()
  61. this.getData()
  62. },
  63. data() {
  64. return {
  65. loading: false,
  66. num:1,
  67. form:{
  68. },
  69. tableData:[],
  70. list: [],
  71. tool: tool,
  72. currentPage: 1,
  73. totalPages: 1,
  74. totalCount: 1,
  75. pageSize: 20,
  76. multipleSelection: [],
  77. is_go_order:true,
  78. numList: [],
  79. selectLock:false,
  80. goodsCategory: '1',
  81. goodsActive: [],
  82. }
  83. },
  84. watch: {
  85. '$route': function () {
  86. this.getData()
  87. },
  88. // 监听多选按钮,判断结算按钮是否可用
  89. // multipleSelection: function (modern, origin) {
  90. // if (modern.length > 0) {
  91. // this.$data.disabled = false
  92. // }
  93. // },
  94. },
  95. methods: {
  96. handleChange(val){
  97. console.log(val);
  98. },
  99. goToAccounts() {
  100. this.is_go_order=true;
  101. // this.multipleSelection.map((item,index)=>{
  102. // item.chose_num = parseInt(item.chose_num);
  103. // if(item.chose_num==0){
  104. // this.$message({
  105. // message: '请选择商品数量进行结算',
  106. // type: 'error'
  107. // })
  108. // this.is_go_order=false
  109. // }
  110. // });
  111. setTimeout(()=>{
  112. if(this.is_go_order){
  113. sessionStorage.setItem('order_goods',JSON.stringify(this.multipleSelection))
  114. sessionStorage.setItem('category_type', this.goodsCategory)
  115. this.$router.push({path: `/shop/order`})
  116. }
  117. },0)
  118. // if (rows) {
  119. // rows.forEach(row => {
  120. // this.$refs.multipleTable.toggleRowSelection(row);
  121. // });
  122. // } else {
  123. // this.$refs.multipleTable.clearSelection();
  124. // }
  125. },
  126. handleSelectionChange(val) {
  127. if( this.selectLock ) return;
  128. let idx = -1,num;
  129. for(let i in this.tableData){
  130. for(let v in val){
  131. if(val[v].ID==this.tableData[i].ID){
  132. idx = i;
  133. num = this.numList[idx];
  134. val[v]["chose_num"] = num;
  135. break;
  136. }
  137. }
  138. }
  139. this.multipleSelection[this.currentPage] = val;
  140. console.log(this.multipleSelection);
  141. },
  142. handleInputNumber(val, row){
  143. let pageList = this.multipleSelection[this.currentPage];
  144. let selectStatus = false;
  145. for(let i in pageList){
  146. if( pageList[i].ID == row.ID ) {
  147. pageList[i].chose_num = val;
  148. selectStatus = true;
  149. break;
  150. }
  151. }
  152. if( selectStatus ) {
  153. this.multipleSelection[this.currentPage] = pageList;
  154. }
  155. },
  156. getScope(scope){
  157. console.log(scope);
  158. },
  159. handleCurrentChange (page) {
  160. this.getData(page, this.pageSize)
  161. },
  162. handleSizeChange (pageSize) {
  163. this.getData(this.currentPage, pageSize)
  164. },
  165. /*getData() {
  166. network.getData(`shop/index`).then(response => {
  167. console.log(response)
  168. this.loading = false;
  169. this.list = response.list;
  170. let settingObj=this.list;
  171. let settingArr = Object.keys(settingObj).map(key => {
  172. //console.log(key); //为每个键名
  173. return settingObj[key]; //把每个对象返回出去生成一个新的数组中相当于0:{id:1}
  174. } );
  175. this.tableData=settingArr;
  176. console.log(this.tableData)
  177. /!* this.$set(this.main_push,index,{...this.main_push[index],cacheImg:`http://naotianshi.cn/${this.lest[index].IMAGES}`})*!/
  178. }).catch(() => {
  179. });
  180. },*/
  181. getData (page, pageSize) {
  182. let obj = this
  183. network.getPageData(this, `shop/index`, page, pageSize, { categoryType: obj.goodsCategory }, function (response) {
  184. obj.loading = false;
  185. obj.currentPage = response.currentPage;
  186. obj.list = response.list;
  187. let settingObj=obj.list;
  188. for(let i in settingObj){
  189. obj.numList[i] = 1;
  190. settingObj[i].chose_num=0;
  191. // obj.$refs.multipleTable.toggleRowSelection(settingObj[i],true);
  192. }
  193. // let settingArr = Object.keys(settingObj).map(key => {
  194. // this.numList[key] = 1;
  195. // // console.log(key); //为每个键名
  196. // settingObj[key].chose_num=0;
  197. // } );
  198. obj.selectLock = true;
  199. obj.tableData=Object.values(settingObj);
  200. let pageList = obj.multipleSelection[obj.currentPage];
  201. obj.$nextTick(function () {
  202. for(let i in obj.tableData){
  203. for( let j in pageList) {
  204. if( pageList[j].ID === obj.tableData[i].ID ) {
  205. obj.numList[i] = pageList[j].chose_num;
  206. obj.tableData[i].chose_num = pageList[j].chose_num;
  207. obj.$refs.multipleTable.toggleRowSelection(obj.tableData[i],true);
  208. break;
  209. }
  210. }
  211. }
  212. obj.selectLock = false;
  213. })
  214. })
  215. },
  216. // 获取商品类型,填充tabs页
  217. getGoodsActive() {
  218. network.getData(`shop/goods-active`).then(response => {
  219. this.goodsActive = response
  220. })
  221. },
  222. // 切换tab页回调
  223. handleClick(tab) {
  224. // 切换标签. 查询商品列表,将当期商品分类传入查询条件filter
  225. this.goodsCategory = tab.name
  226. // 查询商品列表
  227. this.getData()
  228. },
  229. }
  230. }
  231. </script>
  232. <style scoped>
  233. .flex{
  234. display: flex;
  235. }
  236. </style>