addData.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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}} t)</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 ? null : goPhotograph()"></u-icon>
  38. <u-image v-show="photograph" width="100%" height="100%" :src="photograph" @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. receiveAreas: '', //地址编码
  73. areaName: '', //地址
  74. areaInfo: {}, // 省市区
  75. areaIdArr: [], // 省市区id数组
  76. rules: {
  77. }
  78. };
  79. },
  80. onLoad(option) {
  81. this.form = this.$store.state.vuex_OrderAddress
  82. if (this.form.receiveAreasName) {
  83. this.areaIdArr = this.form.receiveAreas.split(',')
  84. this.areaInfo.label = this.form.receiveAreasName.replace(/\,/g,'-')
  85. uni.setNavigationBarTitle({
  86. title: '新增数据录入'
  87. })
  88. } else {
  89. uni.setNavigationBarTitle({
  90. title: '修改数据'
  91. })
  92. }
  93. // 开启分享
  94. uni.showShareMenu({
  95. withShareTicket: true,
  96. menus: ['shareAppMessage', 'shareTimeline']
  97. })
  98. },
  99. onUnload() {
  100. this.$u.vuex("vuex_OrderAddress",{})
  101. },
  102. methods: {
  103. // 签到拍照
  104. goPhotograph() {
  105. const _this = this;
  106. wx.chooseImage({
  107. count: 3, //最多可以选择的图片张数,默认9
  108. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  109. sourceType: ['camera'], //album 从相册选图,camera 使用相机,默认二者都有
  110. success: function(res) {
  111. // tempFilePaths 图片的本地文件路径列表,tempFiles 图片的本地文件列表,每一项是一个 File 对象
  112. console.log(JSON.stringify(res.tempFilePaths));
  113. uni.showLoading({
  114. title: '保存中,请稍后...',
  115. mask: true
  116. })
  117. // saveImgToAliOss(res.tempFilePaths[0],function(ret){
  118. // console.log(ret)
  119. // _this.photograph = ret.data
  120. // uni.hideLoading()
  121. // })
  122. }
  123. });
  124. },
  125. // 预览签到图
  126. previewPictures() {
  127. const photograph = [this.photograph];
  128. uni.previewImage({
  129. urls: photograph
  130. });
  131. },
  132. // 删除签到图
  133. cancelPhotograph() {
  134. setTimeout(() => {
  135. this.photograph = '';
  136. }, 500);
  137. },
  138. submit() {
  139. this.$refs.uForm.validate(valid => {
  140. if (valid) {
  141. console.log('验证通过');
  142. if (this.form.receiverName ==='') {
  143. uni.showToast({
  144. title: '请输入姓名',
  145. icon: 'none'
  146. })
  147. return false
  148. }
  149. if (this.form.receiverPhone ==='') {
  150. uni.showToast({
  151. title: '请输入电话',
  152. icon: 'none'
  153. })
  154. return false
  155. }
  156. // 省市区
  157. if(this.areaIdArr.length == 0){
  158. uni.showToast({icon: 'none',title: '请选择省市区'})
  159. return
  160. }
  161. if (this.form.receiveAddress ==='') {
  162. uni.showToast({
  163. title: '请输入详细地址',
  164. icon: 'none'
  165. })
  166. return false
  167. }
  168. let params = {
  169. receiverName: this.form.receiverName,
  170. receiverPhone: this.form.receiverPhone,
  171. receiveAreasName: this.areaInfo.label.replace(/\-/g,','), // 地址名称
  172. receiveAreas: this.areaIdArr.join(','),
  173. receiveAddress: this.form.receiveAddress // 详细地址
  174. }
  175. if(this.form.id) {
  176. params.id = this.form.id
  177. }
  178. saveAddress(params).then(res=>{
  179. if(res.status == 200) {
  180. uni.showToast({
  181. title: res.message,
  182. icon: 'none'
  183. })
  184. setTimeout(()=>{
  185. uni.navigateBack()
  186. },300)
  187. }
  188. })
  189. } else {
  190. console.log('验证失败');
  191. }
  192. });
  193. },
  194. // 拍照
  195. takePhoto() {
  196. const ctx = uni.createCameraContext();
  197. ctx.takePhoto({
  198. quality: 'high',
  199. success: (res) => {
  200. this.src = res.tempImagePath
  201. }
  202. });
  203. },
  204. error(e) {
  205. console.log(e.detail);
  206. }
  207. },
  208. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  209. onReady() {
  210. this.$refs.uForm.setRules(this.rules);
  211. }
  212. };
  213. </script>
  214. <style lang="scss">
  215. .content{
  216. padding: 0 50upx;
  217. background: #FFFFFF;
  218. width: 100%;
  219. .buttons{
  220. padding: 80upx 100upx;
  221. }
  222. .receiveAddress{
  223. width: 100%;
  224. line-height: 1.5em;
  225. box-sizing: border-box;
  226. font-style: normal;
  227. }
  228. .form-item{
  229. display: flex;
  230. .form-item-icon{
  231. width: 45upx;
  232. height: 45upx;
  233. margin: auto 10upx;
  234. }
  235. }
  236. }
  237. </style>