placeActivityView.vue 14 KB

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