Step2.vue 33 KB

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