placeActivityView.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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-picker title="活动场所" :columns="places" :columns-field-names="customFieldName" @cancel="showPlace = false"
  17. @confirm="getPlace" />
  18. </van-popup>
  19. </van-cell-group>
  20. <van-cell-group>
  21. <van-field v-model="placeActivity.activityTime" center readonly label="活动时间:" placeholder="请选择时间"
  22. input-align="right" right-icon="arrow-down" @click="showAct = true" />
  23. <van-popup v-model:show="showAct" round position="bottom">
  24. <van-picker-group title="活动时间" :tabs="['选择日期', '选择时间']" next-step-text="下一步" @confirm="getTime"
  25. @cancel="showAct = false">
  26. <van-date-picker v-model="currentDate" />
  27. <van-time-picker v-model="currentTime" :columns-type="columnsType" />
  28. </van-picker-group>
  29. </van-popup>
  30. </van-cell-group>
  31. <van-cell-group>
  32. <van-field v-model="placeActivity.participantsNum" center clearable label="参会人数:" placeholder="请填写参会人数"
  33. input-align="right" type="digit" />
  34. </van-cell-group>
  35. <van-cell-group>
  36. <van-field v-model="placeActivity.knownList.name" center required :rules="[{ required: true }]" label="已知名单:"
  37. placeholder="请选择参会已知名单" input-align="right" right-icon="arrow-down" @click="showPerson = true" />
  38. <van-dialog v-model:show="showPerson" title="选择人员名单" show-cancel-button @confirm="reselected">
  39. <person-list @selected="selected" :type="1"></person-list>
  40. </van-dialog>
  41. </van-cell-group>
  42. <van-cell-group>
  43. <van-field v-model="placeActivity.reporter.name" center readonly label="报告人:" placeholder="请选择报告人"
  44. input-align="right" />
  45. </van-cell-group>
  46. <van-cell-group>
  47. <van-field v-model="placeActivity.participation" center clearable label="参加范围:" placeholder="请填写参加范围"
  48. input-align="right" />
  49. </van-cell-group>
  50. <van-cell-group>
  51. <van-field v-model="placeActivity.place" center readonly label="活动地点:" placeholder="请选择场所" input-align="right"
  52. right-icon="arrow-down" />
  53. </van-cell-group>
  54. <van-cell-group>
  55. <van-field v-model="placeActivity.placeDel" center readonly label="详细地址:" placeholder="请选择场所" input-align="right">
  56. <template #right-icon>
  57. <van-icon name="location" @click="getLocation" />
  58. </template>
  59. </van-field>
  60. </van-cell-group>
  61. <van-cell-group>
  62. <van-field v-model="placeActivity.sourceFunds" center clearable label="经费来源:" placeholder="请选择"
  63. input-align="right" />
  64. </van-cell-group>
  65. <van-cell-group>
  66. <van-field v-model="placeActivity.activityPerson.name" center label="活动负责人:" placeholder="请选择活动负责人"
  67. input-align="right" right-icon="arrow-down" @click="showReport = true" />
  68. <van-dialog v-model:show="showReport" title="选择活动负责人" show-cancel-button @confirm="reselected">
  69. <person-list @selected="selected" :type="0" ref="person"></person-list>
  70. </van-dialog>
  71. </van-cell-group>
  72. <van-cell-group>
  73. <van-field v-model="placeActivity.phone" center readonly type="tel" label="联系方式:" placeholder="请填写联系方式"
  74. input-align="right" />
  75. </van-cell-group>
  76. <van-cell-group>
  77. <van-field name="uploader" label="安全预案:">
  78. <template #input>
  79. <van-uploader :after-read="afterRead" v-model="fileList" :max-count="5" capture="camera" accept=""
  80. :preview-full-image="false" :before-delete="deleteRead">
  81. <van-button>上传文件</van-button>
  82. </van-uploader>
  83. </template>
  84. </van-field>
  85. </van-cell-group>
  86. <van-cell-group>
  87. <van-field name="content" label="主题内容:" label-align="top">
  88. <template #input>
  89. <wang-editor ref="subjectContentEditor" v-model="placeActivity.subjectContent" />
  90. </template>
  91. </van-field>
  92. </van-cell-group>
  93. <div class="subbtn">
  94. <van-button type="primary" native-type="submit">提交</van-button>
  95. <van-button type="default" hairline @click="onClickLeft">暂存</van-button>
  96. </div>
  97. </van-form>
  98. </div>
  99. </template>
  100. <script>
  101. import { ref, onMounted } from "vue";
  102. import personList from "../personList.vue";
  103. import placeActivityServer from "@/api/placeActivity/placeActivityServer";
  104. import tools from "@/api/sys/tools";
  105. import UserManage from "@/api/user/UserManage";
  106. import { useRoute } from "vue-router";
  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. 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. id: "",
  146. name: "",
  147. },
  148. phone: "",
  149. state: "0",
  150. assessment: "0",
  151. });
  152. // 富文本编辑器
  153. const subjectContentEditor = ref(null);
  154. // 根据路由初始化
  155. let route = useRoute();
  156. onMounted(() => {
  157. if (route.query.id) {
  158. new placeActivityServer().queryById(route.query.id).then((data) => {
  159. placeActivity.value = data;
  160. let ids = data.knownList.id.split(",");
  161. placeActivity.value.knownList.name = "";
  162. ids.forEach((item) => {
  163. new UserManage().queryById(item).then((data) => {
  164. placeActivity.value.knownList.name += data.name + ",";
  165. });
  166. });
  167. placeActivity.value.safetyPlan.split("|").forEach((item) => {
  168. if (item.trim().length > 0) {
  169. fileupList.value.push({
  170. file: {
  171. name: decodeURIComponent(
  172. item.substring(item.lastIndexOf("/") + 1)
  173. ),
  174. },
  175. url: item,
  176. });
  177. fileList.value.push({
  178. file: {
  179. name: decodeURIComponent(
  180. item.substring(item.lastIndexOf("/") + 1)
  181. ),
  182. },
  183. url: $base + item.replace("程序附件//", "程序附件/"),
  184. });
  185. }
  186. });
  187. subjectContentEditor.value.init(placeActivity.value.subjectContent);
  188. isLoading.value = false;
  189. });
  190. } else {
  191. subjectContentEditor.value.init(placeActivity.value.subjectContent);
  192. // 获取当前登录用户
  193. new placeActivityServer().queryListLonginId().then((data) => {
  194. new tools().queryById(data.id).then((res) => {
  195. placeActivity.value.reporter = res;
  196. });
  197. });
  198. isLoading.value = false;
  199. }
  200. });
  201. // 场所名称
  202. let places = ref([]);
  203. const customFieldName = {
  204. text: "name",
  205. value: "id",
  206. };
  207. new tools()
  208. .placeList({
  209. current: 1,
  210. size: 10000,
  211. })
  212. .then(({ records }) => {
  213. places.value.push(...records);
  214. });
  215. let showPlace = ref(false);
  216. const getPlace = ({ selectedOptions }) => {
  217. showPlace.value = false;
  218. placeActivity.value.siteName = selectedOptions[0];
  219. placeActivity.value.place = selectedOptions[0].placeSelectName;
  220. placeActivity.value.placeDel = selectedOptions[0].place;
  221. };
  222. const getLocation = () => {
  223. xm.getLocation().then(data => {
  224. placeActivity.value.placeDel = data.POIName;
  225. })
  226. }
  227. // 获取活动时间
  228. let showAct = ref(false);
  229. let currentDate = ref(["" + new Date().getFullYear(), "01", "01"]);
  230. let currentTime = ref(["00", "00", "00"]);
  231. const columnsType = ["hour", "minute", "second"];
  232. const getTime = () => {
  233. showAct.value = false;
  234. placeActivity.value.activityTime = `${currentDate.value.join(
  235. "-"
  236. )} ${currentTime.value.join(":")}`;
  237. };
  238. // 已知名单
  239. let showPerson = ref(false);
  240. // 活动负责人
  241. let showReport = ref(false);
  242. let list = {
  243. value: [],
  244. type: "",
  245. };
  246. const selected = (val, type) => {
  247. list.value = val;
  248. list.type = type;
  249. };
  250. const reselected = () => {
  251. let ids = [];
  252. let names = [];
  253. if (list.type == 1) {
  254. list.value.forEach((item) => {
  255. ids.push(item.id);
  256. names.push(item.name);
  257. });
  258. placeActivity.value.knownList.id = ids.join(",");
  259. placeActivity.value.knownList.name = names.join(",");
  260. } else {
  261. placeActivity.value.activityPerson.id = list.value.id;
  262. placeActivity.value.phone = list.value.phone;
  263. placeActivity.value.activityPerson.name = list.value.name;
  264. }
  265. };
  266. // 文件上传
  267. let fileList = ref([]);
  268. let fileupList = ref([]);
  269. const afterRead = (file) => {
  270. file.status = "uploading";
  271. file.message = "上传中";
  272. // 此时可以自行将文件上传至服务器
  273. new tools()
  274. .uploadFile(file, `reporting/reportingActivities`)
  275. .then(({ data, status, statusText }) => {
  276. if (status == 200 || statusText == "OK") {
  277. file.status = "done";
  278. // xm.showToast({
  279. // message: "上传成功",
  280. // });
  281. data.name = decodeURIComponent(
  282. data.url.substring(data.url.lastIndexOf("/") + 1)
  283. );
  284. fileupList.value.push(data);
  285. }
  286. })
  287. .catch(() => {
  288. file.status = "failed";
  289. file.message = "上传失败";
  290. });
  291. };
  292. // 删除文件
  293. const deleteRead = (file) => {
  294. //删除文件操作
  295. for (let index = 0; index < fileList.value.length; index++) {
  296. if (file.file.name == fileList.value[index].file.name) {
  297. fileList.value.splice(index, 1);
  298. if (fileupList.value[index]) {
  299. let delurl = fileupList.value[index].url;
  300. new tools().uploadFiledelete("", delurl).then(({ data }) => { });
  301. fileupList.value.splice(index, 1);
  302. }
  303. }
  304. }
  305. };
  306. // 提交数据
  307. const submit = () => {
  308. isLoading.value = true;
  309. //保存前附件处理
  310. placeActivity.value.safetyPlan = fileupList.value
  311. .map((option) => option.url)
  312. .join("|");
  313. new placeActivityServer().save(placeActivity.value).then((res) => {
  314. if (res.status == 200 || res.statusText == "OK") {
  315. // xm.showToast({
  316. // message: res.data,
  317. // });
  318. }
  319. onClickLeft();
  320. });
  321. };
  322. return {
  323. isLoading,
  324. placeActivity,
  325. // 活动场所
  326. customFieldName,
  327. showPlace,
  328. places,
  329. getPlace,
  330. getLocation,
  331. // 活动时间
  332. showAct,
  333. columnsType,
  334. currentDate,
  335. currentTime,
  336. getTime,
  337. // 返回
  338. onClickLeft,
  339. // 人员选择
  340. showPerson,
  341. showReport,
  342. selected,
  343. reselected,
  344. // 文件上传
  345. afterRead,
  346. deleteRead,
  347. fileList,
  348. submit,
  349. subjectContentEditor,
  350. };
  351. },
  352. };
  353. </script>
  354. <style scoped>
  355. .van-uploader .van-button {
  356. border: none;
  357. color: #36a7f3;
  358. top: -4px;
  359. }
  360. .van-dialog {
  361. width: 80%;
  362. top: 50%;
  363. }
  364. .van-loading {
  365. text-align: center;
  366. margin-top: 80px;
  367. }
  368. </style>