家政小程序
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.

index.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const WxParse = require('../../wxParse/wxParse.js')
  2. const $ = global
  3. new $.Page({
  4. data: {
  5. options: [],
  6. api: ''
  7. },
  8. onLoad(options) {
  9. if (!options.id) {
  10. return $.wx.showToast({
  11. title: '找不到对应id'
  12. });
  13. }
  14. $.request(`classify/${options.id}`, 'GET', {}).then((res) => {
  15. var article = res.data && res.data.content || '';
  16. const fields = res.data.fields || [];
  17. const options = [];
  18. WxParse.wxParse('article', 'html', article, this, 5);
  19. for (let item of fields) {
  20. const group = item.input_group;
  21. options.push({
  22. value: group[0].value || '',
  23. key: item.name
  24. });
  25. }
  26. this.setData({
  27. banner: res.data.photo || '',
  28. fields,
  29. options,
  30. api: res.data.api
  31. });
  32. });
  33. },
  34. bookServer() {
  35. const {
  36. name,
  37. phone,
  38. address,
  39. notes,
  40. options
  41. } = this.data;
  42. if (!name || !phone || !address) {
  43. return $.wx.showToast({
  44. title: '请把信息填写完整'
  45. });
  46. }
  47. if (!this._isPhone(phone)) {
  48. return $.wx.showToast({
  49. title: '请输入正确的手机号码'
  50. });
  51. }
  52. $.wx.showToast({
  53. title: '加载中'
  54. }, 'loading');
  55. const data = {
  56. contact: name,
  57. phone,
  58. address,
  59. notes
  60. }
  61. for (let option of options) {
  62. data[`${option.key}`] = option.value;
  63. }
  64. $.request(api, 'POST', data).then((res) => {
  65. $.wx.hideToast('loading');
  66. $.router.goto({
  67. path: '/pages/order/index',
  68. type: $.ROUTER_TYPE.SWITCH_TAB
  69. });
  70. });
  71. },
  72. radioChange(e) {
  73. const {
  74. index
  75. } = e.currentTarget.dataset || 0;
  76. const {
  77. value
  78. } = e.detail;
  79. const {
  80. options
  81. } = this.data;
  82. options[index].value = value;
  83. this.setData({
  84. options
  85. });
  86. }
  87. })