signPerson.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. },
  147. onShow() {
  148. },
  149. methods: {
  150. getExtForm(){
  151. return new Promise((r,j)=>{
  152. req.getRequest('/api/match/detail',{id:this.id},res=>{
  153. this.parmas = res.extForm?JSON.parse(res.extForm):[]
  154. if(this.parmas.length>0){
  155. this.parmas.map(item=>{
  156. item.value = ''
  157. })
  158. }
  159. r()
  160. })
  161. })
  162. },
  163. pSelect(item,it){
  164. console.log('cc')
  165. if(item.value === it.name){
  166. item.value=''
  167. }else if(item.value != it.name){
  168. item.value=it.name
  169. }
  170. this.parmas = JSON.parse(JSON.stringify(this.parmas))
  171. },
  172. pSelectGroup(item,it){
  173. if(item.value=='') item.value=[]
  174. else item.value = item.value.split(',')
  175. let index = item.value.indexOf(it.name)
  176. if(index!=-1){
  177. item.value.splice(index,1)
  178. }else {
  179. item.value.push(it.name)
  180. }
  181. item.value = item.value.join(',')
  182. this.parmas = JSON.parse(JSON.stringify(this.parmas))
  183. },
  184. submit(){
  185. if(!this.name) return req.msg('请填写报名人员姓名');
  186. if(!this.phone) return req.msg('请填写报名人员手机号码');
  187. if(!util.isMobile(this.phone)) return req.msg('请填写正确的手机号码')
  188. // 数据校验
  189. for(let i=0;i<this.parmas.length;i++){
  190. let item = this.parmas[i]
  191. if(item.required==1){
  192. if(!item.value) return req.msg("请完善"+item.chineseName)
  193. }
  194. }
  195. if(this.index){
  196. console.log('parmas',JSON.stringify(this.parmas))
  197. let personList = []
  198. let parmas = {
  199. name: this.name?this.name:'',
  200. phone: this.phone?this.phone:'',
  201. extend:this.parmas
  202. }
  203. if(req.getStorage('personList')){
  204. personList = req.getStorage('personList')
  205. personList[this.index-1] = parmas
  206. req.setStorage('personList',personList)
  207. }else{
  208. personList = personList.concat(parmas);
  209. }
  210. uni.navigateBack()
  211. }else{
  212. console.log('parmas',JSON.stringify(this.parmas))
  213. let personList = []
  214. if(req.getStorage('personList')){
  215. personList = req.getStorage('personList')
  216. }
  217. let parmas = {
  218. name: this.name?this.name:'',
  219. phone: this.phone?this.phone:'',
  220. extend:this.parmas
  221. }
  222. personList = personList.concat(parmas);
  223. req.setStorage('personList',personList)
  224. uni.navigateBack()
  225. }
  226. },
  227. uploadImage(item) {
  228. let that = this;
  229. let count = 1
  230. if(item.type==5) {
  231. count = 9
  232. item.value = item.value?item.value.split(','):[]
  233. }
  234. uni.chooseImage({
  235. count: count,
  236. sizeType: ['original', 'compressed'],
  237. sourceType: ['album', 'camera'],
  238. success: function({
  239. tempFilePaths
  240. }) {
  241. uni.showLoading({
  242. title:'上传中'
  243. })
  244. var promise = Promise.all(
  245. tempFilePaths.map(tempFilePath => {
  246. return new Promise(function(resolve, reject) {
  247. req.uploadFile('/api/nocheck/upload', tempFilePath,
  248. res => {
  249. if(item.type==5) {
  250. console.log('item.type')
  251. item.value = item.value.concat(res.src)
  252. }
  253. else item.value = res.src
  254. resolve()
  255. });
  256. });
  257. })
  258. );
  259. promise
  260. .then(function(results) {
  261. uni.hideLoading()
  262. item.value = item.value.join(',')
  263. that.parmas = JSON.parse(JSON.stringify(that.parmas))
  264. console.log(results);
  265. })
  266. .catch(function(err) {
  267. uni.hideLoading()
  268. console.log(err);
  269. });
  270. }
  271. });
  272. },
  273. deleteImage(item,index) {
  274. if(item.type==5) {
  275. item.value.splice(index, 1)
  276. }
  277. else item.value = ''
  278. },
  279. },
  280. mounted() {
  281. const systemInfo = uni.getSystemInfoSync();
  282. // px转换到rpx的比例
  283. let pxToRpxScale = 750 / systemInfo.windowWidth;
  284. let systems = {
  285. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  286. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  287. };
  288. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  289. this.systems = systems;
  290. },
  291. onPageScroll: function(e) {
  292. if (e.scrollTop > this.systems.barHeight) {
  293. this.isTop = 1;
  294. } else {
  295. this.isTop = 0;
  296. }
  297. }
  298. }
  299. </script>
  300. <style>
  301. @import "./signPerson.css";
  302. </style>