indexhdt.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <!-- <el-form-item label="公司名称" prop="companyId" >-->
  5. <!-- <el-select v-model="queryParams.companyId" placeholder="请选择所属公司" filterable clearable size="small">-->
  6. <!-- <el-option v-for="(option, index) in companyList" :key="index" :value="option.dictValue" :label="option.dictLabel"></el-option>-->
  7. <!-- </el-select>-->
  8. <!-- </el-form-item>-->
  9. <el-form-item label="项目" prop="project">
  10. <el-select v-model="queryParams.project" placeholder="请选择项目" filterable clearable size="small">
  11. <el-option
  12. v-for="dict in projectOptions"
  13. :key="dict.dictValue"
  14. :label="dict.dictLabel"
  15. :value="dict.dictValue"
  16. />
  17. </el-select>
  18. </el-form-item>
  19. <!-- <el-form-item label="课程" prop="courseId">-->
  20. <!-- <el-select filterable v-model="queryParams.courseId" placeholder="请选择课程" clearable size="small" @change="courseChange(queryParams.courseId)">-->
  21. <!-- <el-option-->
  22. <!-- v-for="dict in courseLists"-->
  23. <!-- :key="dict.dictValue"-->
  24. <!-- :label="dict.dictLabel"-->
  25. <!-- :value="dict.dictValue"-->
  26. <!-- />-->
  27. <!-- </el-select>-->
  28. <!-- </el-form-item>-->
  29. <el-form-item label="年月" prop="time">
  30. <el-date-picker
  31. v-model="time"
  32. type="daterange"
  33. placeholder="选择年月"
  34. :picker-options="pickerOptions"
  35. :value-format="'yyyy-MM-dd'"
  36. @change="handleDateData"
  37. ></el-date-picker>
  38. </el-form-item>
  39. <el-form-item>
  40. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  41. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  42. </el-form-item>
  43. </el-form>
  44. <el-row :gutter="10" class="mb8">
  45. <el-col :span="1.5">
  46. <el-button
  47. type="warning"
  48. plain
  49. icon="el-icon-download"
  50. size="mini"
  51. :loading="exportLoading"
  52. @click="handleExport"
  53. v-hasPermi="['course:courseTrafficLog:export']"
  54. >导出</el-button>
  55. </el-col>
  56. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  57. </el-row>
  58. <el-table border v-loading="loading" :data="courseTrafficLogList" @selection-change="handleSelectionChange" show-summary :summary-method="getSummaries">
  59. <el-table-column type="selection" width="55" align="center" />
  60. <el-table-column label="项目" align="center" prop="projectName" />
  61. <el-table-column label="日期" align="center" prop="month" />
  62. <el-table-column label="使用流量" align="center" prop="totalInternetTraffic">
  63. <template slot-scope="scope">
  64. <span>{{ formatTrafficData(scope.row.totalInternetTraffic) }}</span>
  65. </template>
  66. </el-table-column>
  67. <!-- <el-table-column label="费用" align="center">-->
  68. <!-- <template slot-scope="scope">-->
  69. <!-- <span>{{ formatTrafficMoney(scope.row.totalInternetTraffic) }}</span>-->
  70. <!-- </template>-->
  71. <!-- </el-table-column>-->
  72. </el-table>
  73. <pagination
  74. v-show="total>0"
  75. :total="total"
  76. :page.sync="queryParams.pageNum"
  77. :limit.sync="queryParams.pageSize"
  78. @pagination="getList"
  79. />
  80. </div>
  81. </template>
  82. <script>
  83. import { listCourseTrafficLog, getCourseTrafficLog, delCourseTrafficLog, addCourseTrafficLog, updateCourseTrafficLog, exportCourseTrafficLog } from "@/api/course/courseTrafficLog";
  84. import {courseList} from "@/api/course/courseRedPacketLog";
  85. import {allList}from "@/api/company/company";
  86. export default {
  87. name: "CourseTrafficLog",
  88. data() {
  89. return {
  90. pickerOptions: {
  91. shortcuts: [{
  92. text: '最近一周',
  93. onClick(picker) {
  94. const end = new Date();
  95. const start = new Date();
  96. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  97. picker.$emit('pick', [start, end]);
  98. }
  99. }]
  100. },
  101. companyList:[],
  102. // 遮罩层
  103. loading: false,
  104. // 导出遮罩层
  105. exportLoading: false,
  106. // 选中数组
  107. ids: [],
  108. // 非单个禁用
  109. single: true,
  110. // 非多个禁用
  111. multiple: true,
  112. // 显示搜索条件
  113. showSearch: true,
  114. // 总条数
  115. total: 0,
  116. // 短链课程流量记录表格数据
  117. courseTrafficLogList: [],
  118. projectOptions:[],
  119. courseLists:[],
  120. // 弹出层标题
  121. title: "",
  122. // 是否显示弹出层
  123. open: false,
  124. time: null,
  125. // 查询参数
  126. queryParams: {
  127. startDate: null,
  128. endDate: null,
  129. pageNum: 1,
  130. pageSize: 10,
  131. userId: null,
  132. videoId: null,
  133. qwExternalContactId: null,
  134. internetTraffic: null,
  135. qwUserId: null,
  136. companyUserId: null,
  137. companyId: null,
  138. courseId: null,
  139. tabType: 'project'
  140. },
  141. // 表单参数
  142. form: {},
  143. // 表单校验
  144. rules: {
  145. }
  146. };
  147. },
  148. created() {
  149. courseList().then(response => {
  150. this.courseLists = response.list;
  151. });
  152. this.getDicts("sys_course_project").then(response => {
  153. this.projectOptions = response.data;
  154. });
  155. this.getAllCompany();
  156. },
  157. methods: {
  158. getSummaries(param) {
  159. const { columns, data } = param;
  160. const sums = [];
  161. columns.forEach((column, index) => {
  162. if (index === 0) {
  163. sums[index] = '合计';
  164. return;
  165. }
  166. if (column.property === 'totalInternetTraffic') {
  167. const values = data.map(item => Number(item.totalInternetTraffic));
  168. const total = values.reduce((acc, curr) => acc + curr, 0);
  169. sums[index] = this.formatTrafficData(total);
  170. } else {
  171. sums[index] = '';
  172. }
  173. });
  174. return sums;
  175. },
  176. handleDateData(){
  177. if (this.time) {
  178. this.queryParams.startDate = this.time[0];
  179. this.queryParams.endDate = this.time[1];
  180. } else {
  181. this.queryParams.startDate = null;
  182. this.queryParams.endDate = null;
  183. }
  184. },
  185. getAllCompany() {
  186. allList().then(response => {
  187. this.companyList = response.rows;
  188. });
  189. },
  190. formatTrafficData(traffic) {
  191. if (traffic < 1024) { // Less than 1 KB
  192. return traffic + ' B';
  193. } else if (traffic < 1024 * 1024) { // Less than 1 MB
  194. return (traffic / 1024).toFixed(2) + ' KB';
  195. } else if (traffic < 1024 * 1024 * 1024) { // Less than 1 GB
  196. return (traffic / (1024 * 1024)).toFixed(2) + ' MB';
  197. } else { // More than 1 GB
  198. return (traffic / (1024 * 1024 * 1024)).toFixed(2) + ' GB';
  199. }
  200. },
  201. formatTrafficMoney(traffic){
  202. return (traffic / (1024 * 1024 * 1024) * 0.095).toFixed(2) + ' 元'
  203. },
  204. handleShortcut() {
  205. this.queryParams.time = new Date().toISOString().slice(0, 7);
  206. },
  207. /** 查询短链课程流量记录列表 */
  208. getList() {
  209. this.loading = true;
  210. listCourseTrafficLog(this.queryParams).then(response => {
  211. this.courseTrafficLogList = response.rows;
  212. this.total = response.total;
  213. this.loading = false;
  214. }).finally(()=>{
  215. this.loading = false;
  216. })
  217. },
  218. // 取消按钮
  219. cancel() {
  220. this.open = false;
  221. this.reset();
  222. },
  223. // 表单重置
  224. reset() {
  225. this.form = {
  226. logId: null,
  227. userId: null,
  228. videoId: null,
  229. createTime: null,
  230. qwExternalContactId: null,
  231. internetTraffic: null,
  232. qwUserId: null,
  233. companyUserId: null,
  234. companyId: null,
  235. courseId: null
  236. };
  237. this.resetForm("form");
  238. },
  239. /** 搜索按钮操作 */
  240. handleQuery() {
  241. this.queryParams.pageNum = 1;
  242. this.getList();
  243. },
  244. /** 重置按钮操作 */
  245. resetQuery() {
  246. this.resetForm("queryForm");
  247. this.handleQuery();
  248. },
  249. // 多选框选中数据
  250. handleSelectionChange(selection) {
  251. this.ids = selection.map(item => item.logId)
  252. this.single = selection.length!==1
  253. this.multiple = !selection.length
  254. },
  255. /** 新增按钮操作 */
  256. handleAdd() {
  257. this.reset();
  258. this.open = true;
  259. this.title = "添加短链课程流量记录";
  260. },
  261. /** 修改按钮操作 */
  262. handleUpdate(row) {
  263. this.reset();
  264. const logId = row.logId || this.ids
  265. getCourseTrafficLog(logId).then(response => {
  266. this.form = response.data;
  267. this.open = true;
  268. this.title = "修改短链课程流量记录";
  269. });
  270. },
  271. /** 提交按钮 */
  272. submitForm() {
  273. this.$refs["form"].validate(valid => {
  274. if (valid) {
  275. if (this.form.logId != null) {
  276. updateCourseTrafficLog(this.form).then(response => {
  277. this.msgSuccess("修改成功");
  278. this.open = false;
  279. this.getList();
  280. });
  281. } else {
  282. addCourseTrafficLog(this.form).then(response => {
  283. this.msgSuccess("新增成功");
  284. this.open = false;
  285. this.getList();
  286. });
  287. }
  288. }
  289. });
  290. },
  291. /** 删除按钮操作 */
  292. handleDelete(row) {
  293. const logIds = row.logId || this.ids;
  294. this.$confirm('是否确认删除短链课程流量记录编号为"' + logIds + '"的数据项?', "警告", {
  295. confirmButtonText: "确定",
  296. cancelButtonText: "取消",
  297. type: "warning"
  298. }).then(function() {
  299. return delCourseTrafficLog(logIds);
  300. }).then(() => {
  301. this.getList();
  302. this.msgSuccess("删除成功");
  303. }).catch(() => {});
  304. },
  305. /** 导出按钮操作 */
  306. handleExport() {
  307. const queryParams = this.queryParams;
  308. this.$confirm('是否确认导出所有短链课程流量记录数据项?', "警告", {
  309. confirmButtonText: "确定",
  310. cancelButtonText: "取消",
  311. type: "warning"
  312. }).then(() => {
  313. this.exportLoading = true;
  314. return exportCourseTrafficLog(queryParams);
  315. }).then(response => {
  316. this.download(response.msg);
  317. this.exportLoading = false;
  318. }).catch(() => {});
  319. }
  320. }
  321. };
  322. </script>