index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div v-loading="loading">
  3. <div class="white-box">
  4. <el-table v-if="numList.length > 0" class="withdraw-table" :data="tableData" stripe style="width: 100%;" ref="multipleTable"
  5. @selection-change="handleSelectionChange">
  6. <el-table-column
  7. type="selection"
  8. width="55">
  9. </el-table-column>
  10. <!-- <el-table-column label="创建时间">
  11. <template slot-scope="scope">
  12. {{tool.formatDate(scope.row.CREATED_AT)}}
  13. </template>
  14. </el-table-column> -->
  15. <el-table-column label="商品名称" prop="GOODS_NAME">
  16. </el-table-column>
  17. <el-table-column label="图片" >
  18. <template slot-scope="scope">
  19. <el-image style="width: 100px; height: 100px" :src="tool.getLocaleLink(scope.row.COVER, '/files/')" :preview-src-list="[tool.getLocaleLink(scope.row.COVER, '/files/')]"></el-image>
  20. </template>
  21. </el-table-column>
  22. <el-table-column label="商品价格" prop="SELL_PRICE">
  23. </el-table-column>
  24. <el-table-column label="价格PV" prop="PRICE_PV">
  25. </el-table-column>
  26. <el-table-column label="库存" prop="STORE_NUMS">
  27. </el-table-column>
  28. <el-table-column label="数量" width="155">
  29. <template slot-scope="scope">
  30. <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>
  31. </template>
  32. </el-table-column>
  33. </el-table>
  34. <div class="white-box-footer">
  35. <el-button @click="goToAccounts()">去结算</el-button>
  36. <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import network from '@/utils/network'
  43. import baseInfo from '@/utils/baseInfo'
  44. import store from '@/utils/vuexStore'
  45. import tool from '@/utils/tool'
  46. import Pagination from '@/components/Pagination'
  47. export default {
  48. name: "index",
  49. components: {Pagination},
  50. mounted() {
  51. this.getData()
  52. },
  53. data() {
  54. return {
  55. loading: false,
  56. num:1,
  57. form:{
  58. },
  59. tableData:[],
  60. list: [],
  61. tool: tool,
  62. currentPage: 1,
  63. totalPages: 1,
  64. totalCount: 1,
  65. pageSize: 20,
  66. multipleSelection: [],
  67. is_go_order:true,
  68. numList: [],
  69. selectLock:false,
  70. }
  71. },
  72. watch: {
  73. '$route': function () {
  74. this.getData()
  75. }
  76. },
  77. methods: {
  78. handleChange(val){
  79. console.log(val);
  80. },
  81. goToAccounts() {
  82. this.is_go_order=true;
  83. // this.multipleSelection.map((item,index)=>{
  84. // item.chose_num = parseInt(item.chose_num);
  85. // if(item.chose_num==0){
  86. // this.$message({
  87. // message: '请选择商品数量进行结算',
  88. // type: 'error'
  89. // })
  90. // this.is_go_order=false
  91. // }
  92. // });
  93. console.log('this.multipleSelection',this.multipleSelection);
  94. setTimeout(()=>{
  95. if(this.is_go_order){
  96. sessionStorage.setItem('order_goods',JSON.stringify(this.multipleSelection))
  97. this.$router.push({path: `/shop/order`})
  98. }
  99. },0)
  100. // if (rows) {
  101. // rows.forEach(row => {
  102. // this.$refs.multipleTable.toggleRowSelection(row);
  103. // });
  104. // } else {
  105. // this.$refs.multipleTable.clearSelection();
  106. // }
  107. },
  108. handleSelectionChange(val) {
  109. if( this.selectLock ) return;
  110. let idx = -1,num;
  111. for(let i in this.tableData){
  112. for(let v in val){
  113. if(val[v].ID==this.tableData[i].ID){
  114. idx = i;
  115. num = this.numList[idx];
  116. val[v]["chose_num"] = num;
  117. break;
  118. }
  119. }
  120. }
  121. this.multipleSelection[this.currentPage] = val;
  122. console.log(this.multipleSelection);
  123. },
  124. handleInputNumber(val, row){
  125. let pageList = this.multipleSelection[this.currentPage];
  126. let selectStatus = false;
  127. for(let i in pageList){
  128. if( pageList[i].ID == row.ID ) {
  129. pageList[i].chose_num = val;
  130. selectStatus = true;
  131. break;
  132. }
  133. }
  134. if( selectStatus ) {
  135. this.multipleSelection[this.currentPage] = pageList;
  136. }
  137. },
  138. getScope(scope){
  139. console.log(scope);
  140. },
  141. handleCurrentChange (page) {
  142. this.getData(page, this.pageSize)
  143. },
  144. handleSizeChange (pageSize) {
  145. this.getData(this.currentPage, pageSize)
  146. },
  147. /*getData() {
  148. network.getData(`shop/index`).then(response => {
  149. console.log(response)
  150. this.loading = false;
  151. this.list = response.list;
  152. let settingObj=this.list;
  153. let settingArr = Object.keys(settingObj).map(key => {
  154. //console.log(key); //为每个键名
  155. return settingObj[key]; //把每个对象返回出去生成一个新的数组中相当于0:{id:1}
  156. } );
  157. this.tableData=settingArr;
  158. console.log(this.tableData)
  159. /!* this.$set(this.main_push,index,{...this.main_push[index],cacheImg:`http://naotianshi.cn/${this.lest[index].IMAGES}`})*!/
  160. }).catch(() => {
  161. });
  162. },*/
  163. getData (page, pageSize) {
  164. let obj = this
  165. network.getPageData(this, `shop/index`, page, pageSize, this.filterData, function (response) {
  166. obj.loading = false;
  167. obj.currentPage = response.currentPage;
  168. obj.list = response.list;
  169. let settingObj=obj.list;
  170. for(let i in settingObj){
  171. obj.numList[i] = 1;
  172. settingObj[i].chose_num=0;
  173. // obj.$refs.multipleTable.toggleRowSelection(settingObj[i],true);
  174. }
  175. // let settingArr = Object.keys(settingObj).map(key => {
  176. // this.numList[key] = 1;
  177. // // console.log(key); //为每个键名
  178. // settingObj[key].chose_num=0;
  179. // } );
  180. obj.selectLock = true;
  181. obj.tableData=Object.values(settingObj);
  182. let pageList = obj.multipleSelection[obj.currentPage];
  183. obj.$nextTick(function () {
  184. for(let i in obj.tableData){
  185. for( let j in pageList) {
  186. if( pageList[j].ID === obj.tableData[i].ID ) {
  187. obj.numList[i] = pageList[j].chose_num;
  188. obj.tableData[i].chose_num = pageList[j].chose_num;
  189. obj.$refs.multipleTable.toggleRowSelection(obj.tableData[i],true);
  190. break;
  191. }
  192. }
  193. }
  194. obj.selectLock = false;
  195. })
  196. })
  197. },
  198. }
  199. }
  200. </script>
  201. <style scoped>
  202. .flex{
  203. display: flex;
  204. }
  205. </style>