index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="transfer-box">
  3. <view class="transfer-title">
  4. <view>代金券转赠</view>
  5. <view @click="cancel">取消</view>
  6. </view>
  7. <view class="transfer-list">
  8. <view
  9. class="transfer-item"
  10. v-for="(item, index) in transferPriceList"
  11. :key="index"
  12. :class="idx === index ? 'act' : ''"
  13. @click="changeIdx(index)"
  14. >{{ item }}</view
  15. >
  16. <view
  17. class="transfer-item custom"
  18. :class="idx === 5 ? 'act' : ''"
  19. @click="changeIdx(5)"
  20. >
  21. <text>自定义数额</text>
  22. <input type="number" v-model="customNum" />
  23. </view>
  24. </view>
  25. <view class="transfer-account">
  26. <view class="account-title">转赠账号</view>
  27. <view class="account-input">
  28. <tui-input
  29. placeholder="请输入用户手机号后点击查询"
  30. padding="32rpx 0 32rpx 0"
  31. borderColor="#e7e7e7"
  32. :lineLeft="false"
  33. v-model="searchValue"
  34. >
  35. <template #right>
  36. <view class="query" @click="searchUser">查询</view>
  37. </template>
  38. </tui-input>
  39. </view>
  40. <view class="account-info">
  41. <view class="info-image">
  42. <image :src="buyerUserObj.headImage" />
  43. </view>
  44. <view class="info-text">
  45. <view class="name">{{
  46. buyerUserObj.wechatName || buyerUserObj.name
  47. }}</view>
  48. <view class="text" v-if="buyerUserObj.phone">
  49. <text>ID:{{ buyerUserObj.buyerUserId }}</text>
  50. <text>手机号:{{ buyerUserObj.phone || "" }}</text>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="transfer-btn">
  56. <view class="available"> 可用代金券:<text>{{ voucherWithdrawalIn }}</text> </view>
  57. <view class="btn" @click="immediatelyBtn">立即转赠</view>
  58. </view>
  59. <!-- 自定义弹框组件 -->
  60. <modal
  61. :showModal="modal"
  62. :promptList="promptList"
  63. @closeModal="closeModal"
  64. @btnClick="backClick"
  65. :showBtn="true"
  66. showText="确认赠送"
  67. ></modal>
  68. </view>
  69. </template>
  70. <script>
  71. import { getBandUserInfoApi, bandUserInfoApi } from "@/config/index";
  72. export default {
  73. props: {
  74. voucherWithdrawalIn: {
  75. type: String || Number,
  76. default: 0,
  77. },
  78. },
  79. data() {
  80. return {
  81. // 激活态
  82. idx: "",
  83. // 转赠金额列表
  84. transferPriceList: [50, 100, 200, 1000, 2000],
  85. searchValue: "",
  86. // 转增人员信息
  87. buyerUserObj: {},
  88. // 转赠参数
  89. transferUser: {
  90. voucherNum: "",
  91. buyerUserId: "",
  92. },
  93. // 自定义数额
  94. customNum: "",
  95. modal: false,
  96. // 二次确认信息
  97. promptList: ["转增金额:1000", "转赠账户:15170844121"],
  98. };
  99. },
  100. methods: {
  101. // 查询用户
  102. async searchUser() {
  103. if (this.searchValue == "") {
  104. this.$showToast("请输入用户手机号后点击查询");
  105. return;
  106. }
  107. // 手机正则校验
  108. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/;
  109. if (!phoneCodeVerification.test(this.searchValue)) {
  110. this.$showToast("手机号格式为1开头11位!");
  111. return;
  112. }
  113. let res = await getBandUserInfoApi({ numPhone: this.searchValue });
  114. console.log(res.data, Object.is(res.data, {}));
  115. if (Object.keys(res.data).length == 0) {
  116. this.$showToast("该用户不存在!");
  117. }
  118. this.buyerUserObj = res.data;
  119. this.transferUser.buyerUserId = res.data.buyerUserId;
  120. },
  121. // 修改激活态
  122. changeIdx(val) {
  123. this.idx = val;
  124. },
  125. // 立即转增
  126. immediatelyBtn() {
  127. let num = 0;
  128. if (this.idx == 5 && !this.customNum) {
  129. this.$showToast("请输入自定义数额且不能为0");
  130. return;
  131. }else if(this.idx === ""){
  132. this.$showToast("请选择需要赠送的额度");
  133. return
  134. }
  135. if (this.idx == 5) {
  136. num = this.customNum;
  137. } else {
  138. num = this.transferPriceList[this.idx];
  139. }
  140. if(Object.keys(this.buyerUserObj).length == 0){
  141. this.$showToast("请查询需要赠送的账户");
  142. return
  143. }
  144. // if(this.voucherWithdrawalIn < num){
  145. // this.$showToast("抱歉,你转赠的代金券不足,请先充值代金券");
  146. // return
  147. // }
  148. this.promptList = [
  149. "转增金额:" + num,
  150. "转赠账户:" + this.buyerUserObj.phone,
  151. ]
  152. this.modal = true;
  153. },
  154. // 确认赠送
  155. async backClick() {
  156. let obj = {
  157. voucherNum:0,
  158. buyerUserId:""
  159. }
  160. if (this.idx == 5) {
  161. obj.voucherNum = this.customNum;
  162. } else {
  163. obj.voucherNum = this.transferPriceList[this.idx];
  164. }
  165. obj.buyerUserId = this.buyerUserObj.buyerUserId;
  166. // 请求
  167. let res = await bandUserInfoApi(obj);
  168. console.log(res);
  169. },
  170. // 关闭二次确认弹框
  171. closeModal() {
  172. this.modal = false;
  173. },
  174. // 取消按钮
  175. cancel(){
  176. this.$emit('cancel')
  177. }
  178. },
  179. };
  180. </script>
  181. <style lang="scss" scoped>
  182. @import "./index.scss";
  183. </style>