popupForm.vue 5.2 KB

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