You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

302 lines
9.7 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
  1. <script setup>
  2. import { ref, onMounted, reactive, computed, watch, nextTick } from 'vue'
  3. import { ElMessage } from 'element-plus'
  4. import { Plus } from '@element-plus/icons-vue'
  5. import axios from 'axios'
  6. import { ElMessageBox } from 'element-plus'
  7. import API from '@/util/http.js'
  8. import { uploadFile } from '@/util/request.js';
  9. import request from '@/util/http.js'
  10. import moment from 'moment'
  11. import { e, range, re } from 'mathjs'
  12. import { utils, read } from 'xlsx'
  13. import throttle from 'lodash/throttle'
  14. import { useAdminStore } from "@/store/index.js";
  15. import { storeToRefs } from "pinia";
  16. import _ from 'lodash'
  17. // 国际化
  18. import { useI18n } from 'vue-i18n';
  19. const { t } = useI18n();
  20. const user = ref({})
  21. const getUser = async function (jwcode) {
  22. if (consumeForm.value.jwcode) {
  23. consumeForm.value.jwcode = consumeForm.value.jwcode.replace(/\s/g, '');
  24. } else {
  25. ElMessage.error(t('elmessage.checkJwcode'))
  26. return false
  27. }
  28. try {
  29. const result = await API({
  30. url: '/beanUser/userCard',
  31. data: {
  32. jwcode: consumeForm.value.jwcode
  33. }
  34. })
  35. if (result.code === 0) {
  36. ElMessage.error(result.msg);
  37. } else if (result.data === null) {
  38. ElMessage.error(t('elmessage.noUser'));
  39. } else {
  40. user.value = result.data;
  41. console.log("用户信息", user.value);
  42. ElMessage.success(t('elmessage.searchSuccess'));
  43. }
  44. } catch (error) {
  45. console.log("请求失败", error);
  46. ElMessage.error(t('elmessage.jwcodeError'));
  47. }
  48. }
  49. //提交禁止重复点击
  50. const addDisabled = ref(false)
  51. const consumeForm = ref({
  52. jwcode: '',
  53. permanentBean: '',
  54. freeBean: '',
  55. remark: '',
  56. adminName: ''
  57. })
  58. const formRef = ref(null)
  59. const adminStore = useAdminStore()
  60. const { adminData } = storeToRefs(adminStore)
  61. const rules = reactive({
  62. jwcode: [
  63. { required: true, message: t('elmessage.checkJwcode'), trigger: 'blur' },
  64. {
  65. validator: (rule, value, callback) => {
  66. if (!value) {
  67. callback(new Error(t('elmessage.noEmptyJwcode')));
  68. return;
  69. }
  70. if (/[^0-9]/.test(value)) {
  71. callback(new Error(t('elmessage.limitDigitJwcode')));
  72. return;
  73. }
  74. callback();
  75. }, trigger: 'blur'
  76. }],
  77. permanentBean: [
  78. { required: true, message: t('elmessage.checkPayBean'), trigger: 'change' },
  79. {
  80. validator: (rule, value, callback) => {
  81. if (!value) {
  82. value = 0
  83. }
  84. // 检查是否为非负整数
  85. if (!/^\d+$/.test(value)) {
  86. callback(new Error(t('elmessage.checkNonNegative')));
  87. return;
  88. }
  89. // 检查位数
  90. if (value.length > 6) {
  91. callback(new Error(t('elmessage.limitSix')));
  92. return;
  93. }
  94. callback();
  95. },
  96. trigger: 'blur'
  97. }
  98. ],
  99. freeBean: [
  100. { required: true, message: t('elmessage.checkFreeBean'), trigger: 'change' },
  101. {
  102. validator: (rule, value, callback) => {
  103. if (!value) {
  104. value = 0
  105. }
  106. // 检查是否为非负整数
  107. if (!/^\d+$/.test(value)) {
  108. callback(new Error(t('elmessage.checkNonNegative')));
  109. return;
  110. }
  111. // 检查位数
  112. if (value.length > 6) {
  113. callback(new Error(t('elmessage.limitSix')));
  114. return;
  115. }
  116. callback();
  117. },
  118. trigger: 'blur'
  119. }
  120. ],
  121. remark: [
  122. { required: true, message: t('elmessage.checkRemark'), trigger: 'blur' }
  123. ]
  124. });
  125. //重置表单
  126. const deleteConsumeForm = function () {
  127. formRef.value.resetFields();
  128. }
  129. const handleConsumeForm = async () => {
  130. try {
  131. if (!consumeForm.value.permanentBean) {
  132. consumeForm.value.permanentBean = 0
  133. }
  134. if (!consumeForm.value.freeBean) {
  135. consumeForm.value.freeBean = 0
  136. }
  137. await new Promise((resolve, reject) => {
  138. formRef.value.validate((valid) => {
  139. if (valid) {
  140. if (Number(consumeForm.value.permanentBean) === 0 && Number(consumeForm.value.freeBean) === 0) {
  141. reject(new Error(t('elmessage.noPayBeanFreeBeanZero')));
  142. }
  143. resolve(); // 验证通过,继续执行后续代码
  144. } else {
  145. reject(new Error(t('elmessage.checkFormInfo'))); // 验证失败,抛出错误
  146. }
  147. });
  148. });
  149. console.log('adminData', adminData.value);
  150. // 新增验证逻辑,判断输入数量是否超过用户拥有数量
  151. const inputPermanentBean = Number(consumeForm.value.permanentBean);
  152. const inputFreeBean = Number(consumeForm.value.freeBean);
  153. const userPermanentBean = Number(user.value.permanentBean) || 0;
  154. const userFreeBean = Number(user.value.freeBean) || 0;
  155. // if (inputPermanentBean > userPermanentBean) {
  156. // throw new Error('付费金豆数量超过用户当前所拥有');
  157. // }
  158. // if (inputFreeBean > userFreeBean) {
  159. // throw new Error('免费金豆数量超过用户当前所拥有');
  160. // }
  161. await ElMessageBox.confirm(
  162. t('consume.confirmConsume'),
  163. t('consume.prompt'),
  164. {
  165. confirmButtonText: t('common.confirm'),
  166. cancelButtonText: t('common.cancel'),
  167. type: "primary",
  168. lockScroll: false,
  169. }
  170. )
  171. addDisabled.value = true
  172. const result = await request({
  173. url: '/beanConsume/reduce',
  174. data: {
  175. jwcode: consumeForm.value.jwcode,
  176. permanentBean: consumeForm.value.permanentBean,
  177. freeBean: consumeForm.value.freeBean,
  178. remark: consumeForm.value.remark,
  179. adminName: adminData.value.adminName
  180. }
  181. })
  182. addDisabled.value = false
  183. if (result.code == 200) {
  184. ElMessage.success(t('elmessage.addsuccess'))
  185. deleteConsumeForm()
  186. user.value = {}
  187. } else {
  188. ElMessage.error(result.msg)
  189. }
  190. } catch (error) {
  191. console.log('金豆新增充值失败');
  192. ElMessage.error(error.message || t('elmessage.operationFailed'));
  193. }
  194. }
  195. const throttledHandleConsumeFormt = _.throttle(handleConsumeForm, 5000, {
  196. trailing: false
  197. })
  198. </script>
  199. <template>
  200. <div class="userAndform">
  201. <div class="left">
  202. <el-form :model="consumeForm" :rules="rules" ref="formRef" label-width="auto" style="max-width: 600px"
  203. class="add-form">
  204. <el-form-item prop="jwcode" :label="t('common_add.jwcode')" label-position="left">
  205. <el-input v-model="consumeForm.jwcode" style="width: 220px" @keyup.enter="getUser(consumeForm.jwcode)"/>
  206. <el-button type="primary" @click="getUser(consumeForm.jwcode)" style="margin-left: 20px">{{ t('common.search') }}</el-button>
  207. </el-form-item>
  208. <el-form-item prop="permanentBean" :label="t('common_add.permanentBean')" label-position="left">
  209. <el-input v-model="consumeForm.permanentBean" placeholder="0" style="width: 100px" />
  210. </el-form-item>
  211. <el-form-item prop="freeBean" :label="t('common_add.freeBean')" label-position="left">
  212. <el-input v-model="consumeForm.freeBean" placeholder="0" style="width: 100px" />
  213. </el-form-item>
  214. <el-form-item prop="remark" :label="t('common_add.remark')" label-position="left">
  215. <el-input v-model="consumeForm.remark" style="width: 300px" :rows="5" maxlength="100" show-word-limit
  216. type="textarea" />
  217. </el-form-item>
  218. <el-button @click="deleteConsumeForm" style="margin-left: 9vw;margin-top:1vw" type="success">{{ t('common.reset') }}</el-button>
  219. <el-button type="primary" :disabled="addDisabled" @click="handleConsumeForm" style="margin-top:1vw"> {{ t('common.submit') }}
  220. </el-button>
  221. </el-form>
  222. </div>
  223. <!-- 客户信息栏 -->
  224. <div class="right">
  225. <el-card v-if="user.jwcode" class="customer-info">
  226. <el-form :model="user" label-width="auto" label-position="left">
  227. <el-text size="large" style="margin-left: 5vw">{{ t('common_add_user.customerInfo') }}</el-text>
  228. <!-- 第一行姓名 + 当前付费金豆 -->
  229. <div style="margin-top: 0.5vw;display:flex;">
  230. <p style="min-width:6vw;">{{ t('common_add_user.name') }}:</p>
  231. <p style="color: #2fa1ff;width:6vw;">{{ user.name }}</p>
  232. <p style="width:7vw;">{{ t('common_add_user.permanentBean') }}:</p>
  233. <p v-if="!isNaN(Number(user.permanentBean))" style="color: #2fa1ff;">{{ Number(user.permanentBean) }}</p>
  234. <!-- 如果不是有效的数字显示默认值 -->
  235. <p v-else></p>
  236. </div>
  237. <!-- 第二行精网号 + 免费金豆 -->
  238. <div style="display:flex">
  239. <p style="width:6vw;">{{ t('common_add_user.jwcode') }}:</p>
  240. <p style="color: #2fa1ff;width:6vw;">{{ user.jwcode }}</p>
  241. <p style="width:7vw;">{{ t('common_add_user.freeBean') }}:</p>
  242. <p v-if="user.freeBean !== undefined" style="color: #2fa1ff;">{{ user.freeBean }}</p>
  243. </div>
  244. <!-- 第三行消费次数 + 所属门店 -->
  245. <div style="display:flex">
  246. <p style="width:6vw;">{{ t('common_add_user.store') }}:</p>
  247. <p style="color: #2fa1ff;width:6vw;">{{ user.market }}</p>
  248. <p style="width:7vw;">{{ t('common_add_user.consumeTotalBean') }}:</p>
  249. <p style="color: #2fa1ff;" v-if="user.consumeSum != null">{{ user.consumeSum }}</p>
  250. <p style="color: #2fa1ff;" v-else>{{ 0 }}</p>
  251. </div>
  252. </el-form>
  253. </el-card>
  254. </div>
  255. </div>
  256. </template>
  257. <style scoped lang="scss">
  258. .userAndform {
  259. width: 80vw;
  260. height: 80vh;
  261. display: flex;
  262. .left {
  263. width: 35vw;
  264. height: 80vh;
  265. display: flex;
  266. .add-form {
  267. width: 40vw;
  268. margin-top: 5vh;
  269. }
  270. }
  271. .right {
  272. flex: 1;
  273. display: flex;
  274. // float: left;
  275. .customer-info {
  276. min-width: 35vw;
  277. height: 28vh;
  278. margin-top: 5vh;
  279. // display: flex;
  280. justify-content: center;
  281. }
  282. }
  283. }
  284. </style>