家政小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

index.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. expectedDate,
  42. serviceDate,
  43. options,
  44. type
  45. } = this.data;
  46. if (!name || !phone || !address || !expectedDate || !serviceDate) {
  47. return $.wx.showToast({
  48. title: '请把信息填写完整'
  49. });
  50. }
  51. if (!this._isPhone(phone)) {
  52. return $.wx.showToast({
  53. title: '请输入正确的手机号码'
  54. });
  55. }
  56. $.wx.showToast({
  57. title: '加载中'
  58. }, 'loading');
  59. const data = {
  60. expected_date: expectedDate,
  61. special_demand: notes,
  62. server_time: serviceDate,
  63. address,
  64. contact: name,
  65. phone,
  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(this.data.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. });