index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <div class="app-container">
  3. <!-- 查询条件 -->
  4. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
  5. <el-form-item label="公司名称">
  6. <el-select
  7. v-model="queryParams.companyIds"
  8. multiple
  9. placeholder="请输入公司名称搜索"
  10. style="width: 220px"
  11. clearable
  12. size="small"
  13. >
  14. <el-option
  15. v-for="item in formatterCompanyOptions"
  16. :key="item.dictValue"
  17. :label="item.dictLabel"
  18. :value="item.dictValue"
  19. />
  20. </el-select>
  21. </el-form-item>
  22. <el-form-item label="操作类型">
  23. <el-select v-model="queryParams.operationType" placeholder="请选择操作类型" clearable size="small">
  24. <el-option label="充值" :value="1"></el-option>
  25. <el-option label="扣费" :value="2"></el-option>
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item label="操作人员">
  29. <el-input
  30. v-model="queryParams.userName"
  31. placeholder="请输入操作人员"
  32. clearable
  33. size="small"
  34. @keyup.enter.native="handleQuery"
  35. />
  36. </el-form-item>
  37. <el-form-item label="操作时间">
  38. <el-date-picker
  39. v-model="dateRange"
  40. size="small"
  41. style="width: 240px"
  42. value-format="yyyy-MM-dd HH:mm:ss"
  43. type="datetimerange"
  44. range-separator="-"
  45. start-placeholder="开始日期"
  46. end-placeholder="结束日期"
  47. ></el-date-picker>
  48. </el-form-item>
  49. <el-form-item>
  50. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  51. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  52. </el-form-item>
  53. </el-form>
  54. <!-- 操作按钮区域 -->
  55. <el-row :gutter="10" class="mb8">
  56. <el-col :span="1.5">
  57. <el-button
  58. type="warning"
  59. plain
  60. icon="el-icon-download"
  61. size="mini"
  62. @click="handleExport"
  63. v-hasPermi="['company:trafficLog:export']"
  64. >导出</el-button>
  65. </el-col>
  66. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  67. </el-row>
  68. <!-- 数据表格 -->
  69. <el-table v-loading="loading" :data="trafficRecordList" @selection-change="handleSelectionChange">
  70. <el-table-column type="selection" width="55" align="center" />
  71. <el-table-column label="公司名称" align="center" prop="companyName" :show-overflow-tooltip="true" :formatter="companyNameFormatter"/>
  72. <el-table-column label="操作类型" align="center" prop="operationType">
  73. <template slot-scope="scope">
  74. <el-tag :type="scope.row.operationType === 1 ? 'success' : 'danger'">
  75. {{ scope.row.operationType === 1 ? '充值' : '扣费' }}
  76. </el-tag>
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="流量数量" align="center" prop="trafficAmount" >
  80. <template slot-scope="scope">
  81. <span :class="scope.row.operationType === 1 ? 'recharge' : 'deduction'">
  82. {{ scope.row.operationType === 1 ? '+' : '-' }}{{ formatTrafficAmount(scope.row)}}
  83. </span>
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="操作后余额" align="center" prop="balance" :formatter="formatBalance"/>
  87. <el-table-column label="操作人员" align="center" prop="userName" />
  88. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  89. <el-table-column label="操作时间" align="center" prop="createTime" width="180">
  90. <template slot-scope="scope">
  91. <span>{{ parseTime(scope.row.createTime) }}</span>
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. <!-- 分页 -->
  96. <pagination
  97. v-show="total>0"
  98. :total="total"
  99. :page.sync="queryParams.pageNum"
  100. :limit.sync="queryParams.pageSize"
  101. @pagination="getList"
  102. />
  103. </div>
  104. </template>
  105. <script>
  106. import { listTrafficLog, listTrafficLogExport } from "@/api/company/trafficLog";
  107. import { allList } from '@/api/company/company'
  108. export default {
  109. name: "CompanyTrafficLog",
  110. data() {
  111. return {
  112. // 遮罩层
  113. loading: true,
  114. // 选中数组
  115. ids: [],
  116. // 非单个禁用
  117. single: true,
  118. // 非多个禁用
  119. multiple: true,
  120. // 显示搜索条件
  121. showSearch: true,
  122. // 总条数
  123. total: 0,
  124. // 流量记录表格数据
  125. trafficRecordList: [],
  126. // 日期范围
  127. dateRange: [],
  128. // 公司搜索相关
  129. companySearchLoading: false,
  130. companyOptions: [],
  131. formatterCompanyOptions: [],
  132. // 查询参数
  133. queryParams: {
  134. pageNum: 1,
  135. pageSize: 10,
  136. companyName: null,
  137. companyId: null,
  138. companyIds: [], // 多选公司ID
  139. operationType: null,
  140. userName: null,
  141. createTime: null,
  142. createTimeStart: null,
  143. createTimeEnd: null
  144. }
  145. };
  146. },
  147. created() {
  148. this.getList();
  149. //初始化formatterCompanyOptions
  150. allList().then(e => {
  151. this.formatterCompanyOptions = e.rows;
  152. });
  153. },
  154. methods: {
  155. /** 查询流量记录列表 */
  156. getList() {
  157. this.loading = true;
  158. // 处理日期范围
  159. if (this.dateRange && this.dateRange.length === 2) {
  160. this.queryParams.createTimeStart = this.dateRange[0];
  161. this.queryParams.createTimeEnd = this.dateRange[1];
  162. } else {
  163. this.queryParams.createTimeStart = null;
  164. this.queryParams.createTimeEnd = null;
  165. }
  166. listTrafficLog(this.queryParams).then(response => {
  167. this.trafficRecordList = response.rows;
  168. this.total = response.total;
  169. this.loading = false;
  170. });
  171. },
  172. formatBalance(row){
  173. //对流量值进行判断,换算成GB或TB
  174. if(!row.balance){
  175. return "0 KB";
  176. }
  177. const absBalance = Math.abs(row.balance); // 获取绝对值
  178. if(absBalance < 1024){
  179. return row.balance + " KB";
  180. }
  181. else if(absBalance < 1024 * 1024){
  182. return (row.balance / 1024).toFixed(2) + " MB";
  183. }
  184. else if(absBalance < 1024 * 1024 * 1024){
  185. return (row.balance / (1024 * 1024)).toFixed(2) + " GB";
  186. }
  187. else{
  188. return (row.balance / (1024 * 1024 * 1024)).toFixed(2) + " TB";
  189. }
  190. },
  191. formatTrafficAmount(row){
  192. //对流量值进行判断,换算成GB或TB
  193. if(!row.trafficAmount){
  194. return "0 KB";
  195. }
  196. const absBalance = Math.abs(row.trafficAmount); // 获取绝对值
  197. if(absBalance < 1024){
  198. return row.trafficAmount + " KB";
  199. }
  200. else if(absBalance < 1024 * 1024){
  201. return (row.trafficAmount / 1024).toFixed(2) + " MB";
  202. }
  203. else if(absBalance < 1024 * 1024 * 1024){
  204. return (row.trafficAmount / (1024 * 1024)).toFixed(2) + " GB";
  205. }
  206. else{
  207. return (row.trafficAmount / (1024 * 1024 * 1024)).toFixed(2) + " TB";
  208. }
  209. },
  210. /** 搜索公司 */
  211. searchCompanies(query) {
  212. this.companySearchLoading = true;
  213. allList().then(response => {
  214. this.companyOptions = response.rows;
  215. if (query) {
  216. this.companyOptions = this.companyOptions.filter(item =>
  217. item.dictLabel.includes(query)
  218. );
  219. }
  220. this.companySearchLoading = false;
  221. }).catch(()=>{
  222. this.companySearchLoading = false;
  223. });
  224. },
  225. /** 搜索按钮操作 */
  226. handleQuery() {
  227. this.queryParams.pageNum = 1;
  228. this.getList();
  229. },
  230. /** 重置按钮操作 */
  231. resetQuery() {
  232. this.dateRange = [];
  233. this.resetForm("queryForm");
  234. this.handleQuery();
  235. },
  236. /** 多选框选中数据 */
  237. handleSelectionChange(selection) {
  238. this.ids = selection.map(item => item.id)
  239. this.single = selection.length !== 1
  240. this.multiple = !selection.length
  241. },
  242. companyNameFormatter(row){
  243. return this.formatterCompanyOptions.filter(item => item.dictValue === row.companyId)[0].dictLabel
  244. },
  245. /** 导出按钮操作 */
  246. handleExport() {
  247. const queryParams = {...this.queryParams};
  248. // 处理日期范围
  249. if (this.dateRange && this.dateRange.length === 2) {
  250. queryParams.createTimeStart = this.dateRange[0];
  251. queryParams.createTimeEnd = this.dateRange[1];
  252. }
  253. this.$confirm('是否确认导出所有流量充值记录数据项?', "警告", {
  254. confirmButtonText: "确定",
  255. cancelButtonText: "取消",
  256. type: "warning"
  257. }).then(() => {
  258. this.exportLoading = true;
  259. return listTrafficLogExport(queryParams);
  260. }).then(response => {
  261. this.download(response.msg);
  262. this.exportLoading = false;
  263. }).catch(() => {});
  264. }
  265. }
  266. };
  267. </script>
  268. <style scoped>
  269. .recharge {
  270. color: #67C23A;
  271. font-weight: bold;
  272. }
  273. .deduction {
  274. color: #F56C6C;
  275. font-weight: bold;
  276. }
  277. .mb8 {
  278. margin-bottom: 8px;
  279. }
  280. </style>