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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const WxParse = require('../../wxParse/wxParse.js');
  2. const $ = global;
  3. new $.Page({
  4. data: {
  5. options: [],
  6. api: ''
  7. },
  8. onLoad(options) {
  9. this.setData({
  10. id: options.id
  11. });
  12. if (!options.id) {
  13. return $.wx.showToast({
  14. title: '找不到对应id'
  15. });
  16. }
  17. $.request(`classify/${options.id}`, 'GET', {}).then((res) => {
  18. var article = res.data && res.data.content || '';
  19. const fields = res.data.fields || [];
  20. const options = [];
  21. WxParse.wxParse('article', 'html', article, this, 5);
  22. for (let item of fields) {
  23. const group = item.input_group;
  24. options.push({
  25. value: item.type === 'checkbox' ? ([]) : (group[0].value || ''),
  26. key: item.name_cn
  27. });
  28. }
  29. this.setData({
  30. banner: res.data.photo.split(';') || [],
  31. fields,
  32. options,
  33. api: res.data.api,
  34. type: res.data.type
  35. });
  36. });
  37. },
  38. bookServer() {
  39. const {
  40. name,
  41. phone,
  42. address,
  43. notes,
  44. options,
  45. api,
  46. type
  47. } = this.data;
  48. if (!name || !phone || !address) {
  49. return $.wx.showToast({
  50. title: '请把信息填写完整'
  51. });
  52. }
  53. if (!this._isPhone(phone)) {
  54. return $.wx.showToast({
  55. title: '请输入正确的手机号码'
  56. });
  57. }
  58. $.wx.showToast({
  59. title: '加载中'
  60. }, 'loading');
  61. const data = {
  62. contact: name,
  63. phone,
  64. address,
  65. notes,
  66. type,
  67. options: ''
  68. }
  69. for (let option of options) {
  70. let val = '';
  71. if (Array.isArray(option.value)) {
  72. if (option.value.length > 0) {
  73. val = `${option.key}:${option.value.join(',')}`;
  74. }
  75. } else {
  76. val = `${option.key}:${option.value}`;
  77. }
  78. data.options += (!data.options ? val : (';' + val));
  79. // data[`${option.key}`] = option.value;
  80. }
  81. $.request(api, 'POST', data).then(() => {
  82. $.wx.hideToast('loading');
  83. $.router.goto({
  84. path: '/pages/order/index',
  85. type: $.ROUTER_TYPE.SWITCH_TAB
  86. });
  87. });
  88. },
  89. inputChange(e) {
  90. const { index } = e.currentTarget.dataset || 0;
  91. const { value } = e.detail;
  92. const { options } = this.data;
  93. options[index].value = value;
  94. this.setData({
  95. options
  96. });
  97. },
  98. // 页面分享
  99. onShareAppMessage() {
  100. let that = this;
  101. return {
  102. title: '玥子轩母婴家政',
  103. desc: '预约服务',
  104. path: '/pages/bookService/index?id=' + that.data.id
  105. }
  106. }
  107. });