placeTabletAdd.vue 12 KB

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