entryredItem.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. <template>
  2. <view class="content">
  3. <view style="height: 20rpx;background: #F4F5F7;"></view>
  4. <view class="box">
  5. <view class="boxLine" v-for="(item,index) in categoryList[index1].sectionList[index2].itemList">
  6. <view class="boxLineTop">
  7. <view class="itemName">{{item.itemName}}</view>
  8. <view class="store" v-if="item.keyType==4" @click="pickerClick(item)">
  9. <picker @change="bindPickerChange($event)" :value="item.storeIndex" :item="item" :range="item.array">
  10. <view class="pickerView" v-if="item.itemValue!=null">{{item.itemValue}} 分</view>
  11. <view class="pickerView" v-else>请选择</view>
  12. </picker>
  13. <view>
  14. <image src="../../static/img/jiantou.png" mode="" class="storeJtimg"></image>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="boxlinedescribe">{{item.describe}}</view>
  19. <view class="itemCklineBox" v-if="item.keyType==1">
  20. <view class="itemCkline" :class="{itemckActive:name.check}" @click="itemXx(name)" v-for="(name,nameIndex) in item.array">{{name.name}}</view>
  21. <!-- <view class="itemCkline itemckActive">张杰</view> -->
  22. </view>
  23. <view class="textareaBox" v-if="item.keyType==2">
  24. <textarea placeholder-style="color:#CCCCCC" placeholder="请输入~" v-model="item.itemValue" class="textareaCont"/>
  25. </view>
  26. <view class="imgBox" v-if="item.keyType==3">
  27. <view class="imgLine" v-for="(img,imgindex) in item.imgArr">
  28. <image @click="previewImage(img)" :class="{img4:(imgindex+1)%4==0}" :src="img" mode="" class="itemImg"></image>
  29. <image src="../../static/img/icon_delpic@2x.png" mode="" class="delImg" @click="delimg(item,imgindex)"></image>
  30. </view>
  31. <view class="imgLine" @click="uploadImg(item)">
  32. <image src="../../static/img/icon_addpic@2x.png" mode="" class="itemImg"></image>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view style="height: 160rpx;"></view>
  38. <view class="bottom">
  39. <view class="bottomBtn" @click="sub">保存</view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. pickerindex:null,
  48. array:[0,1,2,3,4,5],
  49. index1:'',
  50. index2:'',
  51. categoryList:'',
  52. pickerItem:'',
  53. }
  54. },
  55. onLoad(opt) {
  56. var name = opt.name;
  57. uni.setNavigationBarTitle({
  58. title: name
  59. })
  60. this.index1=opt.index1;
  61. this.index2=opt.index2;
  62. console.log(this.$store.state.categoryList)
  63. this.categoryList=this.$store.state.categoryList;
  64. this.categoryList[this.index1].sectionList.forEach(v=>{
  65. console.log(v)
  66. if(v.check){
  67. }else{
  68. v.itemList.forEach((item,index)=>{
  69. item.itemValue='';
  70. if(item.keyType==4){
  71. var arr=[];
  72. for(var i=0;i<Number(item.keyValue) +1;i++){
  73. arr.push(i)
  74. }
  75. item.array=arr.reverse();
  76. item.storeIndex=null;
  77. item.itemValue=null;
  78. }else if(item.keyType==1){
  79. item.keyValue=item.keyValue.replace(/,/ig,',')
  80. var array= item.keyValue.split(",")
  81. var arr=[]
  82. array.forEach(name=>{
  83. var obj={
  84. name:name,
  85. check:false
  86. }
  87. arr.push(obj)
  88. })
  89. item.array=arr
  90. }else if(item.keyType==3){
  91. item.imgArr=[]
  92. }
  93. })
  94. }
  95. })
  96. /* this.categoryList[this.index1].sectionList[this.index2].itemList.forEach((item,index)=>{
  97. item.itemValue='';
  98. if(item.keyType==4){
  99. var arr=[];
  100. for(var i=0;i<Number(item.keyValue) +1;i++){
  101. arr.push(i)
  102. }
  103. item.array=arr;
  104. item.storeIndex=null;
  105. item.itemValue=null;
  106. }else if(item.keyType==1){
  107. item.keyValue=item.keyValue.replace(/,/ig,',')
  108. var array= item.keyValue.split(",")
  109. var arr=[]
  110. array.forEach(name=>{
  111. var obj={
  112. name:name,
  113. check:false
  114. }
  115. arr.push(obj)
  116. })
  117. item.array=arr
  118. }else if(item.keyType==3){
  119. item.imgArr=[]
  120. }
  121. }) */
  122. console.log(this.categoryList);
  123. },
  124. methods: {
  125. previewImage(img){
  126. var arr=[];
  127. arr.push(img)
  128. // 预览图片
  129. uni.previewImage({
  130. urls: arr,
  131. longPressActions: {
  132. itemList: ['发送给朋友', '保存图片', '收藏'],
  133. success: function(data) {
  134. console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
  135. },
  136. fail: function(err) {
  137. console.log(err.errMsg);
  138. }
  139. }
  140. });
  141. },
  142. bindPickerChange(e){
  143. console.log(e)
  144. this.pickerItem.itemValue=this.pickerItem.array[e.detail.value] ;
  145. console.log(this.categoryList);
  146. this.categoryList.splice(1,0)
  147. },
  148. delimg(item,imgindex){
  149. item.imgArr.splice(imgindex,1);
  150. //console.log(item)
  151. this.categoryList.splice(1,0)
  152. },
  153. pickerClick(item){
  154. this.pickerItem=item
  155. },
  156. itemXx(name){
  157. console.log(name)
  158. name.check=!name.check;
  159. this.categoryList.splice(1,0)
  160. },
  161. uploadImg(item){
  162. var that=this;
  163. console.log(item)
  164. var length=item.imgArr.length;
  165. if(length==10){
  166. uni.showToast({
  167. title: '最多上传10张',
  168. icon:'none',
  169. duration: 2000,
  170. });
  171. return false;
  172. }
  173. var num=10-length;
  174. uni.chooseImage({
  175. sourceType: ['album'],
  176. count:num,
  177. success: (chooseImageRes) => {
  178. const tempFilePaths = chooseImageRes.tempFilePaths;
  179. tempFilePaths.forEach(v=>{
  180. uni.uploadFile({
  181. url: that.$request.baseUrl+'accompany/SuperCheckSheet/uploadFile', //仅为示例,非真实的接口地址
  182. filePath: v,
  183. name: 'file',
  184. formData: {
  185. 'user': 'test'
  186. },
  187. success: (uploadFileRes) => {
  188. console.log(JSON.parse(uploadFileRes.data).data );
  189. console.log(item.imgArr)
  190. item.imgArr=item.imgArr.concat(JSON.parse(uploadFileRes.data).data) ;
  191. that.categoryList.splice(1,0)
  192. }
  193. });
  194. })
  195. /* that.$http('accompany/SuperCheckSheet/uploadFile', tempFilePaths[0], 'POST').then(res => {
  196. }) */
  197. }
  198. });
  199. },
  200. sub(){
  201. console.log(this.categoryList);
  202. var go=true;
  203. this.categoryList[this.index1].sectionList[this.index2].itemList.forEach(item=>{
  204. if(item.keyType==3){
  205. item.itemValue=item.imgArr.join(',');
  206. console.log(item.itemValue)
  207. }else if(item.keyType==1){
  208. var arr=[]
  209. item.array.forEach(name=>{
  210. if(name.check){
  211. arr.push(name.name)
  212. }
  213. })
  214. item.itemValue=arr.join(',');
  215. }
  216. if(item.itemValue===0){
  217. }else if(item.itemValue===''){
  218. go=false
  219. }else if(!item.itemValue){
  220. go=false
  221. }
  222. })
  223. console.log(this.categoryList[this.index1].sectionList[this.index2].itemList)
  224. if(!go){
  225. uni.showToast({
  226. title: '每一项都是必填,请填写完成',
  227. icon:'none',
  228. duration: 3000,
  229. });
  230. return false;
  231. }
  232. //return false;
  233. this.categoryList[this.index1].sectionList[this.index2].check=true;
  234. uni.navigateBack({
  235. delta:1
  236. })
  237. this.$store.commit('mutationsCategoryList',this.categoryList)
  238. }
  239. }
  240. }
  241. </script>
  242. <style scoped>
  243. .content{
  244. background: #F4F5F7;
  245. min-height: 100vh;
  246. }
  247. /* #ifdef H5 */
  248. .content{
  249. background: #F4F5F7;
  250. min-height:calc(100vh - 44px);
  251. }
  252. /* #endif */
  253. .boxLine{
  254. padding: 30rpx 20rpx;
  255. background: #FFFFFF;
  256. border-bottom: 1px solid #EEEEEE;
  257. }
  258. .boxLineTop{
  259. display: flex;
  260. justify-content: space-between;
  261. }
  262. .store{
  263. color: #FF4F00;font-size: 30rpx;
  264. }
  265. .storeJtimg{
  266. width: 14rpx;
  267. height: 26rpx;
  268. margin-top: 8rpx;
  269. margin-left: 10rpx;
  270. }
  271. .store{
  272. display: flex;
  273. }
  274. .itemName{
  275. color: #3C3C3C;font-size: 30rpx;font-weight: 600;
  276. }
  277. .boxlinedescribe{
  278. color: #999999;
  279. font-size: 26rpx;
  280. padding-top: 10rpx;
  281. }
  282. .itemCklineBox{
  283. display: flex;
  284. flex-wrap: wrap;
  285. padding-top: 20rpx;
  286. }
  287. .itemCkline{
  288. height: 56rpx;
  289. background: #F4F5F7;
  290. border-radius: 28rpx;
  291. line-height: 56rpx;
  292. padding: 0 40rpx;
  293. font-size: 28rpx;
  294. color: #333333;
  295. margin-right: 30rpx;
  296. }
  297. .itemckActive{
  298. background: #FF4F00;color: #FFFFFF;
  299. }
  300. .textareaCont{
  301. width: 670rpx;
  302. height: 120rpx;
  303. background: #F4F5F7;
  304. border-radius: 10rpx;
  305. padding: 28rpx 20rpx;
  306. font-size: 28rpx;
  307. color: #3C3C3C;
  308. }
  309. .textareaBox{
  310. padding-top: 20rpx;
  311. }
  312. .imgBox{
  313. padding-top: 20rpx;
  314. display: flex;
  315. flex-wrap: wrap;
  316. }
  317. .itemImg{
  318. width:150rpx;
  319. height: 150rpx;
  320. margin-right: 35rpx;
  321. margin-top: 30rpx;
  322. }
  323. .img4{
  324. margin-right: 0;
  325. }
  326. .delImg{
  327. width: 32rpx;
  328. height: 32rpx;
  329. position: absolute;
  330. left: 135rpx;
  331. top: 10rpx;
  332. }
  333. .imgLine{
  334. position: relative;
  335. }
  336. .bottom{
  337. width: 750rpx;
  338. height: 120rpx;
  339. background: #FFFFFF;
  340. box-shadow: 0px -4px 8px 0px rgba(153,153,153,0.08);
  341. position: fixed;
  342. left: 0;
  343. bottom: 0;
  344. }
  345. .bottomBtn{
  346. width: 702rpx;
  347. height: 74rpx;
  348. background: linear-gradient(124deg, #FF8700 0%, #FF4F00 100%);
  349. border-radius: 37rpx;
  350. text-align: center;
  351. line-height: 74rpx;
  352. color: #FFFFFF;
  353. font-size:30rpx;
  354. margin-top: 24rpx;
  355. margin-left: 24rpx;
  356. }
  357. </style>