siteInspectionView.vue 10.0 KB

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