active_form.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <view class="form-container">
  3. <view class="form-box" >
  4. <block v-for="(item,index) in formDate" :key="item.rules.name">
  5. <!-- 单行文本框 -->
  6. <view class='line' v-if="item.type=='text' || item.type=='number' || item.type=='password'">
  7. <view :class="item.rules.verify.indexOf('req')!=-1 ? 'line-left' :'p-l14 line-left' "><text class='colorRed' v-if="item.rules.verify.indexOf('req')!=-1">*</text>{{item.label}}</view>
  8. <!-- 发送验证码 -->
  9. <view class="line-right send-code-box" v-if="item.rules.name=='yzm'">
  10. <input :type="item.type" class="input" placeholder-class="plaClass" :placeholder='item.placeholder' v-model="item.rules.value" @input="inputVal(index)"></input>
  11. <view class="send-code" @click="sendCode()" :style="sendColor">{{codeFont}}</view>
  12. </view>
  13. <!-- 普通输入框 -->
  14. <view class="line-right" v-else>
  15. <input :type="item.type" class="input" placeholder-class="plaClass" :placeholder='item.placeholder' v-model="item.rules.value" @input="inputVal(index)"></input>
  16. </view>
  17. </view>
  18. <!-- 下拉选择-->
  19. <view class='line' v-else-if="item.type=='radio'">
  20. <view :class="item.rules.verify.indexOf('req')!=-1 ? 'line-left' :'p-l14 line-left' "><text class='colorRed' v-if="item.rules.verify.indexOf('req')!=-1">*</text>{{item.label}}</view>
  21. <view class="line-right">
  22. <input type="text" class="input" placeholder-class="plaClass" :placeholder='item.placeholder' v-model="item.rules.value"
  23. @click="selectInput(index)"></input>
  24. <view class="select-icon"> </view>
  25. </view>
  26. </view>
  27. <!-- 多行文本框 -->
  28. <view class="textarea-box" v-else-if="item.type=='textarea'">
  29. <view :class="item.rules.verify.indexOf('req')!=-1 ? '' :'p-l14 ' "><text class='colorRed' v-if="item.rules.verify.indexOf('req')!=-1">*</text>{{item.label}}</view>
  30. <view class="line-right">
  31. <textarea rows="" cols="" placeholder-class="plaClass" :placeholder='item.placeholder' v-model="item.rules.value" @input="inputVal(index)">
  32. </textarea>
  33. </view>
  34. </view>
  35. <!-- 上传图片 -->
  36. <view class="img-box" v-else-if="item.type=='image'">
  37. <view :class="item.rules.verify.indexOf('req')!=-1 ? 'img-label' :'p-l14 img-label' "><text class='colorRed' v-if="item.rules.verify.indexOf('req')!=-1">*</text>{{item.label}}</view>
  38. <view class="line-right">
  39. <view v-if="item.updateImg" class="update-img-box">
  40. <view class="update-img-box2">
  41. <img :src="item.rules.value" alt="" mode="aspectFill" class="update-img">
  42. <img src="/static/img/delete_img.png" alt="" class="close-img" @click="deleteImg(index)">
  43. </view>
  44. </view>
  45. <view v-if="!item.updateImg" class="update-btn-box">
  46. <img src="/static/img/update_btn.png" alt="" mode="aspectFill" @click="chooseImage(index)">
  47. </view>
  48. </view>
  49. </view>
  50. </block>
  51. </view>
  52. <view class="select-modal" v-if="show">
  53. <view class="select-bg" @click="cancel"></view>
  54. <view class="select-box" :animation="animationData">
  55. <view class="select-title">
  56. <view class="font32 color-999" @click="cancel">取消</view>
  57. <view class="font32 color-orange" @click="sure">确定</view>
  58. </view>
  59. <view>
  60. <block v-for="(item,index) in selectBox" :key="index">
  61. <view class="select-item" @click="selectItem(item.value,index)">{{item.value}} <i class="select-flag" v-if="item.flag"></i></view>
  62. </block>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. export default {
  70. name: 'activeForm',
  71. data() {
  72. return {
  73. submitData: "",
  74. show: false,
  75. animationData: {},
  76. selectBox:[],
  77. currentSelectIndex:"",
  78. currentSelectValue:"",
  79. codeFont:"获取验证码",
  80. wait:60,
  81. isSend:false,
  82. sendColor:"color:#ff5b01"
  83. }
  84. },
  85. props: {
  86. formDate:{
  87. type:Array,
  88. default:function(){
  89. return []
  90. }
  91. }
  92. },
  93. methods: {
  94. //input输入框的值传给父组件
  95. inputVal:function(index){
  96. this.$emit("input-val",JSON.stringify({
  97. val:this.formDate[index].rules.value,
  98. index:index
  99. }))
  100. },
  101. // 选择下拉框
  102. selectInput: function(index) {
  103. this.selectBox = [];
  104. this.currentSelectIndex="";
  105. this.currentSelectValue="";
  106. this.currentSelectIndex=index;
  107. for (var i = 0; i < this.formDate[index].selectVal.length; i++) {
  108. var selectVal = {
  109. value: this.formDate[index].selectVal[i],
  110. flag: false
  111. }
  112. if (this.formDate[index].selectVal[i] == this.formDate[index].rules.value) { //判断上次选中的那个
  113. selectVal.flag = true;
  114. }
  115. this.selectBox.push(selectVal)
  116. }
  117. this.show = true;
  118. var animation = uni.createAnimation({
  119. duration: 300,
  120. timingFunction: 'ease',
  121. })
  122. this.animation = animation;
  123. animation.bottom("0").step()
  124. this.animationData = this.animation.export()
  125. this.$emit("select-input-btn",index);
  126. },
  127. // 上传图片
  128. chooseImage: function(index) {
  129. var that=this;
  130. uni.chooseImage({
  131. count: 1,
  132. sizeType: ['compressed'],
  133. sourceType: ['album'],
  134. success: (res) => {
  135. this.$emit("choose-image-btn",JSON.stringify(
  136. {
  137. value:res.tempFilePaths[0],
  138. index:index,
  139. }
  140. ))
  141. },
  142. fail: (err) => {
  143. console.log('chooseImage fail', err)
  144. }
  145. })
  146. },
  147. // 删除图片
  148. deleteImg:function(index){
  149. this.$emit("delete-img-btn",index)
  150. },
  151. // 取消
  152. cancel: function() {
  153. var that = this;
  154. var animation = uni.createAnimation({
  155. duration: 300,
  156. timingFunction: 'ease',
  157. })
  158. this.animation = animation;
  159. animation.bottom("-1000upx").step()
  160. this.animationData = this.animation.export()
  161. setTimeout(function() {
  162. that.show = false;
  163. }, 200)
  164. },
  165. // 确定
  166. sure: function() {
  167. this.$emit("sure-btn",JSON.stringify({
  168. currentSelectIndex:this.currentSelectIndex,
  169. currentSelectValue:this.currentSelectValue
  170. }))
  171. console.log(this.formDate)
  172. this.cancel();
  173. },
  174. //选择值
  175. selectItem: function(value, index) {
  176. this.currentSelectValue = value;
  177. for (var i = 0; i < this.selectBox.length; i++) {
  178. this.$set(this.selectBox[i], "flag", false);
  179. }
  180. this.selectBox[index].flag = true;
  181. },
  182. // 发送验证码
  183. sendCode:function(){
  184. var that=this;
  185. var setTime=0;
  186. if(!that.isSend){
  187. that.isSend=true;
  188. setTime=setInterval(function(){
  189. that.wait--;
  190. that.sendColor="color:#999";
  191. that.codeFont=that.wait+"重新发送";
  192. if(that.wait==0){
  193. clearInterval(setTime);
  194. that.codeFont="获取验证码";
  195. that.isSend=false;
  196. that.wait=60;
  197. that.sendColor="color:#ff5b01";
  198. }
  199. },1000)
  200. }
  201. }
  202. }
  203. }
  204. </script>
  205. <style lang="scss">
  206. // 弹框
  207. .select-modal {
  208. position: fixed;
  209. left: 0;
  210. top: 0;
  211. width: 100%;
  212. height: 100%;
  213. z-index: 300000;
  214. .select-bg{
  215. width: 100%;
  216. height: 100%;
  217. background: rgba(0, 0, 0, 0.3);
  218. }
  219. .select-box {
  220. position: absolute;
  221. left: 0;
  222. bottom: -1000upx;
  223. width: 100%;
  224. background: #fff;
  225. max-height: 50%;
  226. // height: 0%;
  227. overflow: auto;
  228. .select-title {
  229. display: flex;
  230. justify-content: space-between;
  231. height: 80upx;
  232. background: #f5f5f5;
  233. line-height: 80upx;
  234. padding: 0 30upx;
  235. }
  236. .select-item {
  237. font-size: 28upx;
  238. color: #333;
  239. border-bottom: 1px solid #eee;
  240. height: 75upx;
  241. line-height: 75upx;
  242. padding: 0 30upx;
  243. i {
  244. display: block;
  245. float: right;
  246. border-bottom: 4upx solid #1ca032;
  247. border-right: 4upx solid #1ca032;
  248. width: 12upx;
  249. height: 26upx;
  250. transform: rotate(45deg);
  251. margin-top: 24.5upx;
  252. }
  253. }
  254. }
  255. @keyframes mymove {
  256. 0% {
  257. max-height: 10%;
  258. }
  259. 100% {
  260. max-height: 50%;
  261. }
  262. }
  263. /*Safari 和 Chrome:*/
  264. @-webkit-keyframes mymove {
  265. 0% {
  266. max-height: 10%;
  267. }
  268. 100% {
  269. max-height: 50%;
  270. }
  271. }
  272. }
  273. // 下拉icon
  274. .select-icon {
  275. // display: block;
  276. float: right;
  277. border-bottom: 2upx solid #999;
  278. border-right: 2upx solid #999;
  279. width: 16upx;
  280. height: 16upx;
  281. transform: rotate(-45deg);
  282. margin-right: 10upx;
  283. }
  284. .color-orange {
  285. color: #ff5b01;
  286. }
  287. .color-999 {
  288. color: #999;
  289. }
  290. .font32 {
  291. font-size: 32upx;
  292. }
  293. .plaClass {
  294. color: #dbdbdb;
  295. }
  296. .form-container {
  297. /* padding: 0 30upx; */
  298. .form-box {
  299. width: 100%;
  300. box-sizing: border-box;
  301. }
  302. .colorRed {
  303. color: red;
  304. }
  305. .img-box {
  306. border-bottom: 1px solid #ededed;
  307. padding: 30upx 0;
  308. .update-img-box{
  309. border: 1px solid #ededed;
  310. display: flex;
  311. .update-img{
  312. width: 140upx;
  313. height: 140upx;
  314. }
  315. }
  316. .update-img-box2{
  317. overflow: hidden;
  318. display: flex;
  319. }
  320. .update-img-box,.update-btn-box{
  321. width: 140upx;
  322. height: 140upx;
  323. position:relative;
  324. margin-top: 20upx;
  325. }
  326. .update-img-box .close-img{
  327. width: 40upx;
  328. height: 40upx;
  329. position: absolute;
  330. right: -12upx;
  331. top: -16upx;
  332. background:#fff;
  333. border-radius: 50%;
  334. }
  335. img{
  336. width: 140upx;
  337. height: 140upx;
  338. object-fit: cover;
  339. }
  340. }
  341. .line-right {
  342. flex: 1;
  343. height: 100%;
  344. display: flex;
  345. align-items: center;
  346. justify-content: space-between;
  347. position: relative;
  348. }
  349. .send-code-box{
  350. .send-code{
  351. font-size: 28upx;
  352. padding: 0;
  353. white-space: nowrap;
  354. // width: 60%;
  355. //color:#ff5b01;
  356. height: 90upx;
  357. line-height: 90upx;
  358. cursor: pointer;
  359. }
  360. }
  361. .line-left {
  362. display: flex;
  363. /* width: 22%; */
  364. width: 35%;
  365. align-items: center;
  366. height: 100%;
  367. font-size: 28upx;
  368. color: #333;
  369. box-sizing: border-box;
  370. }
  371. .img-label{
  372. width: 100%;
  373. height: 100%;
  374. font-size: 28upx;
  375. color: #333;
  376. box-sizing: border-box;
  377. }
  378. .p-l14{
  379. padding-left: 14upx;
  380. }
  381. .textarea-box{
  382. // display: flex;
  383. border-bottom: 1px solid #ededed;
  384. padding-top: 20upx;
  385. // align-items: center;
  386. textarea{
  387. height: 150upx;
  388. font-size: 28upx;
  389. color:#333;
  390. width: 100%;
  391. margin-top: 20upx;
  392. }
  393. }
  394. .line {
  395. margin-top: 30upx;
  396. height: 100upx;
  397. width: 100%;
  398. margin: 0 auto;
  399. border-bottom: 1px solid #ededed;
  400. display: flex;
  401. overflow: hidden;
  402. .input {
  403. padding-right: 20upx;
  404. height: 100%;
  405. width: 100%;
  406. text-align: left;
  407. font-size: 28upx;
  408. color: #333;
  409. border: none;
  410. overflow: hidden;
  411. text-overflow: ellipsis;
  412. outline: none;
  413. }
  414. }
  415. }
  416. </style>