interactPopup.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <popup
  3. class="interact-popup"
  4. v-model:show="show"
  5. closeable
  6. :close-on-click-overlay="false"
  7. @closed="handleClosed"
  8. >
  9. <div class="interact-header">
  10. <div class="interact-title">{{ interactTitle }}</div>
  11. </div>
  12. <div class="interact-form">
  13. <div class="form-item">
  14. <div class="form-label">
  15. <span class="required">*</span>
  16. 请选择互动时间
  17. </div>
  18. <div class="form-input-wrapper">
  19. <el-date-picker
  20. v-model="interactTime"
  21. size="large"
  22. style="width: 100%"
  23. type="date"
  24. placeholder="请选择日期"
  25. :editable="false"
  26. />
  27. </div>
  28. </div>
  29. <div class="form-item">
  30. <div class="form-label">
  31. <span class="required">*</span>
  32. 请选择强制触发互动时间
  33. </div>
  34. <div class="form-input-wrapper">
  35. <el-date-picker
  36. v-model="forceTriggerTime"
  37. size="large"
  38. style="width: 100%"
  39. type="date"
  40. placeholder="请选择日期"
  41. :editable="false"
  42. />
  43. </div>
  44. </div>
  45. <div class="form-item">
  46. <div class="form-label">
  47. <span class="required">*</span>
  48. 请设置互动问题
  49. </div>
  50. <el-input
  51. v-model="interactQuestion"
  52. type="textarea"
  53. :rows="4"
  54. placeholder="请设置互动问题"
  55. class="question-textarea"
  56. />
  57. </div>
  58. </div>
  59. <div class="interact-buttons">
  60. <div class="btn-delete" @click="handleDeleteInteract">删除互动</div>
  61. <div class="btn-save" :class="{ disabled: isSaving }" @click="handleSaveInteract">
  62. {{ saveButtonText }}
  63. </div>
  64. </div>
  65. </popup>
  66. </template>
  67. <script setup>
  68. import { Popup } from "vant";
  69. import { ref, computed } from "vue";
  70. import { ElMessage, ElMessageBox } from "element-plus";
  71. // Emits
  72. const emit = defineEmits(["handleSaveSuccess", "handleDeleteInteract"]);
  73. // 响应式数据
  74. const show = ref(false);
  75. const arrangeId = ref(null);
  76. const isSaving = ref(false);
  77. const interactTitle = ref("梢期杀虫");
  78. const interactTime = ref("");
  79. const forceTriggerTime = ref("");
  80. const interactQuestion = ref("");
  81. // 计算属性
  82. const saveButtonText = computed(() => (isSaving.value ? "保存中..." : "保存修改"));
  83. // 工具函数
  84. const resetInteractData = () => {
  85. interactTime.value = "";
  86. forceTriggerTime.value = "";
  87. interactQuestion.value = "";
  88. };
  89. // 验证函数
  90. const validateInteractForm = () => {
  91. if (!interactTime.value) {
  92. ElMessage.warning("请选择互动时间");
  93. return false;
  94. }
  95. if (!forceTriggerTime.value) {
  96. ElMessage.warning("请选择强制触发互动时间");
  97. return false;
  98. }
  99. if (!interactQuestion.value?.trim()) {
  100. ElMessage.warning("请设置互动问题");
  101. return false;
  102. }
  103. return true;
  104. };
  105. // 显示弹窗方法
  106. const showPopup = ({
  107. arrangeIdVal,
  108. interactTitleVal,
  109. interactTimeVal,
  110. forceTriggerTimeVal,
  111. interactQuestionVal,
  112. }) => {
  113. // 重置数据
  114. resetInteractData();
  115. // 设置数据
  116. arrangeId.value = arrangeIdVal;
  117. interactTitle.value = interactTitleVal || "梢期杀虫";
  118. interactTime.value = interactTimeVal || "";
  119. forceTriggerTime.value = forceTriggerTimeVal || "";
  120. interactQuestion.value = interactQuestionVal || "";
  121. isSaving.value = false;
  122. show.value = true;
  123. };
  124. // 事件处理函数
  125. const handleDeleteInteract = () => {
  126. ElMessageBox.confirm("确定要删除该互动设置吗?", "提示", {
  127. confirmButtonText: "确定",
  128. cancelButtonText: "取消",
  129. type: "warning",
  130. })
  131. .then(() => {
  132. emit("handleDeleteInteract", { arrangeId: arrangeId.value });
  133. show.value = false;
  134. ElMessage.success("删除成功");
  135. })
  136. .catch(() => {
  137. // 用户取消,不做任何操作
  138. });
  139. };
  140. const handleSaveInteract = () => {
  141. if (isSaving.value || !validateInteractForm()) return;
  142. isSaving.value = true;
  143. const paramsObj = {
  144. arrangeId: arrangeId.value,
  145. interactTime: interactTime.value,
  146. forceTriggerTime: forceTriggerTime.value,
  147. interactQuestion: interactQuestion.value.trim(),
  148. };
  149. // TODO: 调用保存互动设置的API
  150. // VE_API.monitor.saveInteractSetting(paramsObj)
  151. // .then((res) => {
  152. // if (res.code === 0) {
  153. // ElMessage.success("保存成功");
  154. // show.value = false;
  155. // emit("handleSaveSuccess", paramsObj);
  156. // } else {
  157. // ElMessage.error(res.message || "保存失败");
  158. // }
  159. // })
  160. // .catch((error) => {
  161. // console.error("保存互动设置失败:", error);
  162. // ElMessage.error("保存失败,请重试");
  163. // })
  164. // .finally(() => {
  165. // isSaving.value = false;
  166. // });
  167. // 临时模拟保存成功
  168. setTimeout(() => {
  169. ElMessage.success("保存成功");
  170. show.value = false;
  171. emit("handleSaveSuccess", paramsObj);
  172. isSaving.value = false;
  173. }, 500);
  174. };
  175. const handleClosed = () => {
  176. resetInteractData();
  177. };
  178. // 暴露方法
  179. defineExpose({
  180. showPopup,
  181. });
  182. </script>
  183. <style lang="scss" scoped>
  184. .interact-popup {
  185. width: 90%;
  186. box-sizing: border-box;
  187. background: #ffffff;
  188. padding: 0;
  189. border-radius: 10px;
  190. ::v-deep {
  191. .van-popup__close-icon {
  192. color: #000;
  193. }
  194. }
  195. .interact-header {
  196. background: linear-gradient(180deg, #d1ebff 0%, #ffffff 100%);
  197. padding: 20px 18px;
  198. text-align: center;
  199. border-radius: 10px 10px 0 0;
  200. .interact-title {
  201. font-size: 18px;
  202. font-weight: 600;
  203. color: #000;
  204. }
  205. }
  206. .interact-form {
  207. padding: 0 18px 20px;
  208. .form-item {
  209. margin-bottom: 20px;
  210. &:last-child {
  211. margin-bottom: 0;
  212. }
  213. .form-label {
  214. font-size: 14px;
  215. color: #000;
  216. margin-bottom: 12px;
  217. display: flex;
  218. align-items: center;
  219. .required {
  220. color: #ff4d4f;
  221. margin-right: 4px;
  222. }
  223. }
  224. .form-input-wrapper {
  225. position: relative;
  226. ::v-deep {
  227. .el-input__inner {
  228. caret-color: transparent;
  229. padding-right: 40px;
  230. }
  231. .el-input__suffix {
  232. display: none;
  233. }
  234. }
  235. .time-icon {
  236. position: absolute;
  237. right: 12px;
  238. top: 50%;
  239. transform: translateY(-50%);
  240. color: #909399;
  241. pointer-events: none;
  242. z-index: 1;
  243. font-size: 16px;
  244. }
  245. }
  246. .question-textarea {
  247. ::v-deep {
  248. .el-textarea__inner {
  249. resize: none;
  250. line-height: 1.5;
  251. min-height: 80px;
  252. }
  253. }
  254. }
  255. }
  256. }
  257. .interact-buttons {
  258. display: flex;
  259. gap: 12px;
  260. padding: 0 18px 20px;
  261. .btn-delete,
  262. .btn-save {
  263. flex: 1;
  264. padding: 8px;
  265. border-radius: 25px;
  266. font-size: 16px;
  267. text-align: center;
  268. cursor: pointer;
  269. transition: all 0.3s;
  270. user-select: none;
  271. }
  272. .btn-delete {
  273. background: #ffffff;
  274. border: 1px solid #ff4d4f;
  275. color: #ff4d4f;
  276. &:hover {
  277. background: #fff5f5;
  278. }
  279. &:active {
  280. opacity: 0.8;
  281. transform: scale(0.98);
  282. }
  283. }
  284. .btn-save {
  285. background: #2199f8;
  286. color: #fff;
  287. border: none;
  288. &:hover:not(.disabled) {
  289. background: #1a8ae6;
  290. }
  291. &:active:not(.disabled) {
  292. opacity: 0.9;
  293. transform: scale(0.98);
  294. }
  295. &.disabled {
  296. opacity: 0.6;
  297. cursor: not-allowed;
  298. pointer-events: none;
  299. }
  300. }
  301. }
  302. }
  303. </style>