signPerson.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view>
  3. <view class="p-form">
  4. <view class="p-label">姓名</view>
  5. <view class="p-input">
  6. <input v-model="name" placeholder="请输入姓名" placeholder-class="p-placeholder"/>
  7. </view>
  8. <view class="p-label">手机号</view>
  9. <view class="p-input">
  10. <input v-model="phone" placeholder="请输入手机号" placeholder-class="p-placeholder"/>
  11. </view>
  12. <view v-for='item,index in parmas' class="p-form-item">
  13. <view class="p-label">{{item.label}}</view>
  14. <!-- 输入框 -->
  15. <view v-if="item.type==1" class="p-input">
  16. <input v-model="item.value" :placeholder="'请输入'+item.label" placeholder-class="p-placeholder"/>
  17. </view>
  18. <!-- 单选 -->
  19. <view v-if="item.type==2" class="p-select">
  20. <view class="ddflex">
  21. <view class="ddflex p-select-item" v-for="it in item.data" @click="pSelect(item,it)">
  22. <image v-if="item.value===it.value" src="/static/images/select_h.png"></image>
  23. <image v-else src="/static/images/select.png"></image>
  24. <view>{{it.label}}</view>
  25. </view>
  26. </view>
  27. </view>
  28. <!-- 多选 -->
  29. <view v-if="item.type==3" class="p-select-group">
  30. <view class="ddflex">
  31. <view :class="'ddflex p-select-group-item '+(item.value.indexOf(it.value)!=-1?'p-select-group-item-active':'')" v-for="it in item.data" @click="pSelectGroup(item,it)">
  32. <view>{{it.label}}</view>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 文本域 -->
  37. <view v-if="item.type==4" class="p-input">
  38. <view class="ddflex">
  39. <textarea v-model="item.value" :placeholder="'请输入'+item.label" placeholder-class="p-placeholder"></textarea>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <view style="height: 150rpx;"></view>
  45. <view class="share-btn">
  46. <view class="btn" @click="submit">保存</view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import util from "../../utils/util.js";
  52. const app = getApp();
  53. const req = require("../../utils/request.js");
  54. export default {
  55. components: {},
  56. props: {},
  57. data() {
  58. return {
  59. systems: {},
  60. isTop:0,
  61. name:'',
  62. phone:'',
  63. parmas:[],
  64. // parmas:[{
  65. // label:'姓名',
  66. // name:'name',
  67. // value:'',
  68. // type:1,//输入框
  69. // },{
  70. // label:'性别',
  71. // name:'sex',
  72. // value:'',
  73. // data:[{label:'男',value:1},{label:'女',value:2}],
  74. // type:2,//单选
  75. // },{
  76. // label:'手机号码',
  77. // name:'phone',
  78. // value:'',
  79. // type:1,//输入框
  80. // },{
  81. // label:'身份证号码',
  82. // name:'userName',
  83. // value:'',
  84. // type:1,//输入框
  85. // },{
  86. // label:'兴趣爱好',
  87. // name:'like',
  88. // value:'',
  89. // data:[{label:'户外运动',value:1},{label:'旅游',value:2}],
  90. // type:3,//多选
  91. // },{
  92. // label:'建议',
  93. // name:'suggest',
  94. // value:'',
  95. // type:4,//文本域
  96. // }],
  97. index:null
  98. }
  99. },
  100. onLoad(options) {
  101. if(options.index){
  102. this.index = options.index
  103. if(req.getStorage('personList')){
  104. let parmas = req.getStorage('personList')[options.index-1]
  105. this.name = parmas.name
  106. this.phone = parmas.phone
  107. this.parmas.map(item=>{
  108. parmas.extend.map(it=>{
  109. if(item.type == it.type&&item.name == it.name){
  110. item.value = it.value
  111. }
  112. })
  113. })
  114. }
  115. }
  116. },
  117. onShow() {
  118. },
  119. methods: {
  120. pSelect(item,it){
  121. if(item.value === it.value){
  122. item.value=''
  123. }else if(item.value != it.value){
  124. item.value=it.value
  125. }
  126. },
  127. pSelectGroup(item,it){
  128. if(item.value=='') item.value=[]
  129. let index = item.value.indexOf(it.value)
  130. if(index!=-1){
  131. item.value.splice(index,1)
  132. }else {
  133. item.value.push(it.value)
  134. }
  135. },
  136. submit(){
  137. if(!this.name) return req.msg('请填写报名人员姓名');
  138. if(!this.phone) return req.msg('请填写报名人员手机号码');
  139. if(!util.isMobile(this.phone)) return req.msg('请填写正确的手机号码')
  140. if(this.index){
  141. console.log('parmas',JSON.stringify(this.parmas))
  142. let personList = []
  143. let parmas = {
  144. name: this.name?this.name:'',
  145. phone: this.phone?this.phone:'',
  146. extend:this.parmas
  147. }
  148. if(req.getStorage('personList')){
  149. personList = req.getStorage('personList')
  150. personList[this.index-1] = parmas
  151. req.setStorage('personList',personList)
  152. }else{
  153. personList = personList.concat(parmas);
  154. }
  155. uni.navigateBack()
  156. }else{
  157. console.log('parmas',JSON.stringify(this.parmas))
  158. let personList = []
  159. if(req.getStorage('personList')){
  160. personList = req.getStorage('personList')
  161. }
  162. let parmas = {
  163. name: this.name?this.name:'',
  164. phone: this.phone?this.phone:'',
  165. extend:this.parmas
  166. }
  167. personList = personList.concat(parmas);
  168. req.setStorage('personList',personList)
  169. uni.navigateBack()
  170. }
  171. }
  172. },
  173. mounted() {
  174. const systemInfo = uni.getSystemInfoSync();
  175. // px转换到rpx的比例
  176. let pxToRpxScale = 750 / systemInfo.windowWidth;
  177. let systems = {
  178. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  179. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  180. };
  181. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  182. this.systems = systems;
  183. },
  184. onPageScroll: function(e) {
  185. if (e.scrollTop > this.systems.barHeight) {
  186. this.isTop = 1;
  187. } else {
  188. this.isTop = 0;
  189. }
  190. }
  191. }
  192. </script>
  193. <style>
  194. @import "./signPerson.css";
  195. </style>