placeActivityView.vue 12 KB

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