readpacket.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <view class="page">
  3. <view class="line">
  4. <view class="left">
  5. <view class="pin" v-if="isgroup==1 && type==1">拼</view> {{money_title}}
  6. </view>
  7. <view class="right">
  8. <input class="input" type="digit" v-if="money>0" v-model="money" maxlength="5"/>
  9. <input class="input" type="digit" v-else placeholder="0.00" @input="money=$event.detail.value" />
  10. </view>
  11. </view>
  12. <block v-if="isgroup==1">
  13. <view class="tips">
  14. <block v-if="type==1">
  15. 当前为拼手气红包,<span class='text' @tap="change_type(2)">改为普通红包</span>
  16. </block>
  17. <block v-else>
  18. 当前为普通红包,<span class='text' @tap="change_type(1)">改为拼手气红包</span>
  19. </block>
  20. </view>
  21. <view class="line">
  22. <view class="left">
  23. 红包个数
  24. </view>
  25. <view class="right">
  26. <input class="input" type="number" v-if="num" v-model="num" @input="listen_num($event.detail.value)" maxlength="3" />
  27. <input class="input" type="number" v-else placeholder="填写个数" @input="listen_num($event.detail.value)" />个
  28. </view>
  29. </view>
  30. <view class="tips" style="color: #666;">
  31. 本群共<span class='text'>{{group.people_count}}</span>人
  32. </view>
  33. </block>
  34. <view class="line">
  35. <input class="input1" :placeholder="system.redpacket_title" v-model="title"/>
  36. </view>
  37. <view class="money_show">
  38. <view class="icon">¥</view>
  39. <view class="title">{{moneytotal}}</view>
  40. </view>
  41. <view :class="{'sendbtn':true,'active':issend}" @tap='subsend()'>塞进红包</view>
  42. <view class="bottom">
  43. 未领取的红包,将在{{system.redpacket_backtime}}小时退回到您的账户
  44. </view>
  45. <payment v-if="showpay" @payresult='payresult' :payinfo="payinfo" title="支付" :getmoney="moneytotal" :fix='fix' type="redpacket" :id="id" @close="showpay=false;"></payment>
  46. </view>
  47. </template>
  48. <script>
  49. import payment from '../../components/payment.vue'
  50. export default {
  51. components: {
  52. payment,
  53. },
  54. data() {
  55. return {
  56. isgroup:0,
  57. id:0,
  58. money_title:'总金额',
  59. type:1,
  60. money:'0.00',
  61. num:0,
  62. title:'',
  63. group:'',
  64. system:uni.getStorageSync('system'),
  65. user:uni.getStorageSync('userInfo'),
  66. showpay:false,
  67. payinfo:{},
  68. fix:true
  69. }
  70. },
  71. computed:{
  72. moneytotal(){
  73. if(this.type==1) var res = this.money;
  74. else var res = this.money*this.num;
  75. if(res>this.system.redpacket_min) return parseFloat(res).toFixed(2);
  76. else return '0.00'
  77. },
  78. issend(){
  79. if(this.moneytotal>0 && this.num>0) return true;
  80. else return false;
  81. }
  82. },
  83. methods:{
  84. listen_num(v){
  85. if(v>0 && parseInt(v)<this.group.people_count) this.num=parseInt(v);
  86. else this.num=1;
  87. },
  88. change_type(type){
  89. this.type=type;
  90. if(type==1) this.money_title='总金额';
  91. else this.money_title='单个金额'
  92. },
  93. payresult(e){
  94. if(e>0){
  95. var mid ='m' +Math.random().toString(36).substring(2);
  96. var sendData={title:this.payinfo.title,status:1,id:e,isgroup:this.isgroup,type:this.type,isopen:0};
  97. if(this.isgroup==1){
  98. var data = {
  99. userid: this.user.id,
  100. group_id: this.id,
  101. type: 'group',
  102. msgtype: 'redpacket',
  103. content: sendData,
  104. mid: mid
  105. };
  106. }else{
  107. var data = {
  108. userid: this.user.id,
  109. friend_uid: this.id,
  110. type: 'chat',
  111. msgtype: 'redpacket',
  112. content: sendData,
  113. mid: mid
  114. };
  115. }
  116. this.$socket.send(data);
  117. setTimeout(function(){
  118. uni.navigateBack();
  119. },100)
  120. }
  121. else{
  122. uni.showToast({
  123. title:'支付发生错误',
  124. icon:'none'
  125. })
  126. }
  127. this.showpay=false;
  128. },
  129. subsend(){
  130. if(!this.issend) return false;
  131. if(parseFloat(this.money)<0.01){
  132. uni.showToast({
  133. title:'请输入红包金额',
  134. icon:'none'
  135. })
  136. return false;
  137. }
  138. if(parseInt(this.num)<1){
  139. uni.showToast({
  140. title:'请输入红包个数',
  141. icon:'none'
  142. })
  143. return false;
  144. }
  145. if(parseFloat(this.money)/parseInt(this.num)<0.01){
  146. uni.showToast({
  147. title:'红包不够分了!',
  148. icon:'none'
  149. })
  150. return false;
  151. }
  152. if(this.isgroup==1 && parseInt(this.num) > parseInt(this.group.people_count)){
  153. uni.showToast({
  154. title:'红包个数不能大于群总人数',
  155. icon:'none'
  156. })
  157. return false;
  158. }
  159. if(parseFloat(this.moneytotal)<parseFloat(this.system.redpacket_min) || parseFloat(this.moneytotal)>parseFloat(this.system.redpacket_max)){
  160. uni.showToast({
  161. title:'红包金额范围:'+this.system.redpacket_min+'-'+this.system.redpacket_max+'元',
  162. icon:'none'
  163. })
  164. return false;
  165. }
  166. if(parseFloat(this.moneytotal)>parseFloat(this.user.money1)){
  167. uni.showModal({
  168. title: '可用余额不足',
  169. content: "您的可用余额不足,请先去充值!",
  170. showCancel: true,
  171. cancelText: '取消',
  172. confirmText: '去充值',
  173. success: res => {
  174. if(res.confirm) {
  175. uni.redirectTo({
  176. url:"/pages/mine/recharge"
  177. })
  178. }
  179. }
  180. });
  181. return false;
  182. }
  183. if(this.title) var title=this.title;
  184. else var title=this.system.redpacket_title;
  185. this.payinfo={isgroup:this.isgroup,type:this.type,permoney:this.money,num:this.num,title:title,chatid:this.id,summoney:this.moneytotal}
  186. this.showpay=true;
  187. },
  188. },
  189. onLoad(opts){
  190. this.id=opts.id;
  191. this.isgroup=opts.isgroup;
  192. if(this.isgroup==0){
  193. this.type=2;
  194. this.num=1;
  195. }
  196. else{
  197. this.group = uni.getStorageSync('group_'+this.id);
  198. }
  199. }
  200. }
  201. </script>
  202. <style lang="scss">
  203. view{
  204. padding: 0px 0px;
  205. margin: 0px 0px;
  206. }
  207. .page{
  208. background-color: #FAFAFA;
  209. font-size: 14px;;
  210. padding-top: 1px;
  211. }
  212. .page .tips{
  213. height: 22px;
  214. line-height: 22px;
  215. text-align: left;
  216. font-size: 12px;
  217. padding: 0px 10px;
  218. }
  219. .page .tips .text{
  220. display: inline-block;
  221. color: #c69848;
  222. }
  223. .page .line{
  224. background-color: #FFFFFF;
  225. margin-top: 15px;
  226. height: 50px;
  227. line-height: 50px;
  228. padding: 0px 10px;;
  229. }
  230. .page .line .left{
  231. width: 100px;
  232. display: inline-block;
  233. text-align: left;
  234. vertical-align: top;
  235. }
  236. .page .line .right{
  237. width: calc(100% - 100px);
  238. vertical-align: top;
  239. display: inline-block;
  240. text-align: right;
  241. }
  242. .page .line .right .input{
  243. height: 40px;
  244. line-height: 40px;
  245. width: calc(100% - 30px);
  246. padding: 0px 5px;
  247. border: 0px;
  248. text-align: right;
  249. display: inline-block;
  250. vertical-align: middle;
  251. }
  252. .page .line .input1{
  253. height: 40px;
  254. line-height: 40px;
  255. width: calc(100% - 10px);
  256. padding: 0px 5px;
  257. border: 0px;
  258. text-align: left;
  259. display: inline-block;
  260. vertical-align: middle;
  261. }
  262. .pin{
  263. height: 18px;
  264. width: 18px;line-height: 18px;
  265. text-align: center;
  266. color:#FFF;
  267. background-color: #c69848;
  268. border-radius: 3px;
  269. display: inline-block;
  270. margin-right: 5px;
  271. }
  272. .money_show{
  273. margin-top: 15px;
  274. height: 50px;
  275. line-height: 50px;
  276. padding: 0px 10px;;
  277. text-align: center;
  278. }
  279. .money_show .icon{
  280. font-size: 14px;
  281. color: #333;
  282. display: inline-block;
  283. }
  284. .money_show .title{
  285. font-size: 34px;
  286. font-weight: 700;
  287. color: #000;
  288. display: inline-block;
  289. }
  290. .sendbtn{
  291. height: 40px;
  292. line-height: 40px;
  293. width: 240px;
  294. display: block;
  295. margin: 15px auto;
  296. border: 0px;
  297. color:#fff;
  298. background-color:#e1e1e1;
  299. font-size:16px;
  300. font-weight:600;
  301. text-align:center;
  302. border-radius: 5px;
  303. }
  304. .sendbtn.active{
  305. background-color: #2319DC;
  306. }
  307. .bottom{
  308. height: 30px;
  309. line-height: 30px;
  310. color: #666;
  311. text-align: center;
  312. position: fixed;
  313. left: 0px;
  314. bottom: 0px;
  315. width: 100%;
  316. }
  317. </style>