task.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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. <calendar ref="calendarRef"></calendar>
  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 class="filter-item" :class="{ active: activeIndex === 3 }" @click="handleActiveFilter(3)">
  21. 已完成({{ taskCounts[3] || 0 }})
  22. </div>
  23. </div>
  24. <div class="select-group">
  25. <el-select class="select-item" v-model="dateValue" placeholder="Select">
  26. <el-option v-for="item in dateOptions" :key="item.value" :label="item.label" :value="item.value" />
  27. </el-select>
  28. <el-select class="select-item" v-model="areaValue" placeholder="Select">
  29. <el-option v-for="item in areaOptions" :key="item.value" :label="item.label" :value="item.value" />
  30. </el-select>
  31. <el-select class="select-item" v-model="areaValue1" placeholder="Select">
  32. <el-option v-for="item in areaOptions1" :key="item.value" :label="item.label" :value="item.value" />
  33. </el-select>
  34. </div>
  35. <!-- <div class="task-content-loading" v-if="loading && noData" v-loading="loading">
  36. </div> -->
  37. <div class="task-content" v-loading="loading">
  38. <div class="task-item" v-for="item in taskList" :key="item.id || item.workRecordId">
  39. <task-item :status="activeIndex === 3 ? 1 : 0" :item-data="item">
  40. <template #footer>
  41. <div class="item-footer" v-if="activeIndex === 0 || activeIndex === 2">
  42. <div class="footer-l" @click="toDetail(item)">
  43. 查看详情
  44. </div>
  45. <div class="footer-r">
  46. <div class="btn second" @click="handleAction(item)">
  47. {{ activeIndex === 0 ? "忽略" : "转发给客户" }}
  48. </div>
  49. <div class="btn primary" @click="toPage(item)">
  50. {{ activeIndex === 0 ? "下发农事" : "请求确认" }}
  51. </div>
  52. </div>
  53. </div>
  54. <div v-else-if="activeIndex === 1" class="item-footer">
  55. <div class="footer-l" @click="toDetail(item)">
  56. 查看详情
  57. </div>
  58. <div class="footer-r">
  59. <div class="btn second">
  60. 转发给客户
  61. </div>
  62. <div class="btn primary" @click="showPriceSheetPopup(item)">
  63. 生成报价单
  64. </div>
  65. </div>
  66. </div>
  67. <div class="item-footer" v-else>
  68. <div class="footer-l farm-name-text">
  69. 来自<span class="name-text">{{ item.farmName || '未知农场' }}</span>
  70. </div>
  71. <div class="footer-r">
  72. <!-- <div class="btn warning">
  73. 分享成果
  74. </div> -->
  75. <div class="btn secondary-text">
  76. 提醒用户拍照
  77. </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" />
  88. <popup v-model:show="showTaskPopup" round class="task-tips-popup">
  89. <template v-if="taskPopupType === 'warning'">
  90. <img class="create-farm-icon" src="@/assets/img/home/create-farm-icon.png" alt="" />
  91. <div class="create-farm-text">
  92. <div>您确认忽略 <span class="main-text">{{ currentTask?.farmName }}</span> 的 <span class="main-text">{{ currentTask?.farmWorkName }}</span> 农事吗</div>
  93. </div>
  94. </template>
  95. <template v-else>
  96. <img class="farm-check-icon" src="@/assets/img/home/right.png" alt="">
  97. <div class="create-farm-text success-text">农事已下发成功</div>
  98. </template>
  99. <div class="create-farm-btn" @click="handlePopupBtn">{{ taskPopupType === 'warning' ? '确认忽略' : '我知道了' }}</div>
  100. </popup>
  101. <!-- 服务报价单 -->
  102. <price-sheet-popup ref="priceSheetPopupRef"></price-sheet-popup>
  103. </template>
  104. <script setup>
  105. import { computed, nextTick, onMounted, ref, watch } from "vue";
  106. import { useStore } from "vuex";
  107. import { Popup } from "vant";
  108. import IndexMap from "../../farm_manage/map/index";
  109. import taskItem from "@/components/taskItem.vue";
  110. import calendar from "./calendar.vue"
  111. import { useRouter } from "vue-router";
  112. import uploadExecute from "./uploadExecute.vue";
  113. import priceSheetPopup from "@/components/popup/priceSheetPopup.vue";
  114. const store = useStore();
  115. const router = useRouter();
  116. const indexMap = new IndexMap();
  117. const mapContainer = ref(null);
  118. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  119. const uploadExecuteRef = ref(null);
  120. const dateValue = ref("1");
  121. const calendarRef = ref(null);
  122. const dateOptions = [
  123. { value: "1", label: "农事类型" },
  124. { value: "2", label: "2" },
  125. { value: "3", label: "3" },
  126. ];
  127. const areaValue = ref("1");
  128. const areaOptions = [
  129. { value: "1", label: "距离" },
  130. { value: "2", label: "2" },
  131. { value: "3", label: "3" },
  132. ];
  133. const areaValue1 = ref("1");
  134. const areaOptions1 = [
  135. { value: "1", label: "区域筛选" },
  136. { value: "2", label: "2" },
  137. { value: "3", label: "3" },
  138. ];
  139. // 任务列表数据
  140. const taskList = ref([]);
  141. // 各状态任务数量
  142. const taskCounts = ref([0, 0, 0]);
  143. // 当前选中的筛选索引
  144. const activeIndex = ref(0);
  145. const noData = ref(false);
  146. const loading = ref(false);
  147. const showTaskPopup = ref(false);
  148. const taskPopupType = ref('warning');
  149. // 根据 activeIndex 计算 startFlowStatus
  150. const getStartFlowStatus = (index) => {
  151. const statusMap = {
  152. 0: 0, // 待确认
  153. 1: '1,2,3', // 待完成
  154. 2: 4, // 待完成
  155. 3: 5 // 已完成
  156. };
  157. return statusMap[index] ?? 0;
  158. };
  159. // 获取单个状态的任务数量
  160. function getTaskCount(flowStatus, index) {
  161. const location = store.state.home.miniUserLocationPoint;
  162. return VE_API.z_farm_work_record.getSimpleList({ role: 2, location, flowStatus }).then(({data}) => {
  163. if (Array.isArray(data)) {
  164. taskCounts.value[index] = data.length;
  165. calendarRef.value && calendarRef.value.setCounts(index, taskCounts.value[index])
  166. if (index === 1) {
  167. calendarRef.value && calendarRef.value.setSolarTerm(data)
  168. indexMap.initData(data)
  169. }
  170. } else if (data?.total !== undefined) {
  171. taskCounts.value[index] = data.total;
  172. } else {
  173. taskCounts.value[index] = 0;
  174. }
  175. }).catch((error) => {
  176. console.error(`获取状态${index}任务数量失败:`, error);
  177. taskCounts.value[index] = 0;
  178. });
  179. }
  180. // 初始化时获取所有状态的任务数量
  181. function initTaskCounts() {
  182. const location = store.state.home.miniUserLocationPoint;
  183. // 并行请求三个状态的数量
  184. Promise.all([
  185. getTaskCount(0, 0), // 待确认
  186. getTaskCount('1,2,3', 1), // 待确认
  187. getTaskCount(4, 2), // 待完成
  188. getTaskCount(5, 3) // 已完成
  189. ]);
  190. }
  191. onMounted(() => {
  192. // 初始化时获取所有状态的数量
  193. initTaskCounts();
  194. // 加载当前选中状态的数据列表
  195. getSimpleList();
  196. const point = store.state.home.miniUserLocationPoint;
  197. nextTick(() => {
  198. indexMap.initMap(point, mapContainer.value, true);
  199. });
  200. });
  201. // 监听 activeIndex 变化,重新加载数据
  202. watch(activeIndex, () => {
  203. getSimpleList();
  204. });
  205. function getSimpleList() {
  206. loading.value = true;
  207. noData.value = false;
  208. const location = store.state.home.miniUserLocationPoint;
  209. const startFlowStatus = getStartFlowStatus(activeIndex.value);
  210. VE_API.z_farm_work_record.getSimpleList({ role: 2, location, flowStatus: startFlowStatus }).then(({data}) => {
  211. loading.value = false;
  212. // 假设返回的数据结构是 { list: [], total: 0 } 或者直接是数组
  213. if (Array.isArray(data) && data.length > 0) {
  214. console.log('ssssget', data);
  215. taskList.value = data;
  216. // 更新当前状态的数量
  217. taskCounts.value[activeIndex.value] = data.length;
  218. if (activeIndex.value === 1) {
  219. calendarRef.value && calendarRef.value.setSolarTerm(taskList.value)
  220. indexMap.initData(taskList.value)
  221. }
  222. } else {
  223. taskList.value = [];
  224. taskCounts.value[activeIndex.value] = 0;
  225. indexMap.initData(taskList.value)
  226. calendarRef.value && calendarRef.value.setSolarTerm(taskList.value)
  227. noData.value = true;
  228. }
  229. }).catch((error) => {
  230. console.error('获取任务列表失败:', error);
  231. loading.value = false;
  232. taskList.value = [];
  233. noData.value = true;
  234. });
  235. }
  236. function handleActiveFilter(i) {
  237. activeIndex.value = i;
  238. }
  239. function toPage(item) {
  240. // router.push("/servicZes_agri")
  241. if (activeIndex.value === 2) {
  242. if (item?.executeEvidence?.length) {
  243. onlyShare.value = true;
  244. } else {
  245. onlyShare.value = false;
  246. }
  247. setTimeout(() => {
  248. uploadExecuteRef.value.showPopup(item.id,'share-sheet');
  249. }, 10);
  250. } else {
  251. // 下发农事请求
  252. const data = {
  253. id: item.id,
  254. };
  255. VE_API.z_farm_work_record.issueFarmWorkRecord(data).then((res) => {
  256. if (res.code === 0) {
  257. taskPopupType.value = 'success';
  258. showTaskPopup.value = true;
  259. getSimpleList()
  260. }
  261. })
  262. // router.push("/service_agri");
  263. }
  264. }
  265. function toDetail(item) {
  266. if (activeIndex.value === 0) {
  267. router.push({
  268. path: "/modify_work",
  269. query: { id: item.id }
  270. });
  271. } else {
  272. router.push({
  273. path: "/completed_work",
  274. query: { id: item.id }
  275. });
  276. }
  277. }
  278. const priceSheetPopupRef = ref(null);
  279. const showPriceSheetPopup = (item) => {
  280. VE_API.z_farm_work_record.getDetail({ id: item.id }).then(({ data }) => {
  281. const res = data[0];
  282. priceSheetPopupRef.value.handleShowPopup(res);
  283. });
  284. };
  285. const onlyShare = ref(false);
  286. const currentTask = ref(null);
  287. function handleAction(item) {
  288. if (activeIndex.value === 0) {
  289. taskPopupType.value = 'warning';
  290. showTaskPopup.value = true;
  291. currentTask.value = item;
  292. }else{
  293. onlyShare.value = true;
  294. setTimeout(() => {
  295. uploadExecuteRef.value.showPopup(item.id,'share-sheet');
  296. }, 10);
  297. }
  298. }
  299. function handlePopupBtn() {
  300. showTaskPopup.value = false;
  301. if (taskPopupType.value === 'warning') {
  302. // 确认忽略
  303. }
  304. }
  305. </script>
  306. <style lang="scss" scoped>
  307. .task-page {
  308. width: 100%;
  309. height: calc(100vh - 50px - 50px);
  310. overflow: auto;
  311. box-sizing: border-box;
  312. background: #f5f7fb;
  313. .map-container {
  314. width: 100%;
  315. height: 162px;
  316. clip-path: inset(0px round 8px);
  317. }
  318. .select-group {
  319. display: flex;
  320. padding: 0 12px;
  321. .select-item {
  322. width: 100%;
  323. ::v-deep {
  324. .el-select__wrapper {
  325. text-align: center;
  326. gap: 2px;
  327. box-shadow: none;
  328. justify-content: center;
  329. background: none;
  330. }
  331. .el-select__selection {
  332. flex: none;
  333. width: fit-content;
  334. }
  335. .el-select__placeholder {
  336. position: static;
  337. transform: none;
  338. width: fit-content;
  339. color: rgba(0, 0, 0, 0.2);
  340. }
  341. .el-select__caret {
  342. color: rgba(0, 0, 0, 0.2);
  343. }
  344. }
  345. }
  346. }
  347. .calendar-wrap {
  348. padding: 10px 0 4px 0;
  349. }
  350. .task-top {
  351. padding: 10px 12px;
  352. }
  353. .task-content-loading {
  354. height: 80px;
  355. border-radius: 8px;
  356. position: absolute;
  357. top: 60px;
  358. left: 0;
  359. width: 100%;
  360. }
  361. .task-content {
  362. min-height: 80px;
  363. }
  364. .empty-data {
  365. text-align: center;
  366. font-size: 14px;
  367. color: #6F7274;
  368. padding: 20px 0;
  369. }
  370. .task-list {
  371. position: relative;
  372. background: #fff;
  373. padding: 8px 12px;
  374. }
  375. .list-filter {
  376. display: flex;
  377. align-items: center;
  378. justify-content: space-around;
  379. .filter-item {
  380. padding: 0 12px;
  381. height: 28px;
  382. color: rgba(0, 0, 0, 0.5);
  383. font-size: 14px;
  384. line-height: 28px;
  385. border-radius: 20px;
  386. &.active {
  387. color: #2199f8;
  388. background: rgba(33, 153, 248, 0.2);
  389. }
  390. }
  391. }
  392. .task-item + .task-item {
  393. margin-top: 10px;
  394. }
  395. .item-footer {
  396. margin-top: 10px;
  397. padding-top: 11px;
  398. border-top: 1px solid rgba(0, 0, 0, 0.1);
  399. display: flex;
  400. align-items: center;
  401. justify-content: space-between;
  402. font-size: 12px;
  403. .footer-l {
  404. color: #8B8B8B;
  405. font-size: 12px;
  406. &.primary-btn {
  407. display: inline-flex;
  408. align-items: center;
  409. border: 1px solid #2199F8;
  410. background: rgba(33, 153, 248, 0.1);
  411. padding: 0 12px;
  412. height: 32px;
  413. box-sizing: border-box;
  414. display: flex;
  415. align-items: center;
  416. border-radius: 20px;
  417. color: #2199F8;
  418. .share-icon {
  419. width: 12px;
  420. padding-right: 4px;
  421. }
  422. }
  423. &.farm-name-text {
  424. font-size: 14px;
  425. color: #6F7274;
  426. .name-text {
  427. padding-left: 4px;
  428. }
  429. }
  430. }
  431. .footer-r {
  432. display: flex;
  433. align-items: center;
  434. .btn {
  435. height: 32px;
  436. line-height: 32px;
  437. padding: 0 12px;
  438. border-radius: 20px;
  439. display: flex;
  440. align-items: center;
  441. box-sizing: border-box;
  442. &.second {
  443. // border: 1px solid #8B8B8B;
  444. // color: #8B8B8B;
  445. color: #2199F8;
  446. background: rgba(33, 153, 248, 0.1);
  447. }
  448. &.primary {
  449. background: #2199F8;
  450. color: #fff;
  451. }
  452. .btn-icon {
  453. padding-right: 4px;
  454. }
  455. &.warning {
  456. color: #FF953D;
  457. background: #fff;
  458. border: 1px solid #FF953D;
  459. }
  460. &.secondary-text {
  461. color: #2199F8;
  462. border: 1px solid #2199F8;
  463. }
  464. }
  465. .btn + .btn {
  466. margin-left: 8px;
  467. }
  468. }
  469. }
  470. }
  471. .task-tips-popup {
  472. width: 75%;
  473. padding: 28px 28px 20px;
  474. display: flex;
  475. flex-direction: column;
  476. align-items: center;
  477. justify-content: center;
  478. .create-farm-icon{
  479. width: 40px;
  480. height: 40px;
  481. margin-bottom: 12px;
  482. }
  483. .farm-check-icon{
  484. width: 68px;
  485. height: 68px;
  486. margin-bottom: 12px;
  487. }
  488. .create-farm-text{
  489. font-size: 20px;
  490. font-weight: 500;
  491. line-height: 40px;
  492. margin-bottom: 32px;
  493. text-align: center;
  494. &.success-text{
  495. font-size: 23px;
  496. font-weight: 400;
  497. }
  498. }
  499. .main-text {
  500. color: #2199F8;
  501. }
  502. .create-farm-btn{
  503. width: 100%;
  504. box-sizing: border-box;
  505. padding: 8px;
  506. border-radius: 25px;
  507. font-size: 16px;
  508. background: #2199F8;
  509. color: #fff;
  510. text-align: center;
  511. }
  512. }
  513. </style>