popForm.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <view class="root" catchtouchmove='return' v-if="bShow">
  3. <!-- 背景黑幕 -->
  4. <view class="blackBg" @click="close()"></view>
  5. <!-- 背景 -->
  6. <view class="formBg">
  7. <!-- 标题 -->
  8. <view class="titleBg">
  9. <view class="title">{{title}}</view>
  10. </view>
  11. <!-- 表单 -->
  12. <view class="middle">
  13. <!-- 上一页 -->
  14. <view style="width: 10%;height: 100%;margin: 3%;">
  15. <view class="lastPage" @click="lastPage()" v-show="bLastPageShow"></view>
  16. </view>
  17. <view class="form">
  18. <view class="item" v-for="(obj,index) in curr_content_arr" :key="index">
  19. <view class="inputName">{{obj.name}}:</view>
  20. <view class="inputBg">
  21. <input type="text" v-model="obj.input" placeholder="">
  22. </view>
  23. </view>
  24. </view>
  25. <!-- 下一页 -->
  26. <view style="width: 10%;height: 100%;margin: 3%;">
  27. <view class="nextPage" @click="nextPage()" v-show="bNextPageShow"></view>
  28. </view>
  29. </view>
  30. <!-- 按钮区 -->
  31. <view class="btnArea">
  32. <button type="default" size="mini" class="confirm" @click="confirm()">确定</button>
  33. <button type="default" size="mini" class="cancel" @click="cancel()">取消</button>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. bShow:false,
  43. title:'标题',
  44. content_arr:[
  45. {
  46. 'name':'11111',
  47. 'input':'aaa',
  48. 'type' :'text'
  49. }
  50. ],
  51. curr_content_arr:[],
  52. curr_page:1,
  53. total_page:0,
  54. itemNumPerPage:5,
  55. bLastPageShow:true,
  56. bNextPageShow:true,
  57. callback:null
  58. }
  59. },
  60. methods: {
  61. isShow(bShow){
  62. this.bShow = bShow;
  63. this.content_arr.length = 0;
  64. this.curr_content_arr.length = 0;
  65. this.curr_page = 1;
  66. this.total_page = 0;
  67. this.itemNumPerPage = 5;
  68. this.bLastPageShow = true;
  69. this.bNextPageShow = true;
  70. this.callback = null;
  71. },
  72. setTitle(title){
  73. this.title = title;
  74. },
  75. setContent(content_arr,callback){
  76. this.content_arr = content_arr;
  77. this.total_page = Math.ceil(this.content_arr.length/this.itemNumPerPage);
  78. let length = this.content_arr.length;
  79. if(length>this.itemNumPerPage)
  80. {
  81. length = this.itemNumPerPage;
  82. }
  83. // console.log('length=',length)
  84. for(let i = 0;i<length;i++){
  85. this.curr_content_arr.push(this.content_arr[i]);
  86. }
  87. this.showNextOrLastPageBtn();
  88. this.callback = callback;
  89. },
  90. close(){
  91. // this.bShow = !this.bShow;
  92. },
  93. confirm(){
  94. for(let i=0;i<this.content_arr.length;i++){
  95. if(this.content_arr[i].input=='')
  96. {
  97. alert(this.content_arr[i].name+'不能为空');
  98. return;
  99. }
  100. }
  101. this.bShow = !this.bShow;
  102. this.callback(this.content_arr);
  103. },
  104. cancel(){
  105. this.bShow = !this.bShow;
  106. },
  107. lastPage(){
  108. this.curr_page--;
  109. this.curr_content_arr.length=0;
  110. let fromIndex = (this.curr_page-1)*this.itemNumPerPage;
  111. let toIndex = fromIndex+this.itemNumPerPage;
  112. for(let i = fromIndex;i<toIndex;i++){
  113. this.curr_content_arr.push(this.content_arr[i]);
  114. }
  115. this.showNextOrLastPageBtn();
  116. },
  117. nextPage(){
  118. this.curr_page++;
  119. this.curr_content_arr.length=0;
  120. let totalItemNum = this.content_arr.length;
  121. let nextPageItemNum = (totalItemNum-(this.curr_page-1)*this.itemNumPerPage)
  122. if(nextPageItemNum>this.itemNumPerPage)
  123. {
  124. nextPageItemNum = this.itemNumPerPage;
  125. }
  126. let fromIndex = (this.curr_page-1)*this.itemNumPerPage;
  127. let toIndex = fromIndex+this.itemNumPerPage;
  128. if(toIndex>totalItemNum)
  129. {
  130. toIndex = totalItemNum;
  131. }
  132. // console.log('from='+fromIndex+';To='+toIndex)
  133. for(let i = fromIndex;i<toIndex;i++){
  134. this.curr_content_arr.push(this.content_arr[i]);
  135. }
  136. // console.log('totalItemNum=',totalItemNum)
  137. // console.log('this.curr_content_arr=',this.curr_content_arr)
  138. this.showNextOrLastPageBtn();
  139. },
  140. showNextOrLastPageBtn()
  141. {
  142. if((this.total_page-this.itemNumPerPage)>0)
  143. {
  144. this.bLastPageShow = false;
  145. this.bNextPageShow = false;
  146. // console.log('0000')
  147. }
  148. else if(this.total_page==this.curr_page)
  149. {
  150. this.bLastPageShow = true;
  151. this.bNextPageShow = false;
  152. // console.log('11111')
  153. }
  154. else if(1==this.curr_page)
  155. {
  156. this.bLastPageShow = false;
  157. this.bNextPageShow = true;
  158. // console.log('2222')
  159. }
  160. else
  161. {
  162. this.bLastPageShow = true;
  163. this.bNextPageShow = true;
  164. // console.log('333333')
  165. }
  166. },
  167. },
  168. }
  169. </script>
  170. <style lang="scss">
  171. .root{
  172. width: 100%;
  173. height: 100%;
  174. position: absolute;
  175. top:0;
  176. left:0;
  177. z-index: 1;
  178. display: flex;
  179. justify-content: center;
  180. align-items: center;
  181. }
  182. .blackBg{
  183. width: 100%;
  184. height: 100%;
  185. opacity: 0.5;
  186. background-color: #000000;
  187. }
  188. .formBg{
  189. position: absolute;
  190. width: 45%;
  191. background-color: #ffffff;
  192. display: flex;
  193. justify-content: space-between;
  194. align-items: center;
  195. flex-direction: column;
  196. }
  197. .titleBg{
  198. width: 100%;
  199. height: 10%;
  200. background-color: #ff0000;
  201. display: flex;
  202. justify-content: center;
  203. align-items: center;
  204. }
  205. .title{
  206. color: #ffffff;
  207. font-size: 40rpx;
  208. margin: 5%;
  209. // border:1px solid #000000;
  210. }
  211. .middle{
  212. width: 100%;
  213. height: 100%;
  214. display: flex;
  215. justify-content: space-between;
  216. align-items: center;
  217. flex-direction: row;
  218. // border:1px solid #000000;
  219. }
  220. .nextPage{
  221. border: 20rpx solid;
  222. border-color:transparent transparent transparent #ff0000;
  223. width:0px;
  224. height:0px;
  225. }
  226. .lastPage{
  227. border: 20rpx solid;
  228. border-color:transparent transparent transparent #ff0000;
  229. width:0px;
  230. height:0px;
  231. -moz-transform:scaleX(-1);
  232. -webkit-transform:scaleX(-1);
  233. -o-transform:scaleX(-1);
  234. transform:scaleX(-1);
  235. /*兼容IE*/
  236. filter:FlipH;
  237. // border:1px solid #000000;
  238. }
  239. .form{
  240. width: 80%;
  241. margin-top: 5%;
  242. display: flex;
  243. justify-content: space-around;
  244. align-items: center;
  245. flex-direction: column;
  246. // border:1px solid #000000;
  247. }
  248. .item{
  249. width: 100%;
  250. margin: 5%;
  251. display: flex;
  252. justify-content: center;
  253. align-items: center;
  254. flex-direction: row;
  255. // border:1px solid #ff0000;
  256. }
  257. .inputName{
  258. width: 20%;
  259. font-size: 20rpx;
  260. font-weight:bold;
  261. // 换行
  262. word-break:break-all;
  263. // word-break:keep-all;
  264. display: flex;
  265. justify-content: flex-start;
  266. align-items: center;
  267. // border:1px solid #000000;
  268. }
  269. .inputBg{
  270. // border:1px solid #000000;
  271. box-shadow: 1px 1px 5px #888888;
  272. display: flex;
  273. justify-content: center;
  274. align-items: center;
  275. width: 80%;
  276. margin-left: 5%;
  277. }
  278. .item input{
  279. width: 80%;
  280. height: 80%;
  281. }
  282. .btnArea{
  283. width: 100%;
  284. // height: 10%;
  285. // border:1px solid #000000;
  286. display: flex;
  287. justify-content: space-around;
  288. align-items: center;
  289. flex-direction: row;
  290. margin: 5%;
  291. }
  292. .confirm{
  293. background: rgb(234, 37, 44);
  294. color: rgb(255, 255, 255);
  295. }
  296. .cancel{
  297. background: rgb(234, 37, 44);
  298. color: rgb(255, 255, 255);
  299. }
  300. </style>