placeTabletAdd.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <van-nav-bar
  3. fixed
  4. title="牌位信息录入"
  5. left-arrow
  6. @click-left="onClickLeft"
  7. :style="{ 'background-color': selectColor }"
  8. />
  9. <div class="main">
  10. <van-cell-group>
  11. <van-field
  12. v-model="inputForm.brandName"
  13. center
  14. required
  15. label="牌位名称:"
  16. placeholder="请填写牌位名称"
  17. input-align="right"
  18. />
  19. </van-cell-group>
  20. <van-cell-group>
  21. <van-field
  22. v-model="locationName"
  23. readonly
  24. required
  25. label="所属场所:"
  26. placeholder="请选择所属场所"
  27. input-align="right"
  28. right-icon="arrow-down"
  29. @click="hs_site = true"
  30. >
  31. </van-field>
  32. <van-dialog v-model:show="hs_site" title="所属场所" show-cancel-button>
  33. <div class="dialog">
  34. <van-list
  35. v-model:loading="loading"
  36. :finished="finished"
  37. finished-text="没有更多了"
  38. @load="onLoad"
  39. >
  40. <van-radio-group v-model="checked">
  41. <van-cell-group inset>
  42. <van-cell
  43. v-for="item in sitelist"
  44. :key="item"
  45. :title="item.name"
  46. clickable
  47. @click="getsite(item)"
  48. >
  49. <template #right-icon>
  50. <van-radio :name="item.id" />
  51. </template>
  52. </van-cell>
  53. </van-cell-group>
  54. </van-radio-group>
  55. </van-list>
  56. </div>
  57. </van-dialog>
  58. </van-cell-group>
  59. <van-cell-group>
  60. <van-field
  61. v-model="inputForm.siteContact"
  62. center
  63. disabled
  64. label="场所联系人:"
  65. placeholder="请填写场所联系人"
  66. input-align="right"
  67. />
  68. </van-cell-group>
  69. <van-cell-group>
  70. <van-field
  71. v-model="inputForm.contactInformation"
  72. center
  73. disabled
  74. label="联系方式:"
  75. placeholder="请填写联系方式"
  76. input-align="right"
  77. />
  78. </van-cell-group>
  79. <van-cell-group>
  80. <van-field
  81. v-model="inputForm.memorialTabletHolder"
  82. center
  83. label="供奉牌位人:"
  84. placeholder="请填写供奉牌位人"
  85. input-align="right"
  86. />
  87. </van-cell-group>
  88. <van-cell-group>
  89. <van-field
  90. v-model="inputForm.memorialTabletHolderPhone"
  91. center
  92. label-width="8em"
  93. label="供奉牌位人电话:"
  94. placeholder="请填写供奉牌位人电话"
  95. input-align="right"
  96. />
  97. </van-cell-group>
  98. <van-cell-group>
  99. <van-field
  100. v-model="inputForm.udCard"
  101. center
  102. required
  103. label="身份证号:"
  104. placeholder="请填写身份证号"
  105. input-align="right"
  106. />
  107. </van-cell-group>
  108. <van-cell-group>
  109. <van-field
  110. v-model="inputForm.nativePlace"
  111. readonly
  112. required
  113. label="籍贯:"
  114. placeholder="请选择籍贯地区"
  115. input-align="right"
  116. right-icon="arrow-down"
  117. @click="hs_nativePlace = true"
  118. />
  119. <van-popup v-model:show="hs_nativePlace" round position="bottom">
  120. <van-picker
  121. title="籍贯"
  122. :columns="nativePlace"
  123. :columns-field-names="customFieldName"
  124. @cancel="hs_nativePlace = false"
  125. @confirm="getnativePlace"
  126. />
  127. </van-popup>
  128. </van-cell-group>
  129. <van-cell-group>
  130. <van-field
  131. v-model="inputForm.currentResidence"
  132. center
  133. readonly
  134. required
  135. label="现居地:"
  136. placeholder="请填写现居地"
  137. input-align="right"
  138. right-icon="arrow-down"
  139. @click="showPlace1 = true"
  140. />
  141. <van-popup v-model:show="showPlace1" round position="bottom">
  142. <van-picker
  143. title="现居地选择"
  144. :columns="options"
  145. :columns-field-names="customFieldName"
  146. @cancel="showPlace1 = false"
  147. @confirm="getPlace1"
  148. />
  149. </van-popup>
  150. </van-cell-group>
  151. <van-cell-group>
  152. <van-field
  153. v-model="inputForm.currentResidenceDel"
  154. center
  155. label="现居地详情:"
  156. placeholder="请填写现居地详情"
  157. input-align="right"
  158. />
  159. </van-cell-group>
  160. <van-cell-group>
  161. <van-field
  162. v-model="inputForm.relationship"
  163. center
  164. label-width="8em"
  165. label="与供奉牌位关系:"
  166. placeholder="请填写与供奉牌位关系"
  167. input-align="right"
  168. />
  169. </van-cell-group>
  170. <van-cell-group>
  171. <van-field
  172. v-model="inputForm.sacrificeExpenses"
  173. center
  174. label-width="10em"
  175. label="供奉费用(元/年):"
  176. placeholder="请填写供奉费用"
  177. input-align="right"
  178. />
  179. </van-cell-group>
  180. <van-cell-group>
  181. <van-field
  182. v-model="inputForm.position"
  183. center
  184. label="牌位位置:"
  185. placeholder="请填写牌位位置"
  186. input-align="right"
  187. />
  188. </van-cell-group>
  189. <van-cell-group>
  190. <van-field
  191. v-model="inputForm.information"
  192. rows="2"
  193. autosize
  194. label-width="8em"
  195. label="被供奉者信息:"
  196. type="textarea"
  197. maxlength="50"
  198. placeholder="请填写被供奉者信息"
  199. show-word-limit
  200. input-align="right"
  201. />
  202. </van-cell-group>
  203. <van-cell-group>
  204. <van-field name="uploader" label-align="top" label="牌位照片:">
  205. <template #input>
  206. <van-uploader readonly v-model="fileList" :max-count="5" accept="" :preview-full-image="false"
  207. :before-delete="deleteRead" @click-upload="chooseImg">
  208. </van-uploader>
  209. </template>
  210. </van-field>
  211. </van-cell-group>
  212. <div class="subbtn">
  213. <van-button type="primary" @click="submit">提交</van-button>
  214. <van-button @click="onClickLeft" type="default" hairline>取消</van-button>
  215. </div>
  216. </div>
  217. </template>
  218. <script>
  219. import { onMounted, ref } from "vue";
  220. import TabletServer from "@/api/tabletManage/TabletServer";
  221. import placePerson from "@/api/placePerson/placePerson";
  222. import PlaceRegister from "@/api/placeRegister/placeRegister";
  223. import tools from "@/api/sys/tools";
  224. import $base from "@/utils/config";
  225. export default {
  226. setup() {
  227. const onClickLeft = () => {
  228. history.back();
  229. };
  230. const inputForm = ref({
  231. id: "",
  232. brandName: "",
  233. siteName: {
  234. id: "",
  235. },
  236. siteContact: "",
  237. contactInformation: "",
  238. memorialTabletHolder: "",
  239. memorialTabletHolderPhone: "",
  240. udCard: "",
  241. nativePlace: "",
  242. currentResidence: "",
  243. currentResidenceDel: "",
  244. relationship: "",
  245. sacrificeExpenses: "",
  246. position: "",
  247. state: "0",
  248. keepOnRecord: "0",
  249. pic: "",
  250. information: "",
  251. });
  252. onMounted(() => {
  253. //籍贯接口
  254. new placePerson().nativePlace().then((res) => {
  255. nativePlace.value.push(...res);
  256. options.value.push(...res);
  257. });
  258. });
  259. // 所属场所
  260. const locationName = ref("");
  261. const checked = ref("");
  262. const sitelist = ref([]);
  263. let hs_site = ref(false);
  264. const getsite = (val) => {
  265. locationName.value = val.name;
  266. const json = Object.assign(inputForm.value, {
  267. siteName: { id: val.id },
  268. siteContact: val.contact,
  269. contactInformation: val.contactNumber,
  270. });
  271. inputForm.value = json;
  272. checked.value = val.id;
  273. };
  274. const loading = ref(false);
  275. const finished = ref(false);
  276. const refreshing = ref(false);
  277. let index = 0;
  278. const onLoad = () => {
  279. loading.value = true;
  280. finished.value = false;
  281. // 异步更新数据
  282. new PlaceRegister()
  283. .religiousList({
  284. current: index + 1,
  285. size: 10,
  286. })
  287. .then(({ records, pages }) => {
  288. sitelist.value = sitelist.value.concat(records);
  289. // 加载状态结束
  290. loading.value = false;
  291. if (index + 1 >= pages) {
  292. finished.value = true;
  293. }
  294. index++;
  295. });
  296. };
  297. //籍贯
  298. const customFieldName = {
  299. text: "name",
  300. value: "id",
  301. };
  302. const options = ref([]);
  303. const nativePlace = ref([]);
  304. let hs_nativePlace = ref(false);
  305. const getnativePlace = ({ selectedOptions }) => {
  306. hs_nativePlace.value = false;
  307. let str = "";
  308. selectedOptions.forEach((item) => {
  309. if (inputForm.nativePlace) {
  310. str = inputForm.nativePlace;
  311. }
  312. str += item.name + "/";
  313. });
  314. inputForm.nativePlace = str;
  315. const json = Object.assign(inputForm.value, { nativePlace: str });
  316. inputForm.value = json;
  317. };
  318. //现居地
  319. let placeAddress = ref("");
  320. let showPlace1 = ref(false);
  321. const getPlace1 = ({ selectedOptions }) => {
  322. showPlace1.value = false;
  323. let str1 = "";
  324. selectedOptions.forEach((item) => {
  325. if (inputForm.currentResidence) {
  326. str1 = inputForm.currentResidence;
  327. }
  328. str1 += item.name + "/";
  329. });
  330. const json = Object.assign(inputForm.value, {
  331. currentResidence: str1,
  332. });
  333. inputForm.value = json;
  334. };
  335. //图片上传
  336. let fileList = ref([]);
  337. let fileImg = ref([]);
  338. const chooseImg = () => {
  339. xm.chooseFile({
  340. count: 1,
  341. name: "file",
  342. url: $base + `/sys/file/webupload/upload?uploadPath=placememorialtablets/placeMemorialTablets`,
  343. headers: { 'Content-Type': 'multipart/form-data', "token": window.localStorage.getItem('MZ_TOKEN') },
  344. }).then(res => {
  345. let data = res[0].data
  346. data.name = decodeURIComponent(
  347. data.id.substring(data.url.lastIndexOf("/") + 1)
  348. );
  349. data.url = $base + data.url;
  350. fileImg.value.push(data);
  351. fileList.value.push(data)
  352. })
  353. }
  354. // 删除文件
  355. const deleteRead = (file) => {
  356. //删除文件操作
  357. for (let index = 0; index < fileList.value.length; index++) {
  358. if (file.id == fileList.value[index].id) {
  359. fileList.value.splice(index, 1);
  360. if (fileImg.value[index]) {
  361. let delurl = fileImg.value[index].url;
  362. new tools().uploadFiledelete("", delurl).then(({ data }) => { });
  363. fileImg.value.splice(index, 1);
  364. }
  365. }
  366. }
  367. };
  368. //数据提交
  369. const submit = () => {
  370. inputForm.value.pic = fileImg.value
  371. .map((option) => option.id)
  372. .join("|");
  373. new TabletServer().save(inputForm.value).then((res) => {
  374. console.log(res);
  375. if (res.status == 200) {
  376. xm.showToast({
  377. message: "牌位信息添加成功",
  378. });
  379. router.push({
  380. path: "/placeTablet",
  381. });
  382. }else{
  383. xm.showToast({
  384. message: "牌位信息添加失败",
  385. });
  386. console.log(res);
  387. }
  388. });
  389. };
  390. return {
  391. inputForm,
  392. onClickLeft,
  393. //所属场所
  394. locationName,
  395. checked,
  396. hs_site,
  397. getsite,
  398. sitelist,
  399. loading,
  400. finished,
  401. onLoad,
  402. refreshing,
  403. //籍贯
  404. nativePlace,
  405. hs_nativePlace,
  406. getnativePlace,
  407. customFieldName,
  408. //现居地
  409. options,
  410. placeAddress,
  411. showPlace1,
  412. getPlace1,
  413. //图片上传
  414. fileList,
  415. chooseImg,
  416. //图片删除
  417. deleteRead,
  418. submit
  419. };
  420. },
  421. };
  422. </script>
  423. <style>
  424. .dialog {
  425. width: 100%;
  426. height: 400px;
  427. overflow: auto;
  428. }
  429. .subbtn {
  430. margin: 20px;
  431. text-align: center;
  432. }
  433. .subbtn .van-button {
  434. width: 40%;
  435. margin: 5px;
  436. }
  437. </style>