placeActivityView.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <van-nav-bar fixed title="场所活动信息上报" left-text="" left-arrow @click-left="onClickLeft" />
  3. <van-loading size="16px" v-show="isLoading">加载中...</van-loading>
  4. <div class="main" v-show="!isLoading">
  5. <!-- <p class="title">场所活动上报</p> -->
  6. <van-form class="formArea" @submit="submit" show-error :show-error-message="false" validate-trigger="onChange">
  7. <!-- <p class="miniTitle">基础信息</p> -->
  8. <van-cell-group>
  9. <van-field v-model="placeActivity.activityName" center clearable label="活动名称:" placeholder="请填写活动名称"
  10. input-align="right" />
  11. </van-cell-group>
  12. <van-cell-group>
  13. <van-field v-model="placeActivity.siteName.name" readonly required :rules="[{ required: true }]" label="场所名称:"
  14. placeholder="请选择场所名称" input-align="right" right-icon="arrow-down" @click="showPlace = true" />
  15. <van-popup v-model:show="showPlace" round position="bottom">
  16. <van-search placeholder="请输入场所名称" shape="round" input-align="center" v-model="interSearch" show-action
  17. @search="onSearch" @cancel="onCancel" />
  18. <van-picker title="活动场所" :columns="places" :columns-field-names="customFieldName" @cancel="showPlace = false"
  19. @confirm="getPlace" />
  20. </van-popup>
  21. </van-cell-group>
  22. <van-cell-group>
  23. <van-field v-model="placeActivity.activityTime" center readonly label="活动时间:" placeholder="请选择时间"
  24. input-align="right" right-icon="arrow-down" @click="showAct = true" />
  25. <van-popup v-model:show="showAct" round position="bottom">
  26. <van-picker-group title="活动时间" :tabs="['选择日期', '选择时间']" next-step-text="下一步" @confirm="getTime"
  27. @cancel="showAct = false">
  28. <van-date-picker v-model="currentDate" />
  29. <van-time-picker v-model="currentTime" :columns-type="columnsType" />
  30. </van-picker-group>
  31. </van-popup>
  32. </van-cell-group>
  33. <van-cell-group>
  34. <van-field v-model="placeActivity.participantsNum" center clearable label="参会人数:" placeholder="请填写参会人数"
  35. input-align="right" type="digit" />
  36. </van-cell-group>
  37. <van-cell-group>
  38. <van-field v-model="placeActivity.knownList.name" center label="已知名单:" placeholder="请选择参会已知名单" input-align="right"
  39. right-icon="arrow-down" @click="showPerson = true" />
  40. <van-dialog v-model:show="showPerson" title="选择人员名单" show-cancel-button @confirm="reselected">
  41. <person-list v-if="showPerson" @selected="selected" :type="1" :siteId="placeActivity.siteName.id"></person-list>
  42. </van-dialog>
  43. </van-cell-group>
  44. <van-cell-group>
  45. <van-field v-model="placeActivity.reporter.name" center readonly label="报告人:" placeholder="请选择报告人"
  46. input-align="right" />
  47. </van-cell-group>
  48. <van-cell-group>
  49. <van-field v-model="placeActivity.participation" center clearable label="参加范围:" placeholder="请填写参加范围"
  50. input-align="right" />
  51. </van-cell-group>
  52. <van-cell-group>
  53. <van-field v-model="placeActivity.place" center readonly label="活动地点:" placeholder="请选择场所" input-align="right"
  54. right-icon="arrow-down" />
  55. </van-cell-group>
  56. <van-cell-group>
  57. <van-field v-model="placeActivity.placeDel" center readonly label="详细地址:" placeholder="请选择场所" input-align="right">
  58. <template #right-icon>
  59. <van-icon name="location" @click="getLocation" />
  60. </template>
  61. </van-field>
  62. </van-cell-group>
  63. <van-cell-group>
  64. <van-field v-model="placeActivity.sourceFunds" center clearable label="经费来源:" placeholder="请填写经费来源"
  65. input-align="right" />
  66. </van-cell-group>
  67. <van-cell-group>
  68. <van-field v-model="placeActivity.activityPerson" center label="活动负责人:" placeholder="请填写活动负责人"
  69. input-align="right" />
  70. </van-cell-group>
  71. <van-cell-group>
  72. <van-field v-model="placeActivity.phone" center type="tel" label="联系方式:" placeholder="请填写联系方式"
  73. input-align="right" />
  74. </van-cell-group>
  75. <van-cell-group>
  76. <van-field name="uploader" label="安全预案:">
  77. <template #input>
  78. <van-uploader readonly v-model="fileList" :max-count="5" accept="" :preview-full-image="false"
  79. :before-delete="deleteRead" @click-upload="chooseImg">
  80. <van-button>上传文件(可添加图片、音、视频和文本等)</van-button>
  81. </van-uploader>
  82. </template>
  83. </van-field>
  84. </van-cell-group>
  85. <van-cell-group>
  86. <van-field name="content" label="主题内容:" label-align="top">
  87. <template #input>
  88. <wang-editor ref="subjectContentEditor" v-model="placeActivity.subjectContent" />
  89. </template>
  90. </van-field>
  91. </van-cell-group>
  92. <div class="subbtn">
  93. <van-button type="primary" native-type="submit">提交</van-button>
  94. <van-button type="default" hairline @click="onClickLeft">取消</van-button>
  95. </div>
  96. </van-form>
  97. </div>
  98. </template>
  99. <script>
  100. import { ref, onMounted } from "vue";
  101. import personList from "../personList.vue";
  102. import placeActivityServer from "@/api/placeActivity/placeActivityServer";
  103. import tools from "@/api/sys/tools";
  104. import UserManage from "@/api/user/UserManage";
  105. import { useRoute } from "vue-router";
  106. import { formatDate, formatTime } from "@/utils/datatime";
  107. // 图片路径
  108. import $base from "@/utils/config";
  109. // 富文本编辑器
  110. import WangEditor from "@/components/editor/WangEditor";
  111. export default {
  112. components: { personList, WangEditor },
  113. setup() {
  114. // 加载
  115. let isLoading = ref(true);
  116. // 返回
  117. const onClickLeft = () => {
  118. history.back();
  119. };
  120. // 活动信息
  121. let placeActivity = ref({
  122. id: "",
  123. activityName: "",
  124. activitiesType: "1",
  125. siteName: {
  126. id: "",
  127. name: "",
  128. },
  129. activityTime: "",
  130. participantsNum: "",
  131. knownList: {
  132. id: "",
  133. name: "",
  134. },
  135. subjectContent: "",
  136. reporter: {
  137. id: "",
  138. name: "",
  139. },
  140. participation: "",
  141. place: "",
  142. placeDel: "",
  143. sourceFunds: "",
  144. safetyPlan: "",
  145. activityPerson: "",
  146. phone: "",
  147. state: "0",
  148. assessment: "0",
  149. });
  150. // 富文本编辑器
  151. const subjectContentEditor = ref(null);
  152. // 根据路由初始化
  153. let route = useRoute();
  154. onMounted(() => {
  155. if (route.query.id) {
  156. new placeActivityServer().queryById(route.query.id).then((data) => {
  157. placeActivity.value = data;
  158. let ids = data.knownList.id.split(",");
  159. placeActivity.value.knownList.name = "";
  160. ids.forEach((item) => {
  161. new UserManage().queryById(item).then((data) => {
  162. placeActivity.value.knownList.name += data.name + ",";
  163. });
  164. });
  165. placeActivity.value.safetyPlan.split("|").forEach((item) => {
  166. if (item.trim().length > 0) {
  167. fileupList.value.push({
  168. name: decodeURIComponent(
  169. item.substring(item.lastIndexOf("/") + 1)
  170. ),
  171. url: $base + item.replace("程序附件//", "程序附件/"),
  172. id: item.replace("程序附件//", "程序附件/")
  173. });
  174. fileList.value.push({
  175. name: decodeURIComponent(
  176. item.substring(item.lastIndexOf("/") + 1)
  177. ),
  178. url: $base + item.replace("程序附件//", "程序附件/"),
  179. id: item.replace("程序附件//", "程序附件/")
  180. });
  181. }
  182. });
  183. subjectContentEditor.value.init(placeActivity.value.subjectContent);
  184. isLoading.value = false;
  185. });
  186. } else {
  187. subjectContentEditor.value.init(placeActivity.value.subjectContent);
  188. // 获取当前登录用户
  189. new placeActivityServer().queryListLonginId().then((data) => {
  190. new tools().queryById(data.id).then((res) => {
  191. placeActivity.value.reporter = res;
  192. });
  193. });
  194. isLoading.value = false;
  195. }
  196. });
  197. // 场所名称
  198. let places = ref([]);
  199. // 场所搜索
  200. let interSearch = ref("");
  201. const onCancel = () => {
  202. interSearch.value = "";
  203. places.value = [];
  204. placelist();
  205. };
  206. const onSearch = () => {
  207. places.value = [];
  208. new tools()
  209. .placeList({
  210. current: 1,
  211. size: 10000,
  212. name: interSearch.value
  213. })
  214. .then(({ records }) => {
  215. places.value.push(...records);
  216. });
  217. };
  218. const customFieldName = {
  219. text: "name",
  220. value: "id",
  221. };
  222. const placelist = () => {
  223. new tools()
  224. .placeList({
  225. current: 1,
  226. size: 10000,
  227. })
  228. .then(({ records }) => {
  229. places.value.push(...records);
  230. });
  231. }
  232. placelist();
  233. let showPlace = ref(false);
  234. const getPlace = ({ selectedOptions }) => {
  235. showPlace.value = false;
  236. placeActivity.value.siteName = selectedOptions[0];
  237. placeActivity.value.place = selectedOptions[0].placeSelectName;
  238. placeActivity.value.placeDel = selectedOptions[0].place;
  239. let searchForm = {
  240. location: {
  241. id: selectedOptions[0].id
  242. }
  243. }
  244. new UserManage()
  245. .list({
  246. current: 1,
  247. size: 10000,
  248. ...searchForm
  249. }).then(({ records }) => {
  250. placeActivity.value.knownList.name = "";
  251. placeActivity.value.knownList.id = "";
  252. records.forEach((item) => {
  253. placeActivity.value.knownList.name += item.name + ",";
  254. placeActivity.value.knownList.id += item.id + ",";
  255. });
  256. })
  257. };
  258. const getLocation = () => {
  259. xm.getLocation().then(data => {
  260. placeActivity.value.placeDel = data.POIName;
  261. })
  262. }
  263. // 获取活动时间
  264. let showAct = ref(false);
  265. let currentDate = ref(formatDate(new Date()));
  266. let currentTime = ref(formatTime(new Date()));
  267. const columnsType = ["hour", "minute", "second"];
  268. const getTime = () => {
  269. showAct.value = false;
  270. placeActivity.value.activityTime = `${currentDate.value.join(
  271. "-"
  272. )} ${currentTime.value.join(":")}`;
  273. };
  274. // 已知名单
  275. let showPerson = ref(false);
  276. let list = {
  277. value: [],
  278. type: "",
  279. };
  280. const selected = (val, type) => {
  281. list.value = val;
  282. list.type = type;
  283. };
  284. const reselected = () => {
  285. let ids = [];
  286. let names = [];
  287. if (list.type == 1) {
  288. list.value.forEach((item) => {
  289. ids.push(item.id);
  290. names.push(item.name);
  291. });
  292. placeActivity.value.knownList.id = ids.join(",");
  293. placeActivity.value.knownList.name = names.join(",");
  294. }
  295. };
  296. // 文件上传
  297. let fileList = ref([]);
  298. let fileupList = ref([]);
  299. const chooseImg = () => {
  300. xm.chooseFile({
  301. count: 1,
  302. name: "file",
  303. url: $base + `/sys/file/webupload/upload?uploadPath=reporting/reportingActivities`,
  304. headers: { 'Content-Type': 'multipart/form-data', "token": window.localStorage.getItem('MZ_TOKEN') },
  305. }).then(res => {
  306. let data = res[0].data
  307. data.name = decodeURIComponent(
  308. data.id.substring(data.url.lastIndexOf("/") + 1)
  309. );
  310. data.url = $base + data.url;
  311. fileupList.value.push(data);
  312. fileList.value.push(data)
  313. })
  314. }
  315. // 删除文件
  316. const deleteRead = (file) => {
  317. //删除文件操作
  318. for (let index = 0; index < fileList.value.length; index++) {
  319. if (file.id == fileList.value[index].id) {
  320. fileList.value.splice(index, 1);
  321. if (fileupList.value[index]) {
  322. let delurl = fileupList.value[index].url;
  323. new tools().uploadFiledelete("", delurl).then(({ data }) => { });
  324. fileupList.value.splice(index, 1);
  325. }
  326. }
  327. }
  328. };
  329. // 提交数据
  330. const submit = () => {
  331. isLoading.value = true;
  332. //保存前附件处理
  333. placeActivity.value.safetyPlan = fileupList.value
  334. .map((option) => option.id)
  335. .join("|");
  336. new placeActivityServer().save(placeActivity.value).then((res) => {
  337. if (res.status == 200 || res.statusText == "OK") {
  338. // xm.showToast({
  339. // message: res.data,
  340. // });
  341. }
  342. onClickLeft();
  343. });
  344. };
  345. return {
  346. isLoading,
  347. placeActivity,
  348. // 活动场所
  349. customFieldName,
  350. showPlace,
  351. places,
  352. interSearch,
  353. onSearch,
  354. onCancel,
  355. getPlace,
  356. getLocation,
  357. // 活动时间
  358. showAct,
  359. columnsType,
  360. currentDate,
  361. currentTime,
  362. getTime,
  363. // 返回
  364. onClickLeft,
  365. // 人员选择
  366. showPerson,
  367. selected,
  368. reselected,
  369. // 文件上传
  370. deleteRead,
  371. fileList,
  372. submit,
  373. subjectContentEditor,
  374. chooseImg
  375. };
  376. },
  377. };
  378. </script>
  379. <style scoped>
  380. .van-uploader .van-button {
  381. border: none;
  382. color: #36a7f3;
  383. top: -4px;
  384. }
  385. .van-dialog {
  386. width: 80%;
  387. top: 50%;
  388. }
  389. .van-loading {
  390. text-align: center;
  391. margin-top: 80px;
  392. }
  393. </style>