placeActivityView.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <template>
  2. <van-nav-bar
  3. fixed
  4. title="信息上报中心"
  5. left-text=""
  6. left-arrow
  7. @click-left="onClickLeft"
  8. />
  9. <van-loading size="16px" v-show="isLoading">加载中...</van-loading>
  10. <div class="main" v-show="!isLoading">
  11. <p class="title">场所活动上报</p>
  12. <van-form
  13. class="formArea"
  14. @submit="submit"
  15. show-error
  16. :show-error-message="false"
  17. validate-trigger="onChange"
  18. >
  19. <p class="miniTitle">基础信息</p>
  20. <van-cell-group>
  21. <van-field
  22. v-model="placeActivity.activityName"
  23. center
  24. clearable
  25. label="活动名称:"
  26. placeholder="请填写活动名称"
  27. input-align="right"
  28. />
  29. </van-cell-group>
  30. <van-cell-group>
  31. <van-field
  32. v-model="placeActivity.siteName.name"
  33. readonly
  34. required
  35. :rules="[{ required: true }]"
  36. label="场所名称:"
  37. placeholder="请选择场所名称"
  38. input-align="right"
  39. right-icon="arrow-down"
  40. @click="showPlace = true"
  41. />
  42. <van-popup v-model:show="showPlace" round position="bottom">
  43. <van-picker
  44. title="活动场所"
  45. :columns="places"
  46. :columns-field-names="customFieldName"
  47. @cancel="showPlace = false"
  48. @confirm="getPlace"
  49. />
  50. </van-popup>
  51. </van-cell-group>
  52. <van-cell-group>
  53. <van-field
  54. v-model="placeActivity.activityTime"
  55. center
  56. readonly
  57. label="活动时间:"
  58. placeholder="请选择时间"
  59. input-align="right"
  60. right-icon="arrow-down"
  61. @click="showAct = true"
  62. />
  63. <van-popup v-model:show="showAct" round position="bottom">
  64. <van-picker-group
  65. title="活动时间"
  66. :tabs="['选择日期', '选择时间']"
  67. next-step-text="下一步"
  68. @confirm="getTime"
  69. @cancel="showAct = false"
  70. >
  71. <van-date-picker v-model="currentDate" />
  72. <van-time-picker
  73. v-model="currentTime"
  74. :columns-type="columnsType"
  75. />
  76. </van-picker-group>
  77. </van-popup>
  78. </van-cell-group>
  79. <van-cell-group>
  80. <van-field
  81. v-model="placeActivity.participantsNum"
  82. center
  83. clearable
  84. label="参会人数:"
  85. placeholder="请填写参会人数"
  86. input-align="right"
  87. type="digit"
  88. />
  89. </van-cell-group>
  90. <van-cell-group>
  91. <van-field
  92. v-model="placeActivity.knownList.name"
  93. center
  94. required
  95. :rules="[{ required: true }]"
  96. label="已知名单:"
  97. placeholder="请选择参会已知名单"
  98. input-align="right"
  99. right-icon="arrow-down"
  100. @click="showPerson = true"
  101. />
  102. <van-dialog
  103. v-model:show="showPerson"
  104. title="选择人员名单"
  105. show-cancel-button
  106. @confirm="reselected"
  107. >
  108. <person-list @selected="selected" :type="1"></person-list>
  109. </van-dialog>
  110. </van-cell-group>
  111. <van-cell-group>
  112. <van-field
  113. v-model="placeActivity.reporter.name"
  114. center
  115. readonly
  116. label="报告人:"
  117. placeholder="请选择报告人"
  118. input-align="right"
  119. />
  120. </van-cell-group>
  121. <van-cell-group>
  122. <van-field
  123. v-model="placeActivity.participation"
  124. center
  125. clearable
  126. label="参加范围:"
  127. placeholder="请填写参加范围"
  128. input-align="right"
  129. />
  130. </van-cell-group>
  131. <van-cell-group>
  132. <van-field
  133. v-model="placeActivity.place"
  134. center
  135. readonly
  136. label="活动地点:"
  137. placeholder="请选择场所"
  138. input-align="right"
  139. right-icon="arrow-down"
  140. />
  141. </van-cell-group>
  142. <van-cell-group>
  143. <van-field
  144. v-model="placeActivity.placeDel"
  145. center
  146. readonly
  147. label="详细地址:"
  148. placeholder="请选择场所"
  149. input-align="right"
  150. >
  151. <template #right-icon>
  152. <van-icon name="location" />
  153. </template>
  154. </van-field>
  155. </van-cell-group>
  156. <van-cell-group>
  157. <van-field
  158. v-model="placeActivity.sourceFunds"
  159. center
  160. clearable
  161. label="经费来源:"
  162. placeholder="请选择"
  163. input-align="right"
  164. />
  165. </van-cell-group>
  166. <van-cell-group>
  167. <van-field
  168. v-model="placeActivity.activityPerson.name"
  169. center
  170. label="活动负责人:"
  171. placeholder="请选择活动负责人"
  172. input-align="right"
  173. right-icon="arrow-down"
  174. @click="showReport = true"
  175. />
  176. <van-dialog
  177. v-model:show="showReport"
  178. title="选择活动负责人"
  179. show-cancel-button
  180. @confirm="reselected"
  181. >
  182. <person-list
  183. @selected="selected"
  184. :type="0"
  185. ref="person"
  186. ></person-list>
  187. </van-dialog>
  188. </van-cell-group>
  189. <van-cell-group>
  190. <van-field
  191. v-model="placeActivity.phone"
  192. center
  193. readonly
  194. type="tel"
  195. label="联系方式:"
  196. placeholder="请填写联系方式"
  197. input-align="right"
  198. />
  199. </van-cell-group>
  200. <van-cell-group>
  201. <van-field name="uploader" label="安全预案:">
  202. <template #input>
  203. <van-uploader
  204. :after-read="afterRead"
  205. v-model="fileList"
  206. :max-count="5"
  207. capture="camera"
  208. accept=""
  209. :preview-full-image="false"
  210. :before-delete="deleteRead"
  211. @click-preview="downHandle"
  212. >
  213. <van-button>上传文件</van-button>
  214. </van-uploader>
  215. </template>
  216. </van-field>
  217. </van-cell-group>
  218. <van-cell-group>
  219. <van-field name="content" label="主题内容:" label-align="top">
  220. <template #input>
  221. <wang-editor
  222. ref="subjectContentEditor"
  223. v-model="placeActivity.subjectContent"
  224. />
  225. </template>
  226. </van-field>
  227. </van-cell-group>
  228. <div class="subbtn">
  229. <van-button type="primary" native-type="submit">提交</van-button>
  230. <van-button type="default" hairline @click="onClickLeft"
  231. >暂存</van-button
  232. >
  233. </div>
  234. </van-form>
  235. </div>
  236. </template>
  237. <script>
  238. import { ref, onMounted } from "vue";
  239. import personList from "../personList.vue";
  240. import placeActivityServer from "@/api/placeActivity/placeActivityServer";
  241. import tools from "@/api/sys/tools";
  242. import UserManage from "@/api/user/UserManage";
  243. import { useRoute } from "vue-router";
  244. // 图片路径
  245. import $base from "@/utils/config";
  246. // 富文本编辑器
  247. import WangEditor from "@/components/editor/WangEditor";
  248. export default {
  249. components: { personList, WangEditor },
  250. setup() {
  251. // 加载
  252. let isLoading = ref(true);
  253. // 返回
  254. const onClickLeft = () => {
  255. history.back();
  256. };
  257. // 活动信息
  258. let placeActivity = ref({
  259. id: "",
  260. activityName: "",
  261. siteName: {
  262. id: "",
  263. name: "",
  264. },
  265. activityTime: "",
  266. participantsNum: "",
  267. knownList: {
  268. id: "",
  269. name: "",
  270. },
  271. subjectContent: "",
  272. reporter: {
  273. id: "",
  274. name: "",
  275. },
  276. participation: "",
  277. place: "",
  278. placeDel: "",
  279. sourceFunds: "",
  280. safetyPlan: "",
  281. activityPerson: {
  282. id: "",
  283. name: "",
  284. },
  285. phone: "",
  286. state: "0",
  287. assessment: "0",
  288. });
  289. // 富文本编辑器
  290. const subjectContentEditor = ref(null);
  291. // 获取当前登录用户
  292. const user = new placeActivityServer().queryListLonginId().then((data) => {
  293. new tools().queryById(data.id).then((res) => {
  294. placeActivity.value.reporter = res;
  295. });
  296. });
  297. // 根据路由初始化
  298. let route = useRoute();
  299. onMounted(() => {
  300. if (route.query.id) {
  301. new placeActivityServer().queryById(route.query.id).then((data) => {
  302. placeActivity.value = data;
  303. let ids = data.knownList.id.split(",");
  304. placeActivity.value.knownList.name = "";
  305. ids.forEach((item) => {
  306. new UserManage().queryById(item).then((data) => {
  307. placeActivity.value.knownList.name += data.name + ",";
  308. });
  309. });
  310. placeActivity.value.safetyPlan.split("|").forEach((item) => {
  311. if (item.trim().length > 0) {
  312. fileupList.value.push({
  313. file: {
  314. name: decodeURIComponent(
  315. item.substring(item.lastIndexOf("/") + 1)
  316. ),
  317. },
  318. url: item,
  319. });
  320. fileList.value.push({
  321. file: {
  322. name: decodeURIComponent(
  323. item.substring(item.lastIndexOf("/") + 1)
  324. ),
  325. },
  326. url: $base + item.replace("程序附件//", "程序附件/"),
  327. });
  328. }
  329. });
  330. subjectContentEditor.value.init(placeActivity.value.subjectContent);
  331. isLoading.value = false;
  332. });
  333. } else {
  334. subjectContentEditor.value.init(placeActivity.value.subjectContent);
  335. placeActivity.value.reporter = user;
  336. isLoading.value = false;
  337. }
  338. });
  339. // 场所名称
  340. let places = ref([]);
  341. const customFieldName = {
  342. text: "name",
  343. value: "id",
  344. };
  345. new tools()
  346. .placeList({
  347. current: 1,
  348. size: 10000,
  349. })
  350. .then(({ records }) => {
  351. places.value.push(...records);
  352. });
  353. let showPlace = ref(false);
  354. const getPlace = ({ selectedOptions }) => {
  355. showPlace.value = false;
  356. placeActivity.value.siteName = selectedOptions[0];
  357. placeActivity.value.place = selectedOptions[0].placeSelectName;
  358. placeActivity.value.placeDel = selectedOptions[0].place;
  359. };
  360. // 获取活动时间
  361. let showAct = ref(false);
  362. let currentDate = ref(["" + new Date().getFullYear(), "01", "01"]);
  363. let currentTime = ref(["00", "00", "00"]);
  364. const columnsType = ["hour", "minute", "second"];
  365. const getTime = () => {
  366. showAct.value = false;
  367. placeActivity.value.activityTime = `${currentDate.value.join(
  368. "-"
  369. )} ${currentTime.value.join(":")}`;
  370. };
  371. // 已知名单
  372. let showPerson = ref(false);
  373. // 活动负责人
  374. let showReport = ref(false);
  375. let list = {
  376. value: [],
  377. type: "",
  378. };
  379. const selected = (val, type) => {
  380. list.value = val;
  381. list.type = type;
  382. };
  383. const reselected = () => {
  384. let ids = [];
  385. let names = [];
  386. if (list.type == 1) {
  387. list.value.forEach((item) => {
  388. ids.push(item.id);
  389. names.push(item.name);
  390. });
  391. placeActivity.value.knownList.id = ids.join(",");
  392. placeActivity.value.knownList.name = names.join(",");
  393. } else {
  394. placeActivity.value.activityPerson.id = list.value.id;
  395. placeActivity.value.phone = list.value.phone;
  396. placeActivity.value.activityPerson.name = list.value.name;
  397. }
  398. };
  399. // 文件上传
  400. let fileList = ref([]);
  401. let fileupList = ref([]);
  402. const afterRead = (file) => {
  403. file.status = "uploading";
  404. file.message = "上传中";
  405. // 此时可以自行将文件上传至服务器
  406. new tools()
  407. .uploadFile(file, `reporting/reportingActivities`)
  408. .then(({ data, status, statusText }) => {
  409. if (status == 200 || statusText == "OK") {
  410. file.status = "done";
  411. // xm.showToast({
  412. // message: "上传成功",
  413. // });
  414. data.name = decodeURIComponent(
  415. data.url.substring(data.url.lastIndexOf("/") + 1)
  416. );
  417. fileupList.value.push(data);
  418. }
  419. })
  420. .catch(() => {
  421. file.status = "failed";
  422. file.message = "上传失败";
  423. });
  424. };
  425. // 删除文件
  426. const deleteRead = (file) => {
  427. //删除文件操作
  428. for (let index = 0; index < fileList.value.length; index++) {
  429. if (file.file.name == fileList.value[index].file.name) {
  430. let delurl = fileupList.value[index].url;
  431. new tools().uploadFiledelete("", delurl).then(({ data }) => {});
  432. fileupList.value.splice(index, 1);
  433. fileList.value.splice(index, 1);
  434. }
  435. }
  436. };
  437. /**
  438. * 下载文件 网页端可用
  439. */
  440. const downHandle = (fileObj) => {
  441. // 声明a标签
  442. const aEle = document.createElement("a");
  443. // 设置下载文件名
  444. aEle.download = fileObj.file.name;
  445. // 下载地址
  446. aEle.href = fileObj.content;
  447. // 调用下载
  448. aEle.click();
  449. };
  450. // 提交数据
  451. const submit = () => {
  452. isLoading.value = true;
  453. //保存前附件处理
  454. placeActivity.value.safetyPlan = fileupList.value
  455. .map((option) => option.url)
  456. .join("|");
  457. new placeActivityServer().save(placeActivity.value).then((res) => {
  458. if (res.status == 200 || res.statusText == "OK") {
  459. // xm.showToast({
  460. // message: res.data,
  461. // });
  462. }
  463. onClickLeft();
  464. });
  465. };
  466. return {
  467. isLoading,
  468. placeActivity,
  469. // 活动场所
  470. customFieldName,
  471. showPlace,
  472. places,
  473. getPlace,
  474. // 活动时间
  475. showAct,
  476. columnsType,
  477. currentDate,
  478. currentTime,
  479. getTime,
  480. // 返回
  481. onClickLeft,
  482. // 人员选择
  483. showPerson,
  484. showReport,
  485. selected,
  486. reselected,
  487. // 文件上传
  488. afterRead,
  489. deleteRead,
  490. downHandle,
  491. fileList,
  492. submit,
  493. subjectContentEditor,
  494. };
  495. },
  496. };
  497. </script>
  498. <style scoped>
  499. .van-uploader .van-button {
  500. border: none;
  501. color: #36a7f3;
  502. top: -4px;
  503. }
  504. .van-dialog {
  505. width: 80%;
  506. top: 50%;
  507. }
  508. .van-loading {
  509. text-align: center;
  510. margin-top: 80px;
  511. }
  512. </style>