signPerson.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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" :key="index">
  13. <view class="p-label">{{item.chineseName}}</view>
  14. <!-- 输入框 -->
  15. <view v-if="item.type==1" class="p-input">
  16. <input v-model="item.value" :placeholder="'请输入'+item.chineseName" 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.selectValues" @click="pSelect(item,it)">
  22. <image v-if="item.value===it.name" src="/static/images/select_h.png"></image>
  23. <image v-else src="/static/images/select.png"></image>
  24. <view>{{it.name}}</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&&item.value.split(',').indexOf(it.name)!=-1?'p-select-group-item-active':'')" v-for="it in item.selectValues" @click="pSelectGroup(item,it)">
  32. <view>{{it.name}}</view>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 图片 -->
  37. <view v-if="item.type==4">
  38. <view class="ddflex" style="margin-top: 30rpx;">
  39. <view class="upload-photo-image" v-if="item.value" @click="uploadImage(item)">
  40. <image :src="item.value" mode="aspectFill"></image>
  41. <image class="upload-photo-close" src="/static/pages/images/close3.png"
  42. @click.stop="deleteImage(item)"></image>
  43. </view>
  44. <view class="upload-photo ddflex" @click="uploadImage(item)" v-else>
  45. <image src="../static/images/photo.png"></image>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 多图片 -->
  50. <view v-if="item.type==5">
  51. <view class="ddflex" style="margin-top: 30rpx;">
  52. <view class="upload-photo-image" v-for="it,idx in item.value?item.value.split(','):[]" @click="uploadImage(item)">
  53. <image :src="it" mode="aspectFill"></image>
  54. <image class="upload-photo-close" src="/static/pages/images/close3.png"
  55. @click.stop="deleteImage(item,idx)"></image>
  56. </view>
  57. <view class="upload-photo ddflex" @click="uploadImage(item)">
  58. <image src="../static/images/photo.png"></image>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 文本域 -->
  63. <!-- <view v-if="item.type==4" class="p-input">
  64. <view class="ddflex">
  65. <textarea v-model="item.value" :placeholder="'请输入'+item.chineseName" placeholder-class="p-placeholder"></textarea>
  66. </view>
  67. </view> -->
  68. </view>
  69. </view>
  70. <view style="height: 150rpx;"></view>
  71. <view class="share-btn">
  72. <view class="btn" @click="submit">保存</view>
  73. </view>
  74. </view>
  75. </template>
  76. <script>
  77. import util from "../../utils/util.js";
  78. const app = getApp();
  79. const req = require("../../utils/request.js");
  80. export default {
  81. components: {},
  82. props: {},
  83. data() {
  84. return {
  85. systems: {},
  86. isTop:0,
  87. name:'',
  88. phone:'',
  89. parmas:[],
  90. // type 1 输入框 2单择框 3多选框 4单图片 5多图片
  91. // parmas:[{
  92. // label:'姓名',
  93. // name:'name',
  94. // value:'',
  95. // type:1,//输入框
  96. // },{
  97. // label:'性别',
  98. // name:'sex',
  99. // value:'',
  100. // data:[{label:'男',value:1},{label:'女',value:2}],
  101. // type:2,//单选
  102. // },{
  103. // label:'手机号码',
  104. // name:'phone',
  105. // value:'',
  106. // type:1,//输入框
  107. // },{
  108. // label:'身份证号码',
  109. // name:'userName',
  110. // value:'',
  111. // type:1,//输入框
  112. // },{
  113. // label:'兴趣爱好',
  114. // name:'like',
  115. // value:'',
  116. // data:[{label:'户外运动',value:1},{label:'旅游',value:2}],
  117. // type:3,//多选
  118. // },{
  119. // label:'建议',
  120. // name:'suggest',
  121. // value:'',
  122. // type:4,//文本域
  123. // }],
  124. index:null,
  125. id:null
  126. }
  127. },
  128. async onLoad(options) {
  129. this.id = options.id
  130. await this.getExtForm()
  131. if(options.index){
  132. this.index = options.index
  133. if(req.getStorage('personList')){
  134. let parmas = req.getStorage('personList')[options.index-1]
  135. this.name = parmas.name
  136. this.phone = parmas.phone
  137. this.parmas.map(item=>{
  138. parmas.extend.map(it=>{
  139. if(item.type == it.type&&item.name == it.name){
  140. item.value = it.value
  141. }
  142. })
  143. })
  144. }
  145. }
  146. if(!req.getStorage('personList')||req.getStorage('personList').length==0){
  147. this.name = req.getStorage('userInfo').realName?req.getStorage('userInfo').realName:''
  148. this.phone = req.getStorage('userInfo').mobile?req.getStorage('userInfo').mobile:''
  149. }
  150. },
  151. onShow() {
  152. },
  153. methods: {
  154. getExtForm(){
  155. return new Promise((r,j)=>{
  156. req.getRequest('/api/match/detail',{id:this.id},res=>{
  157. this.parmas = res.extForm?JSON.parse(res.extForm):[]
  158. if(this.parmas.length>0){
  159. this.parmas.map(item=>{
  160. item.value = ''
  161. })
  162. }
  163. r()
  164. })
  165. })
  166. },
  167. pSelect(item,it){
  168. console.log('cc')
  169. if(item.value === it.name){
  170. item.value=''
  171. }else if(item.value != it.name){
  172. item.value=it.name
  173. }
  174. this.parmas = JSON.parse(JSON.stringify(this.parmas))
  175. },
  176. pSelectGroup(item,it){
  177. if(item.value=='') item.value=[]
  178. else item.value = item.value.split(',')
  179. let index = item.value.indexOf(it.name)
  180. if(index!=-1){
  181. item.value.splice(index,1)
  182. }else {
  183. item.value.push(it.name)
  184. }
  185. item.value = item.value.join(',')
  186. this.parmas = JSON.parse(JSON.stringify(this.parmas))
  187. },
  188. submit(){
  189. if(!this.name) return req.msg('请填写报名人员姓名');
  190. if(!this.phone) return req.msg('请填写报名人员手机号码');
  191. if(!util.isMobile(this.phone)) return req.msg('请填写正确的手机号码')
  192. // 数据校验
  193. for(let i=0;i<this.parmas.length;i++){
  194. let item = this.parmas[i]
  195. if(item.required==1){
  196. if(!item.value) return req.msg("请完善"+item.chineseName)
  197. }
  198. }
  199. if(this.index){
  200. console.log('parmas',JSON.stringify(this.parmas))
  201. let personList = []
  202. let parmas = {
  203. name: this.name?this.name:'',
  204. phone: this.phone?this.phone:'',
  205. extend:this.parmas
  206. }
  207. if(req.getStorage('personList')){
  208. personList = req.getStorage('personList')
  209. personList[this.index-1] = parmas
  210. req.setStorage('personList',personList)
  211. }else{
  212. personList = personList.concat(parmas);
  213. }
  214. uni.navigateBack()
  215. }else{
  216. console.log('parmas',JSON.stringify(this.parmas))
  217. let personList = []
  218. if(req.getStorage('personList')){
  219. personList = req.getStorage('personList')
  220. }
  221. let parmas = {
  222. name: this.name?this.name:'',
  223. phone: this.phone?this.phone:'',
  224. extend:this.parmas
  225. }
  226. personList = personList.concat(parmas);
  227. req.setStorage('personList',personList)
  228. uni.navigateBack()
  229. }
  230. },
  231. uploadImage(item) {
  232. let that = this;
  233. let count = 1
  234. if(item.type==5) {
  235. count = 9
  236. item.value = item.value?item.value.split(','):[]
  237. }
  238. uni.chooseImage({
  239. count: count,
  240. sizeType: ['original', 'compressed'],
  241. sourceType: ['album', 'camera'],
  242. success: function({
  243. tempFilePaths
  244. }) {
  245. uni.showLoading({
  246. title:'上传中'
  247. })
  248. var promise = Promise.all(
  249. tempFilePaths.map(tempFilePath => {
  250. return new Promise(function(resolve, reject) {
  251. req.uploadFile('/api/nocheck/upload', tempFilePath,
  252. res => {
  253. if(item.type==5) {
  254. console.log('item.type')
  255. item.value = item.value.concat(res.src)
  256. }
  257. else item.value = res.src
  258. resolve()
  259. });
  260. });
  261. })
  262. );
  263. promise
  264. .then(function(results) {
  265. uni.hideLoading()
  266. item.value = item.value.join(',')
  267. that.parmas = JSON.parse(JSON.stringify(that.parmas))
  268. console.log(results);
  269. })
  270. .catch(function(err) {
  271. uni.hideLoading()
  272. console.log(err);
  273. });
  274. }
  275. });
  276. },
  277. deleteImage(item,index) {
  278. if(item.type==5) {
  279. item.value.splice(index, 1)
  280. }
  281. else item.value = ''
  282. },
  283. },
  284. mounted() {
  285. const systemInfo = uni.getSystemInfoSync();
  286. // px转换到rpx的比例
  287. let pxToRpxScale = 750 / systemInfo.windowWidth;
  288. let systems = {
  289. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  290. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  291. };
  292. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  293. this.systems = systems;
  294. },
  295. onPageScroll: function(e) {
  296. if (e.scrollTop > this.systems.barHeight) {
  297. this.isTop = 1;
  298. } else {
  299. this.isTop = 0;
  300. }
  301. }
  302. }
  303. </script>
  304. <style>
  305. @import "./signPerson.css";
  306. </style>