account-config.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <div class="account-config-content">
  3. <div class="control-con-header">
  4. <a-form
  5. class="grid-form"
  6. layout="inline"
  7. :form="form"
  8. hide-required-mark
  9. @submit="handleQueryList"
  10. >
  11. <a-row class="grid-form-options">
  12. <a-form-item
  13. class="grid-form-item"
  14. label="账户"
  15. :colon="false"
  16. >
  17. <acount-search class="acount-search-class" :appId.sync="acountId" :multiple="false" request="1,3"></acount-search>
  18. </a-form-item>
  19. <a-form-item class="form-handle-btn">
  20. <a-button type="default" class="reset-class" @click="handleResetList">重置</a-button>
  21. <a-button type="primary" html-type="submit">查询</a-button>
  22. </a-form-item>
  23. </a-row>
  24. </a-form>
  25. <a-button type="primary" class="upload-person" @click="handleAddAccountConfig">新建账户配置</a-button>
  26. </div>
  27. <div class="control-con-table">
  28. <a-table
  29. ref="table"
  30. size="middle"
  31. bordered
  32. :columns="columns"
  33. :dataSource="dataSource"
  34. :pagination="false"
  35. >
  36. <span slot="customTitle">
  37. 花费(元)
  38. <a-tooltip placement="top">
  39. <template slot="title">
  40. <span>当日花费</span>
  41. </template>
  42. <a-icon type="smile-o"/>
  43. </a-tooltip>
  44. </span>
  45. <span slot="acountRelax" slot-scope="text, record">
  46. <a-switch :checked="text === 0" @change="handleSwitchChang($event, record)"/>
  47. </span>
  48. <span slot="action" slot-scope="text, record">
  49. <a @click="handleEdit(record)">编辑</a>
  50. <a-divider type="vertical"/>
  51. <a @click="handleListDelete(record)">删除</a>
  52. <a-divider type="vertical"/>
  53. <a @click="handleUpdateMod(record)">修改出价</a>
  54. <a-divider type="vertical"/>
  55. <a-popover v-model="record.show" trigger="click">
  56. <template slot="content">
  57. <div><a-input v-model="budgetContent" placeholder="请输入" style="width: 140px;"/></div>
  58. <div style="margin-top: 10px;">
  59. <a-button
  60. size="small"
  61. type="primary"
  62. style="margin-left: 15px;margin-right: 15px;"
  63. @click="handlePopoverSure(record, 'budget')"
  64. >
  65. 确定
  66. </a-button>
  67. <a-button size="small" @click="handleBudgetPopover(record)">取消</a-button>
  68. </div>
  69. </template>
  70. <a>修改预算</a>
  71. </a-popover>
  72. </span>
  73. </a-table>
  74. <a-pagination
  75. class="pagin-table-class"
  76. :total="totalAll"
  77. :show-total="total => `共 ${totalAll} 条`"
  78. size="small"
  79. show-size-changer
  80. show-quick-jumper
  81. @change="onShowSizeChange"
  82. @showSizeChange="onShowSizeChange"
  83. />
  84. </div>
  85. <a-modal
  86. title="修改出价"
  87. v-if="modeVisible"
  88. :visible="modeVisible"
  89. dialog-class="mode-modal-class"
  90. @ok="handleModeSure"
  91. @cancel="handleModeCancel"
  92. >
  93. <div>
  94. <a-form-model
  95. ref="ruleForm"
  96. :model="configForm"
  97. :rules="rules"
  98. :label-col="labelCol"
  99. :wrapper-col="wrapperCol"
  100. >
  101. <a-form-model-item v-if="updateModTxt.adBidCreateType === 'FIX'" label="目标转化出价" prop="adCpaBid">
  102. <a-input-number
  103. class="common-input"
  104. v-model="configForm.adCpaBid"
  105. :min="0.1"
  106. :step="0.01"
  107. placeholder="请输入"
  108. />
  109. </a-form-model-item>
  110. <div v-if="updateModTxt.adBidCreateType === 'RAND'">
  111. <a-form-model-item label="目标转化出价范围"
  112. class="dp-link-start" prop="adMinBid">
  113. <a-input-number
  114. class="common-input"
  115. v-model="configForm.adMinBid"
  116. :min="0.1"
  117. :max="10000"
  118. placeholder="请输入最小值"
  119. />
  120. </a-form-model-item>
  121. <span class="icon-span">~</span>
  122. <a-form-model-item class="dp-link-end" prop="adMaxBid">
  123. <a-input-number
  124. class="common-input"
  125. v-model="configForm.adMaxBid"
  126. :min="0.1"
  127. :max="10000"
  128. placeholder="请输入最大值"
  129. />
  130. </a-form-model-item>
  131. </div>
  132. <div v-if="updateModTxt.adBidCreateType === 'STEP'">
  133. <a-form-model-item label="目标转化出价范围" class="dp-link-start" prop="adMinBid">
  134. <a-input-number
  135. class="common-input"
  136. v-model="configForm.adMinBid"
  137. :min="0.1"
  138. :max="10000"
  139. placeholder="请输入最小值"
  140. />
  141. </a-form-model-item>
  142. <span class="icon-span">~</span>
  143. <a-form-model-item class="dp-link-end" prop="adMaxBid">
  144. <a-input-number
  145. class="common-input"
  146. v-model="configForm.adMaxBid"
  147. :min="0.1"
  148. :max="10000"
  149. placeholder="请输入最大值"
  150. />
  151. </a-form-model-item>
  152. <a-form-model-item label="浮动间隔" prop="adStepBid">
  153. <a-input-number
  154. class="common-input"
  155. v-model="configForm.adStepBid"
  156. placeholder="请输入浮动间隔"
  157. />
  158. </a-form-model-item>
  159. </div>
  160. </a-form-model>
  161. </div>
  162. </a-modal>
  163. </div>
  164. </template>
  165. <script>
  166. import AcountSearch from '@/views/modules/Statistics/components/Treeselect.vue';
  167. import {getAction, putAction, deleteAction} from '@/api/manage';
  168. import {mapGetters} from 'vuex';
  169. import {urlAcount} from './account-config-server.js';
  170. export default {
  171. name: 'account-config',
  172. components: {
  173. AcountSearch
  174. },
  175. data() {
  176. let adMinBidValidator = (rule, value, callback) => {
  177. const finallyResult = Number(this.configForm.adMaxBid);
  178. if (finallyResult !== '' && value && Number(value) < finallyResult) {
  179. callback();
  180. }
  181. else {
  182. callback('最低出价不能高于最高出价');
  183. }
  184. };
  185. let adMaxBidValidator = (rule, value, callback) => {
  186. const finallyResult = Number(this.configForm.adMinBid);
  187. if (finallyResult !== undefined && value && Number(value) > finallyResult) {
  188. callback();
  189. }
  190. else {
  191. callback('最高出价不能低于最低出价');
  192. }
  193. };
  194. let floatingIntervalValidator = (rule, value, callback) => {
  195. const finallyResult = Number(this.configForm.adMinBid) + Number(value);
  196. if (finallyResult !== undefined < Number(this.configForm.adMaxBid)) {
  197. callback();
  198. }
  199. else {
  200. callback('最低出价+浮动间隔<最高出价');
  201. }
  202. };
  203. return {
  204. labelCol: {span: 4},
  205. wrapperCol: {span: 14},
  206. configForm: {
  207. adMinBid: undefined,
  208. adMaxBid: undefined,
  209. adStepBid: undefined,
  210. adCpaBid: undefined
  211. },
  212. rules: {
  213. adCpaBid: [
  214. {required: true, message: '请输入', trigger: 'blur'}
  215. ],
  216. adStepBid: [
  217. {required: true, message: '请输入', trigger: 'blur'},
  218. {validator: floatingIntervalValidator, trigger: 'blur'}
  219. ],
  220. adMinBid: [
  221. {required: true, message: '请输入最低出价', trigger: 'blur'},
  222. {validator: adMinBidValidator, trigger: 'blur'}
  223. ],
  224. adMaxBid: [
  225. {required: true, message: '请输入最高出价', trigger: 'blur'},
  226. {validator: adMaxBidValidator, trigger: 'blur'}
  227. ]
  228. },
  229. modeVisible: false,
  230. updateModTxt: {},
  231. modContent: '',
  232. budgetContent: '',
  233. acountId: undefined, // 搜索的账户ID
  234. totalAll: 0,
  235. tablePag: {
  236. page: 1,
  237. size: 10
  238. },
  239. dataSource: [],
  240. columns: [
  241. {
  242. title: '开关',
  243. align: 'center',
  244. dataIndex: 'status',
  245. scopedSlots: {customRender: 'acountRelax'}
  246. },
  247. {
  248. title: '广告账户名称',
  249. align: 'center',
  250. dataIndex: 'accountId_dictText'
  251. },
  252. {
  253. title: '账户ID',
  254. align: 'center',
  255. dataIndex: 'accountId'
  256. },
  257. {
  258. title: '创建时间',
  259. dataIndex: 'createTime',
  260. align: 'center'
  261. },
  262. {
  263. title: '账户余额',
  264. dataIndex: 'validBalance',
  265. align: 'center'
  266. },
  267. {
  268. title: '账户日预算量(元)',
  269. dataIndex: 'adBudget',
  270. align: 'center'
  271. },
  272. {
  273. title: '出价(元)',
  274. dataIndex: 'adCpaBid',
  275. align: 'center'
  276. },
  277. {
  278. align: 'center',
  279. dataIndex: 'cost',
  280. slots: {title: 'customTitle'}
  281. },
  282. {
  283. title: '操作',
  284. dataIndex: 'action',
  285. align: 'center',
  286. scopedSlots: {customRender: 'action'}
  287. }
  288. ]
  289. };
  290. },
  291. created() {
  292. this.form = this.$form.createForm(this);
  293. },
  294. mounted() {
  295. this.handleInitTable();
  296. },
  297. methods: {
  298. ...mapGetters(['nickname', 'avatar', 'userInfo']),
  299. handleModeSure() {
  300. let paramsData = new FormData();
  301. if (this.updateModTxt.adBidCreateType === 'FIX') {
  302. paramsData.append('type', 1);
  303. paramsData.append('id', this.updateModTxt.id);
  304. paramsData.append('adCpaBid', this.configForm.adCpaBid);
  305. }
  306. else if (this.updateModTxt.adBidCreateType === 'RAND') {
  307. paramsData.append('type', 1);
  308. paramsData.append('id', this.updateModTxt.id);
  309. paramsData.append('adMinBid', this.configForm.adMinBid);
  310. paramsData.append('adMaxBid', this.configForm.adMaxBid);
  311. }
  312. else if (this.updateModTxt.adBidCreateType === 'STEP') {
  313. paramsData.append('type', 1);
  314. paramsData.append('id', this.updateModTxt.id);
  315. paramsData.append('adMinBid', this.configForm.adMinBid);
  316. paramsData.append('adMaxBid', this.configForm.adMaxBid);
  317. paramsData.append('adStepBid', this.configForm.adStepBid);
  318. }
  319. this.$refs.ruleForm.validate(valid => {
  320. if (valid) {
  321. this.handlePopoverChange(paramsData);
  322. }
  323. else {
  324. console.log('error submit!!');
  325. return false;
  326. }
  327. });
  328. },
  329. handleModeCancel() {
  330. this.adMinBid = undefined;
  331. this.adMaxBid = undefined;
  332. this.adStepBid = undefined;
  333. this.adCpaBid = undefined;
  334. this.modeVisible = false;
  335. },
  336. handleUpdateMod(record) {
  337. this.updateModTxt = record;
  338. this.modeVisible = true;
  339. },
  340. handlePopoverSure(record, type) {
  341. const defaultList = {
  342. accountId: record.accountId,
  343. bid: this.modContent,
  344. budget: this.budgetContent,
  345. adId: record.adId ? record.adId : '',
  346. id: record.id
  347. };
  348. let paramsData = new FormData();
  349. if (type === 'mod') {
  350. record.visible = false;
  351. // if (this.updateModTxt === 'FIX') {
  352. // paramsData.append('type', 1);
  353. // paramsData.append('id', defaultList.id);
  354. // paramsData.append('adCpaBid', this.modContent);
  355. // }
  356. // else if (this.updateModTxt === 'RAND') {
  357. // paramsData.append('type', 1);
  358. // paramsData.append('id', defaultList.id);
  359. // paramsData.append('adMinBid', this.adMinBid);
  360. // paramsData.append('adMaxBid', this.adMaxBid);
  361. // }
  362. // else if (this.updateModTxt === 'STEP') {
  363. // paramsData.append('type', 1);
  364. // paramsData.append('id', defaultList.id);
  365. // paramsData.append('adMinBid', this.adMinBid);
  366. // paramsData.append('adMaxBid', this.adMaxBid);
  367. // paramsData.append('adStepBid', this.adStepBid);
  368. // }
  369. }
  370. else if (type === 'budget') {
  371. if (Number(defaultList.budget) >= record.adBudget && Number(defaultList.budget) < (record.adBudget + 100)) {
  372. this.$message.error('单次修改预算幅度, 不能低于100.0元');
  373. return;
  374. }
  375. if (Number(defaultList.budget) <= record.adBudget && Number(defaultList.budget) > (record.adBudget - 100)) {
  376. this.$message.error('单次修改预算幅度, 不能低于100.0元');
  377. return;
  378. }
  379. record.show = false;
  380. this.budgetContent = '';
  381. paramsData.append('accountId', defaultList.accountId);
  382. paramsData.append('adId', defaultList.adId);
  383. paramsData.append('type', 2);
  384. paramsData.append('budget', defaultList.budget);
  385. paramsData.append('id', defaultList.id);
  386. }
  387. this.handlePopoverChange(paramsData);
  388. },
  389. handlePopoverChange(data) {
  390. putAction(urlAcount + '/bytedance-api/advertiser/aiBytedanceAdvertiserStrategy/updStaOrCpaOrBudgetById', data).then(result => {
  391. if (result.code === 0) {
  392. this.$message.success(result.message);
  393. this.adMinBid = undefined;
  394. this.adMaxBid = undefined;
  395. this.adStepBid = undefined;
  396. this.adCpaBid = undefined;
  397. this.modeVisible = false;
  398. this.handleInitTable();
  399. }
  400. else {
  401. this.$message.error(result.message);
  402. }
  403. }).catch(error => {
  404. console.log(error, 'eeee');
  405. });
  406. },
  407. handleResetList() {
  408. this.acountId = '';
  409. this.handleInitTable();
  410. },
  411. handleInitTable() {
  412. const paramsData = {
  413. accountId: this.acountId,
  414. logingUserId: this.userInfo().id,
  415. pageNo: this.tablePag.page,
  416. pageSize: this.tablePag.size
  417. };
  418. getAction(urlAcount + '/bytedance-api/advertiser/aiBytedanceAdvertiserStrategy/list', paramsData).then(result => {
  419. if (result.code === 0) {
  420. result.result.records.forEach(item => {
  421. item.show = false;
  422. item.visible = false;
  423. });
  424. this.dataSource = result.result.records;
  425. this.totalAll = result.result.total;
  426. }
  427. else {
  428. this.$message.error(result.message);
  429. }
  430. }).catch(error => {
  431. console.log(error, 'eeee');
  432. });
  433. },
  434. handleListDelete(data) {
  435. let that = this;
  436. this.$confirm({
  437. title: '删除提示',
  438. content: '是否删除该条数据',
  439. onOk() {
  440. deleteAction(urlAcount + '/bytedance-api/advertiser/aiBytedanceAdvertiserStrategy/delete', {id: data.id}).then(result => {
  441. if (result.code === 0) {
  442. that.handleInitTable();
  443. that.$message.success('删除成功');
  444. }
  445. else {
  446. that.$message.error(result.message);
  447. }
  448. }).catch(error => {
  449. console.log(error, 'eeee');
  450. });
  451. }
  452. });
  453. },
  454. handleBudgetPopover(record) {
  455. record.show = false;
  456. },
  457. handleModPopover(record) {
  458. record.visible = false;
  459. },
  460. handleQueryList(event) {
  461. event.preventDefault();
  462. this.handleInitTable();
  463. },
  464. onShowSizeChange(current, pageSize) {
  465. this.tablePag = {
  466. page: current,
  467. size: pageSize
  468. };
  469. this.handleInitTable();
  470. },
  471. handleSwitchChang(checked, data) {
  472. const paramsData = {
  473. id: data.id,
  474. state: checked ? 0 : 1,
  475. accountId: data.accountId
  476. };
  477. const forDate = new FormData();
  478. forDate.append('id', paramsData.id);
  479. forDate.append('state', paramsData.state);
  480. forDate.append('accountId', paramsData.accountId);
  481. putAction(urlAcount + '/bytedance-api/advertiser/aiBytedanceAdvertiserStrategy/updStaById', forDate).then(result => {
  482. if (result.code === 0) {
  483. this.$message.success(result.message);
  484. this.handleInitTable();
  485. }
  486. else {
  487. this.$message.error(result.message);
  488. }
  489. }).catch(error => {
  490. console.log(error, 'eeee');
  491. });
  492. },
  493. handleEdit(data) {
  494. // TODO 切换路由时候,及时删除上一次相同路由
  495. let params = {
  496. accountModal: 'edit',
  497. id: data.id
  498. };
  499. localStorage.setItem('queryList', JSON.stringify(params));
  500. this.$router.push('/account-config/components/configuration-modal');
  501. },
  502. handleAddAccountConfig() {
  503. let params = {
  504. accountModal: 'add'
  505. };
  506. localStorage.setItem('queryList', JSON.stringify(params));
  507. this.$router.push('/account-config/components/configuration-modal');
  508. }
  509. }
  510. };
  511. </script>
  512. <style lang="less" scoped>
  513. @import "account-config";
  514. </style>