createStrategy.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. <template>
  2. <div class="newPlan">
  3. <a-form :form="form">
  4. <!-- 投放范围 -->
  5. <div class="moduler">
  6. <div class="moduler-title">请选择策略创建场景</div>
  7. <div class="ad-range">
  8. <div class="row-item">
  9. <div class="hint-item"></div>
  10. <div class="label-item">
  11. <div class="text-item">创建场景</div>
  12. <div class="required-item"></div>
  13. </div>
  14. <div class="input-item">
  15. <a-form-item>
  16. <a-radio-group v-decorator="['scenes', { initialValue:'2' }]">
  17. <a-radio-button value="1">素材+出价</a-radio-button>
  18. <a-radio-button value="2">素材+定向</a-radio-button>
  19. <a-radio-button value="3">时间+出价</a-radio-button>
  20. </a-radio-group>
  21. </a-form-item>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. <div class="moduler">
  27. <div class="moduler-title">选择账户</div>
  28. <div>
  29. <div class="row-item">
  30. <div class="hint-item"></div>
  31. <div class="label-item">
  32. <div class="text-item">账户</div>
  33. <div class="required-item"></div>
  34. </div>
  35. <div class="input-item">
  36. <a-tree-select
  37. v-model="accountId"
  38. show-search
  39. style="width: 600px;height:30px"
  40. :dropdownMatchSelectWidth='true'
  41. :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
  42. tree-checkable
  43. searchPlaceholder='请输入账户关键字搜索'
  44. :show-checked-strategy="SHOW_PARENT"
  45. placeholder="请选择项目和账户或搜索账户关键字"
  46. treeNodeFilterProp="title"
  47. :allowClear="true"
  48. @change="treeChange"
  49. @search="treeSearch"
  50. @select="treeSelect"
  51. :maxTagCount='1'
  52. :tree-data="treeData"
  53. :filterOption='filterOption'
  54. >
  55. </a-tree-select>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <!-- 推广目的 -->
  61. <div class="moduler">
  62. <div class="moduler-title">请选择营销目标</div>
  63. <div class="row-item">
  64. <div class="hint-item">
  65. </div>
  66. <div class="label-item">
  67. <div class="text-item"></div>
  68. <div class="required-item"></div>
  69. </div>
  70. <div class="input-item">
  71. <a-form-item >
  72. <a-radio-group v-decorator="['marketingGoal',{initialValue:'1' }]" @change="marketingGoalChange">
  73. <a-radio-button value="1">提升应用安装</a-radio-button>
  74. <a-radio-button value="2">获取电商下单</a-radio-button>
  75. <a-radio-button value="3">推广品牌活动</a-radio-button>
  76. <a-radio-button value="4">收集销售线索</a-radio-button>
  77. <a-radio-button value="5">提高应用活跃</a-radio-button>
  78. </a-radio-group>
  79. </a-form-item>
  80. </div>
  81. </div>
  82. </div>
  83. <!-- 基础信息 -->
  84. <div class="moduler">
  85. <div class="moduler-title">请设置基本信息</div>
  86. <div class="row-item">
  87. <div class="hint-item"> </div>
  88. <div class="label-item">
  89. <div class="text-item">策略名称</div>
  90. <div class="required-item"></div>
  91. </div>
  92. <div class="input-item">
  93. <a-form-item>
  94. <a-input v-model="strategyName" allow-clear />
  95. </a-form-item>
  96. </div>
  97. </div>
  98. </div>
  99. <div class="moduler">
  100. <div class="opt">
  101. <a-button type="default" style="margin-right:15px" @click="goBack">取消</a-button>
  102. <a-button type="primary" @click="goNext" :loading="goNextloading">下一步</a-button>
  103. </div>
  104. </div>
  105. </a-form>
  106. <div class="infoModal">
  107. <a-modal v-model="visible" title="提示" @ok="handleOk" :keyboard='false' :maskClosable='false'>
  108. <ul>
  109. <li v-for="(item,index) in errorInfo" :key="index">
  110. <span>账户{{LHKaccountInfo[index].title}}:</span>{{item.message || '投放项目创建成功'}}
  111. </li>
  112. </ul>
  113. <template slot="footer">
  114. <a-button key="back" @click="handleCancel">
  115. 返回本页
  116. </a-button>
  117. <a-button key="submit" type="primary" @click="handleOk">
  118. 下一步
  119. </a-button>
  120. </template>
  121. </a-modal>
  122. </div>
  123. </div>
  124. </template>
  125. <script>
  126. import moment from 'moment'
  127. import { getAction, postAction, downFile, downFilePost } from '@/api/manage'
  128. import { TreeSelect } from 'ant-design-vue';
  129. import qs from 'qs'
  130. const SHOW_PARENT = TreeSelect.SHOW_PARENT;
  131. // import selectCheckAll from './toutiaoTime'
  132. var str = ""
  133. for (let i = 0; i < 7*48; i++) {
  134. str+='0'
  135. }
  136. export default {
  137. components: {
  138. // selectCheckAll,
  139. // newDirectedPackage,
  140. },
  141. data() {
  142. return {
  143. LHKaccountInfo:{},
  144. treeValue: [],
  145. treeData: [],
  146. SHOW_PARENT,
  147. accountId:[],
  148. strategyName: '',
  149. form: this.$form.createForm(this),
  150. goNextloading:false,
  151. goPlanShowloading:false,
  152. dateRange: [moment(), moment()],
  153. visible:false,
  154. errorInfo:[],
  155. validationRules: {
  156. url: [
  157. {
  158. required: true,
  159. validator: this.validateURL,
  160. },
  161. ],
  162. strategyName:[{
  163. required: true,
  164. validator: this.validateName,
  165. }],
  166. bid:[{
  167. required: true,
  168. message:'出价信息必须填写',
  169. // validator: this.validateBid,
  170. }],
  171. roi:[{
  172. required: true,
  173. message:'ROI系数必须填写',
  174. // validator: this.validateBid,
  175. }],
  176. },
  177. }
  178. },
  179. watch: {
  180. },
  181. methods: {
  182. // //项目改变后的事件
  183. treeChange(val) {
  184. // console.log(this.treeData)
  185. console.log(val)
  186. this.accountId = [];
  187. //选择一个后禁用其他
  188. if(val.length==1){
  189. if(val[0]*1){
  190. let selectindex=0
  191. this.treeData.forEach((ele,index)=>{
  192. if(ele.children){
  193. ele.children.map((item,ind)=>{
  194. if(item.value==val[0]){
  195. selectindex=index;
  196. }
  197. })
  198. }
  199. });
  200. // console.log(selectindex)
  201. if(selectindex ||selectindex==0){
  202. this.treeData.forEach((ele,index)=>{
  203. if(index!=selectindex){
  204. ele.disableCheckbox = true;
  205. if(ele.children){
  206. ele.children.map((item,ind)=>{
  207. item.disableCheckbox = true;
  208. })
  209. }
  210. }
  211. })
  212. }
  213. }else{
  214. // console.log(1)
  215. this.treeData.forEach((ele,index)=>{
  216. if(ele.value!=val[0]){
  217. ele.disableCheckbox = true;
  218. if(ele.children){
  219. ele.children.forEach((item,ind)=>{
  220. item.disableCheckbox = true;
  221. })
  222. }
  223. }
  224. })
  225. }
  226. // console.log(this.mediaId)
  227. }
  228. if(val.length==0){
  229. this.treeData.forEach((ele,index)=>{
  230. ele.disableCheckbox = false;
  231. if(ele.children){
  232. ele.children.forEach((item,ind)=>{
  233. item.disableCheckbox = false;
  234. })
  235. }
  236. });
  237. }
  238. if(val){
  239. val.forEach((ele,index)=>{
  240. if(ele*1){
  241. this.accountId.push(ele)
  242. }else{
  243. let projectArr=this.treeData.filter((item)=>{
  244. return item.value==ele
  245. });
  246. // console.log(projectArr)
  247. projectArr[0].children.forEach((element)=>{
  248. this.accountId.push(element.value)
  249. })
  250. }
  251. })
  252. }
  253. console.log(this.accountId);
  254. let LHKaccountInfo=[]
  255. this.accountId.forEach(item=>{
  256. this.treeData.forEach(element=>{
  257. element.children.forEach(ele=>{
  258. if(item==ele.value){
  259. LHKaccountInfo.push(ele)
  260. }
  261. })
  262. })
  263. })
  264. sessionStorage.setItem('LHKaccountInfo',JSON.stringify(LHKaccountInfo))
  265. },
  266. treeSearch(){
  267. },
  268. treeSelect(){
  269. },
  270. filterOption(input, option){
  271. console.log(input, option)
  272. return (
  273. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  274. );
  275. },
  276. //请求项目和账户内容
  277. accountHttp(){
  278. this.treeData=[];
  279. this.accountId=[];
  280. getAction('/ctop/projectMember/getProjectAccountByUserId?mediaType=1', {}).then(res => {
  281. if(res.success){
  282. // console.log(res);
  283. if(res.result){
  284. res.result.forEach((element,index) => {
  285. if(element){
  286. this.treeData.push({});
  287. this.treeData[index].title=element.project.projectName +'_('+ element.project.advertiserName +')';
  288. this.treeData[index].value='project'+element.project.projectId;
  289. this.treeData[index].key=element.project.projectId;
  290. this.treeData[index].mediaId=element.project.mediaId;
  291. this.treeData[index].children=[];
  292. if(element.account.length){
  293. element.account.forEach((ele,i)=>{
  294. this.treeData[index].children.push({});
  295. this.treeData[index].children[i].title=ele.userName+'_'+ele.authName+'_'+element.project.projectName;
  296. this.treeData[index].children[i].value=ele.accountId;
  297. this.treeData[index].children[i].key=ele.accountId;
  298. })
  299. }
  300. }
  301. });
  302. // console.log(this.treeData)
  303. }
  304. }
  305. })
  306. },
  307. handleOk(e) {
  308. this.visible=false;
  309. this.$router.replace({path:'/LaunchHousekeeper/setProjectConvert'})
  310. },
  311. handleCancel(e) {
  312. this.visible = false;
  313. },
  314. //获取表单的某一个属性值
  315. getFormData(className) {
  316. return this.form.getFieldValue(className)
  317. },
  318. dateChange(date, dateString) {
  319. // console.log(date,dateString)
  320. this.form.getFieldDecorator('startTime')
  321. this.form.getFieldDecorator('endTime')
  322. this.form.setFieldsValue({
  323. startTime: date[0].format('YYYY-MM-DD HH:mm'),
  324. endTime: date[1].format('YYYY-MM-DD HH:mm'),
  325. })
  326. },
  327. //推广目的改变
  328. marketingGoalChange(e){
  329. console.log(e.target)
  330. this.marketingGoalHandle(e.target.value)
  331. },
  332. // 验证网址
  333. IsURL(res) {
  334. // var strRegex = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/|www\.)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/
  335. var strRegex = /^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+(.+[A-Za-z0-9-~\/])+$/
  336. var re = new RegExp(strRegex)
  337. // console.log(re.test(res))
  338. if (re.test(res)) {
  339. return true
  340. } else {
  341. return false
  342. }
  343. },
  344. validateURL(rule, value, callback) {
  345. // console.log(rule, value, callback);
  346. if (this.IsURL(value)) {
  347. callback()
  348. } else if (value && !this.IsURL(value)) {
  349. callback('链接地址无法访问,请正确输入')
  350. } else {
  351. callback('链接必须填写')
  352. }
  353. },
  354. validateName(rule, value, callback){
  355. // console.log(rule, value, callback);
  356. if (value) {
  357. callback()
  358. } else {
  359. callback('应用包名称必须填写')
  360. }
  361. },
  362. validateBid(rule, value, callback){
  363. // console.log(rule, value, callback);
  364. if (value) {
  365. callback()
  366. } else {
  367. callback('出价必须填写')
  368. }
  369. },
  370. goBack() {
  371. this.$router.replace('/modules/LaunchHousekeeper/LaunchHousekeeperList')
  372. this.$bus.$emit('remove', '/LaunchHousekeeper/newProject')
  373. },
  374. // 保存并新建创意
  375. goNext() {
  376. this.$nextTick(()=>{
  377. if (this.strategyName) {
  378. let LHKaccountInfo=sessionStorage.getItem('LHKaccountInfo');
  379. if(LHKaccountInfo){
  380. this.LHKaccountInfo=JSON.parse(LHKaccountInfo)
  381. }
  382. this.form.validateFields((err, values) => {
  383. if (!err) {
  384. console.log('Received values of form: ', values)
  385. // console.log(this.strategyNames)
  386. this.goNextloading=true;
  387. values.accountId = this.accountId
  388. values.strategyName=this.strategyName
  389. postAction('/adlab/Project/create', {
  390. ...values,
  391. }).then((res) => {
  392. console.log(res)
  393. if (res.success) {
  394. this.goNextloading=false;
  395. if(res.result){
  396. this.errorInfo=res.result;
  397. this.visible=true;
  398. let projectInfo=[]
  399. res.result.forEach(item=>{
  400. if(item.code==0){
  401. projectInfo.push(item)
  402. }
  403. })
  404. sessionStorage.setItem('projectInfo',JSON.stringify(projectInfo))
  405. }
  406. } else {
  407. this.goNextloading=false;
  408. this.$message.error('网络开小差了,等会再试试')
  409. }
  410. })
  411. }else{
  412. this.$message.error('请正确填写必填项目')
  413. }
  414. })
  415. }else{
  416. this.$message.error('请输入策略名称')
  417. }
  418. })
  419. },
  420. },
  421. marketingGoalHandle(val){
  422. let str='';
  423. switch (val) {
  424. case '1':
  425. str='应用安装'
  426. break;
  427. case '2':
  428. str='电商下单'
  429. break;
  430. case '3':
  431. str='推广品牌'
  432. break;
  433. case '4':
  434. str='营销线上'
  435. break;
  436. case '5':
  437. str='应用活跃'
  438. break;
  439. default:
  440. str='转化错误'
  441. break;
  442. }
  443. return str
  444. },
  445. mounted() {
  446. this.accountHttp()
  447. // this.$bus.$emit('remove', '/modules/BatchCreate/newGroup')
  448. let strategyNamepart=this.marketingGoalHandle(this.getFormData('marketingGoal'));
  449. this.strategyName ='[策略]'+ strategyNamepart + moment().format('MM_DD_hh:mm') ;
  450. },
  451. }
  452. </script>
  453. <style lang="scss">
  454. .newPlan{
  455. .ant-btn-danger {
  456. background-color: #ff4d4f !important;
  457. }
  458. }
  459. .ant-tooltip-inner,
  460. .ant-tooltip,
  461. .ant-tooltip-arrow::before {
  462. background-color: #fff;
  463. color: #333;
  464. }
  465. .ant-tooltip-inner {
  466. span {
  467. display: block;
  468. }
  469. }
  470. .ant-tooltip {
  471. max-width: 450px;
  472. }
  473. .newPlan {
  474. .ant-radio-button-wrapper {
  475. min-width: 80px;
  476. text-align: center;
  477. }
  478. .ant-form-item {
  479. -webkit-box-sizing: border-box;
  480. box-sizing: border-box;
  481. margin: 0;
  482. padding: 0;
  483. color: rgba(0, 0, 0, 0.65);
  484. font-size: 14px;
  485. font-variant: tabular-nums;
  486. line-height: 1.5;
  487. list-style: none;
  488. -webkit-font-feature-settings: 'tnum';
  489. font-feature-settings: 'tnum';
  490. vertical-align: top;
  491. }
  492. .directedBody {
  493. .ant-form-item {
  494. margin-bottom: 20px;
  495. }
  496. }
  497. }
  498. </style>
  499. <style lang="scss" scoped>
  500. .newPlan {
  501. font-family: PingFangSC-Regular, tahoma, arial, 'Hiragino Sans GB', 'Microsoft yahei', sans-serif;
  502. color: #333;
  503. ul,
  504. li {
  505. margin: 0;
  506. padding: 0;
  507. }
  508. .moduler {
  509. background: #fff;
  510. margin-bottom: 16px;
  511. position: relative;
  512. padding: 32px 24px 48px 32px;
  513. border-radius: 4px;
  514. box-shadow: 0px 1px 6px 0px rgba(0, 0, 0, 0.05);
  515. .moduler-title {
  516. display: flex;
  517. align-items: center;
  518. font-size: 22px;
  519. margin-bottom: 20px;
  520. }
  521. .row-item {
  522. display: flex;
  523. justify-content: flex-start;
  524. align-items: center;
  525. margin-bottom: 32px;
  526. }
  527. .row-item:last-of-type {
  528. margin-bottom: 0;
  529. }
  530. .row-item .hint-item {
  531. width: 24px;
  532. min-width: 24px;
  533. align-self: flex-start;
  534. line-height: 20px;
  535. height: 20px;
  536. margin-top: 9px;
  537. }
  538. .row-item .label-item {
  539. position: relative;
  540. align-items: flex-start;
  541. align-self: flex-start;
  542. line-height: 20px;
  543. height: 20px;
  544. margin-top: 10px;
  545. width: 80px;
  546. min-width: 80px;
  547. .text-item {
  548. font-size: 14px;
  549. width: 60px;
  550. }
  551. }
  552. .row-item .required-item {
  553. width: 4px;
  554. height: 4px;
  555. border-radius: 2px;
  556. background: #f45858;
  557. position: absolute;
  558. right: 10px;
  559. top: 50%;
  560. transform: translateY(-50%);
  561. }
  562. .row-item .input-item {
  563. min-width: 480px;
  564. position: relative;
  565. // height: 35px;
  566. .tip {
  567. font-size: 12px;
  568. color: tomato;
  569. }
  570. }
  571. }
  572. .opt {
  573. text-align: right;
  574. }
  575. }
  576. </style>