qrCode.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // StepPage/pages/qrCode/qrCode.js
  2. var qrcode = require('./weapp.qrcode.min');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. ishow:false,
  9. show:false,
  10. mobile:'',
  11. searchList:[],
  12. searchValue:'',
  13. title:'',
  14. shopList:[],
  15. chooseList:[{four_shop_id:'',expires_time:''}],
  16. chooseIndex:0,
  17. state:true
  18. },
  19. handleChoose(item){
  20. let arr = JSON.parse(JSON.stringify(this.data.chooseList));
  21. arr[this.data.chooseIndex].title = item.target.dataset.item.title;
  22. arr[this.data.chooseIndex].four_shop_id = item.target.dataset.item.id;
  23. this.setData({
  24. ishow:false,
  25. chooseList:arr
  26. })
  27. },
  28. handleCancel(){
  29. this.setData({
  30. ishow:false
  31. })
  32. },
  33. handleSearch(e){
  34. this.setData({
  35. ishow:true,
  36. chooseIndex:e.target.dataset.index,
  37. searchList:this.data.shopList
  38. })
  39. },
  40. handleAdd(data){
  41. let arr = this.data.chooseList;
  42. arr.splice(data.target.dataset.index+1,0,{title:'',four_shop_id:'',expires_time:''});
  43. this.setData({
  44. chooseList:arr
  45. })
  46. },
  47. handleDelete(data){
  48. let arr = this.data.chooseList;
  49. if(arr.length==1){
  50. arr = [{title:'',four_shop_id:'',expires_time:''}]
  51. }else{
  52. arr.splice(data.target.dataset.index,1);
  53. }
  54. this.setData({
  55. chooseList:arr
  56. })
  57. },
  58. onSearch(event){
  59. let arr = this.data.shopList.filter(v=>v.title.indexOf(event.detail)!=-1);
  60. this.setData({
  61. searchList:arr
  62. })
  63. },
  64. bindDateChange(e){
  65. let arr = JSON.parse(JSON.stringify(this.data.chooseList));
  66. arr[e.target.dataset.index].expires_time = e.detail.value;
  67. this.setData({
  68. chooseList:arr
  69. })
  70. },
  71. onClose() {
  72. this.setData({ show: false });
  73. },
  74. handleBack(){
  75. wx.redirectTo({
  76. url: '../../../pages/zero/zero',
  77. })
  78. },
  79. handleChangeMobile(e){
  80. this.setData({
  81. mobile:e.detail
  82. })
  83. },
  84. handleNext(){
  85. if(!this.data.mobile||this.data.chooseList.length==0){
  86. return wx.showToast({
  87. icon:'error',
  88. title: '请填写信息',
  89. })
  90. }
  91. if (!/^1[3456789]\d{9}$/.test(this.data.mobile)) {
  92. return wx.showToast({
  93. icon:'error',
  94. title: '手机格式不对',
  95. })
  96. }
  97. if(this.data.state){
  98. this.setData({
  99. state:false
  100. })
  101. let app = getApp();
  102. let openid = app.globalData.openID;
  103. let arr =[]
  104. this.data.chooseList.forEach(ele => {
  105. let obj = {};
  106. obj.four_shop_id = ele.four_shop_id;
  107. obj.expires_time = ele.expires_time?(new Date(new Date(ele.expires_time).toLocaleDateString()).getTime()+86400000-1).toString().slice(0,10):''
  108. arr.push(obj);
  109. });
  110. wx.p.request({
  111. url: `${app.globalData.url}wx/createTemporaryJs`,
  112. method:'POST',
  113. data:{
  114. openid,
  115. mobile:this.data.mobile,
  116. four_shop:arr
  117. }
  118. }).then(res=>{
  119. if(res.data.code==200){
  120. this.setData({
  121. show:true
  122. })
  123. qrcode({
  124. width:200,
  125. height:200,
  126. canvasId:'myQrcode',
  127. text:`https://zhapi.qingyaokeji.com`,
  128. callback:function(){
  129. }
  130. })
  131. }else{
  132. wx.showToast({
  133. icon:'none',
  134. title: res.data.msg,
  135. })
  136. }
  137. setTimeout(()=>{
  138. this.setData({
  139. state:true
  140. })
  141. },2000)
  142. })
  143. }
  144. },
  145. /**
  146. * 生命周期函数--监听页面加载
  147. */
  148. onLoad(options) {
  149. let app = getApp();
  150. let openid = app.globalData.openID;
  151. wx.p.request({
  152. url: `${app.globalData.url}wx/fourShop`,
  153. method:'POST',
  154. data:{
  155. openid
  156. }
  157. }).then(res=>{
  158. if(res.data.code==200){
  159. let shopList = res.data.data
  160. this.setData({
  161. shopList:shopList
  162. })
  163. }
  164. })
  165. },
  166. /**
  167. * 生命周期函数--监听页面初次渲染完成
  168. */
  169. onReady() {
  170. },
  171. /**
  172. * 生命周期函数--监听页面显示
  173. */
  174. onShow() {
  175. },
  176. /**
  177. * 生命周期函数--监听页面隐藏
  178. */
  179. onHide() {
  180. },
  181. /**
  182. * 生命周期函数--监听页面卸载
  183. */
  184. onUnload() {
  185. },
  186. /**
  187. * 页面相关事件处理函数--监听用户下拉动作
  188. */
  189. onPullDownRefresh() {
  190. },
  191. /**
  192. * 页面上拉触底事件的处理函数
  193. */
  194. onReachBottom() {
  195. },
  196. /**
  197. * 用户点击右上角分享
  198. */
  199. onShareAppMessage() {
  200. }
  201. })