car-fund-products.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <div class="app-container">
  3. <el-table
  4. :key="tableKey"
  5. v-loading="listLoading"
  6. :data="tableData"
  7. border
  8. fit
  9. highlight-current-row
  10. style="width: 100%;"
  11. ref="multipleTable"
  12. @selection-change="handleSelectionChange"
  13. >
  14. <el-table-column type="selection" width="70" align="center"></el-table-column>
  15. <el-table-column :label="$t('shop.productName')" align="center" prop="GOODS_NAME">
  16. <template slot-scope="{row}">
  17. <span>{{ row.GOODS_NAME }}</span>
  18. </template>
  19. </el-table-column>
  20. <el-table-column :label="$t('shop.productPicture')" align="center" min-width="70px" prop="GOODS_NAME">
  21. <template slot-scope="{row}">
  22. <el-image
  23. style="width: 70px; height: 70px"
  24. :src="tool.getArImage(row.COVER, '/files/')"
  25. :preview-src-list="[tool.getArImage(row.COVER, '/files/')]"
  26. >
  27. </el-image>
  28. </template>
  29. </el-table-column>
  30. <el-table-column :label="$t('shop.productPrice')" align="center" prop="SELL_PRICE">
  31. <template slot-scope="{row}">
  32. <span>{{ row.SELL_PRICE }}</span>
  33. </template>
  34. </el-table-column>
  35. <el-table-column :label="$t('shop.productBV')" align="center" prop="PRICE_PV">
  36. <template slot-scope="{row}">
  37. <span>{{ row.PRICE_PV }}</span>
  38. </template>
  39. </el-table-column>
  40. <el-table-column :label="$t('shop.taxRate')" align="center" prop="TAX_RATE">
  41. <template slot-scope="{row}">
  42. <span>{{ row.TAX_RATE / 100 }}</span>
  43. </template>
  44. </el-table-column>
  45. <el-table-column :label="$t('shop.taxAmount')" align="center">
  46. <template slot-scope="{row}">
  47. <span>{{ row | taxAmountFilter }}</span>
  48. </template>
  49. </el-table-column>
  50. <el-table-column :label="$t('shop.inventory')" align="center" prop="STORE_NUMS">
  51. <template slot-scope="{row}">
  52. <span>{{ row.STORE_NUMS }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column :label="$t('shop.inventory')" min-width="90" align="center">
  56. <template slot-scope="scope">
  57. <el-input-number size="mini" v-model="storeNums[scope.$index]" :min="0" :max="Number(scope.row.STORE_NUMS)" @change="(val)=>{handleInputNumber(val, scope.row)}"></el-input-number>
  58. </template>
  59. </el-table-column>
  60. </el-table>
  61. <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  62. <div class="white-box-footer" v-show="display" style="margin-top: 15px;">
  63. <div class="flex data" style="float: left; display: inline-block; margin-top: 20px;">
  64. <el-button type="primary" size="small" @click="settlement()" style="float: left;">{{ $t('shop.checkOut') }}</el-button>
  65. </div>
  66. <div class="flex data" style="float: right; display: inline-block; line-height: 35px; font-size: 14px; margin-top: 20px; border: 1px solid #dcdfe6; border-radius: 4px; padding: 0 15px;">
  67. <div style="margin-right: 2rem; display: inline-block;">{{ $t('shop.productPrice') }}:{{ $t('currency.sign') }} {{ sellPriceSum }}</div>
  68. <div style="margin-right: 2rem; display: inline-block;">{{ $t('shop.productBV') }}:{{ $t('currency.sign') }} {{ pricePvSum }}</div>
  69. <div style="display: inline-block;">{{ $t('shop.taxAmount') }}:{{ $t('currency.sign') }} {{ taxSum }}</div>
  70. </div>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import { fetchProductList, fetchProduct } from '@/api/shop'
  76. import waves from '@/directive/waves'
  77. import { parseTime } from '@/utils'
  78. import tool from '@/utils/tool'
  79. import Pagination from '@/components/Pagination'
  80. export default {
  81. name: 'carFundProducts',
  82. components: { Pagination },
  83. directives: { waves },
  84. filters: {
  85. priceFilter(price) {
  86. return tool.formatPrice(price)
  87. },
  88. taxAmountFilter(row) {
  89. return tool.calculateTax(row.SELL_PRICE, row.TAX_RATE)
  90. },
  91. statusFilter(status) {
  92. const statusMap = {
  93. Unpaid: 'info',
  94. Paid: 'success',
  95. }
  96. return statusMap[status]
  97. },
  98. },
  99. data() {
  100. return {
  101. tableKey: 0,
  102. list: [],
  103. total: 0,
  104. tableData: [],
  105. listLoading: true,
  106. listQuery: {
  107. categoryType: 5,
  108. page: 1,
  109. limit: 20,
  110. },
  111. tool: tool,
  112. multipleSelection: [],
  113. sellPriceSum: 0.00,
  114. pricePvSum: 0.00,
  115. taxSum: 0.00,
  116. storeNums: [],
  117. display: false,
  118. currentPage: 1,
  119. }
  120. },
  121. created() {
  122. // 商品列表查询
  123. this.getList()
  124. },
  125. methods: {
  126. // 商品类别
  127. getList() {
  128. this.listLoading = true
  129. fetchProductList(this.listQuery).then(response => {
  130. this.list = response.data.list
  131. this.total = parseInt(response.data.totalCount)
  132. setTimeout(() => {
  133. this.listLoading = false
  134. }, 1.5 * 1000)
  135. let settingObj = this.list
  136. for (let i in this.list) {
  137. this.storeNums[i] = 1
  138. settingObj[i].chose_num = 0
  139. }
  140. this.tableData = Object.values(settingObj)
  141. let pageList = this.multipleSelection[this.currentPage]
  142. this.$nextTick(function () {
  143. for (let i in this.tableData) {
  144. for( let j in pageList) {
  145. if( pageList[j].ID === this.tableData[i].ID ) {
  146. this.$data.storeNums[i] = pageList[j].chose_num
  147. this.tableData[i].chose_num = pageList[j].chose_num
  148. break
  149. }
  150. }
  151. }
  152. })
  153. })
  154. },
  155. // 选择商品计数
  156. handleInputNumber(val, row){
  157. let pageList = this.multipleSelection[this.currentPage]
  158. let selectStatus = false
  159. for (let i in pageList) {
  160. if( pageList[i].ID === row.ID ) {
  161. pageList[i].chose_num = val
  162. selectStatus = true
  163. break
  164. }
  165. }
  166. if (selectStatus) {
  167. this.multipleSelection[this.currentPage] = pageList
  168. this.handleSureChange()
  169. }
  170. },
  171. // 统计商品
  172. handleSureChange() {
  173. if (this.multipleSelection.length > 0) {
  174. let accumulatorSellPrice = 0, accumulatorPricePv = 0, accumulatorTax = 0
  175. this.multipleSelection.forEach(item => {
  176. item.forEach(accumulator => { accumulatorSellPrice += accumulator.SELL_PRICE * accumulator.chose_num * accumulator.DISCOUNT / 100; })
  177. item.forEach(accumulator => { accumulatorPricePv += Number(accumulator.PRICE_PV) * Number(accumulator.chose_num) * (Number(accumulator.DISCOUNT) / 100); })
  178. item.forEach(accumulator => { accumulatorTax += tool.calculateTax(Number(accumulator.SELL_PRICE), Number(accumulator.TAX_RATE), Number(accumulator.chose_num)); })
  179. })
  180. this.sellPriceSum = tool.formatPrice(accumulatorSellPrice)
  181. this.pricePvSum = tool.formatPrice(accumulatorPricePv)
  182. this.taxSum = tool.formatPrice(accumulatorTax)
  183. this.display = true
  184. } else {
  185. this.sellPriceSum = this.pricePvSum = this.taxSum = 0.00
  186. this.display = true
  187. }
  188. },
  189. handleSelectionChange(val) {
  190. let idx = -1, num
  191. for (let i in this.tableData) {
  192. for (let v in val) {
  193. if (val[v].ID === this.tableData[i].ID) {
  194. idx = i
  195. num = this.storeNums[idx]
  196. val[v]["chose_num"] = num
  197. break
  198. }
  199. }
  200. }
  201. this.multipleSelection[this.currentPage] = val
  202. // 计算统计
  203. this.handleSureChange()
  204. },
  205. // 结算商品
  206. settlement() {
  207. }
  208. },
  209. watch: {
  210. // 监听多选按钮,判断结算按钮是否可用
  211. multipleSelection: function (modern) {
  212. console.log(modern, modern.length)
  213. this.$data.display = modern.length > 0
  214. },
  215. },
  216. }
  217. </script>