groupCreate.vue 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. <template>
  2. <a-card :body-style="{padding: '24px 32px'}" :bordered="false">
  3. <a-form @submit="handleSubmit" :form="form">
  4. <a-form-item
  5. label="选择快手账户"
  6. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  7. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  8. <a-select
  9. @change="deepConversion"
  10. v-model="accountId"
  11. showSearch
  12. showArrow
  13. allowClear
  14. placeholder="选择需创建的快手账户"
  15. optionFilterProp="children"
  16. style="width: 500px"
  17. :filterOption="filterOption"
  18. >
  19. <a-select-option v-for="userAccount in accountList" :key="userAccount.accountId"
  20. :value="userAccount.accountId">{{userAccount.authName}}
  21. </a-select-option>
  22. </a-select>
  23. </a-form-item>
  24. <a-form-item
  25. label="选择广告计划模板"
  26. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  27. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  28. <a-select
  29. v-model="campaignTemplateId"
  30. showSearch
  31. showArrow
  32. placeholder="请选择广告计划模板"
  33. optionFilterProp="children"
  34. style="width: 500px"
  35. :filterOption="filterOption"
  36. >
  37. <a-select-option v-for="campaign in campaignList" :key="campaign.id"
  38. :value="campaign.id">{{campaign.campaignName}}
  39. </a-select-option>
  40. </a-select>
  41. </a-form-item>
  42. <a-form-item
  43. label="请选择目标人群"
  44. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  45. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  46. <a-select
  47. v-model="targetPopulation"
  48. showSearch
  49. showArrow
  50. disabled
  51. placeholder="请选择目标人群"
  52. optionFilterProp="children"
  53. style="width: 500px"
  54. :filterOption="filterOption"
  55. >
  56. <a-select-option value="default">请期待</a-select-option>
  57. </a-select>
  58. </a-form-item>
  59. <a-form-item
  60. label="单日预算"
  61. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  62. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  63. <a-radio-group buttonStyle="solid" @change="showBudgetStatusChange" v-model="campaignBudget">
  64. <a-radio-button value="UNLIMITED">不限</a-radio-button>
  65. <a-radio-button value="AS_BUDGET">统一预算</a-radio-button>
  66. </a-radio-group>
  67. </a-form-item>
  68. <a-form-item
  69. label="预算金额"
  70. v-if="showBudgetDaily"
  71. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  72. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  73. <a-input
  74. v-model="dayBudget"
  75. v-decorator="[
  76. 'confirm_dayBudget',
  77. {rules: [{ required: true, message: ' ' },
  78. {validator: handleConfirmValue}]}
  79. ]"
  80. placeholder="不小于500,不超过100000000,仅支持输入自然数" type="number" style="width: 70%"></a-input>
  81. </a-form-item>
  82. <a-form-item
  83. label="投放方式"
  84. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  85. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  86. <a-radio-group v-model="speed">
  87. <a-radio-button value='1'>快速投放</a-radio-button>
  88. <a-radio-button value='2'>平滑投放</a-radio-button>
  89. </a-radio-group>
  90. </a-form-item>
  91. <a-form-item
  92. label="排期"
  93. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  94. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  95. <a-radio-group buttonStyle="solid" v-model="schedulingType" @change="showSetDate">
  96. <a-radio-button value='1'>从今天开始长期投放</a-radio-button>
  97. <a-radio-button value='2'>设置开始和结束日期</a-radio-button>
  98. </a-radio-group>
  99. </a-form-item>
  100. <a-form-item label="设置时间"
  101. v-if="showTime"
  102. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  103. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  104. <a-range-picker
  105. name="buildTime"
  106. style="width: 100%"
  107. v-model="time"/>
  108. </a-form-item>
  109. <a-form-item
  110. label="投放时段"
  111. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  112. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  113. <a-radio-group buttonStyle="solid" v-model="scheduleTimeType" @change="showSetScheduleTime">
  114. <a-radio-button value='1'>全天</a-radio-button>
  115. <a-radio-button value='2'>特定时间</a-radio-button>
  116. </a-radio-group>
  117. </a-form-item>
  118. <a-form-item
  119. label="设置时间段"
  120. v-if="showScheduleTime"
  121. v-model="scheduleTime"
  122. :labelCol="{lg: {span: 7}, sm: {span: 20}}"
  123. :wrapperCol="{lg: {span: 15}, sm: {span: 16} }">
  124. <div id="table_time_selected1" class="table_time_selected1">
  125. </div>
  126. </a-form-item>
  127. <a-form-item
  128. label="创意展现方式"
  129. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  130. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  131. <a-radio-group v-model="showMode">
  132. <a-radio-button value='2'>优先</a-radio-button>
  133. <a-radio-button value='1'>轮播</a-radio-button>
  134. </a-radio-group>
  135. </a-form-item>
  136. <a-form-item
  137. label="优化目标出价类型"
  138. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  139. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  140. <a-radio-group v-model="bidType" buttonStyle="solid" @change="showBidType">
  141. <a-radio-button value='2'>CPC</a-radio-button>
  142. <a-radio-button value='20'>ECPC</a-radio-button>
  143. <a-radio-button value='6'>OCPC</a-radio-button>
  144. </a-radio-group>
  145. </a-form-item>
  146. <a-form-item
  147. label="出价"
  148. v-if="showBid"
  149. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  150. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  151. <a-input
  152. v-model="bid"
  153. v-decorator="[
  154. 'confirm_bid',
  155. {rules: [{ required: true, message: ' ' },
  156. {validator: handleConfirmBid}]}
  157. ]"
  158. placeholder="不低于0.2元,不高于100元" style="width: 70%"></a-input>
  159. </a-form-item>
  160. <a-form-item
  161. label="优化目标"
  162. v-if="showOcpxActionType"
  163. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  164. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  165. <a-radio-group v-model="ocpxActionType" @change="showBidType">
  166. <a-radio-button value="2">行为数</a-radio-button>
  167. <a-radio-button value="180" :disabled="activationDisabled">激活</a-radio-button>
  168. <a-radio-button value="53" :disabled="isFormDisabled">表单转化</a-radio-button>
  169. </a-radio-group>
  170. </a-form-item>
  171. <a-form-item
  172. label="OCPC出价"
  173. v-if="showCpaBid"
  174. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  175. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  176. <a-input
  177. v-model="cpaBid"
  178. placeholder="请填写出价金额" style="width: 70%"></a-input>
  179. </a-form-item>
  180. <a-form-item
  181. label="深度转化目标"
  182. v-if="showDeepConversionType"
  183. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  184. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  185. <a-select
  186. v-model="deepConversionType"
  187. showSearch
  188. showArrow
  189. allowClear
  190. optionFilterProp="children"
  191. style="width: 500px"
  192. :filterOption="filterOption"
  193. >
  194. <a-select-option v-for="conversionType in deepConversionTypes"
  195. :key="conversionType.deep_conversion_type"
  196. :value="conversionType.deep_conversion_type">{{conversionType.desc}}
  197. </a-select-option>
  198. </a-select>
  199. </a-form-item>
  200. <a-form-item
  201. label="深度转化目标出价"
  202. v-if="showDeepConversionBid"
  203. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  204. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  205. <a-input
  206. v-model="deepConversionBid"
  207. placeholder="请填写深度转化出价金额" style="width: 70%"></a-input>
  208. </a-form-item>
  209. <a-form-item
  210. label="广告投放位置"
  211. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  212. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  213. <a-radio-group v-model="placementPosition" buttonStyle="solid" @change="changeShowPosition()">
  214. <a-radio-button value='1' :disabled="true">优选广告位</a-radio-button>
  215. <a-radio-button value='2'>按场景选择广告位</a-radio-button>
  216. </a-radio-group>
  217. </a-form-item>
  218. <a-form-item
  219. label="场景广告位"
  220. v-if="showPosition"
  221. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  222. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  223. <a-radio-group v-model="sceneId">
  224. <a-radio-button value='2'>信息流广告</a-radio-button>
  225. <a-radio-button value='3'>视频后贴片广告</a-radio-button>
  226. </a-radio-group>
  227. </a-form-item>
  228. <a-form-item
  229. label="创意制作方式"
  230. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  231. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  232. <a-radio-group v-model="unitType">
  233. <a-radio-button value='4'>自定义</a-radio-button>
  234. <a-radio-button value='2' :disabled="true">程序化创意</a-radio-button>
  235. </a-radio-group>
  236. </a-form-item>
  237. <a-form-item
  238. label="广告组名称"
  239. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  240. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  241. <a-input v-model="unitName" placeholder="请填写广告组名称" style="width: 70%"></a-input>
  242. </a-form-item>
  243. <a-form-item
  244. label="迭代次数"
  245. :labelCol="{lg: {span: 7}, sm: {span: 7}}"
  246. :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  247. <a-input
  248. v-model="createCount"
  249. placeholder="不小于0,不高于10,仅支持输入自然数" type="number" style="width: 70%"></a-input>
  250. </a-form-item>
  251. <a-form-item
  252. :wrapperCol="{ span: 20 }"
  253. style="text-align: center">
  254. <a-button htmlType="submit" type="primary">提交</a-button>
  255. <a-button style="margin-left: 8px">保存</a-button>
  256. </a-form-item>
  257. </a-form>
  258. </a-card>
  259. </template>
  260. <script>
  261. import {deleteAction, postAction, getAction} from '@/api/manage'
  262. import moment from "moment"
  263. import {mapGetters} from 'vuex'
  264. import jq from 'jquery'
  265. let dateQuantumRangeConst = '';
  266. export default {
  267. name: 'BaseForm',
  268. data() {
  269. return {
  270. accountId: '',// 账号id
  271. accountList: {},
  272. campaignTemplateId: '',// 广告计划模板id
  273. campaignList: {},
  274. targetPopulation: '',
  275. campaignBudget: 'UNLIMITED',
  276. dayBudget: 0,
  277. showBudgetDaily: false,
  278. speed: '1', // 1 快速投放 2平滑投放
  279. schedulingType: '1',// 1 从今天开始长期投放 2 设置开始和结束日期
  280. showTime: false,
  281. createCount: 0,
  282. time: [],
  283. scheduleTimeType: '1',
  284. showScheduleTime: false,
  285. scheduleTime: '',// 投放时间选择值
  286. showMode: '2', // 1 轮播 2 优选
  287. bidType: '2',
  288. showBid: true,
  289. bid: 0,// bid_type 为 CPC/eCPC 出价
  290. ocpxActionType: '2',// 2行为数 180 激活数
  291. showOcpxActionType: false,
  292. showCpaBid: false,
  293. cpaBid: 0,// bid_type 是 OCPC 时该字段必填
  294. unitName: "_" + moment().format('YYYY-MM-DD_HH:mm'),//广告组名称
  295. activationDisabled: true,
  296. isFormDisabled: true,
  297. placementPosition: '2',
  298. showPosition: true,
  299. sceneId: '2',
  300. deepConversionTypes: [],
  301. deepConversionType: '',
  302. showDeepConversionType: false,
  303. showDeepConversionBid: false,
  304. deepConversionBid: 0,
  305. unitType: '4',
  306. form: this.$form.createForm(this),
  307. url: {
  308. insertTemplateUrl: '/kuaishou/create/createGroups',
  309. userAllocationList: '/ctop/userAllocation/list',
  310. campaignList: '/kuaishou/kuaiShouCampaignTemplate/list',
  311. getDeepConversionUrl: '/kuaishou/kuaiShouConversionTypes/getIsActivate',
  312. }
  313. }
  314. },
  315. methods: {
  316. ...mapGetters(["nickname", "avatar", "userInfo"]),
  317. changeShowPosition() {
  318. if (this.placementPosition == 1) {
  319. this.showPosition = false;
  320. } else {
  321. this.showPosition = true;
  322. }
  323. },
  324. deepConversion() {
  325. if (this.accountId != '') {
  326. let params = {};
  327. params.accountId = this.accountId;
  328. getAction(this.url.getDeepConversionUrl, params).then((res) => {
  329. if (res.success) {
  330. if (res.result.isActivate == 1) {
  331. this.activationDisabled = false;
  332. this.deepConversionTypes = res.result.deepConversionTypes;
  333. } else {
  334. this.activationDisabled = true;
  335. }
  336. if (res.result.isFormSubmit == 1) {
  337. this.isFormDisabled = false;
  338. } else {
  339. this.isFormDisabled = true;
  340. }
  341. } else {
  342. this.activationDisabled = true;
  343. this.isFormDisabled = true;
  344. this.showDeepConversionType = false;
  345. this.showDeepConversionBid = false;
  346. }
  347. });
  348. }
  349. },
  350. showBidType() {
  351. if (this.bidType == '6') {
  352. this.showBid = false;
  353. this.showOcpxActionType = true;
  354. this.showCpaBid = true;
  355. if(this.ocpxActionType == '180' && this.deepConversionTypes.length > 0){
  356. this.showDeepConversionType = true;
  357. this.showDeepConversionBid = true;
  358. } else {
  359. this.showDeepConversionType = false;
  360. this.showDeepConversionBid = false;
  361. }
  362. } else {
  363. this.showBid = true;
  364. this.showOcpxActionType = false;
  365. this.showCpaBid = false;
  366. }
  367. this.unitName = "_" + moment().format('YYYY-MM-DD HH:mm');
  368. },
  369. showSetScheduleTime() {
  370. if (this.scheduleTimeType == 2) {
  371. this.showScheduleTime = true;
  372. jq(function () {
  373. load_time_table('table_time_selected1', dateQuantumRangeConst);
  374. });
  375. } else {
  376. this.showScheduleTime = false;
  377. }
  378. },
  379. showSetDate() {
  380. if (this.schedulingType == '2') {
  381. this.showTime = true;
  382. } else {
  383. this.showTime = false;
  384. }
  385. },
  386. handleConfirmValue(rule, value, callback) {
  387. if (this.dayBudget == '' || this.dayBudget <= 500 || this.dayBudget >= 100000000) {
  388. callback('请输入正确预算金额')
  389. }
  390. callback()
  391. },
  392. handleConfirmBid(rule, value, callback) {
  393. if (this.bid == 0 || this.bid <= 0.2 || this.bid >= 100) {
  394. callback('不得低于0.2元,不得高于100元')
  395. }
  396. callback()
  397. },
  398. handleConfirmCpaBid(rule, value, callback) {
  399. if (this.ocpxActionType == '2' && (this.cpaBid == 0 || this.cpaBid <= 1 || this.cpaBid >= 3000)) {
  400. callback('金额不得低于1元,不得高于3000元')
  401. }
  402. if (this.ocpxActionType == '180' && (this.cpaBid == 0 || this.cpaBid <= 5 || this.cpaBid >= 3000)) {
  403. callback('金额不得低于5元,不得高于3000元')
  404. }
  405. callback()
  406. },
  407. showBudgetStatusChange() {
  408. if (this.campaignBudget == 'AS_BUDGET') {
  409. this.showBudgetDaily = true;
  410. } else {
  411. this.showBudgetDaily = false;
  412. this.dayBudget = '0';
  413. }
  414. },
  415. handleSubmit(e) {
  416. e.preventDefault()
  417. this.form.validateFields((err, values) => {
  418. if (!err) {
  419. console.log('Received values of form: ', values);
  420. console.log('预算金额: ', this.dayBudget);
  421. console.log('投放方式: ', this.speed);
  422. if (this.schedulingType == '1') {
  423. console.log('开始投放时间: ', moment().format('YYYY-MM-DD'));
  424. }
  425. if (this.schedulingType == '2') {
  426. console.log('开始投放时间: ', moment(this.time[0]).format('YYYY-MM-DD'));
  427. console.log('结束投放时间: ', moment(this.time[1]).format('YYYY-MM-DD'));
  428. }
  429. if (this.scheduleTimeType == '2') {
  430. this.scheduleTime = jq("#table_time_selected1_time_num").val();
  431. console.log('投放时间段: ', this.scheduleTime);
  432. }
  433. console.log('出价方式:: ', this.bidType);
  434. if (this.bidType == '2' || this.bidType == '20') {
  435. console.log('出价金额,bid:: ', this.bid);
  436. }
  437. if (this.bidType == '6') {
  438. console.log('优化目标:', this.ocpxActionType);
  439. console.log('出价金额,cpaBid:', this.cpaBid);
  440. }
  441. console.log('资源位置: ', this.sceneId);
  442. console.log('创意制作防水: ', this.unitType);
  443. console.log('深度转化目标: ', this.deepConversionType);
  444. console.log('深度转化目标出价: ', this.deepConversionBid);
  445. console.log('广告组名称: ', this.unitName);
  446. let params = {};
  447. params.dayBudget = this.dayBudget * 1000;
  448. params.speed = this.speed;
  449. if (this.schedulingType == '1') {
  450. params.beginTime = moment().format('YYYY-MM-DD');
  451. }
  452. if (this.schedulingType == '2') {
  453. params.beginTime = moment(this.time[0]).format('YYYY-MM-DD');
  454. params.endTime = moment(this.time[1]).format('YYYY-MM-DD');
  455. }
  456. if (this.scheduleTimeType == '2') {
  457. this.scheduleTime = jq("#table_time_selected1_time_num").val();
  458. params.scheduleTime = this.scheduleTime;
  459. }
  460. params.bidType = this.bidType;
  461. if (this.bidType == '2' || this.bidType == '20') {
  462. params.bid = this.bid * 1000;
  463. }
  464. if (this.bidType == '6') {
  465. params.ocpxActionType = this.ocpxActionType;
  466. params.cpaBid = this.cpaBid * 1000;
  467. }
  468. params.showModel = this.showMode;
  469. params.unitName = this.unitName;
  470. params.loginId = this.userInfo().id;
  471. params.accountId = this.accountId;
  472. params.campaignTemplateId = this.campaignTemplateId;
  473. params.createCount = this.createCount;
  474. params.sceneId = this.sceneId;
  475. params.unitType = this.unitType;
  476. params.deepConversionType = this.deepConversionType;
  477. params.deepConversionBid = this.deepConversionBid * 1000;
  478. console.log(params)
  479. postAction(this.url.insertTemplateUrl, params).then((res) => {
  480. console.log(res)
  481. if (res.success) {
  482. alert("广告组模板创建成功");
  483. } else {
  484. alert(res.message);
  485. }
  486. });
  487. }
  488. })
  489. },
  490. onChange(value) {
  491. console.log(value);
  492. },
  493. handleChange(value) {
  494. console.log(`selected ${value}`);
  495. },
  496. handleBlur() {
  497. console.log('blur');
  498. },
  499. handleFocus() {
  500. console.log('focus');
  501. },
  502. filterOption(input, option) {
  503. return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  504. },
  505. },
  506. created: function () {
  507. let params = {};
  508. params.pageSize = '1000';
  509. params.mediaId = '2';
  510. params.userId = this.userInfo().id;
  511. getAction(this.url.userAllocationList, params).then((res) => {
  512. if (res.success) {
  513. this.accountList = res.result.records
  514. }
  515. });
  516. params = {};
  517. params.loginId = this.userInfo().id;
  518. params.pageSize = '1000';
  519. getAction(this.url.campaignList, params).then((res) => {
  520. if (res.success) {
  521. this.campaignList = res.result.records
  522. console.log("-----" + this.campaignList)
  523. }
  524. });
  525. }
  526. }
  527. var box_id;
  528. var StartTD = null;
  529. var StartIndex = null;
  530. var EndTD = null;
  531. var EndIndex = null;
  532. var Selected = 'Selected';
  533. var Start_x = null;
  534. var Start_y = null;
  535. //点击中表格的小时值
  536. var hour;
  537. //点击选中的星期值
  538. var week;
  539. //1为这个格子在此次鼠标拖拽过程中被选中(不执行选中方法),0为没选中过
  540. var td_state = 0;
  541. //生成星期数组
  542. var num = ['一', '二', '三', '四', '五', '六', '日'];
  543. //生成时间值数组
  544. var arr_hour = get_hour_arr();
  545. //按下鼠标左键拖动选中单元格
  546. function SelectTD(StartIndex, EndIndex, Selected) {
  547. var MinX = null;
  548. var MaxX = null;
  549. var MinY = null;
  550. var MaxY = null;
  551. var coordinate = get_coordinate(StartIndex, EndIndex);
  552. MinX = coordinate[0];
  553. MaxX = coordinate[1];
  554. MinY = coordinate[2];
  555. MaxY = coordinate[3];
  556. for (var i = MinY; i <= MaxY; i++) {
  557. for (var j = MinX; j <= MaxX; j++) {
  558. var SelectTR = jq('#' + box_id + ' table tbody tr ').eq(i);
  559. var td_class = jq("td", SelectTR).eq(j).attr('class');
  560. td_state = jq("td", SelectTR).eq(j).attr("td_state");
  561. //在同一次鼠标按下的过程中,选中过的表格不进行选中或取消操作
  562. if (!td_state) {
  563. if (td_class == Selected) {
  564. jq("td", SelectTR).eq(j).removeClass(Selected);
  565. } else {
  566. //筛选掉标明为星期的表格
  567. jq("td", SelectTR).eq(j).attr("class", Selected);
  568. }
  569. jq("td", SelectTR).eq(j).attr("td_state", '1');
  570. }
  571. }
  572. }
  573. //改变二进制值
  574. get_time_val();
  575. //改变日期显示
  576. convert_date();
  577. }
  578. //点击选中或去掉选中整行、整列
  579. function SelectTD_click(StartIndex, EndIndex, Selected) {
  580. var MinX = null;
  581. var MaxX = null;
  582. var MinY = null;
  583. var MaxY = null;
  584. var Selected_true = 0;
  585. var Selected_false = 0;
  586. var coordinate = get_coordinate(StartIndex, EndIndex);
  587. MinX = coordinate[0];
  588. MaxX = coordinate[1];
  589. MinY = coordinate[2];
  590. MaxY = coordinate[3];
  591. //列出此列当中的表格选中状态
  592. for (var i = MinY; i <= MaxY; i++) {
  593. for (var j = MinX; j <= MaxX; j++) {
  594. var SelectTR = jq('#' + box_id + ' table tbody tr ').eq(i);
  595. var td_class = jq("td", SelectTR).eq(j).attr('class');
  596. if (td_class == Selected) {
  597. //表格里存在已选中的元素
  598. Selected_true = 1;
  599. } else {
  600. //表格里存在未选中的元素
  601. Selected_false = 1;
  602. }
  603. }
  604. }
  605. //执行选中或去掉选中方法
  606. for (var i = MinY; i <= MaxY; i++) {
  607. for (var j = MinX; j <= MaxX; j++) {
  608. var SelectTR = jq('#' + box_id + ' table tbody tr ').eq(i);
  609. var td_class = jq("td", SelectTR).eq(j).attr('class');
  610. //一列当中存在已选中与未选中的表格处理:整列全部选中
  611. if (Selected_true == 1 && Selected_false == 1) {
  612. jq("td", SelectTR).eq(j).attr("class", Selected);
  613. } else if (Selected_false == 1) {
  614. //一列当中只存在未选中的表格处理:整列全部选中
  615. jq("td", SelectTR).eq(j).attr("class", Selected);
  616. } else {
  617. //一列当中只存在已选中的表格处理:整列全部去掉选中
  618. jq("td", SelectTR).eq(j).removeClass(Selected);
  619. }
  620. }
  621. }
  622. //改变二进制值
  623. get_time_val();
  624. //改变日期显示
  625. convert_date();
  626. }
  627. //获取选中范围的开始与结束的坐标
  628. function get_coordinate(StartIndex, EndIndex) {
  629. var MinX = null;
  630. var MaxX = null;
  631. var MinY = null;
  632. var MaxY = null;
  633. if (StartIndex.x < EndIndex.x) {
  634. MinX = StartIndex.x;
  635. MaxX = EndIndex.x;
  636. } else {
  637. MinX = EndIndex.x;
  638. MaxX = StartIndex.x;
  639. }
  640. if (StartIndex.y < EndIndex.y) {
  641. MinY = StartIndex.y;
  642. MaxY = EndIndex.y;
  643. } else {
  644. MinY = EndIndex.y;
  645. MaxY = StartIndex.y;
  646. }
  647. return [MinX, MaxX, MinY, MaxY];
  648. }
  649. //改变二进制值
  650. function get_time_val() {
  651. var time_type = '';
  652. jq('#' + box_id + ' table tbody').find('td').each(function (k) {
  653. var Selected_type = jq(this).attr('class');
  654. var week = jq(this).attr('week');
  655. if (Selected_type == Selected && !week) {
  656. time_type += "1";
  657. } else if (!week) {
  658. time_type += "0";
  659. }
  660. });
  661. jq('#' + box_id + '_time_num').val(time_type);
  662. // convert_date();
  663. }
  664. //二进制数转换日期
  665. function convert_date(external_binary) {
  666. //初始化周数数组
  667. var time_week_arr = [];
  668. if (!external_binary) {
  669. //内部调用,进行选中表格和输出时间操作。
  670. var binary = jq('#' + box_id + '_time_num').val();
  671. } else {
  672. //存在外部参入传入,此函数进行返回时间操作。
  673. var date_html = '';
  674. var binary = external_binary;
  675. }
  676. for (var y = 0; y < 7; y++) {
  677. //初始化小时数组
  678. var time_hour_arr = [];
  679. for (var x = 0; x < 24; x++) {
  680. //获取当前点击元素的位置
  681. if (y == 0) {
  682. var index = x;
  683. } else {
  684. var index = (y * 24) + x;
  685. }
  686. //获取td对应的二进制值
  687. var Selected_val = binary.charAt(index);
  688. if (Selected_val == 1) {
  689. //组装保存进数组里
  690. if (time_hour_arr == []) {
  691. //表格的第一个位置的值
  692. time_hour_arr = arr_hour[x];
  693. } else if (binary.charAt(index - 1) == 1 && binary.charAt(index - 2) == 1) {
  694. //此位置(包含上一行)的前两个都为选中时
  695. if (x == 0 && binary.charAt(index + 1) == 0) {
  696. //选中行里第一个,后一个表格没选中,加逗号
  697. time_hour_arr[time_hour_arr.length] = arr_hour[x] + ', ';
  698. } else if (x == 0 && binary.charAt(index + 1) == 1) {
  699. //选中行里第一个,后一个表格已选中,不加逗号
  700. time_hour_arr[time_hour_arr.length] = arr_hour[x];
  701. } else if (x == 1 && binary.charAt(index - 1) == 0) {
  702. //选中行里第二个,上一个表格没选中,加逗号
  703. time_hour_arr[time_hour_arr.length] = arr_hour[x] + ', ';
  704. } else if (x == 1 && binary.charAt(index - 1) == 1) {
  705. //选中行里第二个,上一个表格已选中,前加-号,后加逗号
  706. time_hour_arr[time_hour_arr.length] = '-' + arr_hour[x] + ', ';
  707. } else {
  708. //选中行里除第一、二的表格以外,前一个表格已经选中,此元素前加- 后加逗号
  709. time_hour_arr[time_hour_arr.length - 1] = '-' + arr_hour[x] + ', ';
  710. }
  711. } else if (binary.charAt(index - 1) == 1 && x > 0) {
  712. //选中的前一个已选中,且此次选中的不是行里第一个,此次选中的元素前加-后加逗号
  713. time_hour_arr[time_hour_arr.length] = '-' + arr_hour[x] + ', ';
  714. } else if (binary.charAt(index + 1) != 1 || x == 23) {
  715. //选中的后一个没选中,或者此次选中的是行里最后一个,此次选中的元素加逗号
  716. time_hour_arr[time_hour_arr.length] = arr_hour[x] + ', ';
  717. } else {
  718. //选中的后一已选中,此次选中的元素不加逗号
  719. time_hour_arr[time_hour_arr.length] = arr_hour[x];
  720. }
  721. }
  722. }
  723. time_week_arr[y] = time_hour_arr;
  724. }
  725. // console.info(box_id);
  726. if (!external_binary) {
  727. jq('#' + box_id + '_time_seled').html('');
  728. }
  729. //再次组装并输出数组
  730. var time_html = [];
  731. for (var y = 0; y < 7; y++) {
  732. for (var x = 0; x < time_week_arr[y].length; x++) {
  733. if (!time_html[y]) {
  734. time_html[y] = time_week_arr[y][x];
  735. } else {
  736. time_html[y] += time_week_arr[y][x];
  737. }
  738. }
  739. if (time_html[y]) {
  740. time_html[y] = time_html[y].substring(0, time_html[y].length - 2);
  741. if (!external_binary) {
  742. jq('#' + box_id + '_time_seled').append('<div>星期' + num [y] + ' (' + time_html[y] + ')' + '</div>');
  743. } else {
  744. date_html += '星期' + num [y] + ' (' + time_html[y] + ')' + ', ';
  745. }
  746. }
  747. }
  748. if (external_binary) {
  749. return date_html;
  750. }
  751. // console.info(time_html);
  752. }
  753. //生成时间值数组
  754. function get_hour_arr() {
  755. var arr_hour = [];
  756. var oDate = new Date("2016/07/01 00:00:00"); //实例一个时间对象;
  757. var oDate_hour = oDate.getHours();
  758. var oDate_minute = oDate.getMinutes();
  759. for (var i = 0; i < 24; i++) {
  760. if (oDate_minute < 10) {
  761. var oDate_minute = "0" + oDate_minute;
  762. }
  763. if (i >= 1) {
  764. oDate.setMinutes(oDate.getMinutes() + 60);
  765. oDate_hour = oDate.getHours();
  766. oDate_minute = oDate.getMinutes();
  767. if (oDate_minute < 10) {
  768. var oDate_minute = "0" + oDate_minute;
  769. }
  770. }
  771. arr_hour[i] = oDate_hour + ':' + oDate_minute;
  772. }
  773. return arr_hour;
  774. }
  775. //更新操作
  776. function renewal(id) {
  777. if (id) {
  778. box_id = id;
  779. }
  780. //解绑鼠标移动监听事件
  781. jq('#' + box_id + ' table tbody tr td').unbind("mouseover");
  782. //初始化表格的在此次选中状态
  783. jq('#' + box_id + ' table tbody tr td').attr("td_state", '');
  784. //改变二进制值
  785. get_time_val();
  786. //改变日期显示
  787. convert_date();
  788. }
  789. //二进制数赋值选中表格
  790. function binary_selected() {
  791. var default_time_val = jq('#' + box_id + ' .default_time_val').val();
  792. if (default_time_val) {
  793. for (var i = 0; i < 168; i++) {
  794. var td_selected = default_time_val.charAt(i);
  795. if (td_selected != 0) {
  796. jq('#' + box_id + ' table tbody tr td').eq(i).attr('class', 'Selected');
  797. //更新操作,显示文字形日期
  798. renewal();
  799. }
  800. }
  801. }
  802. }
  803. //实例化程序
  804. function load_time_table(id, value) {
  805. //包住table的元素id
  806. box_id = id;
  807. var html;
  808. html = '<input type="hidden" class="default_time_val" value="' + value + '"/>';
  809. html += '<table cellspacing="0" cellpadding="0" border="0" class="plug-timer-grid" onselectstart="return false" onselect="document.selection.empty()">';
  810. html += '<thead>';
  811. html += '<tr>';
  812. html += '<th></th>';
  813. html += '<th colSpan="12">上午</th>';
  814. html += '<th colSpan="12">下午</th>';
  815. html += '</tr>';
  816. html += '<tr class="hour">';
  817. html += '<th></th>';
  818. html += '</tr>';
  819. html += '</thead>';
  820. html += '<tbody></tbody>';
  821. html += '</table>';
  822. html += '<input class="focus" type="hidden" style="opacity: 0;">';
  823. html += '<div id="' + box_id + '_time_seled" style="line-height: 15px;font-size:10px;"></div>';
  824. html += '<input type="hidden" id="' + box_id + '_time_num" name="time" caption="每日投放时段" switchname="selectTime" value="' + value + '">';
  825. jq('#' + box_id).html('');
  826. jq('#' + box_id).append(html);
  827. var html_tbody_td = '';
  828. var html_thead_td = '';
  829. //创建表格
  830. for (var i = 0; i < 7; i++) {
  831. var week = i + 1;
  832. html_tbody_td += '<tr>';
  833. for (var j = 0; j < 25; j++) {
  834. if (j == 0) {
  835. html_tbody_td += '<th week="' + week + '">星期' + num[i] + '</th>';
  836. } else {
  837. html_tbody_td += '<td>' + '</td>';
  838. }
  839. }
  840. html_tbody_td += '</tr>';
  841. }
  842. //创建表格小时栏目
  843. for (var i = 0; i <= 23; i++) {
  844. html_thead_td += '<td hour="' + i + '">' + i + '</td>';
  845. }
  846. jq('#' + box_id + ' table thead .hour').append(html_thead_td);
  847. jq('#' + box_id + ' table tbody').html(html_tbody_td);
  848. //检查是否有赋有二进制值,如有,将选中相应的表格
  849. binary_selected();
  850. //控制器,控制当前在哪个表格进行操作
  851. jq('.plug-timer-grid').hover(function (e) {
  852. if (1 != e.which) { //判断是否为左击
  853. var id = jq(this).parent().attr('id');
  854. box_id = id;
  855. }
  856. });
  857. //清除所有选中项
  858. jq('.clear').click(function () {
  859. jq(this).parent().find('td').removeClass(Selected);
  860. var id = jq(this).parent().attr('id');
  861. renewal(id);
  862. });
  863. //点击小时选中或去掉整列处理块
  864. jq('#' + box_id + ' table thead tr td').click(function () {
  865. hour = jq(this).attr('hour');
  866. if (hour >= 0) {
  867. var rows = jq('#' + box_id + ' table tbody tr').length;
  868. Start_x = (jq(this).index()) * 2 - 1;
  869. Start_y = 0;
  870. StartIndex = {x: Start_x, y: Start_y};
  871. EndTD = jq(this);
  872. var x = (jq(this).index()) * 2 - 2;
  873. var y = rows - 1; //为了配合for计算公式-1
  874. EndIndex = {x: x, y: y};
  875. //改变第一次按下鼠标时候的改变选中状态
  876. SelectTD_click(StartIndex, EndIndex, Selected);
  877. }
  878. });
  879. //点击星期选中或去掉整行处理块
  880. jq('#' + box_id + ' table tbody tr th').click(function () {
  881. var week = jq(this).attr('week');
  882. if (week >= 0) {
  883. var line = jq('#' + box_id + ' table tbody tr td').length / jq('#' + box_id + ' table tbody tr').length;
  884. Start_x = 0;
  885. Start_y = jq(this).parent().index();
  886. StartIndex = {x: Start_x, y: Start_y};
  887. EndTD = jq(this);
  888. var y = jq(this).parent().index();
  889. var x = line - 1; //为了配合for计算公式-1
  890. EndIndex = {x: x, y: y};
  891. //改变第一次按下鼠标时候的改变选中状态
  892. SelectTD_click(StartIndex, EndIndex, Selected);
  893. }
  894. });
  895. //监听鼠标按下事件(鼠标按下左键拖动选中处理块)
  896. jq('#' + box_id + ' table tbody tr td').unbind("mousedown").bind("mousedown", function () {
  897. //记录刚开始点击的元素位置
  898. Start_x = jq(this).index() - 1;
  899. Start_y = jq(this).parent().index();
  900. StartIndex = {x: Start_x, y: Start_y};
  901. EndTD = jq(this);
  902. var x = jq(this).index() - 1;
  903. var y = jq(this).parent().index();
  904. EndIndex = {x: x, y: y};
  905. //改变第一次按下鼠标时候的改变选中状态
  906. SelectTD(StartIndex, EndIndex, Selected);
  907. StartTD = jq(this);
  908. StartIndex = {x: Start_x, y: Start_y};
  909. //监听鼠标移动事件,实现改变后续鼠标拖拽时候的表格选中状态
  910. jq('#' + box_id + ' table tbody tr td').mouseover(function (e) {
  911. EndTD = jq(this);
  912. var x = jq(this).index() - 1;
  913. var y = jq(this).parent().index();
  914. EndIndex = {x: x, y: y};
  915. if (1 != e.which) { //判断是否为左击
  916. jq('#' + box_id + ' table tbody tr td').unbind("mouseover");
  917. }
  918. //去除停留在td上的光标
  919. jq('#' + box_id + ' .focus').focus();
  920. SelectTD(StartIndex, EndIndex, Selected);
  921. });
  922. //放开鼠标左键时,初始化相关参数和解绑相关监听
  923. jq('html').unbind("mouseup").bind("mouseup", function () {
  924. renewal();
  925. });
  926. });
  927. }
  928. /*外部调用接口*/
  929. //解绑鼠标松开监听事件
  930. function unbundle_mouseover() {
  931. jq('html').unbind("mouseup");
  932. }
  933. /*二进制获取转换后的时间*/
  934. function get_time_html(binary) {
  935. return convert_date(binary);
  936. }
  937. jq(function () {
  938. load_time_table('table_time_selected1', this.dateQuantumRange);
  939. });
  940. </script>
  941. <style type="text/css">
  942. .plug-timer-grid {
  943. width: 100%;
  944. }
  945. .plug-timer-grid td, .plug-timer-grid th {
  946. border: 1px solid #97B4D1;
  947. text-align: center; /*cursor:pointer;*/
  948. font-size: 10px;
  949. line-height: 10px;
  950. }
  951. .Selected {
  952. background-color: rgb(102, 162, 243);
  953. opacity: 0.5;
  954. }
  955. .plug-timer-grid {
  956. border-collapse: collapse;
  957. z-index: 4;
  958. }
  959. .plug-timer-grid thead tr {
  960. display: table-row;
  961. vertical-align: inherit;
  962. border-color: inherit;
  963. }
  964. table td {
  965. height: 20px;
  966. max-width: 5px;
  967. border: 1px solid #dfe6ec;
  968. font-size: 12px;
  969. text-align: center;
  970. vertical-align: middle;
  971. overflow: hidden;
  972. transition: background .5s;
  973. -webkit-transition: background .5s;
  974. }
  975. .plug-timer-grid tbody th {
  976. width: 4%;
  977. }
  978. .plug-timer-grid tbody tr td {
  979. width: 2%;
  980. }
  981. /*.clear{*/
  982. /* margin:20px 0px 20px 0px;*/
  983. /*}*/
  984. </style>