punchin-edit.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <main-layout :showHome="true" :showBack="true">
  3. <template>
  4. <uni-forms ref="baseForm" :modelValue="punchInData" :label-width="80">
  5. <uni-section title="基本信息" padding="16px" type="line">
  6. <uni-forms-item label="任务名称" required>
  7. <uni-easyinput v-model="punchInData.taskName" placeholder="请输入任务名称" />
  8. </uni-forms-item>
  9. <uni-forms-item label="奖励数" required>
  10. <uni-easyinput v-model="punchInData.rewardNum" placeholder="请输入奖励数" type="number" />
  11. </uni-forms-item>
  12. <uni-forms-item label="周末双倍" required>
  13. <uni-data-checkbox v-model="punchInData.weekendDoubleFlag" :localdata="range"></uni-data-checkbox>
  14. </uni-forms-item>
  15. <uni-forms-item label="全勤双倍" required>
  16. <uni-data-checkbox v-model="punchInData.fullAttendanceFlag" :localdata="range"></uni-data-checkbox>
  17. </uni-forms-item>
  18. <uni-forms-item label="打卡类型" required>
  19. <uni-data-select :localdata="punchInTypeRange" v-model="punchInData.category"></uni-data-select>
  20. </uni-forms-item>
  21. <uni-forms-item label="规则描述">
  22. <uni-easyinput type="textarea" v-model="punchInData.description" placeholder="请输入任务描述" />
  23. </uni-forms-item>
  24. </uni-section>
  25. <uni-section title="计数配置" padding="16px" type="line" v-if="punchInData.category == 1">
  26. <uni-forms-item label="判断规则" required>
  27. <uni-data-select :localdata="judgeTypeRange" v-model="punchInData.rule"></uni-data-select>
  28. </uni-forms-item>
  29. <uni-forms-item label="数值" required>
  30. <uni-easyinput v-model="punchInData.countTrack" placeholder="请输入目标数值" type="digit" />
  31. </uni-forms-item>
  32. </uni-section>
  33. <uni-section title="计时配置" padding="16px" type="line" v-if="punchInData.category == 2">
  34. <uni-forms-item label="判断规则" required>
  35. <uni-data-select :localdata="judgeTypeRange" v-model="punchInData.rule"></uni-data-select>
  36. </uni-forms-item>
  37. <uni-forms-item label="时间" required>
  38. <picker mode="time" :value="punchInData.timeTrack" @change="timeChange">
  39. <view class="pick-box">{{punchInData.timeTrack}}</view>
  40. </picker>
  41. </uni-forms-item>
  42. </uni-section>
  43. <view class="button-container">
  44. <button type="default" style="width:300rpx;" @click="cancel">取消</button>
  45. <button type="primary" style="color:#ffffff;backgroundColor:#2A82E4;width:300rpx;" @click="savePunchIn">保存</button>
  46. </view>
  47. </uni-forms>
  48. </template>
  49. </main-layout>
  50. </template>
  51. <script setup>
  52. import { ref } from 'vue';
  53. import { onLoad } from '@dcloudio/uni-app';
  54. import { punchInApi } from '@/service/apis';
  55. /**
  56. * 表单
  57. */
  58. const baseForm = ref(null);
  59. /**
  60. * 表单数据
  61. */
  62. const punchInData = ref({
  63. "rewardNum": 1,
  64. "weekendDoubleFlag": 1,
  65. "fullAttendanceFlag": 1,
  66. "category": 0,
  67. "rule": 0,
  68. "countTrack": 10,
  69. "timeTrack": "00:00"
  70. });
  71. /**
  72. * 选项
  73. */
  74. const range = [
  75. {
  76. "value": 1,
  77. "text": "启用"
  78. },
  79. {
  80. "value": 2,
  81. "text": "关闭"
  82. }
  83. ];
  84. /**
  85. * 打卡类型
  86. */
  87. const punchInTypeRange = [
  88. { value: 0, text: "单次打卡" },
  89. { value: 1, text: "计数" },
  90. { value: 2, text: "计时" },
  91. ];
  92. const judgeTypeRange = [
  93. { value: 0, text: "大于等于" },
  94. { value: 1, text: "小于等于" },
  95. { value: 2, text: "大于" },
  96. { value: 2, text: "小于" },
  97. ];
  98. onLoad(async (e) => {
  99. if (e.id) {
  100. const res = await punchInApi.queryPunchInById({"id": e.id});
  101. punchInData.value = res;
  102. }
  103. });
  104. const weekendDoubleSwitchChange = (e) => {
  105. punchInData.value.weekendDoubleFlag = e.detail.value;
  106. }
  107. const fullAttendanceSwitchChange = (e) => {
  108. punchInData.value.fullAttendanceFlag = e.detail.value;
  109. }
  110. /**
  111. * 保存打卡任务
  112. */
  113. const savePunchIn = () => {
  114. punchInApi.addPunchIn(punchInData.value).then(() => {
  115. uni.showToast({
  116. title: '保存成功',
  117. icon: 'success',
  118. duration: 2000
  119. });
  120. setTimeout(() => {
  121. uni.navigateBack();
  122. }, 2000);
  123. });
  124. }
  125. /**
  126. * 后退
  127. */
  128. const cancel = () => {
  129. uni.navigateBack();
  130. }
  131. /**
  132. * 时间选择监听
  133. */
  134. const timeChange = (e) => {
  135. punchInData.value.timeTrack = e.detail.value;
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. .pick-box {
  140. display: flex;
  141. box-sizing: border-box;
  142. flex-direction: row;
  143. align-items: center;
  144. border: 1px solid #dcdfe6;
  145. border-radius: 4px;
  146. width: auto;
  147. position: relative;
  148. overflow: hidden;
  149. flex: 1;
  150. line-height: 1;
  151. font-size: 14px;
  152. height: 35px;
  153. padding-left: 10px;
  154. }
  155. .button-container {
  156. background-color: #FFFFFF;
  157. display: flex; /* 使用Flexbox布局 */
  158. justify-content: space-between; /* 按钮之间的空间分布 */
  159. padding: 20rpx; /* 容器两侧的空白填充 */
  160. }
  161. // .button {
  162. // flex-grow: 1; /* 按钮占据可用空间 */
  163. // margin: 0 10px; /* 按钮两侧的空白填充 */
  164. // }
  165. </style>