myTaskLayout.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="layout">
  3. <!-- 自定义导航栏 -->
  4. <!-- <view class="custom-nav" :style="{ height: navBarHeight + 'px' }">
  5. <view class="nav-content" :style="{ marginTop: statusBarHeight + 'px' }">
  6. <view class="back" @click="handleBack">
  7. <view class="box-img">
  8. <image src="/static/icons/icon-fh.png" mode="widthFix"></image>
  9. </view>
  10. </view>
  11. <view class="nav-title"> {{ title }} </view>
  12. <view class="nav-right">
  13. <button class="register-btn" @click="handleRegister">账号注册</button>
  14. </view>
  15. </view>
  16. </view> -->
  17. <!-- 添加上边距以避免被导航栏遮挡 -->
  18. <!-- :style="{ paddingTop: navBarHeight + 'px' }" -->
  19. <view class="main-content">
  20. <!-- 顶部导航栏 -->
  21. <view class="tabs">
  22. <view
  23. v-for="(item, index) in tabList"
  24. :key="index"
  25. :class="['tab-item', currentTab === index ? 'active' : '']"
  26. @click="switchTab(index)"
  27. >
  28. {{ item.name }}
  29. </view>
  30. </view>
  31. <!-- 内容区域 -->
  32. <swiper
  33. :current="currentTab"
  34. @change="handleSwiperChange"
  35. :style="{ height: `calc(100vh - 88rpx)` }"
  36. >
  37. <!-- :style="{ height: `calc(100vh - ${navBarHeight}px - 88rpx - 140rpx)` }" -->
  38. <swiper-item v-for="(item, index) in tabList" :key="index">
  39. <CheckInfo
  40. v-if="item.component === 'CheckInfo'"
  41. :task-info="taskInfo"
  42. @update-clock-info="handleClockInfoUpdate"
  43. ></CheckInfo>
  44. <WarehouseInfo
  45. v-if="item.component === 'WarehouseInfo'"
  46. :task-info="taskInfo"
  47. ref="warehouseInfoRef"
  48. ></WarehouseInfo>
  49. <StorageInfo
  50. v-if="item.component === 'StorageInfo'"
  51. :task-info="taskInfo"
  52. ></StorageInfo>
  53. <FinanceInfo
  54. v-if="item.component === 'FinanceInfo'"
  55. :task-info="taskInfo"
  56. ></FinanceInfo>
  57. </swiper-item>
  58. </swiper>
  59. <!-- 验证按钮 -->
  60. <view class="verify-buttons" v-if="currentTab === 1 && !taskInfo.isAllOk">
  61. <button class="btn pass" @click="handleVerify(true)">核验通过</button>
  62. <button class="btn reject" @click="handleVerify(false)">
  63. 核验不通过
  64. </button>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import CheckInfo from "./components/CheckInfo.vue";
  71. import WarehouseInfo from "./components/WarehouseInfo.vue";
  72. import StorageInfo from "./components/StorageInfo.vue";
  73. import FinanceInfo from "./components/FinanceInfo.vue";
  74. import { getTasks } from "@/api/task";
  75. export default {
  76. components: {
  77. CheckInfo,
  78. WarehouseInfo,
  79. StorageInfo,
  80. FinanceInfo,
  81. },
  82. data() {
  83. return {
  84. currentTab: 0,
  85. tabList: [
  86. { name: "打卡信息", component: "CheckInfo" },
  87. { name: "仓房信息", component: "WarehouseInfo" },
  88. { name: "库区信息", component: "StorageInfo" },
  89. { name: "财务信息", component: "FinanceInfo" },
  90. ],
  91. statusBarHeight: 0,
  92. navBarHeight: 0,
  93. taskInfo: null,
  94. noHy: false, //是否核验过
  95. clockInInfo: null, // 添加这个数据属性来存储打卡信息
  96. };
  97. },
  98. computed: {
  99. title() {
  100. if (this.tabList[this.currentTab].name === "打卡信息") {
  101. return "我的任务";
  102. } else {
  103. return this.tabList[this.currentTab].name;
  104. }
  105. },
  106. },
  107. created() {
  108. // 获取系统信息
  109. const systemInfo = uni.getSystemInfoSync();
  110. // 状态栏高度
  111. this.statusBarHeight = systemInfo.statusBarHeight;
  112. // 导航栏高度(默认44px)
  113. const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  114. // 计算导航栏高度 = 状态栏高度 + (胶囊底部 - 状态栏底部) * 2
  115. this.navBarHeight =
  116. this.statusBarHeight +
  117. (menuButtonInfo.bottom - systemInfo.statusBarHeight) * 1;
  118. this.isMiniProgram();
  119. },
  120. onLoad(options) {
  121. if (options.taskInfo) {
  122. try {
  123. this.taskInfo = JSON.parse(decodeURIComponent(options.taskInfo));
  124. uni.setNavigationBarTitle({
  125. title: this.taskInfo.kqmc || "我的任务",
  126. });
  127. // console.log("接收到的任务信息:", this.taskInfo);
  128. } catch (error) {
  129. console.error("解析任务信息失败:", error);
  130. }
  131. }
  132. },
  133. mounted() {
  134. if (this.taskInfo.hyState !== 3) {
  135. // 禁止核验
  136. this.noHy = true;
  137. } else {
  138. this.noHy = false;
  139. }
  140. },
  141. methods: {
  142. handleBack() {
  143. uni.navigateBack();
  144. },
  145. switchTab(index) {
  146. this.currentTab = index;
  147. },
  148. handleSwiperChange(e) {
  149. this.currentTab = e.detail.current;
  150. },
  151. async handleVerify(isPassed) {
  152. if (!this.clockInInfo.dkdd) {
  153. // 重定向到打卡页面
  154. this.currentTab = 0;
  155. uni.showToast({
  156. title: "请先打卡",
  157. icon: "none",
  158. });
  159. return;
  160. }
  161. let data;
  162. if (isPassed) {
  163. data = {
  164. kqIds: [this.taskInfo.kqId],
  165. hyState: 1,
  166. listType: 2,
  167. };
  168. } else {
  169. data = {
  170. kqIds: [this.taskInfo.kqId],
  171. hyState: 2,
  172. listType: 2,
  173. };
  174. }
  175. this.$refs.warehouseInfoRef[0].confirmSelection(data);
  176. // const res = await getTasks(data);
  177. // if (res.code === 0) {
  178. // uni.showToast({
  179. // title: res.msg,
  180. // icon: "success",
  181. // });
  182. // // 跳转到任务列表页面
  183. // uni.reLaunch({
  184. // url: "/pages/taskList-verification/taskListLayout?tab=1",
  185. // });
  186. // } else {
  187. // uni.showToast({
  188. // title: "核验失败",
  189. // icon: "none",
  190. // });
  191. // }
  192. },
  193. handleRegister() {
  194. // 处理注册按钮点击事件
  195. uni.navigateTo({
  196. url: "/pages/register/register",
  197. });
  198. },
  199. // 判断是否为小程序
  200. isMiniProgram() {
  201. // console.log(uni.getSystemInfoSync().platform);
  202. return uni.getLaunchOptionsSync().query.miniProgram;
  203. },
  204. // 添加处理打卡信息更新的方法
  205. handleClockInfoUpdate(info) {
  206. this.clockInInfo = info;
  207. },
  208. },
  209. };
  210. </script>
  211. <style lang="scss" scoped>
  212. .layout {
  213. height: 100vh;
  214. background: linear-gradient(to bottom, #cfddfc 10%, #ffffff);
  215. position: relative;
  216. }
  217. .custom-nav {
  218. position: fixed;
  219. top: 0;
  220. left: 0;
  221. right: 0;
  222. background: #cfddfc;
  223. z-index: 999;
  224. .nav-content {
  225. display: flex;
  226. align-items: center;
  227. justify-content: space-between;
  228. height: 44px;
  229. padding: 0 16px;
  230. .back {
  231. width: 180rpx;
  232. display: flex;
  233. align-items: center;
  234. .box-img {
  235. width: 30rpx;
  236. height: 40rpx;
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. image {
  241. width: 100% !important;
  242. height: 100% !important;
  243. }
  244. }
  245. }
  246. .nav-title {
  247. width: 180rpx;
  248. font-size: 40rpx;
  249. // font-weight: bold;
  250. color: #333;
  251. }
  252. .nav-right {
  253. margin-right: 150rpx;
  254. width: 180rpx;
  255. .register-btn {
  256. margin: 0;
  257. padding: 0;
  258. height: 32px;
  259. line-height: 32px;
  260. font-size: 35rpx;
  261. color: #333;
  262. background: rgba(0, 0, 0, 0);
  263. // border-radius: 16px;
  264. // border: 1px solid #2979ff;
  265. &::after {
  266. border: none;
  267. }
  268. }
  269. }
  270. }
  271. }
  272. .main-content {
  273. box-sizing: border-box;
  274. min-height: 100vh;
  275. }
  276. .tabs {
  277. display: flex;
  278. height: 88rpx;
  279. background-color: #cfddfc;
  280. // border-bottom: 1rpx solid #eee;
  281. background-color: #cfddfc;
  282. }
  283. .tab-item {
  284. flex: 1;
  285. display: flex;
  286. align-items: center;
  287. justify-content: center;
  288. padding: 20rpx 0;
  289. font-size: 35rpx;
  290. color: #333;
  291. position: relative;
  292. font-weight: 400;
  293. &.active {
  294. color: #000;
  295. position: relative;
  296. font-weight: 500;
  297. &::after {
  298. content: "";
  299. position: absolute;
  300. bottom: 0;
  301. left: 50%;
  302. transform: translateX(-50%);
  303. width: 150rpx;
  304. height: 10rpx;
  305. background-color: #4185fa;
  306. }
  307. }
  308. }
  309. .verify-buttons {
  310. position: fixed;
  311. bottom: 0;
  312. left: 0;
  313. right: 0;
  314. padding: 20rpx 0 40rpx 0;
  315. display: flex;
  316. justify-content: space-between;
  317. // background-color: #fff;
  318. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  319. z-index: 100;
  320. .btn {
  321. width: 48%;
  322. height: 80rpx;
  323. line-height: 80rpx;
  324. text-align: center;
  325. border-radius: 10rpx;
  326. font-size: 28rpx;
  327. &.pass {
  328. background-color: #2979ff;
  329. color: #fff;
  330. }
  331. &.reject {
  332. background-color: #fff;
  333. color: #2979ff;
  334. border: 2rpx solid #2979ff;
  335. }
  336. }
  337. }
  338. </style>