add.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <script setup>
  2. import { useRouter, useRoute } from 'vue-router';
  3. import { servicesApi } from '@/api/voice/services';
  4. import { noticeApi } from '@/api/voice/notice';
  5. import { ElMessage } from 'element-plus'
  6. import BaseLayoutViewport from '@/components/BaseLayout';
  7. const router = useRouter();
  8. const route = useRoute();
  9. const formRef = ref(null);
  10. const pumpingValue = ref(null);
  11. const housingValue = ref(null);
  12. const pumpingOptions = ref([]);
  13. const housingOptions = ref([]);
  14. const formData = ref({
  15. timeBegin: '',
  16. timeEnd: '',
  17. reason: ''
  18. })
  19. const tableData = ref([]);
  20. const rules = reactive({
  21. timeBegin: [
  22. { required: true, message: '请选择停水时间', trigger: 'blur' },
  23. ],
  24. reason: [
  25. { required: true, message: '请输入停水原因', trigger: 'blur' },
  26. ]
  27. });
  28. // 删除
  29. const handleDelRow = (row) => {
  30. tableData.value.splice(row.$index, 1);
  31. }
  32. // 添加泵站
  33. const addTableData = async (type) => {
  34. if ( type == 0 && !pumpingValue.value) {
  35. return ElMessage.warning("请先选择泵站");
  36. }
  37. if ( type == 1 && !housingValue.value) {
  38. return ElMessage.warning("请先选择小区");
  39. }
  40. const { data } = await noticeApi.getExtraListByType({ type, id: type == 0 ? pumpingValue.value : housingValue.value })
  41. const combined = tableData.value.concat(data);
  42. const unique = Array.from(new Map(combined.map(item => [JSON.stringify([item.neighbourhoodId, item.pumpingStationId]), item])).values());
  43. tableData.value = unique;
  44. }
  45. // 最终提交
  46. const submitForm = async () => {
  47. if (!formRef.value) return;
  48. await formRef.value.validate(async (valid) => {
  49. if (valid) {
  50. if ( !tableData.value.length ) {
  51. return ElMessage.warning("请先选择停水范围");
  52. }
  53. const id = route.query.id;
  54. if (id) {
  55. await noticeApi.putWater({...formData.value, extraResList: tableData.value}).then(() => {
  56. ElMessage.success("停水公告修改成功");
  57. })
  58. } else {
  59. await noticeApi.postWater({...formData.value, extraResList: tableData.value}).then(() => {
  60. ElMessage.success("停水公告添加成功");
  61. })
  62. }
  63. goBack();
  64. }
  65. })
  66. }
  67. const goBack = () => {
  68. router.push('/voice/notice')
  69. }
  70. const onCleanTableData = () => {
  71. tableData.value = [];
  72. pumpingValue.value = [];
  73. housingValue.value = [];
  74. }
  75. onMounted(() => {
  76. const id = route.query.id;
  77. if ( id ) {
  78. noticeApi.getWater(id).then(({ data }) => {
  79. const { timeBegin, timeEnd, reason, extraResList } = data;
  80. formData.value = {
  81. timeBegin,
  82. timeEnd,
  83. reason,
  84. id
  85. }
  86. tableData.value = extraResList;
  87. })
  88. }
  89. // 泵站
  90. servicesApi.getPumpingList({pageSize: 10000, pageNum: 1}).then(res => {
  91. pumpingOptions.value = res.data;
  92. })
  93. // 小区
  94. servicesApi.getNeighborhoodList({pageSize: 10000, pageNum: 1}).then(res => {
  95. housingOptions.value = res.rows;
  96. })
  97. })
  98. </script>
  99. <template>
  100. <BaseLayoutViewport title="添加停水公告">
  101. <div class="px-[20px]">
  102. <div class="reply-tips-card space-x-[4px]">
  103. <img src="@/assets/images/notice/icon-tips.svg" alt="">
  104. <ul class="tips-content space-y-[8px]">
  105. <li>语音回复话术:</li>
  106. <li>
  107. <span>#停水原因#</span>,于<span>#停水时间#</span>进行停水处理,预计<span>#供水恢复时间#</span> 恢复供水。如遇到其他情况无法按时恢复供水,请关注****公众号获取最新恢复供水时间
  108. <br>或再次拨打190热线进行咨询。
  109. </li>
  110. </ul>
  111. </div>
  112. <div class="pt-[20px]">
  113. <el-form :model="formData" :rules="rules" ref="formRef" label-width="auto" label-position="left">
  114. <el-row :gutter="20" style="width: 900px;">
  115. <el-col :span="24" style="display: flex; align-items: flex-start; justify-content: space-between;">
  116. <el-form-item label="停水时间" prop="timeBegin">
  117. <div>
  118. <el-date-picker
  119. v-model="formData.timeBegin"
  120. type="datetime"
  121. placeholder="请选择停水时间"
  122. style="width: 280px;"
  123. value-format="YYYY-MM-DD HH:mm:ss"
  124. />
  125. </div>
  126. </el-form-item>
  127. <el-form-item label="恢复供水时间" prop="timeEnd">
  128. <div>
  129. <el-date-picker
  130. v-model="formData.timeEnd"
  131. type="datetime"
  132. placeholder="请选择恢复供水时间"
  133. style="width: 280px;"
  134. value-format="YYYY-MM-DD HH:mm:ss"
  135. />
  136. <p class="h-[22px] text-[12px] text-[#999]">如无法确定恢复供水时间, 则不填写</p>
  137. </div>
  138. </el-form-item>
  139. </el-col>
  140. <el-col :span="24">
  141. <el-form-item label="停水原因" prop="reason">
  142. <el-input v-model="formData.reason" placeholder="请输入停水原因" type="textarea" :autosize="{ minRows: 8, maxRows: 6 }" resize="none"/>
  143. </el-form-item>
  144. </el-col>
  145. </el-row>
  146. <div>
  147. <el-form-item label="停水范围" required style="width: 100%;">
  148. <div class="flex justify-between">
  149. <ul class="select-group space-x-[40px] mr-[20px]" style="width: 784px;">
  150. <li class="space-x-[5px]">
  151. <span>根据泵站添加:</span>
  152. <!-- multiple
  153. collapse-tags
  154. collapse-tags-tooltip
  155. :max-collapse-tags="1" -->
  156. <el-select
  157. v-model="pumpingValue"
  158. placeholder="请选择"
  159. filterable
  160. style="width: 200px;"
  161. >
  162. <el-option
  163. v-for="item in pumpingOptions"
  164. :key="item.id"
  165. :label="item.name"
  166. :value="item.id"
  167. />
  168. </el-select>
  169. <div class="custom-btn custom-btn_primary" @click="addTableData(0)">添加</div>
  170. </li>
  171. <li class="space-x-[5px]">
  172. <span>根据小区添加:</span>
  173. <el-select
  174. v-model="housingValue"
  175. placeholder="请选择"
  176. filterable
  177. style="width: 200px;"
  178. >
  179. <el-option
  180. v-for="item in housingOptions"
  181. :key="item.id"
  182. :label="item.name"
  183. :value="item.id"
  184. />
  185. </el-select>
  186. <div class="custom-btn custom-btn_primary" @click="addTableData(1)">添加</div>
  187. </li>
  188. </ul>
  189. <div class="custom-btn custom-btn_primary" @click="onCleanTableData">重置</div>
  190. </div>
  191. </el-form-item>
  192. </div>
  193. </el-form>
  194. </div>
  195. <div class="table-card">
  196. <el-table :data="tableData" style="width: 100%" >
  197. <el-table-column prop="pumpingStationName" label="所属泵站" align="center" />
  198. <el-table-column prop="neighbourhoodName" label="小区名称" align="center"></el-table-column>
  199. <el-table-column prop="neighbourhoodNumberNames" label="楼号" align="center" />
  200. <el-table-column prop="neighbourhoodAddress" label="详细地址" align="center" />
  201. <el-table-column prop="address" label="操作" align="center" width="150">
  202. <template #default="scope">
  203. <span class="text-[#165DFF] cursor-pointer" @click="handleDelRow(scope)">删除</span>
  204. </template>
  205. </el-table-column>
  206. </el-table>
  207. </div>
  208. </div>
  209. <template #footer>
  210. <ul class="flex justify-center space-x-[12px]">
  211. <li class="custom-btn custom-btn_primary" @click="submitForm">保存</li>
  212. <li class="custom-btn custom-btn_default" @click="goBack">返回</li>
  213. </ul>
  214. </template>
  215. </BaseLayoutViewport>
  216. </template>
  217. <style lang="scss" scoped>
  218. .title {
  219. margin-bottom: 24px;
  220. color: #1D2129;
  221. font-size: 18px;
  222. font-weight: bold;
  223. line-height: 26px;
  224. }
  225. :deep(.el-date-editor) {
  226. .el-input__wrapper {
  227. height: 36px;
  228. }
  229. &.el-input {
  230. height: 36px;
  231. }
  232. }
  233. .reply-tips-card {
  234. display: flex;
  235. align-items: start;
  236. height: 100px;
  237. padding: 14px 0 0 16px;
  238. border-radius: 8px;
  239. background: #E6EEFF;
  240. overflow: hidden;
  241. img {
  242. width: 24px;
  243. height: 24px;
  244. flex-shrink: 0;
  245. }
  246. .tips-content {
  247. li:nth-child(1) {
  248. font-weight: bold;
  249. font-size: 16px;
  250. line-height: 24px;
  251. }
  252. li:nth-child(2) {
  253. font-size: 14px;
  254. line-height: 22px;
  255. white-space:nowrap;
  256. span {
  257. color: #165DFF;
  258. }
  259. }
  260. }
  261. }
  262. .select-group {
  263. display: flex;
  264. justify-content: space-between;
  265. width: 100%;
  266. li {
  267. display: flex;
  268. span {
  269. font-size: 14px;
  270. white-space: nowrap;
  271. color: #86909C;
  272. }
  273. // reset select
  274. :deep(.el-select__wrapper) {
  275. height: 100%;
  276. min-height: auto;
  277. }
  278. // reset date-picker
  279. :deep(.el-input__icon ) {
  280. display: none;
  281. }
  282. }
  283. }
  284. </style>