家政小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_cn
  24. });
  25. }
  26. this.setData({
  27. banner: res.data.photo || '',
  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. const val = `${option.key}:${option.value}`;
  68. data.options += (!data.options ? val : (',' + val));
  69. // data[`${option.key}`] = option.value;
  70. }
  71. $.request(api, 'POST', data).then((res) => {
  72. $.wx.hideToast('loading');
  73. $.router.goto({
  74. path: '/pages/order/index',
  75. type: $.ROUTER_TYPE.SWITCH_TAB
  76. });
  77. });
  78. },
  79. radioChange(e) {
  80. const {
  81. index
  82. } = e.currentTarget.dataset || 0;
  83. const {
  84. value
  85. } = e.detail;
  86. const {
  87. options
  88. } = this.data;
  89. options[index].value = value;
  90. this.setData({
  91. options
  92. });
  93. }
  94. })