index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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-row>
  56. <el-col :span="2">
  57. <el-button type="primary" size="small" @click="goToAccounts()">Check Out</el-button><!--去结算-->
  58. </el-col>
  59. <el-col :span="16">
  60. <div class='flex data' style="flex:1; justify-content: center; line-height: 35px; font-size: 14px;">
  61. <div style="margin-right: 2rem;">Product price:₦ {{ sell_price_sum }}</div><!--商品价格-->
  62. <div style="margin-right: 2rem;">Product BV:{{ price_pv_sum }}</div><!--商品BV-->
  63. <div>Product Tax:₦ {{ tax_sum }}</div><!--商品BV-->
  64. </div>
  65. </el-col>
  66. <el-col :span="6">
  67. <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
  68. </el-col>
  69. </el-row>
  70. </div>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import network from '@/utils/network'
  76. import baseInfo from '@/utils/baseInfo'
  77. import store from '@/utils/vuexStore'
  78. import tool from '@/utils/tool'
  79. import Pagination from '@/components/Pagination'
  80. export default {
  81. name: "index",
  82. components: {Pagination},
  83. mounted() {
  84. this.getGoodsActive()
  85. this.getData()
  86. },
  87. data() {
  88. return {
  89. loading: false,
  90. num:1,
  91. form:{
  92. },
  93. tableData:[],
  94. list: [],
  95. tool: tool,
  96. currentPage: 1,
  97. totalPages: 1,
  98. totalCount: 1,
  99. pageSize: 20,
  100. multipleSelection: [],
  101. is_go_order:true,
  102. numList: [],
  103. selectLock:false,
  104. goodsCategory: '1',
  105. goodsActive: [],
  106. maxHeight: tool.getTableHeight(),
  107. sell_price_sum: 0.00,
  108. price_pv_sum: 0.00,
  109. tax_sum: 0.00,
  110. }
  111. },
  112. watch: {
  113. '$route': function () {
  114. this.getData()
  115. },
  116. // 监听多选按钮,判断结算按钮是否可用
  117. // multipleSelection: function (modern, origin) {
  118. // if (modern.length > 0) {
  119. // this.$data.disabled = false
  120. // }
  121. // },
  122. },
  123. methods: {
  124. handleChange(val){
  125. },
  126. goToAccounts() {
  127. if (this.multipleSelection.length <= 0) {
  128. this.$message.error('Please choose the products.')
  129. return false
  130. }
  131. this.is_go_order=true;
  132. // this.multipleSelection.map((item,index)=>{
  133. // item.chose_num = parseInt(item.chose_num);
  134. // if(item.chose_num==0){
  135. // this.$message({
  136. // message: '请选择商品数量进行结算',
  137. // type: 'error'
  138. // })
  139. // this.is_go_order=false
  140. // }
  141. // });
  142. setTimeout(()=>{
  143. if(this.is_go_order){
  144. sessionStorage.setItem('order_goods',JSON.stringify(this.multipleSelection))
  145. sessionStorage.setItem('category_type', this.goodsCategory)
  146. this.$router.push({path: `/shop/order`})
  147. }
  148. },0)
  149. // if (rows) {
  150. // rows.forEach(row => {
  151. // this.$refs.multipleTable.toggleRowSelection(row);
  152. // });
  153. // } else {
  154. // this.$refs.multipleTable.clearSelection();
  155. // }
  156. },
  157. handleSelectionChange(val) {
  158. if( this.selectLock ) return;
  159. let idx = -1,num;
  160. for(let i in this.tableData){
  161. for(let v in val){
  162. if(val[v].ID==this.tableData[i].ID){
  163. idx = i;
  164. num = this.numList[idx];
  165. val[v]["chose_num"] = num;
  166. break;
  167. }
  168. }
  169. }
  170. this.multipleSelection[this.currentPage] = val;
  171. // 计算统计
  172. this.handleSureChange()
  173. },
  174. handleSureChange() {
  175. if (this.multipleSelection.length > 0) {
  176. let accumulatorSellPrice = 0, accumulatorPricePv = 0, accumulatorTax = 0;
  177. this.multipleSelection.forEach(item => {
  178. item.forEach(accumulator => { accumulatorSellPrice += accumulator.SELL_PRICE * accumulator.chose_num * accumulator.DISCOUNT / 100; });
  179. item.forEach(accumulator => { accumulatorPricePv += Number(accumulator.PRICE_PV) * Number(accumulator.chose_num) * (Number(accumulator.DISCOUNT) / 100); });
  180. item.forEach(accumulator => { accumulatorTax += tool.calculateTax(Number(accumulator.SELL_PRICE), Number(accumulator.TAX_RATE), Number(accumulator.chose_num)); });
  181. })
  182. this.sell_price_sum = parseFloat(accumulatorSellPrice).toFixed(2);
  183. this.price_pv_sum = parseFloat(accumulatorPricePv).toFixed(2);
  184. this.tax_sum = parseFloat(accumulatorTax).toFixed(2);
  185. } else {
  186. this.sell_price_sum = 0.00;
  187. this.price_pv_sum = 0.00;
  188. this.tax_sum = 0.00;
  189. }
  190. },
  191. handleInputNumber(val, row){
  192. let pageList = this.multipleSelection[this.currentPage];
  193. let selectStatus = false;
  194. for(let i in pageList){
  195. if( pageList[i].ID == row.ID ) {
  196. pageList[i].chose_num = val;
  197. selectStatus = true;
  198. break;
  199. }
  200. }
  201. if( selectStatus ) {
  202. this.multipleSelection[this.currentPage] = pageList;
  203. // 计算统计
  204. this.handleSureChange()
  205. }
  206. },
  207. getScope(scope){
  208. console.log(scope);
  209. },
  210. handleCurrentChange (page) {
  211. this.getData(page, this.pageSize)
  212. },
  213. handleSizeChange (pageSize) {
  214. this.getData(this.currentPage, pageSize)
  215. },
  216. /*getData() {
  217. network.getData(`shop/index`).then(response => {
  218. console.log(response)
  219. this.loading = false;
  220. this.list = response.list;
  221. let settingObj=this.list;
  222. let settingArr = Object.keys(settingObj).map(key => {
  223. //console.log(key); //为每个键名
  224. return settingObj[key]; //把每个对象返回出去生成一个新的数组中相当于0:{id:1}
  225. } );
  226. this.tableData=settingArr;
  227. console.log(this.tableData)
  228. /!* this.$set(this.main_push,index,{...this.main_push[index],cacheImg:`http://naotianshi.cn/${this.lest[index].IMAGES}`})*!/
  229. }).catch(() => {
  230. });
  231. },*/
  232. getData (page, pageSize) {
  233. let obj = this
  234. network.getPageData(this, `shop/index`, page, pageSize, { categoryType: obj.goodsCategory }, function (response) {
  235. obj.loading = false;
  236. obj.currentPage = response.currentPage;
  237. obj.list = response.list;
  238. let settingObj=obj.list;
  239. for(let i in settingObj){
  240. obj.numList[i] = 1;
  241. settingObj[i].chose_num=0;
  242. // obj.$refs.multipleTable.toggleRowSelection(settingObj[i],true);
  243. }
  244. // let settingArr = Object.keys(settingObj).map(key => {
  245. // this.numList[key] = 1;
  246. // // console.log(key); //为每个键名
  247. // settingObj[key].chose_num=0;
  248. // } );
  249. obj.selectLock = true;
  250. obj.tableData=Object.values(settingObj);
  251. let pageList = obj.multipleSelection[obj.currentPage];
  252. obj.$nextTick(function () {
  253. for(let i in obj.tableData){
  254. for( let j in pageList) {
  255. if( pageList[j].ID === obj.tableData[i].ID ) {
  256. obj.numList[i] = pageList[j].chose_num;
  257. obj.tableData[i].chose_num = pageList[j].chose_num;
  258. obj.$refs.multipleTable.toggleRowSelection(obj.tableData[i],true);
  259. break;
  260. }
  261. }
  262. }
  263. obj.selectLock = false;
  264. })
  265. })
  266. },
  267. // 获取商品类型,填充tabs页
  268. getGoodsActive() {
  269. network.getData(`shop/goods-active`).then(response => {
  270. this.goodsActive = response
  271. })
  272. },
  273. // 切换tab页回调
  274. handleClick(tab) {
  275. // 切换标签. 查询商品列表,将当期商品分类传入查询条件filter
  276. this.goodsCategory = tab.name
  277. // 查询商品列表
  278. this.getData()
  279. },
  280. }
  281. }
  282. </script>
  283. <style scoped>
  284. .flex{
  285. display: flex;
  286. }
  287. </style>