calcprice.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // miniprogram/price/calcprice.js
  2. const app=getApp();
  3. const utils=require("../../utils/http");
  4. let time1=null;
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. priceflag:{
  11. type: Boolean,
  12. value:false
  13. },
  14. },
  15. /**
  16. * 组件的初始数据
  17. */
  18. data: {
  19. imgUrl:app.globalData.imgUrl,
  20. arr:[0,0,0,0,0,0,0,0,0,0],
  21. pricenum:[5,1,5,6,0],
  22. homearr:[
  23. {id:1,name:'1室'},
  24. {id:2,name:'2室'},
  25. {id:3,name:'3室'},
  26. {id:4,name:'4室'},
  27. {id:5,name:'5室'},
  28. {id:6,name:'6室'},
  29. {id:7,name:'7室'},
  30. {id:8,name:'8室'},
  31. {id:9,name:'9室'},
  32. {id:10,name:'10室'}],
  33. hidx:2,
  34. liveroom:[
  35. {id:1,name:'1厅'},
  36. {id:2,name:'2厅'},
  37. {id:3,name:'3厅'},
  38. {id:4,name:'4厅'},
  39. {id:5,name:'5厅'}
  40. ],
  41. lidx:1,
  42. tolitarr:[
  43. {id:1,name:'1卫'},
  44. {id:2,name:'2卫'},
  45. {id:3,name:'3卫'},
  46. {id:4,name:'4卫'},
  47. {id:5,name:'5卫'}
  48. ],
  49. tidx:0,
  50. area:'',
  51. phone:''
  52. },
  53. ready() {
  54. clearInterval(time1);
  55. var num='0000';
  56. time1=setInterval(res=>{
  57. num=parseInt(Math.random()*60000+40000);
  58. num=num+'';
  59. num.split('');
  60. this.setData({
  61. pricenum:num
  62. })
  63. },1000)
  64. },
  65. methods:{
  66. dothis(){},
  67. setareatap(e){
  68. this.setData({
  69. area:e.detail.value
  70. })
  71. },
  72. bindPickerChange: function(e) {
  73. this.setData({
  74. hidx: e.detail.value
  75. })
  76. },
  77. bindliveChange: function(e) {
  78. this.setData({
  79. lidx: e.detail.value
  80. })
  81. },
  82. bindtolietChange: function(e) {
  83. this.setData({
  84. tidx: e.detail.value
  85. })
  86. },
  87. isPhoneNum: function (phone) {
  88. var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\d{8})$/;
  89. if (!myreg.test(phone)) {
  90. return false;
  91. }
  92. return true;
  93. },
  94. setphonetap(e){
  95. this.setData({
  96. phone: e.detail.value
  97. })
  98. },
  99. closetap(){
  100. this.triggerEvent("run", '')
  101. },
  102. subfun(){
  103. const that=this;
  104. if(!that.data.area){
  105. wx.showToast({
  106. title: "房屋面积不能为空",
  107. icon: 'none',
  108. duration: 2000
  109. })
  110. return false;
  111. }
  112. if(!that.data.phone){
  113. wx.showToast({
  114. title: "手机号不能为空",
  115. icon: 'none',
  116. duration: 2000
  117. })
  118. return false;
  119. }
  120. if(!this.isPhoneNum(that.data.phone)){
  121. this.setData({
  122. phone:''
  123. })
  124. wx.showToast({
  125. title: "手机号格式不对!",
  126. icon: 'none',
  127. duration: 2000
  128. })
  129. return false;
  130. }
  131. wx.showLoading({
  132. title: '计算中...',
  133. })
  134. utils.$post({
  135. url: app.globalData.webUrl + 'client/quote_record/add',
  136. header: {
  137. 'Authorization':'bearer '+app.globalData.token
  138. },
  139. data:{
  140. area:that.data.area,
  141. room:that.data.homearr[that.data.hidx].id,//室
  142. hall:that.data.liveroom[that.data.lidx].id,//厅
  143. bathroom:that.data.tolitarr[that.data.tidx].id,//卫
  144. phone:that.data.phone,
  145. },
  146. success: function (res) {
  147. // wx.hideLoading();
  148. if(res.data.code=='0'){
  149. that.triggerEvent("run", '')
  150. wx.showToast({
  151. title: res.data.msg,
  152. icon: 'none',
  153. duration: 2000
  154. })
  155. }
  156. }
  157. })
  158. },
  159. }
  160. })