activityEdit.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. <template>
  2. <view>
  3. <view v-if="stepOne">
  4. <view class="form">
  5. <view class="form-title">基本信息</view>
  6. <view class="form-item-title">封面图</view>
  7. <view class="upload-pic ddflex" v-if="!pic" @click="uploadImage(1)">
  8. <image src="../static/images/pic.png"></image>
  9. <view style="margin-top: 30rpx;">上传封面图</view>
  10. </view>
  11. <image v-else class="upload-image" :src="pic" @click="uploadImage(1)"></image>
  12. <view class="form-limit">* 图片尺寸限制:680*350</view>
  13. <view class="form-item-title">活动详情轮播图</view>
  14. <view class="ddflex" style="margin-top: 30rpx;">
  15. <view class="upload-photo-image" v-for="item ,index in fileList" @click="uploadImage(2,index+1)">
  16. <image :src="item" mode="aspectFill"></image>
  17. <image class="upload-photo-close" src="/static/pages/images/close3.png"
  18. @click.stop="deleteImage(2,index+1)"></image>
  19. </view>
  20. <view class="upload-photo ddflex" @click="uploadImage(2)" v-if="fileList.length<9">
  21. <image src="../static/images/photo.png"></image>
  22. </view>
  23. </view>
  24. <view class="form-limit">* 图片尺寸限制:670*350</view>
  25. </view>
  26. <view class="form-border"></view>
  27. <view class="form">
  28. <view class="form-item-title">活动标题</view>
  29. <view class="form-input-box">
  30. <input v-model="title" placeholder-class="form-input-placeholder" placeholder="请输入活动标题" />
  31. </view>
  32. <view class="form-item-title">活动说明</view>
  33. <view class="form-input-box">
  34. <input v-model="brief" placeholder-class="form-input-placeholder" placeholder="请填写活动简介说明" />
  35. </view>
  36. <view class="form-item-title">
  37. 活动详情
  38. <view class="more ddflex" @click="jumpUrl('/match/editorContent/editorContent')">
  39. <text v-if="!text">编辑</text>
  40. <text v-else style="color: var(--main);">已完善</text>
  41. <image src="../../static/pages/images/more.png"></image>
  42. </view>
  43. </view>
  44. <view class="next-btn" @click="next">下一步</view>
  45. </view>
  46. </view>
  47. <!-- 第二步 -->
  48. <view v-if="stepTwo">
  49. <view class="form">
  50. <view class="form-title">报名设置</view>
  51. <view class="form-item-title">最大报名人数</view>
  52. <view class="form-number-select ddflex">
  53. <view>-</view>
  54. <input v-model="personLimit" type="number" placeholder="最大报名人数"
  55. placeholder-class="form-input-placeholder" />
  56. <view>+</view>
  57. </view>
  58. <view class="form-item-title">报名时间</view>
  59. <view class="ddflex" style="margin-top: 20rpx;">
  60. <picker v-model="enlistStartTime" mode="date" class="flex" @change="enlistStartTimeChange">
  61. <view class="form-date-select" :style="enlistStartTime?'color:#333':''">
  62. {{enlistStartTime?enlistStartTime:'开始日期'}}
  63. </view>
  64. </picker>
  65. <text style="margin: 0 20rpx;">至</text>
  66. <picker v-model="enlistEndTime" mode="date" class="flex" @change="enlistEndTimeChange">
  67. <view class="form-date-select" :style="enlistEndTime?'color:#333':''">
  68. {{enlistEndTime?enlistEndTime:'结束日期'}}
  69. </view>
  70. </picker>
  71. </view>
  72. <view class="form-item-title">活动时间</view>
  73. <view class="ddflex" style="margin-top: 20rpx;">
  74. <picker v-model="startTime" mode="date" class="flex" @change="startTimeChange">
  75. <view class="form-date-select" :style="startTime?'color:#333':''">
  76. {{startTime?startTime:"开始日期"}}
  77. </view>
  78. </picker>
  79. <text style="margin: 0 20rpx;">至</text>
  80. <picker v-model="endTime" mode="date" class="flex" @change="endTimeChange">
  81. <view class="form-date-select" :style="endTime?'color:#333':''">
  82. {{endTime?endTime:"结束日期"}}
  83. </view>
  84. </picker>
  85. </view>
  86. </view>
  87. <view class="form-border"></view>
  88. <view class="form">
  89. <view class="form-title">活动地址</view>
  90. <view class="form-item-title">地址名称</view>
  91. <view class="form-input-box">
  92. <input v-model="house" placeholder-class="form-input-placeholder" placeholder="请输入活动地址简称" />
  93. </view>
  94. <view class="form-item-title">选择城市</view>
  95. <view class="form-input-box">
  96. <!-- <picker class="form-input-placeholder" mode="region" @change="bindRegionChange" :value="region" > -->
  97. <view class="picker" :style="region.length>0?'color: #333;':'color:#cccccc'"
  98. @click="chooseLocation()">
  99. {{region.length > 0 ? region[0]+region[1]+region[2] : '请选择所在城市'}}
  100. </view>
  101. <!-- </picker> -->
  102. <!-- <image src="/card/static/images/area.png" class="loca" @click="chooseLocation()"></image> -->
  103. </view>
  104. <view class="form-item-title">
  105. 详细地址
  106. </view>
  107. <view class="form-input-box">
  108. <input v-model="address" placeholder-class="form-input-placeholder" placeholder="请输入详细地址" />
  109. </view>
  110. <view class="form-item-title ddflex" style="justify-content: space-between;">
  111. 是否全省通用
  112. <switch v-model="isAllSee" :checked="isAllSee" style="transform:scale(0.7)" color="var(--main)"
  113. @change="powerChange"></switch>
  114. </view>
  115. <block v-if="!isAllSee">
  116. <view class="form-input-box" style="border-bottom: none;" @click="showPop()">
  117. 已选择{{checkNum}}个区域
  118. <view class="more ddflex">
  119. <!-- <text v-if="!text">编辑</text>
  120. <text v-else style="color: var(--main);">已完善</text> -->
  121. <image src="../../static/pages/images/more.png"></image>
  122. </view>
  123. </view>
  124. <view class="form-item-title" style="color: red;font-size: 24rpx;margin-top: 0rpx;" v-if="checkNum==0">
  125. *请选择活动生效区域
  126. </view>
  127. <view class="mask" v-if="isShowPop" @click="hidePop"></view>
  128. <view class="popup" v-if="isShowPop">
  129. <view class="popupc ddflex">
  130. <view class="pleft">
  131. <view :class="'li ddflex' + (checkIndex == index ? ' active':'')" style="justify-content: space-between;"
  132. v-for="(item,index) in industryList" :key="index" @click="checkIndustry(index)">
  133. <view class="fflex tover">{{item.label}}</view>
  134. <image v-if="item.isActive" style="width: 25rpx;height: 25rpx;margin-left: 10rpx;" src="/match/static/images/checkBox_h.png" @click.stop="checkBoxIndustry(index)"></image>
  135. <image v-else style="width: 25rpx;height: 25rpx;margin-left: 10rpx;" src="/match/static/images/checkBox.png" @click.stop="checkBoxIndustry(index)"></image>
  136. </view>
  137. </view>
  138. <view class="pright">
  139. <view :class="'li ddflex' + (arrayIndex == index ? ' active':'')" style="justify-content: space-between;"
  140. v-for="(item,index) in rightArray" :key="index" @click="checkArray(index)">
  141. <view class="fflex tover">{{item.label}}</view>
  142. <image v-if="item.isActive" style="width: 25rpx;height: 25rpx;margin-left: 10rpx;" src="/match/static/images/checkBox_h.png" @click.stop="checkBoxArray(index)"></image>
  143. <image v-else style="width: 25rpx;height: 25rpx;margin-left: 10rpx;" src="/match/static/images/checkBox.png" @click.stop="checkBoxArray(index)"></image>
  144. </view>
  145. </view>
  146. </view>
  147. </view>
  148. </block>
  149. <view class="next-btn" @click="submit()">提交</view>
  150. </view>
  151. </view>
  152. </view>
  153. </template>
  154. <script>
  155. import util from "../../utils/util.js";
  156. const app = getApp();
  157. const req = require("../../utils/request.js");
  158. export default {
  159. components: {},
  160. props: {},
  161. data() {
  162. return {
  163. stepOne: true,
  164. stepTwo: false,
  165. pic: '', //封面图
  166. fileList: [], //banner
  167. title: '',
  168. brief: '',
  169. text: '',
  170. personLimit: -1,
  171. enlistStartTime: '',
  172. enlistEndTime: '',
  173. startTime: '',
  174. endTime: '',
  175. house: '',
  176. region: [],
  177. address: '',
  178. regionCode: [],
  179. id: '',
  180. longitude: null,
  181. latitude: null,
  182. isAllSee: true,
  183. isShowPop: false,
  184. checkIndex: 0,
  185. industryList: [],
  186. arrayIndex: -1,
  187. rightArray: [],
  188. companyTreeList:[],
  189. checkNum:0
  190. }
  191. },
  192. async onLoad(options) {
  193. this.id = options.id
  194. await this.getCompanyTreeList()
  195. if (this.id) {
  196. this.getActivityInfo()
  197. }
  198. },
  199. onShow() {
  200. },
  201. methods: {
  202. jumpUrl(url) {
  203. uni.navigateTo({
  204. url: url
  205. })
  206. },
  207. // 获取公司代码
  208. getCompanyTreeList(){
  209. return new Promise((r,j)=>{
  210. req.getRequest('/api/company/treeList',{},res=>{
  211. this.companyTreeList = res
  212. this.industryList = this.companyTreeList[0].children
  213. this.rightArray = this.industryList[0].children
  214. r()
  215. })
  216. })
  217. },
  218. checkIndustry(index){
  219. if(this.checkIndex == index) return false;
  220. this.checkIndex = index;
  221. this.rightArray = this.industryList[this.checkIndex].children;
  222. },
  223. checkBoxIndustry(index){
  224. if(this.industryList[index].isActive){
  225. this.industryList[index].isActive = false
  226. this.industryList[index].children.map(item=>{item.isActive = false})
  227. }else{
  228. this.industryList[index].isActive = true
  229. this.industryList[index].children.map(item=>{item.isActive = true})
  230. }
  231. this.industryList = JSON.parse(JSON.stringify(this.industryList))
  232. this.checkIndex = index;
  233. this.rightArray = this.industryList[this.checkIndex].children;
  234. },
  235. checkBoxArray(index){
  236. if(this.industryList[this.checkIndex].children[index].isActive){
  237. this.industryList[this.checkIndex].children[index].isActive = false
  238. }else{
  239. this.industryList[this.checkIndex].children[index].isActive = true
  240. }
  241. console.log(this.industryList[this.checkIndex].children.some(item=>item.isActive == false))
  242. if(this.industryList[this.checkIndex].children.some(item=>item.isActive == true)){
  243. this.industryList[this.checkIndex].isActive = true
  244. }else{
  245. this.industryList[this.checkIndex].isActive = false
  246. }
  247. this.industryList = JSON.parse(JSON.stringify(this.industryList))
  248. this.rightArray = this.industryList[this.checkIndex].children;
  249. },
  250. getCheckNum(){
  251. console.log(this.checkNum)
  252. this.checkNum = 0
  253. if(!this.isAllSee){
  254. this.industryList.map(item=>{
  255. item.children.map(it=>{
  256. if(it.isActive){
  257. this.checkNum++
  258. }
  259. })
  260. })
  261. }
  262. },
  263. getActivityInfo() {
  264. req.getRequest('/api/match/detail', {
  265. id: this.id
  266. }, res => {
  267. this.pic = res.pic
  268. this.fileList = res.imageList.map(item => {
  269. return item.url
  270. })
  271. this.title = res.title
  272. this.brief = res.brief
  273. this.text = res.text
  274. this.personLimit = res.personLimit
  275. this.enlistStartTime = this.formatTime(res.enlistStartTime)
  276. this.enlistEndTime = this.formatTime(res.enlistEndTime)
  277. this.startTime = this.formatTime(res.startTime)
  278. this.endTime = this.formatTime(res.endTime)
  279. this.house = res.house
  280. this.regionCode = [res.province, res.city, res.country]
  281. this.region = res.areaAdd.split(',')
  282. this.address = res.address
  283. this.longitude = res.lng ? res.lng : null
  284. this.latitude = res.lat ? res.lat : null
  285. if(res.areaCodeList.length>0){
  286. this.isAllSee = false
  287. let areaCodeList = res.areaCodeList.map(item=>item.areaCode)
  288. this.industryList.map(item=>{
  289. item.children.map(it=>{
  290. if(areaCodeList.indexOf(it.value)>-1){
  291. it.isActive = true
  292. }else{
  293. it.isActive = false
  294. }
  295. })
  296. if(item.children.some(it=>it.isActive == true)){
  297. item.isActive = true
  298. }else{
  299. item.isActive = false
  300. }
  301. })
  302. this.getCheckNum()
  303. }else{
  304. this.isAllSee = true
  305. }
  306. })
  307. },
  308. next() {
  309. if (!this.pic) {
  310. return req.msg('请上传封面图')
  311. }
  312. if (this.fileList.length == 0) {
  313. return req.msg('请上传活动轮播图')
  314. }
  315. if (!this.title) {
  316. return req.msg('请填写活动名称')
  317. }
  318. if (!this.brief) {
  319. return req.msg('请填写活动简介')
  320. }
  321. if (!this.text) {
  322. return req.msg('请填写活动详情')
  323. }
  324. this.stepOne = false
  325. this.stepTwo = true
  326. },
  327. uploadImage(type, index) {
  328. let that = this;
  329. let count = 1
  330. if (type == 1) {
  331. count = 1
  332. } else if (type == 2) {
  333. if (index) {
  334. count = 1
  335. } else {
  336. count = 9 - that.fileList.length
  337. }
  338. }
  339. uni.chooseImage({
  340. count: count,
  341. sizeType: ['original', 'compressed'],
  342. sourceType: ['album', 'camera'],
  343. success: function({
  344. tempFilePaths
  345. }) {
  346. var promise = Promise.all(
  347. tempFilePaths.map(tempFilePath => {
  348. return new Promise(function(resolve, reject) {
  349. req.uploadFile('/api/nocheck/upload', tempFilePath,
  350. res => {
  351. // type 1 封面图
  352. if (type == 1) {
  353. that.pic = res.src
  354. } else if (type == 2) {
  355. if (index) {
  356. that.fileList[index] = res.src
  357. that.fileList = JSON.parse(JSON
  358. .stringify(that.fileList))
  359. } else {
  360. that.fileList = that.fileList.concat(
  361. res.src)
  362. }
  363. }
  364. });
  365. });
  366. })
  367. );
  368. promise
  369. .then(function(results) {
  370. console.log(results);
  371. })
  372. .catch(function(err) {
  373. console.log(err);
  374. });
  375. }
  376. });
  377. },
  378. deleteImage(type, index) {
  379. if (type == 2)
  380. this.fileList.splice(index, 1)
  381. },
  382. enlistStartTimeChange(e) {
  383. if (this.enlistEndTime) {
  384. if (this.enlistEndTime < e.detail.value)
  385. return req.msg('报名开始时间不能大于结束时间')
  386. }
  387. this.enlistStartTime = e.detail.value
  388. },
  389. enlistEndTimeChange(e) {
  390. if (this.enlistStartTime) {
  391. if (this.enlistStartTime > e.detail.value)
  392. return req.msg('报名结束时间不能小于开始时间')
  393. }
  394. this.enlistEndTime = e.detail.value
  395. },
  396. startTimeChange(e) {
  397. if (this.endTime) {
  398. if (this.endTime < e.detail.value)
  399. return req.msg('活动开始时间不能大于结束时间')
  400. }
  401. this.startTime = e.detail.value
  402. },
  403. endTimeChange(e) {
  404. if (this.startTime) {
  405. if (this.startTime > e.detail.value)
  406. return req.msg('活动结束时间不能小于开始时间')
  407. }
  408. this.endTime = e.detail.value
  409. },
  410. chooseLocation() {
  411. var tha = this;
  412. uni.chooseLocation({
  413. success: function(res) {
  414. if (res.name) {
  415. tha.address = res.name;
  416. tha.reverseGeocoder(res);
  417. console.log('地址数据》》》:', res);
  418. }
  419. }
  420. });
  421. },
  422. reverseGeocoder(location) {
  423. // #ifdef H5
  424. location = location.latitude + ',' + location.longitude
  425. let url = 'https://apis.map.qq.com/ws/geocoder/v1/?address=';
  426. this.$jsonp(url, {
  427. key: req.public.mapLBSKEY,
  428. location: location,
  429. output: 'jsonp'
  430. }).then(data => {
  431. console.log('解析后的地址地址数据:', data);
  432. data = data.result
  433. this.region = [data.ad_info.province, data.ad_info.city, data.ad_info.district]
  434. this.regionCode = [data.ad_info.adcode.substring(0, 2) + '0000', data.ad_info.adcode.substring(
  435. 0, 4) + '00', data.ad_info.adcode]
  436. this.longitude = data.ad_info.location.lng
  437. this.latitude = data.ad_info.location.lat
  438. }).catch(err => {
  439. console.log(err);
  440. });
  441. // #endif
  442. // #ifndef H5
  443. QQMapWX.initMap();
  444. QQMapWX.reverseGeocoder(location, data => {
  445. console.log('解析后的地址地址数据:', data);
  446. this.region = [data.ad_info.province, data.ad_info.city, data.ad_info.district]
  447. this.regionCode = [data.ad_info.adcode.substring(0, 2) + '0000', data.ad_info.adcode.substring(
  448. 0, 4) + '00', data.ad_info.adcode]
  449. this.longitude = data.ad_info.location.lng
  450. this.latitude = data.ad_info.location.lat
  451. });
  452. //#endif
  453. },
  454. bindRegionChange(event) {
  455. console.log(event)
  456. this.region = event.detail.value
  457. this.regionCode = event.detail.code
  458. },
  459. powerChange(e) {
  460. this.isAllSee = e.detail.value
  461. },
  462. showPop(){
  463. this.isShowPop = true;
  464. },
  465. hidePop(){
  466. this.isShowPop = false;
  467. this.getCheckNum()
  468. },
  469. submit() {
  470. if (!this.pic) {
  471. return req.msg('请上传封面图')
  472. }
  473. if (this.fileList.length == 0) {
  474. return req.msg('请上传活动轮播图')
  475. }
  476. if (!this.title) {
  477. return req.msg('请填写活动名称')
  478. }
  479. if (!this.brief) {
  480. return req.msg('请填写活动简介')
  481. }
  482. if (!this.text) {
  483. return req.msg('请填写活动详情')
  484. }
  485. if (!this.enlistStartTime) {
  486. return req.msg('请选择报名开始时间')
  487. }
  488. if (!this.enlistEndTime) {
  489. return req.msg('请选择报名结束时间')
  490. }
  491. if (!this.startTime) {
  492. return req.msg('请选择活动开始时间')
  493. }
  494. if (!this.endTime) {
  495. return req.msg('请选择活动结束时间')
  496. }
  497. if (!this.house) {
  498. return req.msg('请填写活动地址')
  499. }
  500. if (this.regionCode.length == 0) {
  501. return req.msg('请选择活动所在城市')
  502. }
  503. if (!this.address) {
  504. return req.msg('请填写详细地址')
  505. }
  506. let areaCodeList = []
  507. if(!this.isAllSee){
  508. this.industryList.map(item=>{
  509. item.children.map(it=>{
  510. if(it.isActive){
  511. areaCodeList.push({
  512. areaCode:it.value
  513. })
  514. }
  515. })
  516. })
  517. if(areaCodeList.length==0){
  518. return req.msg('请选择活动生效区域')
  519. }
  520. }else{
  521. areaCodeList.push({
  522. areaCode:this.companyTreeList[0].value
  523. })
  524. }
  525. let dataP = {
  526. pic: this.pic,
  527. fileList: JSON.stringify(this.fileList.map(item => {
  528. return {
  529. url: item
  530. }
  531. })),
  532. title: this.title,
  533. brief: this.brief,
  534. text: this.text,
  535. personLimit: this.personLimit,
  536. enlistStartTime: this.enlistStartTime,
  537. enlistEndTime: this.enlistEndTime,
  538. startTime: this.startTime,
  539. endTime: this.endTime,
  540. house: this.house,
  541. province: this.regionCode[0],
  542. city: this.regionCode[1],
  543. country: this.regionCode[2],
  544. areaAdd: this.region.join(','),
  545. address: this.address,
  546. lng: this.longitude,
  547. lat: this.latitude,
  548. areaCodeList:areaCodeList
  549. }
  550. let prices = [{
  551. title: "VIP",
  552. marketMoney: 0,
  553. money: 0,
  554. vipMoney: 0,
  555. vipModels: [],
  556. personCount: 1,
  557. isDefault: 0
  558. }]
  559. dataP.prices = prices
  560. let url = '/api/match/save'
  561. if (this.id) {
  562. dataP.id = this.id
  563. url = '/api/match/update'
  564. uni.showModal({
  565. title: '提示',
  566. content: '修改活动将重新审核,确定修改?',
  567. success: (res) => {
  568. if (res.confirm) {
  569. req.postRequest(url, dataP, res => {
  570. req.msg('创建成功')
  571. let pages = getCurrentPages();
  572. var prevPage = pages[pages.length - 2];
  573. if (prevPage) {
  574. prevPage.$vm.isLoad = true
  575. prevPage.$vm.form.page = 1
  576. prevPage.$vm.getPageList()
  577. }
  578. setTimeout(() => {
  579. uni.navigateBack()
  580. }, 1000)
  581. })
  582. }
  583. }
  584. })
  585. } else {
  586. req.postRequest(url, dataP, res => {
  587. req.msg('创建成功')
  588. let pages = getCurrentPages();
  589. var prevPage = pages[pages.length - 2];
  590. if (prevPage) {
  591. prevPage.$vm.isLoad = true
  592. prevPage.$vm.form.page = 1
  593. prevPage.$vm.getPageList()
  594. }
  595. setTimeout(() => {
  596. uni.navigateBack()
  597. }, 1000)
  598. })
  599. }
  600. },
  601. formatTime(date) {
  602. date = new Date(date.replace(/-/g, '/'))
  603. return util.formatTime(date).t3
  604. },
  605. },
  606. mounted() {
  607. }
  608. }
  609. </script>
  610. <style>
  611. @import "./activityEdit.css";
  612. </style>