index.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import {
  2. stateConfig,
  3. stateFormData
  4. } from "../../utils/orderAddOptions";
  5. import { httpAdd } from "../../api/serverOrder";
  6. import { valMobile } from "../../utils/validate";
  7. import {
  8. createStoreBindings
  9. } from 'mobx-miniprogram-bindings'
  10. import {
  11. store
  12. } from "../../store/index";
  13. Page({
  14. data: {
  15. phone: "",
  16. token: "",
  17. loading: false,
  18. popupOptions: [],
  19. popupType: "",
  20. popupKey: "",
  21. popupTitle: "",
  22. popupApi: "",
  23. show: false,
  24. config: stateConfig,
  25. formData: {
  26. ...stateFormData
  27. },
  28. popupValue: '',
  29. background: [
  30. 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg',
  31. 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg',
  32. 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg',
  33. 'https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg',
  34. ],
  35. indicatorDots: true,
  36. vertical: false,
  37. autoplay: true,
  38. interval: 3000,
  39. duration: 500,
  40. date: '',
  41. },
  42. onLoad() {
  43. this.storeBindings = createStoreBindings(this, {
  44. store,
  45. fields: ["token", "phone"],
  46. actions: ["setPhone"],
  47. });
  48. },
  49. onUnload() {
  50. this.storeBindings.destroyStoreBindings();
  51. },
  52. onShow() {
  53. if (typeof this.getTabBar === 'function' &&
  54. this.getTabBar()) {
  55. this.getTabBar().setData({
  56. selected: 0
  57. })
  58. }
  59. },
  60. async submitTap() {
  61. const token = this.data.token || ""
  62. if (token === '') {
  63. wx.navigateTo({
  64. url: "../../userLogin/pages/login/index"
  65. })
  66. return
  67. }
  68. const {
  69. loading,
  70. formData,
  71. phone
  72. } = this.data
  73. if (loading) return
  74. this.setData({
  75. loading: true
  76. })
  77. const {
  78. city,
  79. act_time_start,
  80. act_day_count,
  81. item_id,
  82. name,
  83. // budget,
  84. participant,
  85. require_item,
  86. req_demand,
  87. } = formData
  88. const keyMsg = this.valKey()
  89. if (keyMsg) {
  90. this.showToastMsg(keyMsg)
  91. this.setData({
  92. loading: false
  93. })
  94. return
  95. }
  96. const msg = valMobile(phone)
  97. if (msg) {
  98. this.showToastMsg(msg)
  99. this.setData({
  100. loading: false
  101. })
  102. return
  103. }
  104. const {
  105. code,
  106. data,
  107. msg: ss
  108. } = await httpAdd({
  109. city,
  110. act_time: act_time_start,
  111. act_day_count,
  112. item_id,
  113. name,
  114. // budget,
  115. participant,
  116. require_item,
  117. req_demand: req_demand.toString(),
  118. phone
  119. })
  120. if (code === 1) {
  121. this.showToastMsg('会务订单创建成功!')
  122. wx.navigateTo({
  123. url: '../../userOrder/pages/order-details/index?id=' + data.reqCode
  124. })
  125. this.setData({
  126. formData: {
  127. ...formData
  128. }
  129. })
  130. } else if (code === 0) {
  131. this.showToastMsg(ss)
  132. } else {
  133. }
  134. this.setData({
  135. loading: false
  136. })
  137. },
  138. valKey() {
  139. let msg = ""
  140. const {
  141. formData,
  142. config
  143. } = this.data
  144. const list = [
  145. "city",
  146. "act_time",
  147. "name",
  148. // "budget",
  149. "item_id",
  150. "participant",
  151. "require_item",
  152. "req_demand"
  153. ]
  154. list.forEach((key) => {
  155. if (config[key] === 'checkbox') {
  156. if (formData[key].length === 0) {
  157. msg = `至少选择一个${config[key].title}!`
  158. }
  159. } else {
  160. if (!formData[key]) {
  161. msg = `${config[key].title}不能为空!`
  162. }
  163. }
  164. })
  165. return msg
  166. },
  167. onPhoneChange(event: any) {
  168. this.setData({
  169. phone: event.detail.value
  170. })
  171. },
  172. onNameChange(event: any) {
  173. const {
  174. formData
  175. } = this.data
  176. let model = {
  177. ...formData,
  178. name: event.detail.value
  179. }
  180. this.setData({
  181. formData: model
  182. })
  183. },
  184. //输入组件 只读点击选择数据
  185. onFormChange(event: any) {
  186. const token = this.data.token || ""
  187. const key = event.currentTarget.dataset.type
  188. const type = this.data.config[key].type
  189. if (token === '') {
  190. this.showToastMsg("请先登录!")
  191. return
  192. }
  193. const {
  194. act_time_start,
  195. act_time_end
  196. } = this.data.formData
  197. this.setData({
  198. popupValue: type !== 'time' ? this.data.formData[key] : act_time_start ? [act_time_start, act_time_end] : [],
  199. popupType: type,
  200. popupTitle: this.data.config[key].title,
  201. popupApi: this.data.config[key].api,
  202. popupKey: key,
  203. show: true,
  204. popupOptions: []
  205. });
  206. },
  207. tapItemClick(e: any) {
  208. const {
  209. label,
  210. popupKey,
  211. popupType,
  212. value,
  213. count,
  214. end
  215. } = e.detail
  216. let form = {
  217. ...this.data.formData
  218. }
  219. form[popupKey] = value
  220. form[popupKey + '_name'] = label
  221. if (popupType === 'time') {
  222. form.act_day_count = count;
  223. form.act_time_start = value;
  224. form.act_time_end = end
  225. }
  226. this.setData({
  227. show: false,
  228. formData: form
  229. });
  230. },
  231. popupLeft() {
  232. this.setData({
  233. show: false,
  234. });
  235. },
  236. showToastMsg(msg: string) {
  237. wx.showToast({
  238. title: msg,
  239. icon: 'none',
  240. duration: 2000
  241. })
  242. },
  243. })