punchin-edit.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.name" 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"></uni-data-select>
  20. </uni-forms-item>
  21. <uni-forms-item label="规则描述">
  22. <uni-easyinput type="textarea" v-model="punchInData.desc" placeholder="请输入自我介绍" />
  23. </uni-forms-item>
  24. </uni-section>
  25. <uni-section title="计数配置" padding="16px" type="line">
  26. <uni-forms-item label="判断规则" required>
  27. <uni-data-select :localdata="judgeTypeRange"></uni-data-select>
  28. </uni-forms-item>
  29. <uni-forms-item label="数值" required>
  30. <uni-easyinput v-model="punchInData.rewardNum" placeholder="请输入奖励数" type="digit" />
  31. </uni-forms-item>
  32. </uni-section>
  33. <uni-section title="计时配置" padding="16px" type="line">
  34. <uni-forms-item label="判断规则" required>
  35. <uni-data-select :localdata="judgeTypeRange"></uni-data-select>
  36. </uni-forms-item>
  37. <uni-forms-item label="时间" required>
  38. <picker mode="time" :value="punchInData.time">
  39. <view class="pick-box">{{punchInData.time}}</view>
  40. </picker>
  41. </uni-forms-item>
  42. </uni-section>
  43. <view class="button-container">
  44. <button type="default" style="width:300rpx;">取消</button>
  45. <button type="primary" style="color:#ffffff;backgroundColor:#2A82E4;width:300rpx;">保存</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. "time": '12:00'
  67. });
  68. /**
  69. * 选项
  70. */
  71. const range = [
  72. {
  73. "value": 1,
  74. "text": "启用"
  75. },
  76. {
  77. "value": 2,
  78. "text": "关闭"
  79. }
  80. ];
  81. /**
  82. * 打卡类型
  83. */
  84. const punchInTypeRange = [
  85. { value: 0, text: "单次打卡" },
  86. { value: 1, text: "计数" },
  87. { value: 2, text: "技时" },
  88. ];
  89. const judgeTypeRange = [
  90. { value: 0, text: "大于等于" },
  91. { value: 1, text: "小于等于" },
  92. { value: 2, text: "大于" },
  93. { value: 2, text: "小于" },
  94. ];
  95. onLoad(async (e) => {
  96. if (e.id) {
  97. const res = await punchInApi.queryPunchInById({"id": e.id});
  98. punchIn.value = res;
  99. }
  100. });
  101. const weekendDoubleSwitchChange = (e) => {
  102. punchIn.value.weekendDoubleFlag = e.detail.value;
  103. }
  104. const fullAttendanceSwitchChange = (e) => {
  105. punchIn.value.fullAttendanceFlag = e.detail.value;
  106. }
  107. /**
  108. * 保存打卡任务
  109. */
  110. const savePunchIn = () => {
  111. punchInApi.addPunchIn(punchIn.value).then(() => {
  112. uni.showToast({
  113. title: '保存成功',
  114. icon: 'success',
  115. duration: 2000
  116. });
  117. setTimeout(() => {
  118. uni.navigateBack();
  119. }, 2000);
  120. });
  121. }
  122. /**
  123. * 后退
  124. */
  125. const cancel = () => {
  126. uni.navigateBack();
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .pick-box {
  131. display: flex;
  132. box-sizing: border-box;
  133. flex-direction: row;
  134. align-items: center;
  135. border: 1px solid #dcdfe6;
  136. border-radius: 4px;
  137. width: auto;
  138. position: relative;
  139. overflow: hidden;
  140. flex: 1;
  141. line-height: 1;
  142. font-size: 14px;
  143. height: 35px;
  144. padding-left: 10px;
  145. }
  146. .button-container {
  147. background-color: #FFFFFF;
  148. display: flex; /* 使用Flexbox布局 */
  149. justify-content: space-between; /* 按钮之间的空间分布 */
  150. padding: 20rpx; /* 容器两侧的空白填充 */
  151. }
  152. // .button {
  153. // flex-grow: 1; /* 按钮占据可用空间 */
  154. // margin: 0 10px; /* 按钮两侧的空白填充 */
  155. // }
  156. </style>