index.vue 13 KB

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