executePopup.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <popup v-model:show="showValue" class="execute-popup" closeable>
  3. <div class="popup-content">
  4. <div class="time-wrap">
  5. <div class="name pb-10">
  6. 请选择实际执行时间
  7. </div>
  8. <div class="time-input">
  9. <el-date-picker format="YYYY-MM-DD" value-format="YYYY-MM-DD" v-model="executeTime"
  10. :disabled-date="disabledDate" size="large" style="width: 100%" type="date" placeholder="请选择日期"
  11. :editable="false" />
  12. </div>
  13. </div>
  14. <div class="upload-wrap" :class="{ 'upload-cont': fileList.length }">
  15. <div class="name">农事凭证</div>
  16. <div class="sub-name">请上传农事执行现场照片及所用药肥凭证照片</div>
  17. <uploader class="uploader" v-model="fileList" multiple :max-count="5" :after-read="afterRead" @delete="handleDelete"
  18. @click="handleClick('rg')">
  19. <img class="img" v-show="!fileList.length" src="@/assets/img/home/example-4.png" alt="" />
  20. <img class="plus" src="@/assets/img/home/plus.png" alt="" />
  21. </uploader>
  22. <div class="service-input">
  23. <el-input v-model="serviceInput" placeholder="请输入农资机构名称" />
  24. </div>
  25. </div>
  26. <div class="button-wrap">
  27. <div @click="closeTask" class="button primary">确认上传</div>
  28. </div>
  29. </div>
  30. </popup>
  31. <popup v-model:show="showRemindValue" class="execute-popup" closeable>
  32. <div class="popup-content">
  33. <div class="name">
  34. <span class="required">*</span>请选择下次提醒时间
  35. </div>
  36. <div class="time-number-input">
  37. <el-input-number v-model="remindTime" :min="1" :max="30" :step="1" size="large" style="width: 100%" />
  38. <span class="time-unit">天后</span>
  39. </div>
  40. <div class="button-wrap">
  41. <div @click="handleRemind" class="button primary">确认</div>
  42. </div>
  43. </div>
  44. </popup>
  45. </template>
  46. <script setup>
  47. import { Popup, Uploader } from "vant";
  48. import { ref } from "vue";
  49. import { ElMessage } from "element-plus";
  50. import { getFileExt } from "@/utils/util";
  51. import UploadFile from "@/utils/upliadFile";
  52. import { useStore } from "vuex";
  53. import { useRouter } from "vue-router";
  54. const store = useStore();
  55. const miniUserId = store.state.home.miniUserId;
  56. const router = useRouter();
  57. const props = defineProps({
  58. executionData: {
  59. type: Object,
  60. default: () => ({}),
  61. },
  62. });
  63. const showValue = ref(false);
  64. const fileList = ref([]);
  65. const fileArr = ref([]);
  66. const sourceEvidenceList = ref([]);
  67. const sourceAuditStatusList = ref([]);
  68. const executeTime = ref("");
  69. const serviceInput = ref("");
  70. const uploadFileObj = new UploadFile();
  71. const emit = defineEmits(['executeSuccess']);
  72. const afterRead = (file) => {
  73. // 处理多张照片的情况:file 可能是数组
  74. const files = Array.isArray(file) ? file : [file];
  75. files.forEach((item) => {
  76. // 将文件上传至服务器
  77. let fileVal = item.file;
  78. if (!fileVal) return; // 如果没有 file 属性,跳过
  79. item.status = "uploading";
  80. item.message = "上传中...";
  81. let ext = getFileExt(fileVal.name);
  82. let key = `birdseye-look-mini/${miniUserId}/${new Date().getTime()}.${ext}`;
  83. uploadFileObj.put(key, fileVal).then((resFilename) => {
  84. item.status = "done";
  85. item.message = "";
  86. fileArr.value.push(resFilename);
  87. }).catch(() => {
  88. item.status = 'failed';
  89. item.message = '上传失败';
  90. ElMessage.error('图片上传失败,请稍后再试!')
  91. });
  92. });
  93. };
  94. function handleDelete(file) {
  95. // fileList.value = fileList.value.filter(item => item.filePath !== file.filePath);
  96. // fileArr.value = fileArr.value.filter(item => item !== file.filePath);
  97. console.log("fileList", fileList.value);
  98. if (isEdit.value) {
  99. fileArr.value = fileList.value.map(item => item.filePath);
  100. }
  101. }
  102. function closeTask() {
  103. // stepIndex.value = 2
  104. if (!fileArr.value.length) return ElMessage.warning('请上传农事凭证')
  105. if (!executeTime.value) return ElMessage.warning('请选择实际执行时间')
  106. if (!serviceInput.value) return ElMessage.warning('请输入农资机构名称')
  107. const params = {
  108. recordId: recordId.value,
  109. executorOrganizationName: serviceInput.value,
  110. executeDate: executeTime.value,
  111. executeEvidence: fileArr.value,
  112. }
  113. console.log("params", params);
  114. VE_API.report.addExecuteImgAndComplete(params).then((res) => {
  115. if (res.code === 0) {
  116. ElMessage.success('上传成功')
  117. showValue.value = false;
  118. setTimeout(() => {
  119. emit('executeSuccess');
  120. }, 800)
  121. } else {
  122. ElMessage.error(res.msg)
  123. }
  124. }).catch((err) => {
  125. ElMessage.error('操作失败')
  126. })
  127. }
  128. const handleClick = () => {
  129. // 预留点击上传区域的埋点或其它逻辑
  130. };
  131. const disabledDate = (time) => {
  132. // 示例:不允许选择未来日期
  133. return time.getTime() > Date.now();
  134. };
  135. const showRemindValue = ref(false);
  136. const remindTime = ref(1);
  137. function showRemindPopup() {
  138. showRemindValue.value = true;
  139. }
  140. function handleRemind() {
  141. if (!remindTime.value) return ElMessage.warning('请选择下次提醒时间')
  142. showRemindValue.value = false;
  143. }
  144. const recordId = ref(null);
  145. const isEdit = ref(false);
  146. function openPopup(id, extraData = {}) {
  147. showValue.value = true;
  148. recordId.value = id;
  149. fileArr.value = extraData.evidenceList.map(item => item.filePath);
  150. fileList.value = extraData.evidenceList
  151. isEdit.value = extraData.isEdit
  152. executeTime.value = extraData.executeDate
  153. serviceInput.value = extraData.executorOrganizationName
  154. // sourceEvidenceList.value = Array.isArray(extraData.evidenceList) ? extraData.evidenceList : [];
  155. // sourceAuditStatusList.value = Array.isArray(extraData.auditStatusList) ? extraData.auditStatusList : [];
  156. }
  157. defineExpose({
  158. openPopup,
  159. showRemindPopup,
  160. });
  161. </script>
  162. <style lang="scss" scoped>
  163. .execute-popup {
  164. width: 90%;
  165. border-radius: 8px;
  166. .popup-content {
  167. padding: 24px 16px 20px 16px;
  168. background: linear-gradient(360deg, #FFFFFF 74.2%, #D1EBFF 100%);
  169. border-radius: 8px;
  170. }
  171. }
  172. .pb-10 {
  173. padding-bottom: 12px;
  174. }
  175. .name {
  176. color: #000000;
  177. font-size: 16px;
  178. font-weight: 500;
  179. // padding-bottom: 12px;
  180. .required {
  181. color: #ff4d4f;
  182. margin-right: 2px;
  183. }
  184. }
  185. .sub-name {
  186. font-size: 12px;
  187. color: rgba(0, 0, 0, 0.4);
  188. padding-bottom: 12px;
  189. }
  190. .tips-text {
  191. color: #FA7406;
  192. padding: 5px 10px;
  193. border: 1px solid #FA7406;
  194. border-radius: 5px;
  195. margin-bottom: 10px;
  196. background: #fff;
  197. }
  198. .service-input {
  199. padding-top: 12px;
  200. }
  201. .upload-wrap {
  202. &.upload-cont {
  203. ::v-deep {
  204. .van-uploader__wrapper {
  205. // flex-wrap: nowrap;
  206. }
  207. }
  208. }
  209. .img {
  210. width: 80px;
  211. height: 80px;
  212. margin-right: 12px;
  213. }
  214. .plus {
  215. margin-right: 12px;
  216. width: 80px;
  217. height: 80px;
  218. }
  219. }
  220. .upload-wrap {
  221. ::v-deep {
  222. .van-image__img {
  223. border-radius: 8px;
  224. }
  225. .avatar-uploader .el-upload {
  226. width: 100%;
  227. border: 1px dashed #dddddd;
  228. border-radius: 6px;
  229. cursor: pointer;
  230. position: relative;
  231. overflow: hidden;
  232. }
  233. // .van-uploader__input-wrapper
  234. .van-uploader,
  235. .van-uploader__wrapper {
  236. width: 100%;
  237. }
  238. .el-icon.avatar-uploader-icon {
  239. font-size: 28px;
  240. color: #8c939d;
  241. width: 100%;
  242. height: 128px;
  243. text-align: center;
  244. background: #f6f6f6;
  245. }
  246. }
  247. }
  248. .button-wrap {
  249. display: flex;
  250. justify-content: center;
  251. margin: 24px 4px 0 4px;
  252. .button {
  253. border-radius: 20px;
  254. color: #fff;
  255. padding: 7px 0;
  256. text-align: center;
  257. font-size: 16px;
  258. &.primary {
  259. flex: 1;
  260. background: #2199f8;
  261. color: #fff;
  262. }
  263. }
  264. }
  265. .time-wrap {
  266. margin-bottom: 12px;
  267. .time-input {
  268. width: 100%;
  269. }
  270. }
  271. .time-number-input {
  272. display: flex;
  273. align-items: center;
  274. width: 100%;
  275. .time-unit {
  276. font-size: 14px;
  277. color: rgba(0, 0, 0, 0.4);
  278. flex: none;
  279. margin-left: 8px;
  280. }
  281. }
  282. </style>