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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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: item.type === 'checkbox' ? ([]) : (group[0].value || ''),
  23. key: item.name_cn
  24. });
  25. }
  26. this.setData({
  27. banner: res.data.photo.split(';') || [],
  28. fields,
  29. options,
  30. api: res.data.api,
  31. type: res.data.type
  32. });
  33. });
  34. },
  35. bookServer() {
  36. const {
  37. name,
  38. phone,
  39. address,
  40. notes,
  41. options,
  42. api,
  43. type
  44. } = this.data;
  45. if (!name || !phone || !address) {
  46. return $.wx.showToast({
  47. title: '请把信息填写完整'
  48. });
  49. }
  50. if (!this._isPhone(phone)) {
  51. return $.wx.showToast({
  52. title: '请输入正确的手机号码'
  53. });
  54. }
  55. $.wx.showToast({
  56. title: '加载中'
  57. }, 'loading');
  58. const data = {
  59. contact: name,
  60. phone,
  61. address,
  62. notes,
  63. type,
  64. options: ''
  65. }
  66. for (let option of options) {
  67. let val = '';
  68. if (Array.isArray(option.value)) {
  69. if (option.value.length > 0) {
  70. val = `${option.key}:${option.value.join(',')}`;
  71. }
  72. } else {
  73. val = `${option.key}:${option.value}`;
  74. }
  75. data.options += (!data.options ? val : (';' + val));
  76. // data[`${option.key}`] = option.value;
  77. }
  78. $.request(api, 'POST', data).then(() => {
  79. $.wx.hideToast('loading');
  80. $.router.goto({
  81. path: '/pages/order/index',
  82. type: $.ROUTER_TYPE.SWITCH_TAB
  83. });
  84. });
  85. },
  86. inputChange(e) {
  87. const { index } = e.currentTarget.dataset || 0;
  88. const { value } = e.detail;
  89. const { options } = this.data;
  90. options[index].value = value;
  91. this.setData({
  92. options
  93. });
  94. }
  95. });