index.js 4.4 KB

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