task.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <template>
  2. <div class="task-page" :style="{ height: `calc(100vh - ${tabBarHeight}px - 50px)` }">
  3. <div class="task-top">
  4. <div class="map-container" ref="mapContainer"></div>
  5. <div class="calendar-wrap">
  6. <customCalendar ref="calendarRef" @dateSelect="handleDateSelect"></customCalendar>
  7. </div>
  8. </div>
  9. <div class="task-list">
  10. <div class="list-filter">
  11. <div class="filter-item" :class="{ active: activeIndex === 0 }" @click="handleActiveFilter(0)">
  12. 待完成({{ taskCounts[0] || 0 }})
  13. </div>
  14. <div class="filter-item" :class="{ active: activeIndex === 1 }" @click="handleActiveFilter(1)">
  15. 已完成({{ taskCounts[1] || 0 }})
  16. </div>
  17. <div class="filter-item" :class="{ active: activeIndex === 2 }" @click="handleActiveFilter(2)">
  18. 待复核({{ taskCounts[2] || 0 }})
  19. </div>
  20. </div>
  21. <div class="select-group">
  22. <el-select
  23. class="select-item"
  24. v-model="selectParma.farmWorkTypeId"
  25. placeholder="农事类型"
  26. @change="getSimpleList"
  27. >
  28. <el-option v-for="item in farmWorkTypeList" :key="item.id" :label="item.name" :value="item.id" />
  29. </el-select>
  30. <el-select
  31. class="select-item"
  32. v-model="selectParma.districtCode"
  33. placeholder="区域筛选"
  34. @change="getSimpleList"
  35. >
  36. <el-option v-for="item in districtList" :key="item.code" :label="item.name" :value="item.code" />
  37. </el-select>
  38. </div>
  39. <!-- <div class="task-content-loading" v-if="loading && noData" v-loading="loading">
  40. </div> -->
  41. <div class="task-content" v-loading="loading">
  42. <div class="task-item" v-for="(item, index) in taskList" :key="item.id || item.workRecordId">
  43. <task-item
  44. :key="activeIndex + '-' + index"
  45. :itemIndex="activeIndex"
  46. :status="activeIndex === 0 ? 0 : 1"
  47. :item-data="item"
  48. @handleUploadSuccess="handleUploadSuccess"
  49. :ref="(el) => setTaskItemRef(el, index)"
  50. >
  51. <template #footer>
  52. <div class="item-footer" v-if="activeIndex === 2">
  53. <div class="footer-l farm-name-text van-ellipsis">
  54. 来自<span class="name-text">{{ item.farmName || "--" }}</span>
  55. </div>
  56. <div class="footer-r" v-if="item.reviewImage && item.reviewImage.length">
  57. <div class="btn warning" @click="generateReport(item)">生成成果报告</div>
  58. </div>
  59. <div class="footer-r" v-else>
  60. <div class="btn primary" @click="handleAction(item)">上传复核照片</div>
  61. </div>
  62. </div>
  63. <div v-else-if="activeIndex === 1" class="item-footer">
  64. <div class="footer-l farm-name-text van-ellipsis">
  65. 来自<span class="name-text">{{ item.farmName || "--" }}</span>
  66. </div>
  67. <div class="footer-r">
  68. <div class="btn warning" @click="generateReport(item)">生成成果报告</div>
  69. </div>
  70. </div>
  71. <div v-else-if="activeIndex === 0" class="item-footer">
  72. <div class="footer-l" @click="toDetail(item)">查看详情</div>
  73. <div class="footer-r" v-if="item.expectedExecuteDate">
  74. <div class="btn primary" @click="showUploadExecutePopup(item)">上传照片</div>
  75. </div>
  76. <div class="footer-r" v-else>
  77. <div class="btn warning" @click="selectExecuteTime(item)">确认执行时间</div>
  78. </div>
  79. </div>
  80. </template>
  81. </task-item>
  82. </div>
  83. <div class="empty-data" v-if="noData">暂无数据</div>
  84. </div>
  85. </div>
  86. </div>
  87. <upload-execute ref="uploadExecuteRef" :onlyShare="onlyShare" @uploadSuccess="handleUploadSuccess" />
  88. <!-- 服务报价单 -->
  89. <price-sheet-popup :key="activeIndex" ref="priceSheetPopupRef"></price-sheet-popup>
  90. <offer-popup ref="offerPopupRef" @uploadSuccess="handleUploadSuccess"></offer-popup>
  91. <!-- 确认执行时间 -->
  92. <calendar
  93. teleport="#app"
  94. v-model:show="showCalendar"
  95. @confirm="onConfirmExecuteTime"
  96. :min-date="minDate"
  97. :max-date="maxDate"
  98. />
  99. </template>
  100. <script setup>
  101. import { computed, nextTick, onActivated, onMounted, ref, watch } from "vue";
  102. import { useStore } from "vuex";
  103. import { Popup, Calendar } from "vant";
  104. import IndexMap from "../../farm_manage/map/index";
  105. import taskItem from "@/components/taskItem.vue";
  106. import customCalendar from "./calendar.vue";
  107. import { useRouter } from "vue-router";
  108. import uploadExecute from "./uploadExecute.vue";
  109. import priceSheetPopup from "@/components/popup/priceSheetPopup.vue";
  110. import { ElMessage } from "element-plus";
  111. import offerPopup from "@/components/popup/offerPopup.vue";
  112. import { formatDate } from "@/common/commonFun";
  113. const store = useStore();
  114. const router = useRouter();
  115. const indexMap = new IndexMap();
  116. const mapContainer = ref(null);
  117. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  118. const uploadExecuteRef = ref(null);
  119. const dateValue = ref("1");
  120. const calendarRef = ref(null);
  121. const showPopup = ref(false);
  122. const executionData = ref(null);
  123. const selectParma = ref({
  124. farmWorkTypeId: null,
  125. districtCode: null,
  126. });
  127. // 任务列表数据(用于显示,可能被筛选)
  128. const taskList = ref([]);
  129. // 完整的任务列表数据(用于日历显示,不被筛选影响)
  130. const fullTaskList = ref([]);
  131. // 各状态任务数量
  132. const taskCounts = ref([0, 0, 0]);
  133. // 当前选中的筛选索引
  134. const activeIndex = ref(0);
  135. // 筛选日期(用于按日期筛选)
  136. const filterDate = ref(null);
  137. const noData = ref(false);
  138. const loading = ref(false);
  139. // 根据 activeIndex 计算 startFlowStatus
  140. const getStartFlowStatus = (index) => {
  141. const statusMap = {
  142. 0: 4, // 待完成
  143. 1: 5, // 已完成
  144. 2: 5, // 待复核
  145. };
  146. return statusMap[index] ?? 4;
  147. };
  148. // 获取单个状态的任务数量
  149. function getTaskCount(flowStatus, index) {
  150. const location = store.state.home.miniUserLocationPoint;
  151. const needReview = activeIndex.value === 2 ? 1 : null;
  152. const includePrescription = activeIndex.value === 0 ? false : true;
  153. return VE_API.z_farm_work_record
  154. .getSimpleList({ role: 2, location, flowStatus, needReview, includePrescription })
  155. .then(({ data }) => {
  156. if (Array.isArray(data)) {
  157. taskCounts.value[index] = data.length;
  158. calendarRef.value && calendarRef.value.setCounts(index, taskCounts.value[index]);
  159. if (index === 0) {
  160. calendarRef.value && calendarRef.value.setSolarTerm(data);
  161. indexMap.initData(data);
  162. }
  163. } else if (data?.total !== undefined) {
  164. taskCounts.value[index] = data.total;
  165. } else {
  166. taskCounts.value[index] = 0;
  167. }
  168. })
  169. .catch((error) => {
  170. console.error(`获取状态${index}任务数量失败:`, error);
  171. taskCounts.value[index] = 0;
  172. });
  173. }
  174. const taskItemRefs = ref([]);
  175. const setTaskItemRef = (el, index) => {
  176. if (el) {
  177. taskItemRefs.value[index] = el;
  178. }
  179. };
  180. const handleUploadSuccess = async () => {
  181. // 刷新列表
  182. await getSimpleList();
  183. };
  184. const cityCode = ref("");
  185. //根据城市的坐标返回区县列表
  186. const districtList = ref([]);
  187. function getDistrictListByCity() {
  188. VE_API.z_farm_work_record.getDistrictListByCity({ point: mapPoint.value }).then(({ data }) => {
  189. districtList.value = data || [];
  190. // cityCode.value = data[0].code.slice(0, -2);
  191. cityCode.value = "";
  192. districtList.value.unshift({ code: cityCode.value, name: "全部" });
  193. selectParma.value.districtCode = cityCode.value;
  194. getSimpleList();
  195. });
  196. }
  197. //农事类型列表
  198. const farmWorkTypeList = ref([]);
  199. function getFarmWorkTypeList() {
  200. VE_API.z_farm_work_record.getFarmWorkTypeList().then(({ data }) => {
  201. farmWorkTypeList.value = data;
  202. farmWorkTypeList.value.unshift({ id: 0, name: "全部" });
  203. });
  204. }
  205. // 初始化时获取所有状态的任务数量
  206. function initTaskCounts() {
  207. const location = store.state.home.miniUserLocationPoint;
  208. // 并行请求状态的数量
  209. Promise.all([
  210. getTaskCount(4, 0), // 待完成
  211. getTaskCount(5, 1), // 已完成
  212. getTaskCount(5, 2), // 待复核
  213. ]);
  214. }
  215. const mapPoint = ref(null);
  216. onMounted(() => {
  217. mapPoint.value = store.state.home.miniUserLocationPoint;
  218. // 初始化时获取所有状态的数量
  219. initTaskCounts();
  220. // 加载当前选中状态的数据列表
  221. getSimpleList();
  222. getDistrictListByCity();
  223. getFarmWorkTypeList();
  224. nextTick(() => {
  225. indexMap.initMap(mapPoint.value, mapContainer.value, true);
  226. });
  227. });
  228. onActivated(() => {
  229. getSimpleList();
  230. });
  231. // 标记是否正在通过日期选择切换筛选(避免 watch 清除日期筛选)
  232. const isDateSelecting = ref(false);
  233. // 监听 activeIndex 变化,重新加载数据
  234. watch(activeIndex, () => {
  235. // 如果正在通过日期选择切换,不清除日期筛选
  236. if (isDateSelecting.value) {
  237. isDateSelecting.value = false;
  238. getSimpleList();
  239. return;
  240. }
  241. // 切换筛选时清除日期筛选
  242. filterDate.value = null;
  243. // 清除日历选中状态
  244. if (calendarRef.value) {
  245. calendarRef.value.clearSelection();
  246. }
  247. getSimpleList();
  248. });
  249. function getSimpleList() {
  250. loading.value = true;
  251. noData.value = false;
  252. // 清空refs数组,避免索引错乱
  253. taskItemRefs.value = [];
  254. const startFlowStatus = getStartFlowStatus(activeIndex.value);
  255. const needReview = activeIndex.value === 2 ? 1 : null;
  256. const params = {
  257. ...selectParma.value,
  258. role: 2,
  259. location: mapPoint.value,
  260. flowStatus: startFlowStatus,
  261. farmWorkTypeId: selectParma.value.farmWorkTypeId || null,
  262. needReview: needReview,
  263. includePrescription: activeIndex.value === 0 ? false : true,
  264. };
  265. return VE_API.z_farm_work_record
  266. .getSimpleList(params)
  267. .then(({ data }) => {
  268. loading.value = false;
  269. // 假设返回的数据结构是 { list: [], total: 0 } 或者直接是数组
  270. let filteredData = data;
  271. // 保存完整数据(用于日历显示)
  272. if (activeIndex.value === 0) {
  273. // 如果是"待完成"状态,保存完整数据用于日历
  274. fullTaskList.value = Array.isArray(data) ? data : [];
  275. }
  276. // 如果有日期筛选,在前端再次过滤(确保数据准确)
  277. if (filterDate.value && Array.isArray(filteredData)) {
  278. filteredData = filteredData.filter((item) => {
  279. if (!item.executeDate) return false;
  280. const itemDate = formatDate(new Date(item.executeDate));
  281. return itemDate === filterDate.value;
  282. });
  283. }
  284. if (Array.isArray(filteredData) && filteredData.length > 0) {
  285. taskList.value = filteredData;
  286. // 更新当前状态的数量
  287. taskCounts.value[activeIndex.value] = filteredData.length;
  288. if (activeIndex.value === 0) {
  289. // 传递给日历的数据应该是完整的未筛选数据
  290. const calendarData = filterDate.value ? fullTaskList.value : taskList.value;
  291. console.log('calendarData', calendarData);
  292. calendarRef.value && calendarRef.value.setSolarTerm(calendarData);
  293. // 地图使用筛选后的数据
  294. indexMap.initData(taskList.value);
  295. }
  296. } else {
  297. noData.value = true;
  298. taskList.value = [];
  299. taskCounts.value[activeIndex.value] = 0;
  300. }
  301. })
  302. .catch((error) => {
  303. console.error("获取任务列表失败:", error);
  304. loading.value = false;
  305. taskList.value = [];
  306. taskCounts.value[activeIndex.value] = 0;
  307. if (activeIndex.value === 0) {
  308. // 即使筛选后没有数据,日历也应该显示完整数据
  309. const calendarData = filterDate.value ? fullTaskList.value : [];
  310. indexMap.initData(taskList.value);
  311. calendarRef.value && calendarRef.value.setSolarTerm(calendarData);
  312. }
  313. noData.value = true;
  314. });
  315. }
  316. // 处理日历日期选择
  317. const handleDateSelect = (date) => {
  318. if (date) {
  319. // 有日期选择,切换到"待完成"筛选并设置筛选日期
  320. filterDate.value = date;
  321. // 如果当前不是"待完成"状态,切换到"待完成"
  322. if (activeIndex.value !== 2) {
  323. isDateSelecting.value = true; // 标记正在通过日期选择切换
  324. activeIndex.value = 2;
  325. // watch 会处理 getSimpleList
  326. } else {
  327. // 如果已经是"待完成"状态,直接重新加载列表
  328. getSimpleList();
  329. }
  330. } else {
  331. // 取消日期筛选
  332. filterDate.value = null;
  333. // 重新加载列表
  334. getSimpleList();
  335. }
  336. };
  337. function handleActiveFilter(i) {
  338. activeIndex.value = i;
  339. // watch 会自动处理清除日期筛选和日历选中状态
  340. selectParma.value.districtCode = cityCode.value;
  341. selectParma.value.farmWorkTypeId = null;
  342. }
  343. function toPage(item) {
  344. // router.push("/servicZes_agri")
  345. // if (activeIndex.value === 2) {
  346. // } else {
  347. // // 下发农事请求
  348. // const data = {
  349. // id: item.id,
  350. // };
  351. // VE_API.z_farm_work_record.issueFarmWorkRecord(data).then((res) => {
  352. // if (res.code === 0) {
  353. // taskPopupType.value = "success";
  354. // showTaskPopup.value = true;
  355. // getSimpleList();
  356. // }
  357. // });
  358. // }
  359. }
  360. const offerPopupRef = ref(null);
  361. const showUploadExecutePopup = (item) => {
  362. offerPopupRef.value.openPopup(item);
  363. };
  364. const generateReport = (item) => {
  365. router.push({
  366. path: "/achievement_report",
  367. query: { miniJson: JSON.stringify({ id: item.id }) },
  368. });
  369. };
  370. function toDetail(item) {
  371. // router.push({
  372. // path: "/modify",
  373. // query: { id: item.id },
  374. // });
  375. router.push({
  376. path: "/completed_work",
  377. query: { miniJson: JSON.stringify({ id: item.id }) },
  378. });
  379. }
  380. const showCalendar = ref(false);
  381. const maxDate = ref();
  382. const minDate = new Date(2010, 0, 1);
  383. const executeItem = ref(null);
  384. const selectExecuteTime = (item) => {
  385. executeItem.value = item;
  386. maxDate.value = new Date(item.executeDeadlineDate);
  387. showCalendar.value = true;
  388. };
  389. const onConfirmExecuteTime = (date) => {
  390. showCalendar.value = false;
  391. VE_API.z_farm_work_record
  392. .updateExpectedExecuteDate({ recordId: executeItem.value.id, expectedExecuteDate: formatDate(date) })
  393. .then((res) => {
  394. if (res.code === 0) {
  395. ElMessage.success("操作成功");
  396. getSimpleList();
  397. }
  398. });
  399. };
  400. const priceSheetPopupRef = ref(null);
  401. const showPriceSheetPopup = (item) => {
  402. VE_API.z_farm_work_record.getDetail({ id: item.id }).then(({ data }) => {
  403. const res = data[0];
  404. priceSheetPopupRef.value.handleShowPopup(res);
  405. });
  406. };
  407. const onlyShare = ref(false);
  408. function handleAction(item) {
  409. setTimeout(() => {
  410. uploadExecuteRef.value.showPopup(item, "share-sheet");
  411. }, 10);
  412. }
  413. function handleForward(item) {
  414. if (item.quoteCount && item.quoteCount != 0) {
  415. onlyShare.value = true;
  416. setTimeout(() => {
  417. uploadExecuteRef.value.showPopup(
  418. { ...item, type: "quotation", farmWorkOrderId: item.orderId },
  419. "share-sheet"
  420. );
  421. }, 10);
  422. } else {
  423. ElMessage.warning("暂无报价数据,无法分享");
  424. return;
  425. }
  426. }
  427. </script>
  428. <style lang="scss" scoped>
  429. .task-page {
  430. width: 100%;
  431. height: calc(100vh - 50px - 50px);
  432. overflow: auto;
  433. box-sizing: border-box;
  434. background: #f5f7fb;
  435. .map-container {
  436. width: 100%;
  437. height: 162px;
  438. clip-path: inset(0px round 8px);
  439. }
  440. .select-group {
  441. display: flex;
  442. padding: 0 12px;
  443. .select-item {
  444. width: 100%;
  445. ::v-deep {
  446. .el-select__wrapper {
  447. text-align: center;
  448. gap: 2px;
  449. box-shadow: none;
  450. justify-content: center;
  451. background: none;
  452. }
  453. .el-select__selection {
  454. flex: none;
  455. width: fit-content;
  456. }
  457. .el-select__placeholder {
  458. position: static;
  459. transform: none;
  460. width: fit-content;
  461. color: rgba(0, 0, 0, 0.2);
  462. }
  463. .el-select__caret {
  464. color: rgba(0, 0, 0, 0.2);
  465. }
  466. }
  467. }
  468. }
  469. .calendar-wrap {
  470. padding: 10px 0 4px 0;
  471. }
  472. .task-top {
  473. padding: 10px 12px;
  474. }
  475. .task-content-loading {
  476. height: 80px;
  477. border-radius: 8px;
  478. position: absolute;
  479. top: 60px;
  480. left: 0;
  481. width: 100%;
  482. }
  483. .task-content {
  484. min-height: 80px;
  485. }
  486. .empty-data {
  487. text-align: center;
  488. font-size: 14px;
  489. color: #6f7274;
  490. padding: 20px 0;
  491. }
  492. .task-list {
  493. position: relative;
  494. background: #fff;
  495. padding: 8px 12px;
  496. }
  497. .list-filter {
  498. display: flex;
  499. align-items: center;
  500. justify-content: center;
  501. gap: 20px;
  502. .filter-item {
  503. padding: 0 12px;
  504. height: 28px;
  505. color: rgba(0, 0, 0, 0.5);
  506. font-size: 14px;
  507. line-height: 28px;
  508. border-radius: 20px;
  509. &.active {
  510. color: #2199f8;
  511. background: rgba(33, 153, 248, 0.2);
  512. }
  513. }
  514. }
  515. .task-item + .task-item {
  516. margin-top: 10px;
  517. }
  518. .item-footer {
  519. margin-top: 10px;
  520. padding-top: 11px;
  521. border-top: 1px solid rgba(0, 0, 0, 0.1);
  522. display: flex;
  523. align-items: center;
  524. justify-content: space-between;
  525. font-size: 12px;
  526. .footer-l {
  527. color: #8b8b8b;
  528. font-size: 12px;
  529. &.primary-btn {
  530. display: inline-flex;
  531. align-items: center;
  532. border: 1px solid #2199f8;
  533. background: rgba(33, 153, 248, 0.1);
  534. padding: 0 12px;
  535. height: 32px;
  536. box-sizing: border-box;
  537. display: flex;
  538. align-items: center;
  539. border-radius: 20px;
  540. color: #2199f8;
  541. .share-icon {
  542. width: 12px;
  543. padding-right: 4px;
  544. }
  545. }
  546. &.farm-name-text {
  547. font-size: 14px;
  548. color: #6f7274;
  549. .name-text {
  550. padding-left: 4px;
  551. }
  552. }
  553. }
  554. .footer-r {
  555. display: flex;
  556. align-items: center;
  557. .btn {
  558. height: 32px;
  559. line-height: 32px;
  560. padding: 0 12px;
  561. border-radius: 20px;
  562. display: flex;
  563. align-items: center;
  564. box-sizing: border-box;
  565. &.second {
  566. // border: 1px solid #8B8B8B;
  567. // color: #8B8B8B;
  568. color: #2199f8;
  569. background: rgba(33, 153, 248, 0.1);
  570. }
  571. &.primary {
  572. background: #2199f8;
  573. color: #fff;
  574. }
  575. .btn-icon {
  576. padding-right: 4px;
  577. }
  578. &.warning {
  579. color: #ff953d;
  580. background: #fff;
  581. border: 1px solid #ff953d;
  582. }
  583. &.secondary-text {
  584. color: #2199f8;
  585. border: 1px solid #2199f8;
  586. }
  587. }
  588. .btn + .btn {
  589. margin-left: 8px;
  590. }
  591. }
  592. }
  593. }
  594. </style>
  595. <style lang="scss">
  596. .van-calendar__popup {
  597. z-index: 9999 !important;
  598. }
  599. </style>