Просмотр исходного кода

【feat】【v3】

1.增加兑换功能
2.增加图表工具ucharts依赖
3.完善逻辑
ChenYL 9 месяцев назад
Родитель
Сommit
b2ae490605
6 измененных файлов с 200 добавлено и 10 удалено
  1. 7 0
      package-lock.json
  2. 3 2
      package.json
  3. 15 1
      src/apis/rewardApi.js
  4. 156 7
      src/pages/rewardMarket.vue
  5. 13 0
      src/pages/task/taskDetail.vue
  6. 6 0
      src/pages/taskTodo.vue

+ 7 - 0
package-lock.json

@@ -24,6 +24,7 @@
         "@dcloudio/uni-mp-xhs": "3.0.0-4030620241128001",
         "@dcloudio/uni-quickapp-webview": "3.0.0-4030620241128001",
         "@dcloudio/uni-ui": "^1.5.7",
+        "@qiun/uni-ucharts": "^2.5.0-20230101",
         "vue": "3.4.21",
         "vue-avatar": "^2.3.3",
         "vue-i18n": "9.14.2"
@@ -4004,6 +4005,12 @@
         "url": "https://opencollective.com/parcel"
       }
     },
+    "node_modules/@qiun/uni-ucharts": {
+      "version": "2.5.0-20230101",
+      "resolved": "https://registry.npmmirror.com/@qiun/uni-ucharts/-/uni-ucharts-2.5.0-20230101.tgz",
+      "integrity": "sha512-qpgzAUgrShgKNn0uMoN54n6/MkFeQQpK2gur0Fzokn8oTIMCVjTfnt8C2UhD20pPlm6MFxwkWF+bsJ3qd4QMvg==",
+      "license": "Apache"
+    },
     "node_modules/@rollup/pluginutils": {
       "version": "5.1.4",
       "resolved": "https://registry.npmmirror.com/@rollup/pluginutils/-/pluginutils-5.1.4.tgz",

+ 3 - 2
package.json

@@ -67,9 +67,10 @@
     "@dcloudio/uni-mp-xhs": "3.0.0-4030620241128001",
     "@dcloudio/uni-quickapp-webview": "3.0.0-4030620241128001",
     "@dcloudio/uni-ui": "^1.5.7",
+    "@qiun/uni-ucharts": "^2.5.0-20230101",
     "vue": "3.4.21",
-    "vue-i18n": "9.14.2",
-    "vue-avatar": "^2.3.3"
+    "vue-avatar": "^2.3.3",
+    "vue-i18n": "9.14.2"
   },
   "devDependencies": {
     "@dcloudio/types": "3.4.14",

+ 15 - 1
src/apis/rewardApi.js

@@ -47,4 +47,18 @@ export function saveReward(data) {
 	loading: true,
 	loadingText: "正在保存奖励信息,请稍后..."
   });
-}
+}
+
+/**
+ * 兑换奖励
+ * @param {Object} data
+ */
+export function exchangeReward(data) {
+	return request({
+	  url: "/reward/exchangeReward",
+	  method: "post",
+	  data,
+	  loading: true,
+	  loadingText: "正在兑换奖励,请稍后..."
+	});
+  }

+ 156 - 7
src/pages/rewardMarket.vue

@@ -18,12 +18,31 @@
           <view class="reward-item-title">{{ reward.rewardName }}</view>
           <view class="reward-item-points">{{ reward.exchangePoints }}积分</view>
           <view class="reward-item-btn">
-            <view class="reward-exchange-btn">立即兑换</view>
+            <view class="reward-exchange-btn" @click="exchnageReward(reward.id)">立即兑换</view>
           </view>
         </view>
       </uni-grid-item>
     </uni-grid>
   </view>
+
+  <!-- 兑换弹出框 -->
+  <uni-popup ref="exchangeDialog" type="dialog" :is-mask-click="false">
+    <uni-popup-dialog mode="input" :before-close="true" title="兑换奖励" confirmText="兑换" @confirm="exchangeFormConfirm"
+      @close="exchangeFormClose">
+      <uni-forms ref="exchangeForm" :modelValue="exchangeFormData" :label-width="250" label-position="top"
+        :rules="exchangeFormRules">
+        <uni-forms-item label="待兑换的奖励" required name="rewardId">
+          <uni-data-select :localdata="rewardSelectedData" v-model="exchangeFormData.rewardId"></uni-data-select>
+        </uni-forms-item>
+        <uni-forms-item label="兑换使用的积分账户" required name="accountId">
+          <uni-data-select :localdata="accountSelectedData" v-model="exchangeFormData.accountId"></uni-data-select>
+        </uni-forms-item>
+        <uni-forms-item label="待兑换数量" required name="exchangeCount">
+          <uni-easyinput v-model="exchangeFormData.exchangeCount" placeholder="1" type="digit" />
+        </uni-forms-item>
+      </uni-forms>
+    </uni-popup-dialog>
+  </uni-popup>
 </template>
 
 <script setup>
@@ -31,6 +50,17 @@ import { ref } from 'vue';
 import { onPullDownRefresh, onShow } from '@dcloudio/uni-app';
 import { accountApi, rewardApi } from '@/apis/apis';
 
+// 组件
+/**
+ * 兑换弹出框
+ */
+const exchangeDialog = ref(null);
+
+/**
+* 兑换表单
+*/
+const exchangeForm = ref(null);
+
 // 属性
 /**
  * 基本户
@@ -47,11 +77,56 @@ const generalAccountList = ref([]);
  */
 const rewardList = ref([]);
 
+/**
+ * 兑换表单数据
+ */
+const exchangeFormData = ref({});
+
+/**
+ * 兑换表单规则
+ */
+const exchangeFormRules = ref({
+  rewardId: {
+    rules: [{
+      required: true,
+      errorMessage: "待兑换的奖励不能为空"
+    }]
+  },
+  accountId: {
+    rules: [{
+      required: true,
+      errorMessage: "兑换使用的积分账户不能为空"
+    }]
+  },
+  exchangeCount: {
+    rules: [{
+      required: true,
+      errorMessage: '待兑换数量不能为空'
+    }, {
+      format: 'number',
+      errorMessage: "请输入有效数字"
+    }, {
+      minimum: 1,
+      errorMessage: "最小值{minimum}"
+    }]
+  }
+});
+
+/**
+ * 奖励 下拉框数据
+ */
+const rewardSelectedData = ref([]);
+
+/**
+* 账户 下拉框数据
+*/
+const accountSelectedData = ref([]);
+
 // 方法
 /**
- * 拉取账户数据
+ * 拉取账户信息
  */
-const loadAccountData = async () => {
+const loadAccountInfoData = async () => {
   let res = await accountApi.queryAccountInfo();
   if (!res) {
     basicAccount.value = null;
@@ -62,23 +137,97 @@ const loadAccountData = async () => {
   generalAccountList.value = res.generalAccountList;
 };
 
+/**
+ * 拉取账户数据
+ */
+const loadAccountData = async () => {
+  let res = await accountApi.queryAccountList();
+  if (!res) {
+    accountSelectedData.value = [];
+    return;
+  }
+  accountSelectedData.value = res.map(item => {
+    let text = `${item.accountName}(${item.points}积分)`;
+    return {
+      text,
+      value: item.id
+    }
+  });
+}
+
 /**
  * 拉取奖励数据
  */
 const loadRewardData = async () => {
   let res = await rewardApi.queryRewardList();
   rewardList.value = res;
+  if (!res) {
+    rewardList.value = [];
+    rewardSelectedData.value = [];
+    return;
+  }
+
+  rewardList.value = res;
+  rewardSelectedData.value = res.map(item => {
+    let text = `${item.rewardName}(${item.exchangePoints}积分)`;
+    return {
+      text,
+      value: item.id
+    }
+  });
 };
 
-// 生命周期
-onShow(() => {
+/**
+ * 拉取数据
+ */
+const loadData = async () => {
+  loadAccountInfoData();
   loadAccountData();
   loadRewardData();
+};
+
+/**
+ * 兑换奖励
+ */
+const exchnageReward = (id) => {
+  exchangeFormData.value.rewardId = id;
+  if (accountSelectedData.value.length > 0) {
+    exchangeFormData.value.accountId = accountSelectedData.value[0].value;
+  }
+  exchangeDialog.value.open();
+};
+
+/**
+ * 计时表单提交
+ */
+const exchangeFormConfirm = async () => {
+  if (!exchangeFormData.value.exchangeCount) {
+    exchangeFormData.value.exchangeCount = 1;
+  }
+  exchangeForm.value.validate().then(data => {
+    return rewardApi.exchangeReward(exchangeFormData.value);
+  }).then(e => {
+    exchangeFormData.value = {};
+    exchangeDialog.value.close();
+    loadData();
+  });
+}
+
+/**
+ * 计时表单取消
+ */
+const exchangeFormClose = async () => {
+  exchangeFormData.value = {};
+  exchangeDialog.value.close();
+}
+
+// 生命周期
+onShow(() => {
+  loadData();
 });
 
 onPullDownRefresh(() => {
-  loadAccountData();
-  loadRewardData();
+  loadData();
   uni.stopPullDownRefresh();
 });
 </script>

+ 13 - 0
src/pages/task/taskDetail.vue

@@ -264,6 +264,19 @@ const loadData = async () => {
     "taskId": currentTaskId.value
   });
 
+  // 没有统计数据
+  if (!res) {
+    res = {
+      punchInTotalCount: 0,
+      punchInCount: 0,
+      punchInDoneCount: 0,
+      punchInRate: 0,
+      punchInDoneRate: 0,
+      points: 0,
+      piTaskHistoryStatVOS: []
+    };
+  }
+
   if (currentStatPeriod.value == STAT_PERIOD.MONTH) {
     statMonth.value = res;
   } else {

+ 6 - 0
src/pages/taskTodo.vue

@@ -158,6 +158,12 @@ const timeTrackFormConfirm = async () => {
   });
 }
 
+/**
+ * 计时表单取消
+ */
+const timeTrackFormClose = async () => {
+  timeTrackInputDialog.value.close();
+}
 
 /**
  * 打卡