siteInspectionView.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <van-nav-bar
  3. fixed
  4. title="场所检查情况上报"
  5. left-text=""
  6. left-arrow
  7. @click-left="onClickLeft"
  8. :style="{ 'background-color': selectColor }"
  9. />
  10. <van-loading size="16px" v-show="isLoading">加载中...</van-loading>
  11. <div class="main" v-show="!isLoading">
  12. <div class="formArea">
  13. <!-- <p class="miniTitle">基础信息</p> -->
  14. <van-cell-group>
  15. <van-field
  16. v-model="siteInspection.siteName.name"
  17. readonly
  18. required
  19. center
  20. label="场所名称:"
  21. placeholder="请选择"
  22. input-align="right"
  23. right-icon="arrow-down"
  24. @click="showPlace = true"
  25. />
  26. <van-popup v-model:show="showPlace" round position="bottom">
  27. <van-picker
  28. title="场所选择"
  29. :columns="places"
  30. :columns-field-names="customFieldName"
  31. @cancel="showPlace = false"
  32. @confirm="getPlace"
  33. />
  34. </van-popup>
  35. </van-cell-group>
  36. <van-cell-group>
  37. <van-field
  38. v-model="siteInspection.place"
  39. center
  40. readonly
  41. label="地点:"
  42. placeholder="请填写地点"
  43. input-align="right"
  44. right-icon="arrow-down"
  45. />
  46. <van-popup v-model:show="showArea" round position="bottom">
  47. <van-cascader
  48. v-model="cascaderValue"
  49. title="请选择所在地区"
  50. :options="options"
  51. @close="showArea = false"
  52. @finish="onFinish"
  53. :field-names="fieldNames"
  54. />
  55. </van-popup>
  56. </van-cell-group>
  57. <!-- <van-cell-group>
  58. <van-field
  59. v-model="siteInspection.placeDel"
  60. center
  61. label="详细地点:"
  62. placeholder="请填写详细地点"
  63. input-align="right"
  64. right-icon="location"
  65. />
  66. </van-cell-group> -->
  67. <van-cell-group>
  68. <van-field v-model="siteInspection.placeDel" center label="详细地址:" placeholder="请填写具体地址" input-align="right">
  69. <template #right-icon>
  70. <van-icon name="location" @click="getLocation" />
  71. </template>
  72. </van-field>
  73. </van-cell-group>
  74. <van-cell-group>
  75. <van-field
  76. v-model="siteInspection.supervisionTime"
  77. center
  78. readonly
  79. label="督查时间:"
  80. placeholder="请选择督查时间"
  81. input-align="right"
  82. right-icon="arrow-down"
  83. @click="showAct = true"
  84. />
  85. <van-popup v-model:show="showAct" round position="bottom">
  86. <van-picker-group
  87. title="督查时间"
  88. :tabs="['选择日期', '选择时间']"
  89. next-step-text="下一步"
  90. @confirm="getTime"
  91. @cancel="showAct = false"
  92. >
  93. <van-date-picker v-model="currentDate" />
  94. <van-time-picker v-model="currentTime" :columns-type="columnsType" />
  95. </van-picker-group>
  96. </van-popup>
  97. </van-cell-group>
  98. <van-cell-group>
  99. <van-field name="uploader" label="附件:">
  100. <template #input>
  101. <!-- <van-uploader
  102. :after-read="afterRead"
  103. v-model="fileList"
  104. :max-count="6"
  105. capture="camera"
  106. accept=""
  107. :before-delete="fjdelete"
  108. >
  109. <van-button icon="plus">上传文件</van-button>
  110. </van-uploader> -->
  111. <van-uploader readonly v-model="fileList" :max-count="5" accept="" :preview-full-image="false"
  112. :before-delete="deleteRead" @click-upload="chooseImg">
  113. <van-button>上传文件</van-button>
  114. </van-uploader>
  115. </template>
  116. </van-field>
  117. </van-cell-group>
  118. <van-cell-group>
  119. <div class="rowTextArea">
  120. <van-field
  121. v-model="siteInspection.supervisionContent"
  122. center
  123. rows="2"
  124. type="textarea"
  125. label="督查内容:"
  126. label-align="top"
  127. />
  128. </div>
  129. </van-cell-group>
  130. </div>
  131. <div class="subbtn">
  132. <van-button type="primary" @click="submit">提交</van-button>
  133. <van-button type="default" hairline>取消</van-button>
  134. </div>
  135. </div>
  136. </template>
  137. <script>
  138. import { reactive, ref , onMounted} from "vue";
  139. import personList from "../personList.vue";
  140. import siteInspectionService from "@/api/siteInspection/siteInspectionService";
  141. import { useRoute } from "vue-router";
  142. import tools from "@/api/sys/tools";
  143. // 图片路径
  144. import $base from "@/utils/config";
  145. export default {
  146. components: { personList },
  147. setup() {
  148. // 导航栏颜色
  149. const selectColor = ref(window.localStorage.getItem("MZ_COLOR"));
  150. const onClickLeft = () => {
  151. history.back();
  152. };
  153. const siteInspection = ref({
  154. id: "",
  155. siteName: {
  156. id: "",
  157. },
  158. place: "",
  159. placeDel: "",
  160. supervisionTime: "",
  161. supervisionContent: "",
  162. //附件
  163. enclosure: "",
  164. state: "0",
  165. assessment: "0",
  166. });
  167. // 根据路由初始化
  168. let route = useRoute();
  169. onMounted(() => {
  170. if (route.query.id) {
  171. new siteInspectionService().queryById(route.query.id).then((data) => {
  172. siteInspection.value = data;
  173. //附件处理
  174. siteInspection.value.enclosure.split("|").forEach((item) => {
  175. if (item.trim().length > 0) {
  176. fileList.value.push({
  177. name: decodeURIComponent(
  178. item.substring(item.lastIndexOf("/") + 1)
  179. ),
  180. url: $base + item.replace('程序附件//','程序附件/'),
  181. });
  182. fileupList.value.push({
  183. name: decodeURIComponent(
  184. item.substring(item.lastIndexOf("/") + 1)
  185. ),
  186. url: item,
  187. });
  188. }
  189. });
  190. });
  191. }
  192. });
  193. // 场所名称
  194. let places = ref([]);
  195. const customFieldName = {
  196. text: "name",
  197. value: "id",
  198. };
  199. new tools()
  200. .placeList({
  201. current: 1,
  202. size: 10000,
  203. })
  204. .then(({ records }) => {
  205. places.value.push(...records);
  206. });
  207. let showPlace = ref(false);
  208. const getPlace = ({ selectedOptions }) => {
  209. if(selectedOptions[0]!=undefined&&selectedOptions[0]!=null){
  210. showPlace.value = false;
  211. siteInspection.value.siteName = selectedOptions[0];
  212. siteInspection.value.place = selectedOptions[0].placeSelectName
  213. }
  214. };
  215. // 获取督查时间
  216. let showAct = ref(false);
  217. let currentDate = ref(["" + new Date().getFullYear(), "01", "01"]);
  218. let currentTime = ref(["00", "00"]);
  219. const columnsType = ['hour', 'minute', 'second'];
  220. const getTime = () => {
  221. showAct.value = false;
  222. siteInspection.value.supervisionTime = `${currentDate.value.join(
  223. "-"
  224. )} ${currentTime.value.join(":")}`;
  225. };
  226. let list = {
  227. value: [],
  228. type: "",
  229. };
  230. // 地区选择
  231. let showArea = ref(false);
  232. const cascaderValue = ref("");
  233. const fieldNames = {
  234. text: "name",
  235. value: "code",
  236. children: "children",
  237. };
  238. // 选项列表,children 代表子选项,支持多级嵌套
  239. let options = ref([]);
  240. new tools().treeData().then((res) => {
  241. options.value.push(res[0]);
  242. });
  243. // 全部选项选择完毕后,会触发 finish 事件
  244. const onFinish = ({ selectedOptions }) => {
  245. if(selectedOptions[0]!=undefined&&selectedOptions[0]!=null){
  246. showArea.value = false;
  247. siteInspection.value.place = selectedOptions
  248. .map((option) => option.name)
  249. .join("/");
  250. }
  251. };
  252. // 文件上传
  253. let fileList = ref([]);
  254. let fileupList = ref([]);
  255. const chooseImg = () => {
  256. xm.chooseFile({
  257. count: 1,
  258. name: "file",
  259. url: $base + `/sys/file/webupload/upload?uploadPath=csjcqk/siteInspection`,
  260. headers: { 'Content-Type': 'multipart/form-data', "token": window.localStorage.getItem('MZ_TOKEN') },
  261. }).then(res => {
  262. let data = res[0].data
  263. data.name = decodeURIComponent(
  264. data.id.substring(data.url.lastIndexOf("/") + 1)
  265. );
  266. data.url = $base + data.url;
  267. fileupList.value.push(data);
  268. fileList.value.push(data)
  269. })
  270. }
  271. // const afterRead = (file) => {
  272. // // 此时可以自行将文件上传至服务器
  273. // new tools()
  274. // .uploadFile(file, `csjcqk/siteInspection`)
  275. // .then(({ data }) => {
  276. // console.log(data);
  277. // data.name = decodeURIComponent(
  278. // data.url.substring(
  279. // data.url.lastIndexOf("/") + 1
  280. // )
  281. // );
  282. // //data.url = `${$base}` + data.url;
  283. // fileupList.value.push(data);
  284. // });
  285. // };
  286. // 删除文件
  287. const deleteRead = (file) => {
  288. //删除文件操作
  289. for (let index = 0; index < fileList.value.length; index++) {
  290. if (file.id == fileList.value[index].id) {
  291. fileList.value.splice(index, 1);
  292. if (fileupList.value[index]) {
  293. let delurl = fileupList.value[index].url;
  294. new tools().uploadFiledelete("", delurl).then(({ data }) => { });
  295. fileupList.value.splice(index, 1);
  296. }
  297. }
  298. }
  299. };
  300. // const fjdelete = (file) => {
  301. // //删除文件操作
  302. // for (let index = 0; index < fileList.value.length; index++) {
  303. // if(file.file==fileList.value[index].file){
  304. // let delurl=fileupList.value[index].url;
  305. // new tools()
  306. // .uploadFiledelete("", delurl)
  307. // .then(({ data }) => {
  308. // });
  309. // fileupList.value.splice(index,1);
  310. // fileList.value.splice(index,1);
  311. // }
  312. // }
  313. // };
  314. const getLocation = () => {
  315. xm.getLocation().then(data => {
  316. siteInspection.value.placeDel = data.POIName;
  317. })
  318. }
  319. // 提交数据
  320. const submit = () => {
  321. //添加保存前判断
  322. if(siteInspection.value.siteName.id==""){
  323. window.xm.showToast({
  324. message:"请先选择场所信息!"
  325. })
  326. }else{
  327. //保存前附件处理
  328. siteInspection.value.enclosure = fileupList.value.map((option) => option.id).join("|");
  329. new siteInspectionService().save(siteInspection.value).then((res) => {
  330. if(res.data=="保存场所检查情况成功"){
  331. window.xm.showToast({
  332. message:"保存成功!"
  333. })
  334. history.back();
  335. }
  336. });
  337. }
  338. };
  339. return {
  340. // 导航栏颜色
  341. selectColor,
  342. siteInspection,
  343. // 场所
  344. customFieldName,
  345. showPlace,
  346. places,
  347. getPlace,
  348. // 时间
  349. showAct,
  350. currentDate,
  351. currentTime,
  352. columnsType,
  353. getTime,
  354. // 返回
  355. onClickLeft,
  356. // 地区选择
  357. showArea,
  358. fieldNames,
  359. options,
  360. onFinish,
  361. cascaderValue,
  362. getLocation,
  363. // 文件上传
  364. chooseImg,
  365. fileList,
  366. fileupList,
  367. deleteRead,
  368. submit,
  369. };
  370. },
  371. };
  372. </script>
  373. <style scoped>
  374. .van-cell__value .van-field__right-icon .van-icon-location {
  375. color: #36a7f3 !important;
  376. }
  377. .van-uploader .van-button {
  378. border: none;
  379. color: #36a7f3;
  380. top: -4px;
  381. }
  382. .van-dialog {
  383. width: 80%;
  384. top: 50%;
  385. }
  386. .van-loading {
  387. text-align: center;
  388. margin-top: 80px;
  389. }
  390. .preview-cover {
  391. position: absolute;
  392. bottom: 0;
  393. box-sizing: border-box;
  394. width: 100%;
  395. padding: 4px;
  396. color: #fff;
  397. font-size: 12px;
  398. text-align: center;
  399. background: rgba(0, 0, 0, 0.3);
  400. }
  401. .rowTextArea::v-deep .van-field__value {
  402. width: 94%;
  403. border: 2px solid #ccc;
  404. border-radius: 10px;
  405. padding: 10px;
  406. }
  407. .rowTextArea::v-deep .van-cell {
  408. display: flow-root;
  409. }
  410. </style>