index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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">
  59. <el-table-column type="selection" width="55" align="center" />
  60. <el-table-column label="公司名称" align="center" prop="companyName" />
  61. <el-table-column label="项目" align="center" prop="projectName" />
  62. <el-table-column label="课程" align="center" prop="courseName" />
  63. <el-table-column label="日期" align="center" prop="month" />
  64. <el-table-column label="使用流量" align="center">
  65. <template slot-scope="scope">
  66. <span>{{ formatTrafficData(scope.row.totalInternetTraffic) }}</span>
  67. </template>
  68. </el-table-column>
  69. <!-- <el-table-column label="费用" align="center">-->
  70. <!-- <template slot-scope="scope">-->
  71. <!-- <span>{{ formatTrafficMoney(scope.row.totalInternetTraffic) }}</span>-->
  72. <!-- </template>-->
  73. <!-- </el-table-column>-->
  74. </el-table>
  75. <pagination
  76. v-show="total>0"
  77. :total="total"
  78. :page.sync="queryParams.pageNum"
  79. :limit.sync="queryParams.pageSize"
  80. @pagination="getList"
  81. />
  82. </div>
  83. </template>
  84. <script>
  85. import { listCourseTrafficLog, getCourseTrafficLog, delCourseTrafficLog, addCourseTrafficLog, updateCourseTrafficLog, exportCourseTrafficLog } from "@/api/course/courseTrafficLog";
  86. import {courseList} from "@/api/course/courseRedPacketLog";
  87. import {allList}from "@/api/company/company";
  88. export default {
  89. name: "CourseTrafficLog",
  90. data() {
  91. return {
  92. pickerOptions: {
  93. shortcuts: [{
  94. text: '最近一周',
  95. onClick(picker) {
  96. const end = new Date();
  97. const start = new Date();
  98. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  99. picker.$emit('pick', [start, end]);
  100. }
  101. }]
  102. },
  103. companyList:[],
  104. // 遮罩层
  105. loading: true,
  106. // 导出遮罩层
  107. exportLoading: false,
  108. // 选中数组
  109. ids: [],
  110. // 非单个禁用
  111. single: true,
  112. // 非多个禁用
  113. multiple: true,
  114. // 显示搜索条件
  115. showSearch: true,
  116. // 总条数
  117. total: 0,
  118. // 短链课程流量记录表格数据
  119. courseTrafficLogList: [],
  120. projectOptions:[],
  121. courseLists:[],
  122. // 弹出层标题
  123. title: "",
  124. // 是否显示弹出层
  125. open: false,
  126. time: null,
  127. // 查询参数
  128. queryParams: {
  129. startDate: null,
  130. endDate: null,
  131. pageNum: 1,
  132. pageSize: 10,
  133. userId: null,
  134. videoId: null,
  135. qwExternalContactId: null,
  136. internetTraffic: null,
  137. qwUserId: null,
  138. companyUserId: null,
  139. companyId: null,
  140. courseId: null,
  141. },
  142. // 表单参数
  143. form: {},
  144. // 表单校验
  145. rules: {
  146. }
  147. };
  148. },
  149. created() {
  150. courseList().then(response => {
  151. this.courseLists = response.list;
  152. });
  153. this.getDicts("sys_course_project").then(response => {
  154. this.projectOptions = response.data;
  155. });
  156. this.getList();
  157. this.getAllCompany();
  158. },
  159. methods: {
  160. handleDateData(){
  161. if (this.time) {
  162. this.queryParams.startDate = this.time[0];
  163. this.queryParams.endDate = this.time[1];
  164. } else {
  165. this.queryParams.startDate = null;
  166. this.queryParams.endDate = null;
  167. }
  168. },
  169. getAllCompany() {
  170. allList().then(response => {
  171. this.companyList = response.rows;
  172. });
  173. },
  174. formatTrafficData(traffic) {
  175. if (traffic < 1024) { // Less than 1 KB
  176. return traffic + ' B';
  177. } else if (traffic < 1024 * 1024) { // Less than 1 MB
  178. return (traffic / 1024).toFixed(2) + ' KB';
  179. } else if (traffic < 1024 * 1024 * 1024) { // Less than 1 GB
  180. return (traffic / (1024 * 1024)).toFixed(2) + ' MB';
  181. } else { // More than 1 GB
  182. return (traffic / (1024 * 1024 * 1024)).toFixed(2) + ' GB';
  183. }
  184. },
  185. formatTrafficMoney(traffic){
  186. return (traffic / (1024 * 1024 * 1024) * 0.095).toFixed(2) + ' 元'
  187. },
  188. handleShortcut() {
  189. this.queryParams.time = new Date().toISOString().slice(0, 7);
  190. },
  191. /** 查询短链课程流量记录列表 */
  192. getList() {
  193. this.loading = true;
  194. listCourseTrafficLog(this.queryParams).then(response => {
  195. this.courseTrafficLogList = response.rows;
  196. this.total = response.total;
  197. this.loading = false;
  198. });
  199. },
  200. // 取消按钮
  201. cancel() {
  202. this.open = false;
  203. this.reset();
  204. },
  205. // 表单重置
  206. reset() {
  207. this.form = {
  208. logId: null,
  209. userId: null,
  210. videoId: null,
  211. createTime: null,
  212. qwExternalContactId: null,
  213. internetTraffic: null,
  214. qwUserId: null,
  215. companyUserId: null,
  216. companyId: null,
  217. courseId: null
  218. };
  219. this.resetForm("form");
  220. },
  221. /** 搜索按钮操作 */
  222. handleQuery() {
  223. this.queryParams.pageNum = 1;
  224. this.getList();
  225. },
  226. /** 重置按钮操作 */
  227. resetQuery() {
  228. this.resetForm("queryForm");
  229. this.handleQuery();
  230. },
  231. // 多选框选中数据
  232. handleSelectionChange(selection) {
  233. this.ids = selection.map(item => item.logId)
  234. this.single = selection.length!==1
  235. this.multiple = !selection.length
  236. },
  237. /** 新增按钮操作 */
  238. handleAdd() {
  239. this.reset();
  240. this.open = true;
  241. this.title = "添加短链课程流量记录";
  242. },
  243. /** 修改按钮操作 */
  244. handleUpdate(row) {
  245. this.reset();
  246. const logId = row.logId || this.ids
  247. getCourseTrafficLog(logId).then(response => {
  248. this.form = response.data;
  249. this.open = true;
  250. this.title = "修改短链课程流量记录";
  251. });
  252. },
  253. /** 提交按钮 */
  254. submitForm() {
  255. this.$refs["form"].validate(valid => {
  256. if (valid) {
  257. if (this.form.logId != null) {
  258. updateCourseTrafficLog(this.form).then(response => {
  259. this.msgSuccess("修改成功");
  260. this.open = false;
  261. this.getList();
  262. });
  263. } else {
  264. addCourseTrafficLog(this.form).then(response => {
  265. this.msgSuccess("新增成功");
  266. this.open = false;
  267. this.getList();
  268. });
  269. }
  270. }
  271. });
  272. },
  273. /** 删除按钮操作 */
  274. handleDelete(row) {
  275. const logIds = row.logId || this.ids;
  276. this.$confirm('是否确认删除短链课程流量记录编号为"' + logIds + '"的数据项?', "警告", {
  277. confirmButtonText: "确定",
  278. cancelButtonText: "取消",
  279. type: "warning"
  280. }).then(function() {
  281. return delCourseTrafficLog(logIds);
  282. }).then(() => {
  283. this.getList();
  284. this.msgSuccess("删除成功");
  285. }).catch(() => {});
  286. },
  287. /** 导出按钮操作 */
  288. handleExport() {
  289. const queryParams = this.queryParams;
  290. this.$confirm('是否确认导出所有短链课程流量记录数据项?', "警告", {
  291. confirmButtonText: "确定",
  292. cancelButtonText: "取消",
  293. type: "warning"
  294. }).then(() => {
  295. this.exportLoading = true;
  296. return exportCourseTrafficLog(queryParams);
  297. }).then(response => {
  298. this.download(response.msg);
  299. this.exportLoading = false;
  300. }).catch(() => {});
  301. }
  302. }
  303. };
  304. </script>