task.vue 18 KB

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