index.vue 11 KB

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