crowd-control.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <template>
  2. <div class="crowd-control-content">
  3. <div class="control-con-header">
  4. <a-form
  5. class="grid-form" layout="inline"
  6. :form="form"
  7. hide-required-mark
  8. @submit="handleQueryList"
  9. >
  10. <a-row class="grid-form-options">
  11. <a-form-item
  12. class="grid-form-item"
  13. label="名称"
  14. :colon="false"
  15. >
  16. <a-input
  17. v-decorator="['name']" type="text"
  18. placeholder="请输入"
  19. />
  20. </a-form-item>
  21. <a-form-item
  22. class="grid-form-item" label="账户"
  23. :colon="false"
  24. >
  25. <acount-search class="acount-search-class" :appId.sync="acountId" :multiple="false"></acount-search>
  26. </a-form-item>
  27. <a-form-item
  28. class="grid-form-item grid-form-type" label="状态"
  29. :colon="false"
  30. >
  31. <a-select
  32. v-decorator="['status']"
  33. placeholder="请选择"
  34. allow-clear
  35. >
  36. <a-select-option v-for="item in statusTasks" :key="item.label">
  37. {{ item.value }}
  38. </a-select-option>
  39. </a-select>
  40. </a-form-item>
  41. <a-form-item class="form-handle-btn">
  42. <a-button type="default" class="reset-class" @click="handleResetForm">重置</a-button>
  43. <a-button type="primary" html-type="submit">查询</a-button>
  44. </a-form-item>
  45. </a-row>
  46. </a-form>
  47. <a-button type="primary" class="upload-person" @click="handleUploadPerson">
  48. 上传人群包
  49. </a-button>
  50. </div>
  51. <div class="control-con-table">
  52. <a-table
  53. ref="table"
  54. size="middle"
  55. bordered
  56. :columns="columns"
  57. :dataSource="dataSource"
  58. :pagination="false"
  59. >
  60. <span slot="action" slot-scope="text, record">
  61. <a @click="handleEdit(record)">推送</a>
  62. <a-divider type="vertical" />
  63. <a @click="handleDelete(record)">删除</a>
  64. </span>
  65. <span slot="cause" slot-scope="text, record">
  66. <a class="cause-text-class" @click="handleCause(record)">{{ text }}</a>
  67. </span>
  68. <span slot="depRelax" slot-scope="text, record">
  69. <a @click="handleAcountRelax('dep', record)">{{ text }}</a>
  70. </span>
  71. <span slot="acountRelax" slot-scope="text, record">
  72. <a @click="handleAcountRelax('acount', record)">{{ text }}</a>
  73. </span>
  74. </a-table>
  75. <a-pagination
  76. class="pagin-table-class"
  77. :total="totalAll"
  78. :show-total="total => `共 ${totalAll} 条`"
  79. size="small"
  80. show-size-changer
  81. show-quick-jumper
  82. @change="onShowSizeChange"
  83. @showSizeChange="onShowSizeChange"
  84. />
  85. </div>
  86. <a-modal
  87. v-if="personVisible"
  88. title="上传人群包"
  89. class="person-modal"
  90. :visible="personVisible"
  91. :confirm-loading="confirmLoading"
  92. @ok="handleOk"
  93. @cancel="handleCancel"
  94. >
  95. <div>
  96. <a-form-model
  97. ref="ruleForm"
  98. :model="personForm"
  99. :rules="personRules"
  100. :label-col="labelCol"
  101. :wrapper-col="wrapperCol"
  102. >
  103. <a-form-model-item label="匹配类型" prop="resource">
  104. <a-radio-group v-model="personForm.resource">
  105. <a-radio v-for="item in mateTypeTasks" :key="item.label" :value="item.label">{{ item.value }}</a-radio>
  106. </a-radio-group>
  107. </a-form-model-item>
  108. <a-form-model-item ref="name" label="人群包名称" prop="name">
  109. <a-input
  110. v-model="personForm.name"
  111. placeholder="请输入人群包名称"
  112. />
  113. </a-form-model-item>
  114. <a-form-model-item label="选择账户">
  115. <acount-search class="acount-search-class" :appId.sync="uploadAcountIds" :multiple="false"></acount-search>
  116. </a-form-model-item>
  117. <a-form-model-item label="上传人群包">
  118. <a-upload
  119. name="file"
  120. :file-list="fileList"
  121. :before-upload="beforeUpload"
  122. @change="handleChange"
  123. >
  124. <a-button><a-icon type="upload" />文件上传</a-button>
  125. </a-upload>
  126. <p class="upload-txt-rules">1、文件格式:支持上传*.txt(utf-8)文本;也支持将单个/多个*.txt文件经过Zip格式压缩上传</p>
  127. <p class="upload-txt-rules">2、文件大小:单个文件大小不能超过1G</p>
  128. <p class="upload-txt-rules">3、内容编排:每行一条记录</p>
  129. </a-form-model-item>
  130. </a-form-model>
  131. </div>
  132. </a-modal>
  133. <a-modal
  134. title="推送账户"
  135. v-if="pushVisible"
  136. :visible="pushVisible"
  137. :confirm-loading="pushConfirmLoading"
  138. dialog-class="push-modal"
  139. @ok="handlePushSure"
  140. @cancel="handlePushCancel"
  141. >
  142. <div>
  143. <div class="acount-title">
  144. <div class="acount-title-left">已选人群包</div>
  145. <div class="acount-title-right">{{ tableSelectList.orientationName }} (ID: {{ tableSelectList.id }})</div>
  146. </div>
  147. <div class="acount-title push-plate">
  148. <div class="acount-title-left">推送平台</div>
  149. <div class="acount-title-right">
  150. <a-radio-group default-value="a" button-style="solid">
  151. <a-radio-button value="a">效果</a-radio-button>
  152. <a-radio-button value="b" disabled>品牌</a-radio-button>
  153. </a-radio-group>
  154. </div>
  155. </div>
  156. <tree-select @applyType="handleApplyType"></tree-select>
  157. </div>
  158. </a-modal>
  159. <a-modal
  160. title="相关项目"
  161. v-if="causeVisible"
  162. :visible="causeVisible"
  163. :confirm-loading="causeConfirmLoading"
  164. :footer="null"
  165. dialog-class="cause-modal"
  166. @cancel="handleCauseCancel"
  167. >
  168. <div>
  169. <div class="cause-modal-table-class">
  170. <a-table :columns="causeColumns" :data-source="causeData" bordered :pagination="false"></a-table>
  171. </div>
  172. <a-pagination
  173. class="pagin-table-class"
  174. :total="totalAllCause"
  175. size="small"
  176. @change="handleCauseSizeChange"
  177. />
  178. </div>
  179. </a-modal>
  180. <a-modal
  181. title="相关项目"
  182. v-if="relaxVisible"
  183. :visible="relaxVisible"
  184. :confirm-loading="relaxConfirmLoading"
  185. :footer="null"
  186. dialog-class="relax-modal"
  187. @cancel="handleRelaxCancel"
  188. >
  189. <div>
  190. <div class="acount-title">
  191. <div class="acount-title-left">人群包名称</div>
  192. <div class="acount-title-right">{{ acountRelaxDetail.orientationName }}</div>
  193. </div>
  194. <div class="acount-title push-plate">
  195. <div class="acount-title-left">目标账户</div>
  196. <div class="acount-title-right">{{ acountRelaxDetail.accountName }}</div>
  197. </div>
  198. <template v-if="relaxStatus === 'dep'">
  199. <a-table :columns="depColumns" :data-source="depData" bordered>
  200. </a-table>
  201. </template>
  202. <template v-if="relaxStatus === 'acount'">
  203. <a-table :columns="acountColumns" :data-source="acountData" bordered></a-table>
  204. </template>
  205. </div>
  206. </a-modal>
  207. </div>
  208. </template>
  209. <script>
  210. import TreeSelect from './components/tree-select/tree-select';
  211. import {getAction, postAction} from '@/api/manage';
  212. import AcountSearch from '@/views/modules/Statistics/components/Treeselect.vue';
  213. import AppMarketService from './crowd-control-service';
  214. let COS = require('cos-js-sdk-v5');
  215. let cos = new COS({
  216. SecretId: 'AKIDE6IpMi8fJQRCg1iuWzFajjRs43kbbets',
  217. SecretKey: 'tXzuwMfplTTK3c9GFUyETilasvQfePu9'
  218. });
  219. export default {
  220. name: 'crowd-control',
  221. components: {
  222. TreeSelect,
  223. AcountSearch
  224. },
  225. data() {
  226. let that = this;
  227. return {
  228. totalAllCause: 0,
  229. acountId: undefined, // 搜索的账户ID
  230. uploadAcountIds: '',
  231. totalAll: 10,
  232. finallyRightTree: [],
  233. fileList: [],
  234. relaxVisible: false,
  235. relaxConfirmLoading: false,
  236. pushVisible: false,
  237. pushConfirmLoading: false,
  238. causeVisible: false,
  239. causeConfirmLoading: false,
  240. labelCol: {span: 4},
  241. wrapperCol: {span: 14},
  242. personVisible: false,
  243. confirmLoading: false,
  244. mateTypeTasks: AppMarketService.setMateTypeTasks(), // 匹配类型
  245. populationTypeTasks: AppMarketService.setPopulationTypeTasks(), // 人群包类型
  246. statusTasks: AppMarketService.setStatusTasks(), // 状态枚举
  247. relaxStatus: '',
  248. causeData: [], // 原因的table列表数据,
  249. depData: [], // 相关项目的table列表数据,
  250. acountData: [], // 相关账户的table列表数据,
  251. acountColumns: AppMarketService.setAcountColumns(), // 相关账户的table列表
  252. depColumns: AppMarketService.setDepColumns(), // 相关项目的table列表
  253. causeColumns: AppMarketService.setCauseColumns(), // 原因的table列表
  254. dataSource: [],
  255. columns: [
  256. {
  257. title: '人群包名称',
  258. align: 'center',
  259. width: 200,
  260. ellipsis: true,
  261. dataIndex: 'orientationName'
  262. },
  263. {
  264. title: '人群包类型',
  265. align: 'center',
  266. dataIndex: 'populationType',
  267. customRender(t) {
  268. return t ? that.populationTypeTasks.find(item => item.label === Number(t)).value : '-';
  269. }
  270. },
  271. {
  272. title: '匹配类型',
  273. align: 'center',
  274. dataIndex: 'typeStr'
  275. },
  276. {
  277. title: '上传时间',
  278. dataIndex: 'statDate',
  279. align: 'center'
  280. },
  281. {
  282. title: '覆盖数量',
  283. dataIndex: 'coverNum',
  284. align: 'center'
  285. },
  286. {
  287. title: '状态',
  288. dataIndex: 'status',
  289. align: 'center',
  290. customRender(t) {
  291. return t ? that.statusTasks.find(item => item.label === t).value : '-';
  292. }
  293. },
  294. {
  295. title: '原因',
  296. dataIndex: 'statusStr',
  297. align: 'center',
  298. scopedSlots: {customRender: 'cause'}
  299. },
  300. {
  301. title: '目标账户',
  302. dataIndex: 'accountName',
  303. align: 'center',
  304. ellipsis: true
  305. },
  306. {
  307. title: '相关项目',
  308. dataIndex: 'projectCount',
  309. align: 'center',
  310. scopedSlots: {customRender: 'depRelax'}
  311. },
  312. {
  313. title: '相关账户',
  314. dataIndex: 'accountCount',
  315. align: 'center',
  316. scopedSlots: {customRender: 'acountRelax'}
  317. },
  318. {
  319. title: '操作',
  320. dataIndex: 'action',
  321. align: 'center',
  322. scopedSlots: {customRender: 'action'}
  323. }
  324. ],
  325. personForm: {
  326. name: '',
  327. resource: ''
  328. },
  329. personRules: AppMarketService.setPersonRules(), // 上传人群包表单校验规则
  330. tablePag: {
  331. page: 1,
  332. size: 10
  333. },
  334. // table 原因的分页
  335. causePag: {
  336. page: 1,
  337. size: 10
  338. },
  339. tableSelectList: {},
  340. acountRelaxDetail: {},
  341. causeDetailData: {}
  342. };
  343. },
  344. created() {
  345. this.form = this.$form.createForm(this);
  346. },
  347. mounted() {
  348. this.handleGetTableList({});
  349. },
  350. methods: {
  351. onShowSizeChange(current, pageSize) {
  352. const paramsData = this.form.getFieldsValue();
  353. this.tablePag = {
  354. page: current,
  355. size: pageSize
  356. };
  357. this.handleGetTableList(paramsData);
  358. },
  359. handleCauseSizeChange(current, pageSize) {
  360. this.causePag = {
  361. page: current,
  362. size: pageSize
  363. };
  364. this.handleCauseTableData();
  365. },
  366. handleGetTableList(data) {
  367. const paramsData = {
  368. orientationName: data.name,
  369. accountName: this.acountId,
  370. status: data.status,
  371. pageNo: this.tablePag.page,
  372. pageSize: this.tablePag.size
  373. };
  374. getAction('/kuaishouCrowdPack/queryPageList', paramsData).then(result => {
  375. if (result.code === 200) {
  376. this.dataSource = result.result.list || [];
  377. this.totalAll = result.result.total || 0;
  378. }
  379. else {
  380. this.$message.error(result.message);
  381. }
  382. }).catch(error => {
  383. console.log(error, 'eeee');
  384. });
  385. },
  386. handleDelete(data) {
  387. this.$confirm({
  388. title: '删除提示',
  389. content: '确定要删除这一条吗?',
  390. onOk() {
  391. getAction('/kuaishouCrowdPack/delete', {id: data.id}).then(result => {
  392. if (result.code === 200) {
  393. this.handleGetTableList({});
  394. }
  395. else {
  396. this.$message.error(result.message);
  397. }
  398. }).catch(error => {
  399. console.log(error, 'eeee');
  400. });
  401. }
  402. });
  403. },
  404. handleAcountRelaxTable() {
  405. const paramsData = {
  406. signature: this.acountRelaxDetail.signature,
  407. accountId: this.acountRelaxDetail.accountId,
  408. type: this.relaxStatus === 'dep' ? 1 : 2
  409. };
  410. getAction('/kuaishouCrowdPack/queryRel', paramsData).then(result => {
  411. if (result.code === 200) {
  412. if (this.relaxStatus === 'dep') {
  413. this.depData = result.result.list;
  414. }
  415. else if (this.relaxStatus === 'acount') {
  416. this.acountData = result.result.list;
  417. }
  418. }
  419. else {
  420. this.$message.error(result.message);
  421. }
  422. }).catch(error => {
  423. console.log(error, 'eeee');
  424. });
  425. },
  426. handleAcountRelax(txt, recd) {
  427. if (txt === 'dep') {
  428. this.relaxStatus = 'dep';
  429. }
  430. else if (txt === 'acount') {
  431. this.relaxStatus = 'acount';
  432. }
  433. this.acountRelaxDetail = recd;
  434. this.handleAcountRelaxTable();
  435. this.relaxVisible = true;
  436. },
  437. handleRelaxCancel() {
  438. this.relaxVisible = false;
  439. },
  440. handleCause(list) {
  441. this.causeVisible = true;
  442. this.causeDetailData = list;
  443. this.handleCauseTableData();
  444. },
  445. handleCauseTableData() {
  446. const paramsData = {
  447. signature: this.causeDetailData.signature,
  448. pageNo: this.causePag.page,
  449. pageSize: this.causePag.size
  450. };
  451. getAction('/kuaishouCrowdPack/queryFailReason', paramsData).then(result => {
  452. if (result.code === 200) {
  453. this.causeData = result.result.list || [];
  454. this.totalAllCause = result.result.total || 0;
  455. }
  456. else {
  457. this.$message.error(result.message);
  458. }
  459. }).catch(error => {
  460. console.log(error, 'eeee');
  461. });
  462. },
  463. handleApplyType(list) {
  464. this.finallyRightTree = list;
  465. },
  466. handleEdit(val) {
  467. this.tableSelectList = val;
  468. this.pushVisible = true;
  469. },
  470. handleCauseCancel() {
  471. this.causeVisible = false;
  472. },
  473. handlePushSure() {
  474. const paramsData = {
  475. accountIds: this.finallyRightTree.map(item => item.key),
  476. orientationId: this.tableSelectList.orientationId,
  477. accountId: this.tableSelectList.accountId
  478. };
  479. postAction('/kuaishouCrowdPack/accountPush', paramsData).then(result => {
  480. if (result.code === 200) {
  481. this.pushVisible = false;
  482. this.handleGetTableList({});
  483. }
  484. else {
  485. this.$message.error(result.message);
  486. }
  487. }).catch(error => {
  488. console.log(error, 'eeeeeee');
  489. });
  490. },
  491. handlePushCancel() {
  492. this.pushVisible = false;
  493. },
  494. beforeUpload(file) {
  495. const isZip = file.type.includes('zip') || file.type.includes('text');
  496. const fileOvesize = file.size > (1024 * 1024 * 1024);
  497. if (!isZip) {
  498. this.fileList = [];
  499. this.$message.error('只能上传zip格式的文件或者txt文件');
  500. return false;
  501. }
  502. if (fileOvesize) {
  503. this.$message.error('文件大小不能超过1G');
  504. return;
  505. }
  506. this.cosUpload(file);
  507. },
  508. handleChange(info) {
  509. this.fileList = info.fileList;
  510. },
  511. cosUpload(file) {
  512. let that = this;
  513. let date = new Date();
  514. let y = date.getFullYear();
  515. let MM = date.getMonth() + 1;
  516. MM = MM < 10 ? '0' + MM : MM;
  517. let d = date.getDate();
  518. d = d < 10 ? '0' + d : d;
  519. let timeElse = new Date().getTime();
  520. let arr = file.name.split('.');
  521. let str = '';
  522. for (let i = 0; i < arr.length; i++) {
  523. if (i === arr.length - 1) {
  524. }
  525. else {
  526. if (i === arr.length - 2) {
  527. str += arr[i];
  528. }
  529. else {
  530. str += arr[i] + '.';
  531. }
  532. }
  533. }
  534. cos.putObject(
  535. {
  536. Bucket: 'media-1301855440',
  537. Region: 'ap-chongqing',
  538. // 存储桶所在地域,必须字段
  539. Key: that.uploadType + '/' + y + '-' + MM + '-' + d + '/' + str + '-' + timeElse + '.' + arr[arr.length - 1],
  540. StorageClass: 'STANDARD',
  541. Body: file // 上传文件对象
  542. },
  543. function (err, data) {
  544. if (err) {
  545. that.$message.error('上传失败!!!' + err);
  546. return;
  547. }
  548. that.loadingElse = false;
  549. that.fileList.push({
  550. uid: file.name,
  551. name: file.name,
  552. status: 'done',
  553. url: '//' + data.Location
  554. });
  555. if (that.fileList.length > 1) {
  556. that.fileList = that.fileList.slice(-1);
  557. }
  558. }
  559. );
  560. },
  561. handleQueryList(event) {
  562. event.preventDefault();
  563. const paramsData = this.form.getFieldsValue();
  564. this.handleGetTableList(paramsData);
  565. },
  566. handleResetForm() {
  567. this.form.resetFields();
  568. this.acountId = undefined;
  569. this.handleGetTableList({});
  570. },
  571. handleUploadPerson() {
  572. this.personVisible = true;
  573. },
  574. handleOk() {
  575. this.$refs.ruleForm.validate(valid => {
  576. if (valid) {
  577. if (!this.uploadAcountIds) {
  578. this.$message.error('请选择账户');
  579. return;
  580. }
  581. if (!this.fileList.length) {
  582. this.$message.error('请上传文件');
  583. return;
  584. }
  585. this.handleUploadRuleForm();
  586. }
  587. else {
  588. return false;
  589. }
  590. });
  591. },
  592. handleUploadRuleForm() {
  593. const paramsData = {
  594. type: this.personForm.resource,
  595. orientationName: this.personForm.name,
  596. accountId: this.uploadAcountIds,
  597. url: this.fileList[0].url
  598. };
  599. postAction('/kuaishouCrowdPack/uploadCrowdPack', paramsData).then(result => {
  600. if (result.code === 200) {
  601. this.personVisible = false;
  602. this.handleGetTableList({});
  603. }
  604. else {
  605. this.$message.error(result.message);
  606. }
  607. }).catch(error => {
  608. console.log(error, 'eeee');
  609. });
  610. },
  611. handleCancel() {
  612. this.personVisible = false;
  613. this.$refs.ruleForm.resetFields();
  614. this.uploadAcountIds = '';
  615. }
  616. }
  617. };
  618. </script>
  619. <style lang="less" scoped>
  620. @import "crowd-control";
  621. </style>