addData.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="content">
  3. <u-form :model="form" ref="uForm" :label-width="140" :error-type="['toast']">
  4. <view class="form-item">
  5. <image src="../../static/CLOTHES.png" mode="" class="form-item-icon"></image>
  6. <u-form-item label="其他垃圾" >
  7. <u-input placeholder="请输入" :maxlength="30" v-model="form.receiverName" />
  8. <text slot="right" style="color: #000000;">桶(约{{125}} kg)</text>
  9. </u-form-item>
  10. </view>
  11. <view class="form-item">
  12. <image src="../../static/CLOTHES.png" mode="" class="form-item-icon"></image>
  13. <u-form-item label="厨余垃圾" >
  14. <u-input placeholder="请输入" :maxlength="11" type="number" v-model="form.receiverPhone" />
  15. <text slot="right" style="color: #000000;">桶(约{{125}} kg)</text>
  16. </u-form-item>
  17. </view>
  18. <view class="form-item">
  19. <image src="../../static/CLOTHES.png" mode="" class="form-item-icon"></image>
  20. <u-form-item label="建筑垃圾" >
  21. <u-input placeholder="请输入" :maxlength="11" type="number" v-model="form.receiverPhone" />
  22. <text slot="right" style="color: #000000;">吨(约{{125}} kg)</text>
  23. </u-form-item>
  24. </view>
  25. <view class="form-item">
  26. <image src="../../static/CLOTHES.png" mode="" class="form-item-icon"></image>
  27. <u-form-item label="信息备注" style="width: 100%;">
  28. <u-input placeholder="请输入" :maxlength="11" type="textarea" v-model="form.receiverPhone" />
  29. <!-- <textarea :auto-height="true" placeholder="请输入备注(最多500个字符)" :maxlength="500" v-model="form.receiveAddress" class="receiveAddress"/> -->
  30. </u-form-item>
  31. </view>
  32. <view class="form-item">
  33. <image src="../../static/CLOTHES.png" mode="" class="form-item-icon"></image>
  34. <u-form-item label="清运照片" style="width: 100%;">
  35. <text style="color: #c0c4cc;" v-if="!photograph">最多3张</text>
  36. <u-icon v-show="photograph" name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph"></u-icon>
  37. <u-icon slot="right" name="camera" color="#2979ff" size="60" class="photograph-icon" @click="photograph.length ? null : goPhotograph()"></u-icon>
  38. <u-image width="100%" height="100%" v-for="item in photograph" :src="item" @click="previewPictures"></u-image>
  39. <!-- <u-icon slot="right" name="camera" color="#2979ff" size="60" class="photograph-icon"></u-icon> -->
  40. <!-- <camera device-position="back" flash="off"></camera>
  41. <!-- <button type="primary" @click="takePhoto">拍照</button>
  42. <!-- <uni-icons type="camera" @click="takePhoto" size="30rpx"></uni-icons>
  43. <view>预览</view>
  44. <image mode="widthFix" :src="src"></image> -->
  45. </u-form-item>
  46. </view>
  47. </u-form>
  48. <view class="buttons">
  49. <u-button type="primary" @click="submit">提交</u-button>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. saveAddress
  56. } from '@/api/receiveAddress.js'
  57. import Address from '@/components/address.vue'
  58. export default {
  59. components: {
  60. Address
  61. },
  62. data() {
  63. return {
  64. show: false,
  65. src:"",
  66. photograph: [], // 图片路径
  67. form: {
  68. receiverName: '',
  69. receiverPhone: '',
  70. receiveAddress: '' // 详细地址
  71. },
  72. };
  73. },
  74. onLoad(option) {
  75. console.log(option,option.id,'ppppppppp')
  76. // 查看
  77. if(option && option.id){
  78. }else {
  79. console.log('--------新增')
  80. this.photograph = []
  81. }
  82. },
  83. onUnload() {
  84. },
  85. methods: {
  86. // 签到拍照
  87. goPhotograph() {
  88. uni.chooseImage({
  89. count: 3, //默认9
  90. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  91. sourceType: ['album','camera'], //从相册选择
  92. success: (res) =>{
  93. console.log(JSON.stringify(res.tempFilePaths));
  94. // this.photograph = JSON.stringify(res.tempFilePaths)
  95. uni.showLoading({
  96. title: '保存中,请稍后...',
  97. mask: true
  98. })
  99. saveImgToAliOss(res.tempFilePaths[0],function(ret){
  100. console.log(ret)
  101. _this.photograph = ret.data
  102. uni.hideLoading()
  103. })
  104. }
  105. });
  106. // const _this = this;
  107. // wx.chooseImage({
  108. // count: 3, //最多可以选择的图片张数,默认9
  109. // sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  110. // sourceType: ['camera'], //album 从相册选图,camera 使用相机,默认二者都有
  111. // success: function(res) {
  112. // // tempFilePaths 图片的本地文件路径列表,tempFiles 图片的本地文件列表,每一项是一个 File 对象
  113. // console.log(JSON.stringify(res.tempFilePaths));
  114. // uni.showLoading({
  115. // title: '保存中,请稍后...',
  116. // mask: true
  117. // })
  118. // // saveImgToAliOss(res.tempFilePaths[0],function(ret){
  119. // // console.log(ret)
  120. // // _this.photograph = ret.data
  121. // // uni.hideLoading()
  122. // // })
  123. // }
  124. // });
  125. },
  126. // 预览签到图
  127. previewPictures() {
  128. const photograph = [this.photograph];
  129. uni.previewImage({
  130. urls: photograph
  131. });
  132. },
  133. // 删除签到图
  134. cancelPhotograph() {
  135. setTimeout(() => {
  136. this.photograph = '';
  137. }, 500);
  138. },
  139. submit() {
  140. this.$refs.uForm.validate(valid => {
  141. if (valid) {
  142. console.log('验证通过');
  143. if (this.form.receiverName ==='') {
  144. uni.showToast({
  145. title: '请输入姓名',
  146. icon: 'none'
  147. })
  148. return false
  149. }
  150. if (this.form.receiverPhone ==='') {
  151. uni.showToast({
  152. title: '请输入电话',
  153. icon: 'none'
  154. })
  155. return false
  156. }
  157. // 省市区
  158. if(this.areaIdArr.length == 0){
  159. uni.showToast({icon: 'none',title: '请选择省市区'})
  160. return
  161. }
  162. if (this.form.receiveAddress ==='') {
  163. uni.showToast({
  164. title: '请输入详细地址',
  165. icon: 'none'
  166. })
  167. return false
  168. }
  169. let params = {
  170. receiverName: this.form.receiverName,
  171. receiverPhone: this.form.receiverPhone,
  172. receiveAreasName: this.areaInfo.label.replace(/\-/g,','), // 地址名称
  173. receiveAreas: this.areaIdArr.join(','),
  174. receiveAddress: this.form.receiveAddress // 详细地址
  175. }
  176. if(this.form.id) {
  177. params.id = this.form.id
  178. }
  179. saveAddress(params).then(res=>{
  180. if(res.status == 200) {
  181. uni.showToast({
  182. title: res.message,
  183. icon: 'none'
  184. })
  185. setTimeout(()=>{
  186. uni.navigateBack()
  187. },300)
  188. }
  189. })
  190. } else {
  191. console.log('验证失败');
  192. }
  193. });
  194. },
  195. // 拍照
  196. takePhoto() {
  197. const ctx = uni.createCameraContext();
  198. ctx.takePhoto({
  199. quality: 'high',
  200. success: (res) => {
  201. this.src = res.tempImagePath
  202. }
  203. });
  204. },
  205. error(e) {
  206. console.log(e.detail);
  207. }
  208. },
  209. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  210. onReady() {
  211. this.$refs.uForm.setRules(this.rules);
  212. }
  213. };
  214. </script>
  215. <style lang="scss">
  216. .content{
  217. padding: 0 50upx;
  218. background: #FFFFFF;
  219. width: 100%;
  220. .buttons{
  221. padding: 80upx 100upx;
  222. }
  223. .receiveAddress{
  224. width: 100%;
  225. line-height: 1.5em;
  226. box-sizing: border-box;
  227. font-style: normal;
  228. }
  229. .form-item{
  230. display: flex;
  231. .form-item-icon{
  232. width: 45upx;
  233. height: 45upx;
  234. margin: auto 10upx;
  235. }
  236. }
  237. }
  238. </style>