actEdit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <template>
  2. <view class="body">
  3. <view class="content uni-column">
  4. <view class="uni-column uni-jcc top">
  5. <my-topbar :title="title" :showBack="true" @btnBackClick="btnBack"></my-topbar>
  6. <view class="top-content uni-row">
  7. </view>
  8. </view>
  9. <view class="main uni-column">
  10. <uni-forms ref="form" class="form" :modelValue="formData" :rules="checkRules">
  11. <uni-forms-item label="赛事名称" name="compName">
  12. <uni-easyinput maxlength="25" placeholder="请输入赛事名称" v-model="formData.compName" :disabled="pubState > 1 ? true : false" />
  13. </uni-forms-item>
  14. <uni-forms-item label="赛事起始时间" name="compBeginTime">
  15. <uni-datetime-picker v-model="formData.compBeginTime" type="datetime" placeholder="选择赛事起始时间" />
  16. </uni-forms-item>
  17. <uni-forms-item label="赛事截止时间" name="compEndTime">
  18. <uni-datetime-picker v-model="formData.compEndTime" type="datetime" placeholder="选择赛事截止时间" />
  19. </uni-forms-item>
  20. <uni-forms-item label="赛事简介" name="description">
  21. <uni-easyinput type="textarea" autoHeight maxlength="500" v-model="formData.description"
  22. placeholder="请输入赛事简介" :disabled="pubState > 1 ? true : false" />
  23. </uni-forms-item>
  24. <uni-forms-item label="活动规则" name="rules">
  25. <uni-easyinput type="textarea" autoHeight maxlength="500" v-model="formData.rules"
  26. placeholder="请输入活动规则" :disabled="pubState > 1 ? true : false" />
  27. </uni-forms-item>
  28. <uni-forms-item label="赛事LOGO" name="matchLogo">
  29. <uni-file-picker v-model="matchLogoObj" :auto-upload="false" limit="1" :title="pubState > 1 ? '' : '请选择赛事使用的LOGO图片'"
  30. :sizeType="['original', 'compressed']" file-mediatype="image"
  31. file-extname="jpg,jpeg,png,gif,bmp,heic" @select="onLogoUploadSelect"
  32. @delete="onLogoUploadDelete" :readonly="pubState > 1 ? true : false"></uni-file-picker>
  33. </uni-forms-item>
  34. <uni-forms-item label="赛事场地" name="mapId">
  35. <e-select v-model="formData.mapId" :options="mapRs" :props="mapSelectionProps" clearable
  36. maxHeight="40vh" :placeholder="'请选择赛事场地(可输入关键字)'" @getText="getMapSelectText"
  37. @change="mapSelectChange" :disabled="pubState > 1 ? true : false"></e-select>
  38. </uni-forms-item>
  39. <uni-forms-item label="赛事方案" name="planId">
  40. <e-select v-model="formData.planId" :options="planRs" :props="planSelectionProps" clearable
  41. maxHeight="40vh" :placeholder="'请选择赛事方案'" @getText="getPlanSelectText"
  42. @change="planSelectChange" :disabled="pubState > 1 ? true : false"></e-select>
  43. </uni-forms-item>
  44. <uni-forms-item label="联系人姓名" name="contactName">
  45. <uni-easyinput maxlength="20" placeholder="请输入联系人姓名" v-model="formData.contactName" />
  46. </uni-forms-item>
  47. <uni-forms-item label="联系人电话" name="phone">
  48. <uni-easyinput maxlength="11" placeholder="请输入联系人电话" v-model="formData.phone" />
  49. </uni-forms-item>
  50. </uni-forms>
  51. <view class="uni-row uni-jcse" style="width: 90%;">
  52. <button class="button" @click="btnBack">返回</button>
  53. <button class="button button-save" @click="saveClick">保存</button>
  54. <!-- <button class="button button-submit" @click="submitClick">发布</button> -->
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import {
  62. mapState,
  63. mapGetters
  64. } from 'vuex';
  65. import tools from '/utils/tools.js';
  66. // import { tplStyleList, userLevel, pubState } from '/utils/define.js';
  67. import {
  68. apiCompInfoDetail,
  69. apiCompInfoEdit,
  70. apiUploadFiles,
  71. apiSelectSsctQuery,
  72. apiSelectMapQuery,
  73. apiSelectPlanQuery,
  74. checkResCode
  75. } from '/utils/api.js';
  76. export default {
  77. data() {
  78. return {
  79. queryObj: {},
  80. queryString: "",
  81. from: "",
  82. compId: 0, // 赛事ID
  83. pubState: 0, //发布状态 0:审核中 1:内测 2:已发布
  84. title: "赛事修改",
  85. mapSelectionProps: {
  86. text: 'Label',
  87. value: 'Value',
  88. },
  89. planSelectionProps: {
  90. text: 'Label',
  91. value: 'Value',
  92. },
  93. mapRs: [], // 地图(场地)信息集合
  94. planRs: [], // 方案信息集合
  95. matchLogoObj: {},
  96. formData: {
  97. matchLogo: "", // 赛事LOGO
  98. matchBanner: "", // 赛事BANNER
  99. compName: "", // 赛事名称
  100. description: "", // 赛事简介
  101. rules: "", // 活动规则
  102. contactName: "", // 联系人姓名
  103. phone: "", // 联系人电话
  104. regBeginTime: "", // 报名开始时间 (格式 2025-01-02 15:42:35)
  105. regBeginSecond: "", // 报名开始时间戳,单位 秒
  106. regEndTime: "", // 报名结束时间
  107. regEndSecond: "", // 报名结束时间戳,单位 秒
  108. compBeginTime: "", // 赛事开始时间
  109. compBeginSecond: "", // 赛事开始时间戳,单位 秒
  110. compEndTime: "", // 赛事结束时间
  111. compEndSecond: "", // 赛事结束时间戳,单位 秒
  112. mapId: null, // 场地ID
  113. planId: null // 方案ID
  114. },
  115. checkRules: {
  116. compName: {
  117. rules: [{
  118. required: true,
  119. errorMessage: '请输入赛事名称',
  120. },
  121. {
  122. minLength: 5,
  123. maxLength: 25,
  124. errorMessage: '赛事名称长度在 {minLength} 到 {maxLength} 个字符',
  125. }
  126. ]
  127. },
  128. compBeginTime: {
  129. rules: [{
  130. required: true,
  131. errorMessage: '请选择赛事起始时间',
  132. }]
  133. },
  134. compEndTime: {
  135. rules: [{
  136. required: true,
  137. errorMessage: '请选择赛事截止时间',
  138. },
  139. {
  140. validateFunction: function(rule, value, data, callback) {
  141. if (value <= data.compBeginSecond) {
  142. callback('截止时间必须大于起始时间');
  143. return false;
  144. } else {
  145. return true;
  146. }
  147. }
  148. }
  149. ]
  150. },
  151. description: {
  152. rules: [{
  153. required: true,
  154. errorMessage: '请输入赛事简介',
  155. },
  156. {
  157. minLength: 20,
  158. maxLength: 500,
  159. errorMessage: '赛事简介长度在 {minLength} 到 {maxLength} 个字符',
  160. }
  161. ]
  162. },
  163. rules: {
  164. rules: [{
  165. required: true,
  166. errorMessage: '请输入活动规则',
  167. },
  168. {
  169. minLength: 20,
  170. maxLength: 500,
  171. errorMessage: '活动规则长度在 {minLength} 到 {maxLength} 个字符',
  172. }
  173. ]
  174. },
  175. // matchLogo: {
  176. // rules: [{
  177. // required: true,
  178. // errorMessage: '请选择赛事LOGO',
  179. // }]
  180. // },
  181. mapId: {
  182. rules: [{
  183. required: true,
  184. errorMessage: '请选择赛事场地',
  185. },
  186. {
  187. minimum: 1,
  188. errorMessage: '请选择赛事场地',
  189. }
  190. ]
  191. },
  192. planId: {
  193. rules: [{
  194. required: true,
  195. errorMessage: '请选择赛事方案',
  196. },
  197. {
  198. minimum: 1,
  199. errorMessage: '请选择赛事方案',
  200. }
  201. ]
  202. },
  203. contactName: {
  204. rules: [{
  205. required: true,
  206. errorMessage: '请输入联系人姓名',
  207. },
  208. {
  209. minLength: 2,
  210. maxLength: 20,
  211. errorMessage: '联系人姓名长度在 {minLength} 到 {maxLength} 个字符',
  212. }
  213. ]
  214. },
  215. phone: {
  216. rules: [{
  217. required: true,
  218. errorMessage: '请输入联系人电话',
  219. },
  220. {
  221. pattern: "^((1[3456789][0-9]{1})+\\d{8})$",
  222. errorMessage: '请输入合法的手机号',
  223. }
  224. ]
  225. }
  226. }
  227. }
  228. },
  229. computed: {
  230. ...mapState([
  231. 'username', // 映射 this.username 为 store.state.username
  232. 'token'
  233. ]),
  234. ...mapGetters([
  235. 'metadata'
  236. ]),
  237. },
  238. onLoad(query) {
  239. // console.log(query);
  240. this.queryObj = query;
  241. this.queryString = tools.objectToQueryString(this.queryObj);
  242. // console.log(queryString);
  243. this.from = query["from"] ?? "";
  244. this.compId = query["compId"] ?? 0;
  245. this.compInfoDetail();
  246. this.selectMapQuery();
  247. },
  248. mounted() {},
  249. methods: {
  250. // 自助赛事详情查询
  251. compInfoDetail() {
  252. uni.request({
  253. url: apiCompInfoDetail,
  254. header: this.metadata,
  255. method: "POST",
  256. data: {
  257. compId: this.compId
  258. },
  259. success: (res) => {
  260. console.log("[compInfoDetail] res", res);
  261. if (checkResCode(res)) {
  262. this.pubState = res.data.data.otherInfo.pubState;
  263. const config = res.data.data.config;
  264. // console.log("[compInfoDetail] config", config);
  265. this.formData.matchLogo = config.tplInfo.matchLogo;
  266. this.formData.matchBanner = config.tplInfo.matchBanner;
  267. this.formData.compName = config.matchInfo.compName;
  268. this.formData.description = config.matchInfo.description;
  269. this.formData.rules = config.matchInfo.rules;
  270. this.formData.contactName = config.matchInfo.contactName;
  271. this.formData.phone = config.matchInfo.phone;
  272. this.formData.regBeginTime = tools.timestampToTime(config.matchInfo.regBeginSecond * 1000);
  273. this.formData.regBeginSecond = config.matchInfo.regBeginSecond;
  274. this.formData.regEndTime = tools.timestampToTime(config.matchInfo.regEndSecond * 1000);
  275. this.formData.regEndSecond = config.matchInfo.regEndSecond;
  276. this.formData.compBeginTime = tools.timestampToTime(config.matchInfo.compBeginSecond * 1000);
  277. this.formData.compBeginSecond = config.matchInfo.compBeginSecond;
  278. this.formData.compEndTime = tools.timestampToTime(config.matchInfo.regEndSecond * 1000);
  279. this.formData.compEndSecond = config.matchInfo.compEndSecond;
  280. this.formData.mapId = config.mapInfo[0].mapId;
  281. this.formData.planId = config.mapInfo[0].planId;
  282. this.matchLogoObj = {
  283. // "name": "",
  284. // "extname": "",
  285. "url": config.tplInfo.matchLogo
  286. };
  287. this.selectPlanQuery(this.formData.mapId);
  288. }
  289. },
  290. fail: (err) => {
  291. console.log("[compInfoDetail] err", err);
  292. },
  293. });
  294. },
  295. // 自助修改赛事信息
  296. compInfoEdit() {
  297. this.formData.regBeginTime = this.formData.compBeginTime;
  298. this.formData.regEndTime = this.formData.compEndTime;
  299. this.formData.regBeginSecond = Date.parse(this.formData.regBeginTime) / 1000;
  300. this.formData.regEndSecond = Date.parse(this.formData.regEndTime) / 1000;
  301. this.formData.compBeginSecond = Date.parse(this.formData.compBeginTime) / 1000;
  302. this.formData.compEndSecond = Date.parse(this.formData.compEndTime) / 1000;
  303. console.log("[compInfoEdit] formData:", this.formData);
  304. console.log("[compInfoEdit] formData:", JSON.stringify(this.formData));
  305. uni.request({
  306. url: apiCompInfoEdit,
  307. header: this.metadata,
  308. method: "POST",
  309. data: {
  310. compId: this.compId,
  311. inJson: JSON.stringify(this.formData)
  312. },
  313. success: (res) => {
  314. console.log("compInfoEdit", res);
  315. if (checkResCode(res)) {
  316. // const data = res.data.data;
  317. uni.showToast({
  318. title: `保存成功`,
  319. icon: 'none',
  320. duration: 3000
  321. });
  322. setTimeout(() => {
  323. this.btnBack();
  324. // this.$router.go(0); // 刷新当前页面
  325. }, 200);
  326. }
  327. },
  328. fail: (err) => {
  329. console.log("compInfoEdit err", err);
  330. },
  331. });
  332. },
  333. // 自助选择公共模板
  334. selectSsctQuery() {
  335. uni.request({
  336. url: apiSelectSsctQuery,
  337. header: this.metadata,
  338. method: "POST",
  339. data: {},
  340. success: (res) => {
  341. console.log("selectSsctQuery", res);
  342. if (checkResCode(res)) {
  343. // const data = res.data.data;
  344. }
  345. },
  346. fail: (err) => {
  347. console.log("selectSsctQuery err", err);
  348. },
  349. });
  350. },
  351. // 自助选择地图
  352. selectMapQuery() {
  353. uni.request({
  354. url: apiSelectMapQuery,
  355. header: this.metadata,
  356. method: "POST",
  357. data: {},
  358. success: (res) => {
  359. console.log("selectMapQuery", res);
  360. if (checkResCode(res)) {
  361. const data = res.data.data;
  362. this.mapRs = data;
  363. }
  364. },
  365. fail: (err) => {
  366. console.log("selectMapQuery err", err);
  367. },
  368. });
  369. },
  370. // 自助根据地图选择方案
  371. selectPlanQuery(mapId) {
  372. uni.request({
  373. url: apiSelectPlanQuery,
  374. header: this.metadata,
  375. method: "POST",
  376. data: {
  377. mapId: mapId
  378. },
  379. success: (res) => {
  380. console.log("selectPlanQuery", res);
  381. if (checkResCode(res)) {
  382. const data = res.data.data;
  383. this.planRs = data;
  384. }
  385. },
  386. fail: (err) => {
  387. console.log("selectPlanQuery err", err);
  388. },
  389. });
  390. },
  391. btnBack() {
  392. if (this.from == "index") {
  393. const url = "/pages/actManage/index";
  394. tools.appAction(url, "uni.switchTab");
  395. } else if (this.from == "actDetail") {
  396. const url = "/pages/actManage/actDetail?compId=" + this.compId;
  397. tools.appAction(url, "uni.navigateTo");
  398. } else {
  399. window.history.back();
  400. }
  401. },
  402. onLogoUploadSelect(e) {
  403. console.log('[onLogoUploadSelect] 选择文件:', e);
  404. // const imgUrl = e.tempFilePaths[0]; // 获取图片的本地路径
  405. const img = e.tempFiles[0]; // 获取图片信息
  406. // 上传图片
  407. if (img) {
  408. uni.uploadFile({
  409. url: apiUploadFiles, // 你的服务器上传接口地址
  410. filePath: img.path, // 选择的图片路径
  411. name: 'uploadFile', // 必填,后台用来解析的文件名
  412. header: {
  413. // "Content-Type": "multipart/form-data", // H5端不需要添加本句代码
  414. "token": this.token
  415. },
  416. formData: {
  417. // 'user': 'test'
  418. },
  419. success: (uploadFileRes) => {
  420. // console.log("[onLogoUploadSelect] uploadFileRes", uploadFileRes);
  421. // console.log("上传成功", JSON.parse(uploadFileRes.data));
  422. let data = JSON.parse(uploadFileRes.data).data;
  423. this.formData.matchLogo = data.url;
  424. this.matchLogoObj = {
  425. "name": img.name,
  426. "extname": img.extname,
  427. "url": data.url
  428. };
  429. },
  430. fail: (err) => {
  431. console.error("上传失败", err);
  432. }
  433. });
  434. }
  435. },
  436. onLogoUploadDelete() {
  437. this.formData.matchLogo = "";
  438. },
  439. saveClick() {
  440. // console.log(this.formData);
  441. let that = this;
  442. this.$refs.form.validate().then(res => {
  443. // console.log('表单数据信息:', res);
  444. uni.showModal({
  445. title: '提示',
  446. content: `修改后需要重新进行审核\r\n您确定要继续吗?`,
  447. confirmText: '确定', //确定文本的文字
  448. cancelText: '取消', //确定文本的文字
  449. showCancel: true, //没有取消按钮的弹框
  450. success: function(res) {
  451. if (res.confirm) {
  452. that.compInfoEdit();
  453. } else if (res.cancel) {
  454. }
  455. }
  456. });
  457. }).catch(err => {
  458. console.log('表单错误信息:', err);
  459. uni.showToast({
  460. title: `错误: ${err[0].errorMessage}`,
  461. icon: 'none',
  462. duration: 3000
  463. });
  464. });
  465. },
  466. submitClick() {
  467. },
  468. // 获取 赛事场地 输入框中值
  469. getMapSelectText(data) {
  470. // console.log("getMapSelectText:", data);
  471. // this.coiName = data;
  472. },
  473. // 获取 赛事方案 输入框中值
  474. getPlanSelectText(data) {
  475. // console.log("getPlanSelectText:", data);
  476. // this.coiName = data;
  477. },
  478. // 获取 赛事场地 选择选项值
  479. mapSelectChange(data) {
  480. // console.log("mapSelectChange:", data);
  481. if (data == "clear") { // 用户点击清空图标
  482. this.planRs = [];
  483. }
  484. const mapId = data.Value;
  485. if (mapId > 0) {
  486. this.selectPlanQuery(mapId);
  487. }
  488. },
  489. // 获取 赛事方案 选择选项值
  490. planSelectChange(data) {
  491. // console.log("mapSelectChange:", data);
  492. },
  493. },
  494. }
  495. </script>
  496. <style scoped>
  497. .top {
  498. height: 36px;
  499. flex-shrink: 0;
  500. background: rgb(255, 195, 0, 0.26);
  501. }
  502. .main {}
  503. .form {
  504. width: 90%;
  505. margin-top: 20px;
  506. }
  507. .uni-forms-item {
  508. align-items: center;
  509. margin-bottom: 22px;
  510. }
  511. .input {
  512. width: 90%;
  513. height: 30px;
  514. padding: 0 8px;
  515. border: 1px solid;
  516. border-color: #c6c6c6;
  517. border-radius: 3px;
  518. font-size: 14px;
  519. }
  520. .input-placeholder {
  521. font-weight: 300;
  522. color: #bfbfbf;
  523. font-size: 14px;
  524. }
  525. .button {
  526. width: 36vw;
  527. margin-top: 5px;
  528. margin-bottom: 25px;
  529. border-radius: 6px;
  530. font-weight: 500;
  531. color: #333333;
  532. word-spacing: 15px;
  533. }
  534. .button-save {
  535. color: #ffffff;
  536. background-color: #55aa00;
  537. }
  538. .button-submit {
  539. color: #ffffff;
  540. background-color: #0055ff;
  541. }
  542. </style>