books.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="uni-main">
  3. <view class="sticky-nav">
  4. <view class="nav-box">
  5. <u-icon name="arrow-left" color="#000" size="48" @click="navBack()"></u-icon>
  6. <text class="title">填写资料</text>
  7. </view>
  8. </view>
  9. <uni-forms ref="form" :modelValue="formData">
  10. <view class="uni-forms-item" name="gd_name">
  11. <view class="title">功德主:</view>
  12. <input class="uni-input" name="gd_name" v-model="formData.gd_name" maxlength="20" placeholder="输入功德主姓名" />
  13. </view>
  14. <view class="uni-forms-item" name="ws_name">
  15. <view class="title">往生者:</view>
  16. <input class="uni-input" name="ws_name" v-model="formData.ws_name" maxlength="20" placeholder="输入往生者姓名" />
  17. </view>
  18. <view class="uni-forms-item" name="xy_content">
  19. <view class="title">心愿:</view>
  20. <textarea class="uni-textarea" rows="5" v-model="formData.xy_content" cols="6" name="xy_content" maxlength="200" placeholder="输入心愿内容" />
  21. </view>
  22. </uni-forms>
  23. <view class="uni-forms_check">
  24. <checkbox-group @change="checkboxChange">
  25. <label>
  26. <checkbox value="1" style="border-color: #ab820d !important;
  27. color: #ab820d !important;" :checked="formData.checked" />同意并接受<text class="agree"><navigator url="/pages/index/agree">服务协议</navigator></text>
  28. </label>
  29. </checkbox-group>
  30. </view>
  31. <view class="uni-forms_submit">
  32. <view class="uni-counts_box">
  33. <text class="uni-counts-title">合计:</text>
  34. <view class="uni-counts">
  35. <view class="count">
  36. <text class="total">{{formData.total}}券</text>
  37. <text>{{formData.coupon_give}}随喜券</text>
  38. <text>{{formData.coupon}}券费用</text>
  39. </view>
  40. <button type="default" class="submit-btn" @click="formSubmit()">提交</button>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. info: {
  51. id: 0,
  52. },
  53. formData: {
  54. },
  55. // 表单数据
  56. tempFormData: {
  57. id: 0,
  58. gd_name: '',
  59. ws_name: '',
  60. xy_content: '',
  61. coupon_give: 0,
  62. coupon: 0,
  63. total: 0,
  64. checked: false,
  65. },
  66. }
  67. },
  68. onLoad(option) {
  69. let _uni = this
  70. _uni.info.id = option.id
  71. _uni.info.id = typeof(_uni.info.id) != 'undefined'? _uni.info.id : 0;
  72. if(_uni.info.id<=0){
  73. uni.showToast({
  74. title: '活动参数错误',
  75. icon: 'none'
  76. })
  77. setTimeout(function(){
  78. uni.navigateBack({
  79. data: _uni.info.id,
  80. })
  81. }, 1200)
  82. return false;
  83. }
  84. if(option.num<=0){
  85. uni.showToast({
  86. title: '请先选择随喜券',
  87. icon: 'none'
  88. })
  89. setTimeout(function(){
  90. uni.navigateBack({
  91. data: _uni.info.id,
  92. })
  93. }, 1200)
  94. return false;
  95. }
  96. this.tempFormData.coupon_give = option.num;
  97. this.formData = Object.assign({}, this.tempFormData)
  98. this.getInfo(_uni.info.id)
  99. },
  100. methods: {
  101. navBack() {
  102. uni.navigateTo({
  103. url: '/pages/temple/activity?id='+this.info.id
  104. });
  105. },
  106. checkboxChange(data){
  107. this.formData.checked = data.detail.value[0]
  108. },
  109. getInfo(id) {
  110. let _uni = this
  111. this.$request.api('/api/activity/info', {id: id}).then(res => {
  112. if(res.success == true){
  113. _uni.info = res.data
  114. _uni.tempFormData.id = _uni.info.id
  115. _uni.tempFormData.coupon = parseInt(_uni.info.price)
  116. _uni.tempFormData.total = parseInt(parseInt(_uni.formData.coupon_give)+parseInt(_uni.info.price))
  117. _uni.formData = Object.assign({}, _uni.tempFormData)
  118. }
  119. }).catch(err => {
  120. uni.showToast({
  121. title: typeof(err.msg) != 'undefined'? err.msg : '服务器错误'
  122. })
  123. })
  124. },
  125. // 表单提交
  126. formSubmit() {
  127. let _uni = this
  128. if(this.formData.gd_name=='' || this.formData.gd_name==null){
  129. uni.showToast({
  130. title: '请填写功德主姓名',
  131. icon: 'none'
  132. })
  133. return false;
  134. }
  135. if(this.formData.ws_name=='' || this.formData.ws_name==null){
  136. uni.showToast({
  137. title: '请填写往生者姓名',
  138. icon: 'none'
  139. })
  140. return false;
  141. }
  142. if(this.formData.xy_content=='' || this.formData.xy_content==null || this.formData.xy_content.length<=1){
  143. uni.showToast({
  144. title: '请填写心愿内容',
  145. icon: 'none'
  146. })
  147. return false;
  148. }
  149. if(!this.formData.checked){
  150. uni.showToast({
  151. title: '请先阅读和勾选服务协议',
  152. icon: 'none'
  153. })
  154. return false;
  155. }
  156. // 提交
  157. uni.showLoading({
  158. title: '提交中...',
  159. })
  160. this.$request.api('/api/activity/books', _uni.formData).then(res => {
  161. uni.hideLoading();
  162. if(res.success == true){
  163. uni.showToast({
  164. title: res.msg,
  165. icon: 'none'
  166. })
  167. _uni.formData = _uni.tempFormData
  168. }else{
  169. uni.showToast({
  170. title: res.msg,
  171. icon: 'none'
  172. })
  173. }
  174. }).catch(error => {
  175. uni.showToast({
  176. title: typeof(error.msg) != 'undefined'? error.msg : '服务器错误',
  177. icon: 'none'
  178. })
  179. })
  180. }
  181. },
  182. }
  183. </script>
  184. <style lang="less" >
  185. page {
  186. height: 100%;
  187. width: 100%;
  188. }
  189. .uni-main {
  190. width: 100%;
  191. height: 100%;
  192. background-color: #f1f1f1;
  193. font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  194. }
  195. .sticky-nav {
  196. position: sticky;
  197. width: 100%;
  198. top: 0;
  199. z-index: 1;
  200. border-bottom: 1rpx solid rgb(229, 229, 229);
  201. }
  202. .nav-box {
  203. width: 100%;
  204. padding-top: 50rpx;
  205. display: flex;
  206. align-items: center;
  207. background: #fff;
  208. height: 100rpx;
  209. padding-bottom: 50rpx;
  210. /deep/.u-icon {
  211. margin-left: 20rpx !important;
  212. }
  213. .title {
  214. font-size: 38rpx;
  215. color: #000;
  216. width: 100%;
  217. text-align: left;
  218. }
  219. .right-icon {
  220. float: right;
  221. margin-right: 20rpx;
  222. }
  223. }
  224. .uni-forms {
  225. padding: 20rpx 20rpx;
  226. background-color: #fff;
  227. }
  228. .uni-forms-item .title {
  229. height: 60rpx;
  230. line-height: 60rpx;
  231. color: #905d11;
  232. }
  233. .uni-input {
  234. height: 60rpx;
  235. line-height: 60rpx;
  236. background-color: #f1f1f1;
  237. color: #e64340;
  238. padding: 4rpx 8rpx;
  239. }
  240. .uni-textarea {
  241. width: auto;
  242. color: #e64340;
  243. background-color: #f1f1f1;
  244. padding: 4rpx 8rpx;
  245. }
  246. .uni-forms_check {
  247. margin: 20rpx 20rpx 0rpx;
  248. }
  249. .agree * {
  250. display: inline-block;
  251. color: #d8ab37;
  252. }
  253. .uni-forms_submit {
  254. width: 100%;
  255. position: absolute;
  256. bottom: 0;
  257. background-color: #fff;
  258. }
  259. .uni-forms_submit .uni-counts {
  260. display: inline-block;
  261. float: right;
  262. font-size: 0;
  263. }
  264. .uni-counts-title {
  265. vertical-align: middle;
  266. margin: 0px 10rpx;
  267. line-height: 144rpx;
  268. font-size: 32rpx;
  269. }
  270. .uni-counts_box {
  271. overflow: hidden;
  272. }
  273. .uni-counts .count {
  274. font-size: 24rpx;
  275. display: inline-block;
  276. vertical-align: top;
  277. line-height: 36rpx;
  278. margin-top: 20rpx;
  279. margin-right: 4rpx;
  280. }
  281. .uni-counts .count .total {
  282. // font-weight: bold;
  283. font-size: 36rpx;
  284. color: #d8ab37;
  285. }
  286. .uni-counts .count uni-text {
  287. display: block;
  288. }
  289. .uni-counts .submit-btn {
  290. width: 180rpx;
  291. display: inline-block;
  292. background-color: #d8ab37;
  293. color: #fff;
  294. padding: 26rpx 4rpx;
  295. border-radius: 0;
  296. }
  297. </style>