popupForm.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <!-- 对话框表单 -->
  3. <el-dialog custom-class="ba-operate-dialog" :close-on-click-modal="false"
  4. :model-value="baTable.form.operate ? true : false" @close="baTable.toggleForm"
  5. width="30%"
  6. >
  7. <template #header>
  8. <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
  9. {{ baTable.form.operate ? baTable.form.operate == "edit" ? "编辑" : "添加" : "无标题" }}
  10. </div>
  11. </template>
  12. <el-scrollbar v-loading="baTable.form.loading">
  13. <div class="ba-operate-form" :class="'ba-' + baTable.form.operate + '-form'"
  14. style="width: calc(100% - 40px);margin-bottom: 40px;">
  15. <el-form ref="formRef" @keyup.enter="baTable.onSubmit(formRef)" :model="baTable.form.items"
  16. label-position="right" :label-width="'100px'" :rules="rules"
  17. v-if="!baTable.form.loading">
  18. <el-form-item label="所在区(县)" v-if="baTable.form.operate == 'add'">
  19. <el-select v-model="districtId" placeholder="请选择" style="width: 100%" @change="selectDstrict"
  20. >
  21. <el-option v-for="item in districtList" :label="item.districtName" :value="item.id"></el-option>
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item prop="communityId" label="所在小区">
  25. <el-select v-model="baTable.form.items!.communityId" placeholder="请选择" style="width: 100%"
  26. @change="selectCommunity" v-if="baTable.form.operate == 'add'">
  27. <el-option v-for="item in communityList" :label="item.communityName" :value="item.id"></el-option>
  28. </el-select>
  29. <el-input v-else :disabled="true" v-model="baTable.form.items!.communityName"></el-input>
  30. </el-form-item>
  31. <el-form-item prop="buildingIds" label="相关楼号">
  32. <el-select v-model="baTable.form.items!.buildingIds" placeholder="请选择" style="width: 100%" clearable
  33. multiple>
  34. <el-option v-for="item in buildingList" :label="item.buildingNumber" :value="item.id"></el-option>
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item prop="mapUrl" label="上传地图">
  38. <pictureUpload v-model:fileUrl="baTable.form.items!.mapUrl"></pictureUpload>
  39. </el-form-item>
  40. </el-form>
  41. </div>
  42. </el-scrollbar>
  43. <template #footer>
  44. <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
  45. <el-button @click="baTable.toggleForm('')">取消</el-button>
  46. <el-button v-blur :loading="baTable.form.submitLoading" @click="onSubmit" type="primary">
  47. {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? "保存并编辑下一项" : "保存" }}
  48. </el-button>
  49. </div>
  50. </template>
  51. </el-dialog>
  52. </template>
  53. <script setup lang="ts">
  54. import { ref, reactive, inject, onMounted, watch } from "vue";
  55. import type baTableClass from "/@/utils/baTable";
  56. import type { ElForm, FormItemRule } from "element-plus";
  57. import FormItem from "/@/components/formItem/index.vue";
  58. import { building_list, community_list, district_list, orderExpress } from "/@/api/controllerUrls";
  59. import { ElNotification } from "element-plus/es";
  60. import pictureUpload from "/@/components/pictureUpload/multiple.vue";
  61. import request from "/@/api/request";
  62. const formRef = ref<InstanceType<typeof ElForm>>();
  63. const baTable = inject("baTable") as baTableClass;
  64. console.log(baTable.mapInfo);
  65. const rules: Partial<Record<string, FormItemRule[]>> = reactive({
  66. communityId: [
  67. {
  68. required: true,
  69. message: "请选择",
  70. trigger: "blur"
  71. }
  72. ],
  73. buildingIds: [
  74. {
  75. required: true,
  76. message: "请选择",
  77. trigger: "blur"
  78. }
  79. ],
  80. mapUrl: [
  81. {
  82. required: true,
  83. message: "请上传",
  84. trigger: "blur"
  85. }
  86. ]
  87. });
  88. onMounted(() => {
  89. getInitData();
  90. });
  91. watch(() => baTable.mapInfo.value, (nValue, oValue) => {
  92. if (baTable.form.operate == "edit") {
  93. selectCommunity(nValue.communityId);
  94. }
  95. });
  96. //区县列表
  97. let districtList = ref([]);
  98. let districtId = ref("");
  99. function getInitData() {
  100. request.index(district_list, {}, "").then((res: any) => {
  101. if (res.code == 1) {
  102. districtList.value = res.data;
  103. }
  104. });
  105. }
  106. //小区列表
  107. let communityList = ref([]);
  108. //选择区县,获取小区列表
  109. function selectDstrict(event: any) {
  110. request.index(community_list, {
  111. districtIds: event
  112. }, "").then((res: any) => {
  113. if (res.code == 1) {
  114. communityList.value = res.data;
  115. }
  116. });
  117. }
  118. //楼号列表
  119. let buildingList = ref([]);
  120. //选择小区,获取楼号列表
  121. function selectCommunity(event: any) {
  122. request.index(building_list, {
  123. communityIds: event
  124. }, "").then((res: any) => {
  125. if (res.code == 1) {
  126. buildingList.value = res.data;
  127. }
  128. });
  129. }
  130. function onSubmit(){
  131. delete baTable.form.items!.communityName
  132. baTable.onSubmit(formRef.value)
  133. }
  134. </script>
  135. <style scoped lang="scss">
  136. .avatar-uploader {
  137. display: flex;
  138. align-items: center;
  139. justify-content: center;
  140. position: relative;
  141. border-radius: var(--el-border-radius-small);
  142. box-shadow: var(--el-box-shadow-light);
  143. border: 1px dashed var(--color-sub-1);
  144. cursor: pointer;
  145. overflow: hidden;
  146. width: 110px;
  147. height: 110px;
  148. }
  149. .avatar-uploader:hover {
  150. border-color: var(--color-primary);
  151. }
  152. .avatar {
  153. width: 110px;
  154. height: 110px;
  155. display: block;
  156. }
  157. .image-slot {
  158. display: flex;
  159. align-items: center;
  160. justify-content: center;
  161. height: 100%;
  162. }
  163. </style>