You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

309 lines
8.1 KiB

  1. // pages/payment/mjCoupon/mjCoupon.js
  2. const config = require('../../../config/config.js')
  3. const Http = require('../../../utils/HttpBasics.js')
  4. const util = require('../../../utils/util.js')
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. phone: '',
  12. optionsData:'',
  13. avaList:[],
  14. coListH:[],
  15. arr:[],
  16. orderId:'',
  17. END:'',
  18. TYPE:'',
  19. ID:'',
  20. coupon_id:'',
  21. composeOrderId:"",
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. console.log(options)
  28. this.setData({
  29. optionsData: options,
  30. flag: "coupons",
  31. payPrice: Number(options.val),
  32. });
  33. if (options.phone&&options.phone != 'undefined') {
  34. // options.phone = (options.phone != 'undefined' ? options.phone : '未绑定')
  35. this.setData({
  36. phone: this.data.optionsData.phone,
  37. coupon_id: this.data.optionsData.coupon_id,
  38. flag: "record",
  39. });
  40. let postData = {
  41. phone: this.data.phone
  42. }
  43. this.submitForm(postData)
  44. }
  45. if (options.END &&options.END != 'undefined') {
  46. this.setData({
  47. coupon_id: this.data.optionsData.coupon_id,
  48. flag: "coupons",
  49. checked: true
  50. });
  51. let postData1 = {
  52. cUserId: this.data.optionsData.ID
  53. }
  54. this.getCoupons1()
  55. }
  56. },
  57. showInfo(){
  58. wx.showToast({
  59. title: '抱歉,请输入正确的手机号',
  60. icon: 'none',
  61. duration: 2000,
  62. mask: false
  63. });
  64. },
  65. //切换扫会员码
  66. getCoupons() {
  67. this.setData({
  68. flag: "coupons",
  69. })
  70. },
  71. //切换手机号
  72. getRecord() {
  73. this.setData({
  74. flag: "record",
  75. })
  76. },
  77. getList(e) {
  78. console.log(e.detail.value)
  79. this.setData({
  80. phone: e.detail.value
  81. })
  82. },
  83. submitForm() {
  84. const reg = /^1[0|1|2|3|4|5|6|7|8|9]\d{9}$/;
  85. let _this = this;
  86. let postData = {
  87. phone: _this.data.phone,
  88. payPrice: _this.data.optionsData.val,
  89. }
  90. if (!reg.test(_this.data.phone)) {
  91. wx.showToast({
  92. title: '抱歉,请输入正确的手机号',
  93. icon: 'none',
  94. duration: 2000,
  95. mask: false
  96. });
  97. return;
  98. }
  99. Http.post({
  100. url: config.api.getManjian,
  101. data: postData
  102. })
  103. .then(res => {
  104. if (res && res.data.coList) {
  105. res.data.coList.map((item, index) => {
  106. item = Object.assign(item, { checked: false })
  107. if (this.data.coupon_id == item.coupon_id) {
  108. item.checked = true;
  109. }
  110. });//15313025161
  111. this.setData({
  112. avaList: res.data.coList,
  113. orderId: res.data.order.id,
  114. composeOrderId: res.data.order.composeOrderId
  115. })
  116. } else {
  117. wx.showToast({
  118. title: '抱歉,暂无可使用的优惠券!',
  119. icon: 'none',
  120. duration: 2000,
  121. mask: false
  122. });
  123. this.setData({
  124. avaList: '',
  125. orderId: res.data.order.id
  126. })
  127. //15669929956
  128. }
  129. })
  130. .catch(err => {
  131. wx.showToast({
  132. title: err.message,
  133. icon: 'none',
  134. duration: 2000,
  135. mask: false
  136. });
  137. });
  138. },
  139. /**
  140. * 扫描会员码
  141. */
  142. gotoSaoyiSao: function () {
  143. let optionsData = this.data.optionsData
  144. let that = this
  145. wx.scanCode({
  146. success: function (val) {
  147. console.log(val.result);
  148. if (util.isJSON(val.result)) {
  149. let value = JSON.parse(val.result);
  150. let postData1 = {
  151. cUserId: value.ID,
  152. payPrice: optionsData.val,
  153. }
  154. that.setData({
  155. END: value.END,
  156. TYPE: value.TYPE,
  157. ID: value.ID
  158. })
  159. if (value.END == 'C' && value.TYPE == 'memberCode' && value.ID.length >= 18) {
  160. console.log(444444444444)
  161. Http.post({
  162. url: config.api.getManjian,
  163. data: postData1
  164. }).then (res => {
  165. console.log(res, 9999999999)
  166. if (res.code == 200) {
  167. if (res.data.coList) {
  168. res.data.coList.map((item, index) => {
  169. item = Object.assign(item, { checked: false })
  170. if (that.data.coupon_id == item.coupon_id) {
  171. item.checked = true;
  172. }
  173. });
  174. that.setData({
  175. avaList: res.data.coList,
  176. orderId: res.data.order.id,
  177. composeOrderId: res.data.order.composeOrderId
  178. })
  179. }else{
  180. wx.showToast({
  181. title: '抱歉,暂无可使用的优惠券!',
  182. icon: 'none',
  183. duration: 2000,
  184. mask: false
  185. });
  186. that.setData({
  187. avaList: '',
  188. orderId: res.data.order.id
  189. })
  190. }
  191. }
  192. }).catch(err =>{
  193. wx.showModal({
  194. title: "抱歉",
  195. content: err.message,
  196. showCancel: false
  197. })
  198. that.setData({
  199. avaList: '',
  200. // orderId: res.data.order.id
  201. })
  202. })
  203. } else {
  204. wx.showToast({
  205. title: '请扫描正确的二维码',
  206. icon: 'none',
  207. duration: 1300
  208. })
  209. }
  210. } else {
  211. wx.showToast({
  212. title: '请扫描正确的二维码',
  213. icon: 'none',
  214. duration: 1300
  215. })
  216. }
  217. },
  218. fail: function () {
  219. wx.showToast({
  220. title: '请扫描正确的二维码',
  221. icon: 'none',
  222. duration: 1300
  223. })
  224. }
  225. })
  226. },
  227. getCoupons1() {
  228. this.setData({
  229. END: this.data.optionsData.ID,
  230. TYPE: this.data.optionsData.TYPE,
  231. ID: this.data.optionsData.ID,
  232. })
  233. let postData1 = {
  234. cUserId: this.data.optionsData.ID,
  235. payPrice: this.data.optionsData.val,
  236. }
  237. Http.post({
  238. url: config.api.getManjian,
  239. data: postData1
  240. }).then(res => {
  241. if (res.code == 200) {
  242. res.data.coList.map((item, index) => {
  243. item = Object.assign(item, { checked: false })
  244. if (this.data.coupon_id == item.coupon_id) {
  245. item.checked = true;
  246. }
  247. });
  248. this.setData({
  249. avaList: res.data.coList,
  250. orderId: res.data.order.id
  251. })
  252. } else {
  253. wx.showModal({
  254. title: "抱歉",
  255. content: res.message,
  256. showCancel: false
  257. })
  258. }
  259. })
  260. },
  261. /**
  262. * 选择使用的优惠券
  263. */
  264. choicecoupon: function (e) {
  265. let that = this;
  266. let index = e.currentTarget.dataset.index;
  267. let item = this.data.avaList[index];
  268. let title = e.currentTarget.dataset.title;
  269. let id = e.currentTarget.dataset.id;
  270. let enable = e.currentTarget.dataset.enable;
  271. if (enable != 0){
  272. item.checked = !item.checked;
  273. this.setData({
  274. avaList: that.data.avaList,
  275. });
  276. }
  277. let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。
  278. let prevPage = pages[pages.length - 2];
  279. if (enable == 0) {
  280. wx.showToast({
  281. title: '当前金额不可使用此券',
  282. icon: 'none',
  283. duration: 2000,
  284. mask: false
  285. });
  286. }else{
  287. console.log(that.data.composeOrderId,"that.data.composeOrderId")
  288. prevPage.setData({ // 将我们想要传递的参数在这里直接setData。上个页面就会执行这里的操作。
  289. coupon_id: e.currentTarget.dataset.coupon_id,
  290. title: e.currentTarget.dataset.title,
  291. price: e.currentTarget.dataset.price,
  292. orderId: that.data.orderId,
  293. composeOrderId: that.data.composeOrderId,
  294. phone: that.data.phone,
  295. ID: that.data.ID,
  296. TYPE: that.data.TYPE,
  297. END: that.data.END,
  298. })
  299. wx.navigateBack({
  300. delta: 1 // 返回上一级页面。
  301. })
  302. }
  303. },
  304. })