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.

287 lines
9.1 KiB

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