No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

257 líneas
5.8 KiB

  1. // pages/Add/index.js
  2. const config = require('../../config/config.js')
  3. const Http = require('../../utils/http.js')
  4. const HttpBasics = require('../../utils/HttpBasics.js')
  5. const util = require('../../utils/util.js')
  6. var app = getApp()
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. paramData: null,
  13. isAdmin: null,
  14. userData: null,
  15. couList: [],
  16. couListH: [],
  17. pages: 1,
  18. page: 1,
  19. checkedArr: [],
  20. showModal: false,
  21. arr: [],
  22. dataH: [],
  23. quanPageNum: 1,
  24. quanPageSize: 15,
  25. quanTotalpageNum: 0,
  26. titleH: [],
  27. pageNavigationObj: null,
  28. submitAble: true,
  29. errM: '',
  30. codeE: ''
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. console.log(options, 'options');
  37. options.phone = (options.phone != 'undefined' ? options.phone : '未绑定')
  38. options.nickName = (options.nickName != 'undefined' ? options.nickName : '未绑定')
  39. this.setData({
  40. paramData: options,
  41. page: 1,
  42. loading: false
  43. });
  44. this.getUserInfo()
  45. this.getMerchentCoupon(1)
  46. },
  47. onShow: function (options) {
  48. this.setData({
  49. showModal: false,
  50. submitAble: true
  51. });
  52. this.getUserInfo()
  53. this.getMerchentCoupon(1)
  54. },
  55. getUserInfo() {
  56. let that = this;
  57. app.globalData.userInfo().then(res => {
  58. that.setData({
  59. userData: res
  60. })
  61. }).catch(err => {
  62. wx.showToast({
  63. title: '商户信息获取出错',
  64. icon: 'none',
  65. duration: 2000,
  66. mask: false
  67. });
  68. })
  69. },
  70. /**
  71. * 获取会员可赠送的券
  72. */
  73. getMerchentCoupon(page, dealType) {
  74. let that = this;
  75. let postData = {
  76. token: app.globalData.token,
  77. pageNum: page,
  78. pageSize: 6,
  79. sendType: 7,
  80. expired: 0,
  81. status: 0
  82. }
  83. HttpBasics.get({
  84. url: config.api.wxMerchantcouponSend,
  85. data: postData,
  86. })
  87. .then(res => {
  88. if (res.data && res.data.list && res.data.list.length >= 0) {
  89. this.setData({
  90. pageNavigationObj: res.data,
  91. })
  92. wx.stopPullDownRefresh();
  93. res.data.list.map((item, index) => {
  94. item.validEndDate = util.formatTime(item.validEndDate, 'yyyy-MM-dddd')
  95. item.validStartDate = util.formatTime(item.validStartDate, 'yyyy-MM-dddd')
  96. item = Object.assign(item, { checked: false })
  97. });
  98. var tmpArr = [];
  99. if (page == 1) {
  100. tmpArr = [];
  101. } else {
  102. tmpArr = that.data.couListH;
  103. }
  104. tmpArr = [...tmpArr, ...res.data.list];
  105. that.setData({
  106. page: page + 1,
  107. couListH: tmpArr,
  108. })
  109. if (tmpArr.length >= res.data.total) {
  110. that.setData({
  111. loading: "没有更多数据"
  112. })
  113. return false;
  114. } else {
  115. that.setData({
  116. loading: "小主,我在玩命加载中..."
  117. })
  118. }
  119. }
  120. })
  121. .catch(err => {
  122. wx.showToast({
  123. title: '玩命加载中,请检查网络连接',
  124. icon: 'none',
  125. duration: 2000,
  126. mask: false
  127. });
  128. });
  129. },
  130. /**
  131. * 刷新
  132. */
  133. onPullDownRefresh: function (e) {
  134. let that = this;
  135. that.setData({
  136. pageNum: 1,
  137. loading: false,
  138. page: 1,
  139. showModal: false,
  140. arr: []
  141. });
  142. that.getMerchentCoupon(1, 'fromPullDown');
  143. },
  144. onReachBottom() {
  145. let that = this;
  146. let page = that.data.page++;
  147. if (that.data.pageNavigationObj.pages + 1 >= page) {
  148. that.getMerchentCoupon(page);
  149. }
  150. },
  151. /**
  152. * 选择使用的优惠券
  153. */
  154. choicecoupon: function (e) {
  155. let that = this;
  156. let index = e.currentTarget.dataset.index;
  157. let item = that.data.couListH[index];
  158. item.checked = !item.checked;
  159. this.setData({
  160. couListH: that.data.couListH,
  161. });
  162. },
  163. /**
  164. * 确认
  165. */
  166. submitForm() {
  167. let selArr = this.data.couListH;
  168. for (let i = 0; i < selArr.length; i++) {
  169. this.data.arr = this.data.couListH.filter((value, index) => {
  170. return value.checked == true
  171. })
  172. }
  173. if (this.data.arr.length != 0) {
  174. this.setData({
  175. showModal: true,
  176. arr: this.data.arr
  177. })
  178. } else {
  179. wx.showToast({
  180. title: '抱歉,您还未选择券',
  181. icon: 'none',
  182. duration: 2000,
  183. mask: false
  184. });
  185. }
  186. },
  187. /**
  188. * 弹框确认注券
  189. */
  190. sure() {
  191. let that = this;
  192. that.data.dataH = that.data.arr.map(item => item.id)
  193. that.data.titleH = that.data.arr.map(item => item.title)
  194. that.setData({
  195. submitAble: false
  196. })
  197. HttpBasics.post({
  198. url: config.api.wxMerchantcouponhandSel,
  199. data: {
  200. wxCouponSendIds: that.data.dataH,
  201. cUserId: that.data.paramData.id,
  202. }
  203. })
  204. .then(res => {
  205. wx.showToast({
  206. title: '注券成功!',
  207. icon: 'none',
  208. duration: 2000,
  209. mask: false
  210. });
  211. wx.navigateTo({
  212. url: '/pages/editSuccess/index?type=3&titleH=' + that.data.titleH
  213. })
  214. that.setData({
  215. submitAble: true
  216. })
  217. })
  218. .catch(err => {
  219. // that.setData({
  220. // submitAble: true,
  221. // errM: err.message,
  222. // codeErr: err.code
  223. // })
  224. // if (err.message){
  225. // that.setData({
  226. // submitAble: false
  227. // })
  228. // }
  229. that.setData({
  230. submitAble: true,
  231. })
  232. wx.showToast({
  233. title: err.message ? err.message : err.data,
  234. icon: 'none',
  235. duration: 2000,
  236. mask: false
  237. });
  238. });
  239. },
  240. /**
  241. * 取消弹框
  242. */
  243. closeModal: function () {
  244. this.getMerchentCoupon(1)
  245. this.setData({
  246. showModal: false,
  247. codeErr: '',
  248. submitAble: true
  249. })
  250. },
  251. })