placeActivityView.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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" @search="onSearch"
  17. @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 required :rules="[{ required: true }]" label="已知名单:"
  39. placeholder="请选择参会已知名单" input-align="right" 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. // 图片路径
  107. import $base from "@/utils/config";
  108. // 富文本编辑器
  109. import WangEditor from "@/components/editor/WangEditor";
  110. export default {
  111. components: { personList, WangEditor },
  112. setup() {
  113. // 加载
  114. let isLoading = ref(true);
  115. // 返回
  116. const onClickLeft = () => {
  117. history.back();
  118. };
  119. // 活动信息
  120. let placeActivity = ref({
  121. id: "",
  122. activityName: "",
  123. activitiesType: "1",
  124. siteName: {
  125. id: "",
  126. name: "",
  127. },
  128. activityTime: "",
  129. participantsNum: "",
  130. knownList: {
  131. id: "",
  132. name: "",
  133. },
  134. subjectContent: "",
  135. reporter: {
  136. id: "",
  137. name: "",
  138. },
  139. participation: "",
  140. place: "",
  141. placeDel: "",
  142. sourceFunds: "",
  143. safetyPlan: "",
  144. activityPerson: "",
  145. phone: "",
  146. state: "0",
  147. assessment: "0",
  148. });
  149. // 富文本编辑器
  150. const subjectContentEditor = ref(null);
  151. // 根据路由初始化
  152. let route = useRoute();
  153. onMounted(() => {
  154. if (route.query.id) {
  155. new placeActivityServer().queryById(route.query.id).then((data) => {
  156. placeActivity.value = data;
  157. let ids = data.knownList.id.split(",");
  158. placeActivity.value.knownList.name = "";
  159. ids.forEach((item) => {
  160. new UserManage().queryById(item).then((data) => {
  161. placeActivity.value.knownList.name += data.name + ",";
  162. });
  163. });
  164. placeActivity.value.safetyPlan.split("|").forEach((item) => {
  165. if (item.trim().length > 0) {
  166. fileupList.value.push({
  167. name: decodeURIComponent(
  168. item.substring(item.lastIndexOf("/") + 1)
  169. ),
  170. url: $base + item.replace("程序附件//", "程序附件/"),
  171. id: item.replace("程序附件//", "程序附件/")
  172. });
  173. fileList.value.push({
  174. name: decodeURIComponent(
  175. item.substring(item.lastIndexOf("/") + 1)
  176. ),
  177. url: $base + item.replace("程序附件//", "程序附件/"),
  178. id: item.replace("程序附件//", "程序附件/")
  179. });
  180. }
  181. });
  182. subjectContentEditor.value.init(placeActivity.value.subjectContent);
  183. isLoading.value = false;
  184. });
  185. } else {
  186. subjectContentEditor.value.init(placeActivity.value.subjectContent);
  187. // 获取当前登录用户
  188. new placeActivityServer().queryListLonginId().then((data) => {
  189. new tools().queryById(data.id).then((res) => {
  190. placeActivity.value.reporter = res;
  191. });
  192. });
  193. isLoading.value = false;
  194. }
  195. });
  196. // 场所名称
  197. let places = ref([]);
  198. // 场所搜索
  199. let interSearch = ref("");
  200. const onCancel = () => {
  201. interSearch.value = "";
  202. places.value = [];
  203. placelist();
  204. };
  205. const onSearch = () => {
  206. places.value = [];
  207. new tools()
  208. .placeList({
  209. current: 1,
  210. size: 10000,
  211. name: interSearch.value
  212. })
  213. .then(({ records }) => {
  214. places.value.push(...records);
  215. });
  216. };
  217. const customFieldName = {
  218. text: "name",
  219. value: "id",
  220. };
  221. const placelist = () => {
  222. new tools()
  223. .placeList({
  224. current: 1,
  225. size: 10000,
  226. })
  227. .then(({ records }) => {
  228. places.value.push(...records);
  229. });
  230. }
  231. placelist();
  232. let showPlace = ref(false);
  233. const getPlace = ({ selectedOptions }) => {
  234. showPlace.value = false;
  235. placeActivity.value.siteName = selectedOptions[0];
  236. placeActivity.value.place = selectedOptions[0].placeSelectName;
  237. placeActivity.value.placeDel = selectedOptions[0].place;
  238. let searchForm = {
  239. location: {
  240. id: selectedOptions[0].id
  241. }
  242. }
  243. new UserManage()
  244. .list({
  245. current: 1,
  246. size: 10000,
  247. ...searchForm
  248. }).then(({ records }) => {
  249. placeActivity.value.knownList.name = "";
  250. placeActivity.value.knownList.id = "";
  251. records.forEach((item) => {
  252. placeActivity.value.knownList.name += item.name + ",";
  253. placeActivity.value.knownList.id += item.id + ",";
  254. });
  255. })
  256. };
  257. const getLocation = () => {
  258. xm.getLocation().then(data => {
  259. placeActivity.value.placeDel = data.POIName;
  260. })
  261. }
  262. // 获取活动时间
  263. let showAct = ref(false);
  264. let currentDate = ref(["" + new Date().getFullYear(), "01", "01"]);
  265. let currentTime = ref(["00", "00", "00"]);
  266. const columnsType = ["hour", "minute", "second"];
  267. const getTime = () => {
  268. showAct.value = false;
  269. placeActivity.value.activityTime = `${currentDate.value.join(
  270. "-"
  271. )} ${currentTime.value.join(":")}`;
  272. };
  273. // 已知名单
  274. let showPerson = ref(false);
  275. let list = {
  276. value: [],
  277. type: "",
  278. };
  279. const selected = (val, type) => {
  280. list.value = val;
  281. list.type = type;
  282. };
  283. const reselected = () => {
  284. let ids = [];
  285. let names = [];
  286. if (list.type == 1) {
  287. list.value.forEach((item) => {
  288. ids.push(item.id);
  289. names.push(item.name);
  290. });
  291. placeActivity.value.knownList.id = ids.join(",");
  292. placeActivity.value.knownList.name = names.join(",");
  293. }
  294. };
  295. // 文件上传
  296. let fileList = ref([]);
  297. let fileupList = ref([]);
  298. const chooseImg = () => {
  299. xm.chooseFile({
  300. count: 1,
  301. name: "file",
  302. url: $base + `/sys/file/webupload/upload?uploadPath=reporting/reportingActivities`,
  303. headers: { 'Content-Type': 'multipart/form-data', "token": window.localStorage.getItem('MZ_TOKEN') },
  304. }).then(res => {
  305. let data = res[0].data
  306. data.name = decodeURIComponent(
  307. data.id.substring(data.url.lastIndexOf("/") + 1)
  308. );
  309. data.url = $base + data.url;
  310. fileupList.value.push(data);
  311. fileList.value.push(data)
  312. })
  313. }
  314. // 删除文件
  315. const deleteRead = (file) => {
  316. //删除文件操作
  317. for (let index = 0; index < fileList.value.length; index++) {
  318. if (file.id == fileList.value[index].id) {
  319. fileList.value.splice(index, 1);
  320. if (fileupList.value[index]) {
  321. let delurl = fileupList.value[index].url;
  322. new tools().uploadFiledelete("", delurl).then(({ data }) => { });
  323. fileupList.value.splice(index, 1);
  324. }
  325. }
  326. }
  327. };
  328. // 提交数据
  329. const submit = () => {
  330. isLoading.value = true;
  331. //保存前附件处理
  332. placeActivity.value.safetyPlan = fileupList.value
  333. .map((option) => option.id)
  334. .join("|");
  335. new placeActivityServer().save(placeActivity.value).then((res) => {
  336. if (res.status == 200 || res.statusText == "OK") {
  337. // xm.showToast({
  338. // message: res.data,
  339. // });
  340. }
  341. onClickLeft();
  342. });
  343. };
  344. return {
  345. isLoading,
  346. placeActivity,
  347. // 活动场所
  348. customFieldName,
  349. showPlace,
  350. places,
  351. interSearch,
  352. onSearch,
  353. onCancel,
  354. getPlace,
  355. getLocation,
  356. // 活动时间
  357. showAct,
  358. columnsType,
  359. currentDate,
  360. currentTime,
  361. getTime,
  362. // 返回
  363. onClickLeft,
  364. // 人员选择
  365. showPerson,
  366. selected,
  367. reselected,
  368. // 文件上传
  369. deleteRead,
  370. fileList,
  371. submit,
  372. subjectContentEditor,
  373. chooseImg
  374. };
  375. },
  376. };
  377. </script>
  378. <style scoped>
  379. .van-uploader .van-button {
  380. border: none;
  381. color: #36a7f3;
  382. top: -4px;
  383. }
  384. .van-dialog {
  385. width: 80%;
  386. top: 50%;
  387. }
  388. .van-loading {
  389. text-align: center;
  390. margin-top: 80px;
  391. }
  392. </style>