index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. <!-- 修改为多选搜索框 -->
  7. <el-select
  8. v-model="queryParams.companyIds"
  9. multiple
  10. filterable
  11. remote
  12. reserve-keyword
  13. placeholder="请输入公司名称搜索"
  14. :remote-method="searchCompanies"
  15. :loading="companySearchLoading"
  16. style="width: 220px"
  17. clearable
  18. size="small"
  19. >
  20. <el-option
  21. v-for="item in companyOptions"
  22. :key="item.dictValue"
  23. :label="item.dictLabel"
  24. :value="item.dictValue"
  25. />
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  30. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  31. </el-form-item>
  32. </el-form>
  33. <!-- 操作按钮区域 -->
  34. <el-row :gutter="10" class="mb8">
  35. <el-col :span="1.5">
  36. <el-button
  37. type="primary"
  38. plain
  39. icon="el-icon-plus"
  40. size="mini"
  41. @click="handleRecharge"
  42. v-hasPermi="['company:traffic:charge']"
  43. >流量充值</el-button>
  44. </el-col>
  45. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  46. </el-row>
  47. <!-- 数据表格 -->
  48. <el-table v-loading="loading" :data="trafficRecordList" @selection-change="handleSelectionChange">
  49. <el-table-column label="公司名称" align="center" prop="companyName" :show-overflow-tooltip="true" />
  50. <el-table-column label="流量余额" align="center" prop="balance" :formatter="formatBalance"/>
  51. <!-- <el-table-column label="操作人员" align="center" prop="createBy" />
  52. <el-table-column label="操作时间" align="center" prop="createTime" width="180">
  53. <template slot-scope="scope">
  54. <span>{{ parseTime(scope.row.createTime) }}</span>
  55. </template>
  56. </el-table-column>-->
  57. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  58. <template slot-scope="scope">
  59. <el-button
  60. size="mini"
  61. type="text"
  62. icon="el-icon-money"
  63. @click="handleRechargeCompany(scope.row)"
  64. v-hasPermi="['company:traffic:charge']"
  65. >充值</el-button>
  66. </template>
  67. </el-table-column>
  68. </el-table>
  69. <!-- 分页 -->
  70. <pagination
  71. v-show="total>0"
  72. :total="total"
  73. :page.sync="queryParams.pageNum"
  74. :limit.sync="queryParams.pageSize"
  75. @pagination="getList"
  76. />
  77. <!-- 流量充值对话框 -->
  78. <el-dialog :title="rechargeTitle" :visible.sync="rechargeOpen" width="500px" append-to-body :before-close="resetOption">
  79. <el-form ref="rechargeForm" :model="rechargeForm" :rules="rechargeRules" label-width="100px">
  80. <el-form-item label="公司ID" prop="companyId" v-show="!isCompanyRecharge">
  81. <el-select
  82. v-model="rechargeForm.companyId"
  83. filterable
  84. remote
  85. placeholder="请输入公司名称搜索"
  86. :remote-method="searchCompanies"
  87. :loading="companySearchLoading"
  88. @change="syncCompanyName"
  89. style="width: 220px"
  90. clearable
  91. size="small"
  92. >
  93. <el-option
  94. v-for="item in companyOptions"
  95. :key="item.dictValue"
  96. :label="item.dictValue"
  97. :value="item.dictValue"
  98. >
  99. <span style="float: left">{{ item.dictValue }}</span>
  100. <span style="margin-left: 30px">{{ item.dictLabel }}</span>
  101. </el-option>
  102. </el-select>
  103. </el-form-item>
  104. <el-form-item label="公司名称" prop="companyName">
  105. <el-input v-model="rechargeForm.companyName" placeholder="请输入公司名称" size="small" disabled/>
  106. </el-form-item>
  107. <el-form-item label="充值金额" prop="chargeAmount">
  108. <el-input-number
  109. v-model="rechargeForm.chargeAmount"
  110. :min="1"
  111. :max="999999999"
  112. placeholder="请输入充值金额(元)"
  113. controls-position="right"
  114. style="width: 100%"
  115. @input="chargeAmountInput"
  116. />
  117. <span v-if="this.amountToTraffic" class="el-form-item__error"> 约充值 {{ this.amountToTraffic }}流量 </span>
  118. </el-form-item>
  119. <el-form-item label="备注" prop="remark">
  120. <el-input
  121. v-model="rechargeForm.remark"
  122. type="textarea"
  123. placeholder="请输入备注"
  124. :rows="3"
  125. />
  126. </el-form-item>
  127. </el-form>
  128. <div slot="footer" class="dialog-footer">
  129. <el-button type="primary" @click="submitRechargeForm">确 定</el-button>
  130. <el-button @click="cancelRecharge">取 消</el-button>
  131. </div>
  132. </el-dialog>
  133. </div>
  134. </template>
  135. <script>
  136. import { listTrafficRecords, rechargeTraffic, trafficConversion } from '@/api/company/traffic'
  137. import { allList } from '@/api/company/company'
  138. import { resetForm } from '@/utils/common'
  139. import { delAdIqiyiAccount } from '@/api/ad/AdIqiyiAccount'
  140. export default {
  141. name: "CompanyTraffic",
  142. data() {
  143. return {
  144. amountToTraffic: 0,
  145. // 遮罩层
  146. loading: true,
  147. // 选中数组
  148. ids: [],
  149. // 非单个禁用
  150. single: true,
  151. // 非多个禁用
  152. multiple: true,
  153. // 显示搜索条件
  154. showSearch: true,
  155. // 总条数
  156. total: 0,
  157. // 流量记录表格数据
  158. trafficRecordList: [],
  159. // 弹出层标题
  160. rechargeTitle: "",
  161. // 是否显示充值弹出层
  162. rechargeOpen: false,
  163. // 公司搜索相关
  164. companySearchLoading: false,
  165. companyOptions: [],
  166. isCompanyRecharge: false,
  167. // 查询参数
  168. queryParams: {
  169. pageNum: 1,
  170. pageSize: 10,
  171. companyName: null,
  172. companyIds: [], // 修改为数组
  173. createTimeStart: null,
  174. createTimeEnd: null
  175. },
  176. // 流量充值表单参数(保持不变)
  177. rechargeForm: {
  178. companyId: null,
  179. companyName: null,
  180. chargeAmount: null,
  181. remark: null
  182. },
  183. // 流量详情数据
  184. detailData: {},
  185. // 表单校验(保持不变)
  186. rechargeRules: {
  187. companyId: [
  188. { required: true, message: "公司ID不能为空", trigger: "blur" }
  189. ],
  190. chargeAmount: [
  191. { required: true, message: "充值金额不能为空", trigger: "blur" },
  192. { type: "number", min: 1, message: "充值金额必须大于0", trigger: "blur" }
  193. ]
  194. }
  195. };
  196. },
  197. created() {
  198. this.getList();
  199. },
  200. methods: {
  201. resetForm,
  202. resetOption(){
  203. this.rechargeOpen = false;
  204. this.companyOptions = [];
  205. this.rechargeForm = {};
  206. },
  207. /** 查询流量记录列表 */
  208. getList() {
  209. this.loading = true;
  210. listTrafficRecords(this.queryParams).then(response => {
  211. this.trafficRecordList = response.rows;
  212. this.total = response.total;
  213. this.loading = false;
  214. });
  215. },
  216. /** 流量计算*/
  217. chargeAmountInput() {
  218. if(!this.rechargeForm.chargeAmount){
  219. this.amountToTraffic = 0;
  220. return;
  221. }
  222. trafficConversion({traffic:this.rechargeForm.chargeAmount}).then(
  223. response => {
  224. this.amountToTraffic = response.data;
  225. //对流量值进行判断,换算成GB或TB
  226. if(!this.amountToTraffic){
  227. this.amountToTraffic = "0 KB";
  228. }
  229. if(this.amountToTraffic < 1024){
  230. this.amountToTraffic = this.amountToTraffic + " KB";
  231. }
  232. else if(this.amountToTraffic < 1024 * 1024){
  233. this.amountToTraffic = (this.amountToTraffic / 1024).toFixed(2) + " MB";
  234. }
  235. else if(this.amountToTraffic < 1024 * 1024 * 1024){
  236. this.amountToTraffic = (this.amountToTraffic / (1024 * 1024)).toFixed(2) + " GB";
  237. }
  238. else{
  239. this.amountToTraffic = (this.amountToTraffic / (1024 * 1024 * 1024)).toFixed(2) + " TB";
  240. }
  241. }
  242. )
  243. }
  244. ,
  245. /** 搜索公司 */
  246. searchCompanies( query) {
  247. allList().then(response => {
  248. this.companyOptions = response.rows.filter(item => item.dictLabel.includes(query));
  249. this.companySearchLoading = false;
  250. }).catch(()=>{
  251. this.companySearchLoading = false;
  252. });
  253. },
  254. syncCompanyName(){
  255. if(!this.rechargeForm.companyId){
  256. this.rechargeForm.companyName = null;
  257. }
  258. this.rechargeForm.companyName = this.companyOptions.filter(item => item.dictValue === this.rechargeForm.companyId)[0].dictLabel;
  259. },
  260. /** 搜索按钮操作 */
  261. handleQuery() {
  262. this.queryParams.pageNum = 1;
  263. this.getList();
  264. },
  265. /** 重置按钮操作 */
  266. resetQuery() {
  267. this.resetForm("queryForm");
  268. this.rechargeForm = {};
  269. this.handleQuery();
  270. },
  271. formatBalance(row){
  272. //对流量值进行判断,换算成GB或TB
  273. if(!row.balance){
  274. return "0 KB";
  275. }
  276. const absBalance = Math.abs(row.balance); // 获取绝对值
  277. if(absBalance < 1024){
  278. return row.balance + " KB";
  279. }
  280. else if(absBalance < 1024 * 1024){
  281. return (row.balance / 1024).toFixed(2) + " MB";
  282. }
  283. else if(absBalance < 1024 * 1024 * 1024){
  284. return (row.balance / (1024 * 1024)).toFixed(2) + " GB";
  285. }
  286. else{
  287. return (row.balance / (1024 * 1024 * 1024)).toFixed(2) + " TB";
  288. }
  289. },
  290. /** 多选框选中数据 */
  291. handleSelectionChange(selection) {
  292. this.ids = selection.map(item => item.id)
  293. this.single = selection.length !== 1
  294. this.multiple = !selection.length
  295. },
  296. /** 流量充值按钮操作 */
  297. handleRecharge() {
  298. this.rechargeTitle = "流量充值";
  299. this.resetForm("rechargeForm");
  300. this.rechargeForm = {};
  301. this.companyOptions = [];
  302. this.isCompanyRecharge = false;
  303. this.rechargeForm.operationType = 1; // 默认充值
  304. this.rechargeOpen = true;
  305. },/** 流量充值按钮操作 */
  306. handleRechargeCompany(row) {
  307. this.rechargeTitle = "流量充值";
  308. this.resetForm("rechargeForm");
  309. this.rechargeForm = {};
  310. this.companyOptions = [];
  311. this.isCompanyRecharge = true;
  312. this.rechargeForm.companyId = row.companyId;
  313. this.rechargeForm.companyName = row.companyName;
  314. this.rechargeForm.operationType = 1; // 默认充值
  315. this.rechargeOpen = true;
  316. },
  317. /** 提交流量充值 */
  318. submitRechargeForm() {
  319. this.$refs["rechargeForm"].validate(valid => {
  320. if (valid) {
  321. //添加confirm提示
  322. this.$confirm('确定要为 '+this.rechargeForm.companyName+' 充值 '+this.rechargeForm.chargeAmount+' 元吗?', '提示', {
  323. confirmButtonText: '确定',
  324. cancelButtonText: '取消',
  325. type: 'warning'
  326. }).then(() => {
  327. return rechargeTraffic(this.rechargeForm);
  328. }).then(response => {
  329. if(response.code === 200){
  330. this.msgSuccess("充值成功");
  331. }else{
  332. this.msgError(response.msg);
  333. }
  334. this.rechargeOpen = false;
  335. this.getList();
  336. }).catch(() => {});
  337. }
  338. });
  339. },
  340. /** 取消充值 */
  341. cancelRecharge() {
  342. this.rechargeOpen = false;
  343. this.resetForm("rechargeForm");
  344. this.rechargeForm = {};
  345. }
  346. }
  347. };
  348. </script>
  349. <style scoped>
  350. .mb8 {
  351. margin-bottom: 8px;
  352. }
  353. </style>