account-config.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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 solt="accountBudget" slot-scope="text, record">
  49. {{ record.accountBudgetMode === '1' ? '不限' : text }}
  50. </span>
  51. <span slot="action" slot-scope="text, record">
  52. <a @click="handleEdit(record)">编辑</a>
  53. <a-divider type="vertical"/>
  54. <a @click="handleListDelete(record)">删除</a>
  55. <a-divider type="vertical"/>
  56. <a @click="handleUpdateMod(record)">修改出价</a>
  57. <a-divider type="vertical"/>
  58. <a @click="handleUpdateBudget(record)">修改预算</a>
  59. </span>
  60. </a-table>
  61. <a-pagination
  62. class="pagin-table-class"
  63. :total="totalAll"
  64. :show-total="total => `共 ${totalAll} 条`"
  65. size="small"
  66. show-size-changer
  67. show-quick-jumper
  68. @change="onShowSizeChange"
  69. @showSizeChange="onShowSizeChange"
  70. />
  71. </div>
  72. <a-modal
  73. title="修改预算"
  74. v-if="budgetVisible"
  75. :visible="budgetVisible"
  76. dialog-class="mode-modal-class"
  77. @ok="handleBudgetSure"
  78. @cancel="handleBudgetCancel"
  79. >
  80. <div>
  81. <a-form-model
  82. ref="budgetForm"
  83. :model="budgetForm"
  84. :rules="budgetRules"
  85. :label-col="labelCol"
  86. :wrapper-col="wrapperCol"
  87. >
  88. <a-form-model-item label="预算方式">
  89. <a-radio-group
  90. v-model="budgetForm.budgetType"
  91. button-style="solid"
  92. @change="handleAccountMode"
  93. >
  94. <a-radio-button value="1">不限预算</a-radio-button>
  95. <a-radio-button value="2">指定预算</a-radio-button>
  96. </a-radio-group>
  97. </a-form-model-item>
  98. <a-form-model-item v-if="budgetForm.budgetType === '2'" label="账户日预算" prop="budget">
  99. <a-input-number
  100. v-model="budgetForm.budget"
  101. :min="1000"
  102. :max="9999999.99"
  103. :step="0.01"
  104. @blur="handleAccountBudget"
  105. /> 元
  106. </a-form-model-item>
  107. <!-- <div v-if="adBudgetShowTitle" style="width: 500px;color: #f00;margin-left: 140px;">单次修改预算幅度, 不能低于100.0元</div> -->
  108. </a-form-model>
  109. </div>
  110. </a-modal>
  111. <a-modal
  112. title="修改出价"
  113. v-if="modeVisible"
  114. :visible="modeVisible"
  115. dialog-class="mode-modal-class"
  116. @ok="handleModeSure"
  117. @cancel="handleModeCancel"
  118. >
  119. <div>
  120. <a-form-model
  121. ref="ruleForm"
  122. :model="configForm"
  123. :rules="rules"
  124. :label-col="labelCol"
  125. :wrapper-col="wrapperCol"
  126. >
  127. <a-form-model-item v-if="updateModTxt.adBidCreateType === 'FIX'" label="目标转化出价" prop="adCpaBid">
  128. <a-input-number
  129. class="common-input"
  130. v-model="configForm.adCpaBid"
  131. :min="0.1"
  132. :step="0.01"
  133. placeholder="请输入"
  134. />
  135. </a-form-model-item>
  136. <div v-if="updateModTxt.adBidCreateType === 'RAND'">
  137. <a-form-model-item label="目标转化出价范围"
  138. class="dp-link-start" prop="adMinBid">
  139. <a-input-number
  140. class="common-input"
  141. v-model="configForm.adMinBid"
  142. :min="0.1"
  143. :max="10000"
  144. :step="0.01"
  145. placeholder="请输入最小值"
  146. />
  147. </a-form-model-item>
  148. <span class="icon-span">~</span>
  149. <a-form-model-item class="dp-link-end" prop="adMaxBid">
  150. <a-input-number
  151. class="common-input"
  152. v-model="configForm.adMaxBid"
  153. :min="0.1"
  154. :max="10000"
  155. :step="0.01"
  156. placeholder="请输入最大值"
  157. />
  158. </a-form-model-item>
  159. </div>
  160. <div v-if="updateModTxt.adBidCreateType === 'STEP'">
  161. <a-form-model-item label="目标转化出价范围" class="dp-link-start" prop="adMinBid">
  162. <a-input-number
  163. class="common-input"
  164. v-model="configForm.adMinBid"
  165. :min="0.1"
  166. :max="10000"
  167. :step="0.01"
  168. placeholder="请输入最小值"
  169. />
  170. </a-form-model-item>
  171. <span class="icon-span">~</span>
  172. <a-form-model-item class="dp-link-end" prop="adMaxBid">
  173. <a-input-number
  174. class="common-input"
  175. v-model="configForm.adMaxBid"
  176. :min="0.1"
  177. :max="10000"
  178. :step="0.01"
  179. placeholder="请输入最大值"
  180. />
  181. </a-form-model-item>
  182. <a-form-model-item label="浮动间隔" prop="adStepBid">
  183. <a-input-number
  184. class="common-input"
  185. :min="0"
  186. :step="0.01"
  187. v-model="configForm.adStepBid"
  188. placeholder="请输入浮动间隔"
  189. />
  190. </a-form-model-item>
  191. </div>
  192. </a-form-model>
  193. </div>
  194. </a-modal>
  195. </div>
  196. </template>
  197. <script>
  198. import AcountSearch from '@/views/modules/Statistics/components/Treeselect.vue';
  199. import {getAction, putAction, deleteAction} from '@/api/manage';
  200. import {mapGetters} from 'vuex';
  201. import {urlAcount} from './account-config-server.js';
  202. export default {
  203. name: 'account-config',
  204. components: {
  205. AcountSearch
  206. },
  207. data() {
  208. let adMinBidValidator = (rule, value, callback) => {
  209. const finallyResult = Number(this.configForm.adMaxBid);
  210. if (finallyResult !== '' && value && Number(value) <= finallyResult) {
  211. callback();
  212. }
  213. else {
  214. callback('最低出价不能高于最高出价');
  215. }
  216. };
  217. let adCpaBidValidator = (rule, value, callback) => {
  218. if (Number(this.updateModTxt.adBudget) < Number(value)) {
  219. callback('出价不能大于预算');
  220. }
  221. else {
  222. callback();
  223. }
  224. };
  225. let adMaxBidValidator = (rule, value, callback) => {
  226. const finallyResult = Number(this.configForm.adMinBid);
  227. if (finallyResult && value && Number(value) <= finallyResult) {
  228. callback('最高出价不能低于最低出价');
  229. }
  230. else if (Number(this.updateModTxt.adBudget) < Number(value)) {
  231. callback('出价不能大于预算');
  232. }
  233. else if (Number(this.configForm.adMaxBid) > Number(this.configForm.adMinBid) + Number(this.configForm.adStepBid)) {
  234. this.$refs['ruleForm'].clearValidate(['adStepBid']);
  235. callback();
  236. }
  237. else {
  238. this.$refs['ruleForm'].clearValidate(['adMinBid']);
  239. callback();
  240. }
  241. };
  242. let floatingIntervalValidator = (rule, value, callback) => {
  243. const finallyResult = Number(this.configForm.adMinBid) + Number(value);
  244. if (finallyResult < Number(this.configForm.adMaxBid)) {
  245. callback();
  246. }
  247. else {
  248. callback('最低出价+浮动间隔<最高出价');
  249. }
  250. };
  251. let budgetValidator = (rule, value, callback) => {
  252. // const finallyResult = Number(this.configForm.adMinBid) + Number(value);
  253. // if (finallyResult < Number(this.configForm.adMaxBid)) {
  254. // callback();
  255. // }
  256. // else {
  257. // callback('最低出价+浮动间隔<最高出价');
  258. // }
  259. const changeBudget = this.updateModTxt.accountBudget;
  260. if (Number(value) > Number(changeBudget) && Number(value) < (Number(changeBudget) + 100)) {
  261. callback('单次修改预算幅度, 不能低于100.0元');
  262. }
  263. else if (Number(value) < Number(changeBudget) && Number(value) > (Number(changeBudget) - 100)) {
  264. callback('单次修改预算幅度, 不能低于100.0元');
  265. }
  266. else {
  267. callback();
  268. }
  269. };
  270. return {
  271. adBudgetShowTitle: false,
  272. budgetVisible: false,
  273. budgetForm: {
  274. budgetType: '1',
  275. budget: 0
  276. },
  277. budgetRules: {
  278. budget: [
  279. {required: true, message: '请输入', trigger: 'blur'},
  280. {validator: budgetValidator, trigger: 'blur'}
  281. ]
  282. },
  283. labelCol: {span: 4},
  284. wrapperCol: {span: 14},
  285. configForm: {
  286. adMinBid: undefined,
  287. adMaxBid: undefined,
  288. adStepBid: undefined,
  289. adCpaBid: undefined
  290. },
  291. rules: {
  292. adCpaBid: [
  293. {required: true, message: '请输入', trigger: 'blur'},
  294. {validator: adCpaBidValidator, trigger: 'blur'}
  295. ],
  296. adStepBid: [
  297. {required: true, message: '请输入', trigger: 'blur'},
  298. {validator: floatingIntervalValidator, trigger: 'blur'}
  299. ],
  300. adMinBid: [
  301. {required: true, message: '请输入最低出价', trigger: 'blur'},
  302. {validator: adMinBidValidator, trigger: 'blur'}
  303. ],
  304. adMaxBid: [
  305. {required: true, message: '请输入最高出价', trigger: 'blur'},
  306. {validator: adMaxBidValidator, trigger: 'blur'}
  307. ]
  308. },
  309. modeVisible: false,
  310. updateModTxt: {},
  311. modContent: '',
  312. budgetContent: '',
  313. acountId: undefined, // 搜索的账户ID
  314. totalAll: 0,
  315. tablePag: {
  316. page: 1,
  317. size: 10
  318. },
  319. dataSource: [],
  320. columns: [
  321. {
  322. title: '开关',
  323. align: 'center',
  324. dataIndex: 'status',
  325. scopedSlots: {customRender: 'acountRelax'}
  326. },
  327. {
  328. title: '广告账户名称',
  329. align: 'center',
  330. dataIndex: 'accountId_dictText'
  331. },
  332. {
  333. title: '账户ID',
  334. align: 'center',
  335. dataIndex: 'accountId'
  336. },
  337. {
  338. title: '创建时间',
  339. dataIndex: 'createTime',
  340. align: 'center'
  341. },
  342. {
  343. title: '账户余额',
  344. dataIndex: 'validBalance',
  345. align: 'center'
  346. },
  347. {
  348. title: '账户日预算量(元)',
  349. dataIndex: 'accountBudget',
  350. align: 'center'
  351. },
  352. {
  353. title: '出价(元)',
  354. dataIndex: 'adCpaBidStr',
  355. align: 'center'
  356. },
  357. {
  358. align: 'center',
  359. dataIndex: 'cost',
  360. slots: {title: 'customTitle'}
  361. },
  362. {
  363. title: '操作',
  364. dataIndex: 'action',
  365. align: 'center',
  366. scopedSlots: {customRender: 'action'}
  367. }
  368. ]
  369. };
  370. },
  371. created() {
  372. this.form = this.$form.createForm(this);
  373. },
  374. mounted() {
  375. this.handleInitTable();
  376. },
  377. methods: {
  378. ...mapGetters(['nickname', 'avatar', 'userInfo']),
  379. handleAccountMode(e) {
  380. this.budgetForm.budget = 1000;
  381. this.adBudgetShowTitle = false;
  382. },
  383. handleAccountBudget(e) {
  384. const adBudgetInput = e.target.value;
  385. // const changeBudget = this.updateModTxt.accountBudget;
  386. this.budgetForm.budget = Number(Number(adBudgetInput).toFixed(2));
  387. // if (Number(adBudgetInput) >= Number(changeBudget) && Number(adBudgetInput) < (Number(changeBudget) + 100)) {
  388. // this.adBudgetShowTitle = true;
  389. // }
  390. // else if (Number(adBudgetInput) <= Number(changeBudget) && Number(adBudgetInput) > (Number(changeBudget) - 100)) {
  391. // this.adBudgetShowTitle = true;
  392. // }
  393. // else {
  394. // this.adBudgetShowTitle = false;
  395. // }
  396. },
  397. handleModeSure() {
  398. let paramsData = new FormData();
  399. if (this.updateModTxt.adBidCreateType === 'FIX') {
  400. paramsData.append('type', 1);
  401. paramsData.append('id', this.updateModTxt.id);
  402. paramsData.append('adCpaBid', this.configForm.adCpaBid);
  403. }
  404. else if (this.updateModTxt.adBidCreateType === 'RAND') {
  405. paramsData.append('type', 1);
  406. paramsData.append('id', this.updateModTxt.id);
  407. paramsData.append('adMinBid', this.configForm.adMinBid);
  408. paramsData.append('adMaxBid', this.configForm.adMaxBid);
  409. }
  410. else if (this.updateModTxt.adBidCreateType === 'STEP') {
  411. paramsData.append('type', 1);
  412. paramsData.append('id', this.updateModTxt.id);
  413. paramsData.append('adMinBid', this.configForm.adMinBid);
  414. paramsData.append('adMaxBid', this.configForm.adMaxBid);
  415. paramsData.append('adStepBid', this.configForm.adStepBid);
  416. }
  417. this.$refs.ruleForm.validate(valid => {
  418. if (valid) {
  419. this.handlePopoverChange(paramsData);
  420. }
  421. else {
  422. console.log('error submit!!');
  423. return false;
  424. }
  425. });
  426. },
  427. handleModeCancel() {
  428. this.adMinBid = undefined;
  429. this.adMaxBid = undefined;
  430. this.adStepBid = undefined;
  431. this.adCpaBid = undefined;
  432. this.modeVisible = false;
  433. },
  434. handleUpdateMod(record) {
  435. this.updateModTxt = record;
  436. this.configForm.adMinBid = record.adMinBid;
  437. this.configForm.adMaxBid = record.adMaxBid;
  438. this.configForm.adStepBid = record.adStepBid;
  439. this.modeVisible = true;
  440. },
  441. handleUpdateBudget(record) {
  442. this.updateModTxt = record;
  443. this.budgetForm.budgetType = record.accountBudgetMode;
  444. this.budgetForm.budget = record.accountBudget;
  445. this.budgetVisible = true;
  446. },
  447. handleBudgetSure() {
  448. let paramsData = new FormData();
  449. paramsData.append('accountId', this.updateModTxt.accountId);
  450. paramsData.append('adId', this.updateModTxt.adId);
  451. paramsData.append('type', 2);
  452. paramsData.append('budget', this.budgetForm.budget);
  453. paramsData.append('budgetType', this.budgetForm.budgetType);
  454. paramsData.append('id', this.updateModTxt.id);
  455. paramsData.append('cost', this.updateModTxt.cost);
  456. if (this.adBudgetShowTitle) {
  457. return;
  458. }
  459. this.$refs.budgetForm.validate(valid => {
  460. if (valid) {
  461. this.handlePopoverChange(paramsData);
  462. }
  463. else {
  464. console.log('error submit!!');
  465. return false;
  466. }
  467. });
  468. },
  469. handleBudgetCancel() {
  470. this.budgetVisible = false;
  471. this.budgetForm.budgetType = '1';
  472. },
  473. handlePopoverChange(data) {
  474. putAction(urlAcount + '/bytedance-api/advertiser/aiBytedanceAdvertiserStrategy/updStaOrCpaOrBudgetById', data).then(result => {
  475. if (result.code === 0) {
  476. this.$message.success(result.message);
  477. this.adMinBid = undefined;
  478. this.adMaxBid = undefined;
  479. this.adStepBid = undefined;
  480. this.adCpaBid = undefined;
  481. this.modeVisible = false;
  482. this.budgetVisible = false;
  483. this.budgetForm.budgetType = '1';
  484. this.handleInitTable();
  485. }
  486. else {
  487. this.$message.error(result.message);
  488. }
  489. }).catch(error => {
  490. console.log(error, 'eeee');
  491. });
  492. },
  493. handleResetList() {
  494. this.acountId = '';
  495. this.handleInitTable();
  496. },
  497. handleInitTable() {
  498. const paramsData = {
  499. accountId: this.acountId,
  500. loginUserId: this.userInfo().id,
  501. pageNo: this.tablePag.page,
  502. pageSize: this.tablePag.size
  503. };
  504. getAction(urlAcount + '/bytedance-api/advertiser/aiBytedanceAdvertiserStrategy/list', paramsData).then(result => {
  505. if (result.code === 0) {
  506. result.result.records.forEach(item => {
  507. item.show = false;
  508. item.visible = false;
  509. if (item.accountBudgetMode === '1') {
  510. item.accountBudget = '不限';
  511. }
  512. });
  513. this.dataSource = result.result.records;
  514. this.totalAll = result.result.total;
  515. }
  516. else {
  517. this.$message.error(result.message);
  518. }
  519. }).catch(error => {
  520. console.log(error, 'eeee');
  521. });
  522. },
  523. handleListDelete(data) {
  524. let that = this;
  525. this.$confirm({
  526. title: '删除提示',
  527. content: '是否删除该条数据',
  528. onOk() {
  529. deleteAction(urlAcount + '/bytedance-api/advertiser/aiBytedanceAdvertiserStrategy/delete', {id: data.id}).then(result => {
  530. if (result.code === 0) {
  531. that.handleInitTable();
  532. that.$message.success('删除成功');
  533. }
  534. else {
  535. that.$message.error(result.message);
  536. }
  537. }).catch(error => {
  538. console.log(error, 'eeee');
  539. });
  540. }
  541. });
  542. },
  543. handleBudgetPopover(record) {
  544. record.show = false;
  545. },
  546. handleModPopover(record) {
  547. record.visible = false;
  548. },
  549. handleQueryList(event) {
  550. event.preventDefault();
  551. this.handleInitTable();
  552. },
  553. onShowSizeChange(current, pageSize) {
  554. this.tablePag = {
  555. page: current,
  556. size: pageSize
  557. };
  558. this.handleInitTable();
  559. },
  560. handleSwitchChang(checked, data) {
  561. const paramsData = {
  562. id: data.id,
  563. state: checked ? 0 : 1,
  564. accountId: data.accountId
  565. };
  566. const forDate = new FormData();
  567. forDate.append('id', paramsData.id);
  568. forDate.append('state', paramsData.state);
  569. forDate.append('accountId', paramsData.accountId);
  570. putAction(urlAcount + '/bytedance-api/advertiser/aiBytedanceAdvertiserStrategy/updStaById', forDate).then(result => {
  571. if (result.code === 0) {
  572. this.$message.success(result.message);
  573. this.handleInitTable();
  574. }
  575. else {
  576. this.$message.error(result.message);
  577. }
  578. }).catch(error => {
  579. console.log(error, 'eeee');
  580. });
  581. },
  582. handleEdit(data) {
  583. // TODO 切换路由时候,及时删除上一次相同路由
  584. let params = {
  585. accountModal: 'edit',
  586. id: data.id
  587. };
  588. localStorage.setItem('queryList', JSON.stringify(params));
  589. this.$router.push('/account-config/components/configuration-modal');
  590. },
  591. handleAddAccountConfig() {
  592. let params = {
  593. accountModal: 'add'
  594. };
  595. localStorage.setItem('queryList', JSON.stringify(params));
  596. this.$router.push('/account-config/components/configuration-modal');
  597. }
  598. }
  599. };
  600. </script>
  601. <style lang="less" scoped>
  602. @import "account-config";
  603. </style>