addFleet.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <view class="center1">
  3. <view class="flex row form_css">
  4. <view class="left-text">车队名称</view>
  5. <view class="right-text">
  6. <u--input placeholder="输入车队名称,4-15个字" inputAlign='right' clearable border="none" maxlength="15"
  7. v-model="formData.fleetName">
  8. </u--input>
  9. </view>
  10. </view>
  11. <view class="flex row form_css">
  12. <view class="left-text">常驻城市</view>
  13. <view class="right-text">
  14. <view @click="selectAddress">{{title1 ? title1 : "选择常驻地址"}}
  15. <image src="../../static/images/myimg/gengduo1.png" mode=""
  16. style="width: 18rpx;height: 24rpx;margin:14rpx 0 0 20rpx;"></image>
  17. </view>
  18. <itmister-address-picker ref="addressElone" @confirmChange="confirmChangeOne"></itmister-address-picker>
  19. </view>
  20. </view>
  21. <view class="flex row form_css">
  22. <view class="left-text">邀请权限</view>
  23. <view class="right-text">
  24. <u-radio-group v-model="formData.invitationPermission">
  25. <u-radio key="1" label="所有队员" name="1" style="margin-right: 30rpx;" checked="true"></u-radio>
  26. <u-radio key="2" label="仅管理员" name="2"></u-radio>
  27. </u-radio-group>
  28. </view>
  29. </view>
  30. <view class="row">
  31. <view class="left-text">车队简介</view>
  32. <u--textarea class="textarea" v-model="formData.fleetProfile" placeholder="输入车队简介,10-500个字" count
  33. border="none" maxlength="500" height="100"></u--textarea>
  34. </view>
  35. <view class="row">
  36. <view class="left-text">封面照片</view>
  37. <u-upload class="uview-upload" :fileList="fileList1" @afterRead="afterRead($event)" @delete="deletePic"
  38. name="1" multiple :maxCount="1">
  39. <!-- <image src="fileList1[0]"
  40. mode="widthFix" style="width: 250px;height: 150px;"></image> -->
  41. </u-upload>
  42. </view>
  43. <view class=" row ">
  44. <view class="left-text">车队照片 (非必传)</view>
  45. <u-upload class="uview-upload" :fileList="fileList2" @afterRead="afterRead1($event)" @delete="deletePic"
  46. name="2" multiple :maxCount="9" style="z-index: 9999;"></u-upload>
  47. </view>
  48. <u-toast ref="uToast"></u-toast>
  49. <!-- <u-button type="primary" @click="submit">提交</u-button> -->
  50. </view>
  51. </template>
  52. <script>
  53. // import Linkage from '@/components/gaojianghua-linkage/linkage.vue'
  54. import uploadImage from '@/components/ossutil/uploadFile.js';
  55. import permision from "@/js_sdk/wa-permission/permission.js";
  56. import itmisterAddressPicker from '@/components/itmister-address-picker/itmister-address-picker.nvue'
  57. export default {
  58. components: {
  59. // Linkage
  60. itmisterAddressPicker
  61. },
  62. data() {
  63. return {
  64. formData: {
  65. fleetMemberInfo: {},
  66. invitationPermission: "1",
  67. },
  68. show: false,
  69. title1: "",
  70. fileList1: [],
  71. fileList2: []
  72. }
  73. },
  74. onShow() {
  75. this.$forceUpdate()
  76. },
  77. onLoad(options) {
  78. this.id = options.id
  79. this.get_camera_permission()
  80. if (this.id) { //修改
  81. uni.setNavigationBarTitle({
  82. title: '设置'
  83. })
  84. this.getList()
  85. }
  86. },
  87. onNavigationBarButtonTap(e) {
  88. this.submit()
  89. },
  90. methods: {
  91. async get_camera_permission() {
  92. var photol=await permision.requestAndroidPermission("android.permission.CAMERA")
  93. if(photol == false){
  94. uni.showModal({
  95. title: '提示',
  96. content: '您已经关闭相册权限,去设置',
  97. success: function (res) {
  98. if (res.confirm) {
  99. permision.gotoAppPermissionSetting()
  100. // plus.runtime.openURL("app-settings:");
  101. } else if (res.cancel) {
  102. console.log('用户点击取消');
  103. }
  104. }
  105. });
  106. }
  107. },
  108. selectAddress() {
  109. this.$refs.addressElone.show();
  110. },
  111. // 确认选中
  112. confirmChangeOne(address) {
  113. // if(address.province == '全国'){
  114. // uni.$u.toast("发货地不可以是全国")
  115. // // this.$refs.addressElone.show();
  116. // return
  117. // }
  118. this.formData.province = address.province ? address.province : ''
  119. this.formData.city = address.city ? address.city : ''
  120. this.formData.Area = address.area ? address.area : ''
  121. if (address.city == '全省') {
  122. this.title1 = address.province
  123. this.formData.sendCity = ""
  124. this.formData.sendArea = ""
  125. } else if (address.area == '全市') {
  126. this.title1 = address.province + address.city
  127. this.formData.sendArea = ""
  128. } else {
  129. this.title1 = address.province + address.city + address.area;
  130. }
  131. },
  132. getList() {
  133. this.$request.baseRequest('get', '/fleetInfo/getFleetInfo', {
  134. id: this.id
  135. }).then(res => {
  136. this.formData = res.data
  137. if (this.formData.city) {
  138. this.title1 = this.formData.province + this.formData.city
  139. }
  140. if (this.formData.area) {
  141. this.title1 = this.formData.province + this.formData.city + this.formData.area
  142. }
  143. if (this.formData.coverUrl) {
  144. let coverUrlList = this.formData.coverUrl.split(",")
  145. for (let i = 0; i < coverUrlList.length; i++) {
  146. this.fileList1.push({
  147. url: coverUrlList[i]
  148. })
  149. }
  150. }
  151. if (this.formData.fleetUrl) {
  152. let fleetUrlList = this.formData.fleetUrl.split(",")
  153. // this.fileList2 = this.formData.fleetUrl.split(",")
  154. for (let i = 0; i < fleetUrlList.length; i++) {
  155. this.fileList2.push({
  156. url: fleetUrlList[i]
  157. })
  158. }
  159. }
  160. })
  161. .catch(res => {
  162. uni.$u.toast(res.message);
  163. });
  164. },
  165. conceal1(param) {
  166. const {
  167. chooseprovince,
  168. choosecity,
  169. choosearea
  170. } = param
  171. // 获取到传过来的 省 市 区 县数据
  172. this.formData.province = chooseprovince
  173. this.formData.city = choosecity == '全部' ? "" : choosecity
  174. this.formData.area = choosearea == '全部' ? "" : choosearea
  175. this.title1 = chooseprovince + choosecity + choosearea
  176. if (chooseprovince == '全国') {
  177. this.succeed()
  178. }
  179. if (choosecity == '全部') {
  180. this.succeed()
  181. } else if (choosearea != '') {
  182. this.succeed()
  183. }
  184. },
  185. succeed() {
  186. // this.$refs.uDropdown.close();
  187. this.show = false
  188. },
  189. // 删除图片
  190. deletePic(event) {
  191. console.log(this[`fileList${event.name}`])
  192. this[`fileList${event.name}`].splice(event.index, 1)
  193. },
  194. // 新增图片
  195. async afterRead(event) {
  196. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  197. let lists = [].concat(event.file)
  198. console.log(this[`fileList${event.name}`])
  199. let fileListLen = this[`fileList${event.name}`].length
  200. lists.map((item) => {
  201. this[`fileList${event.name}`].push({
  202. ...item,
  203. status: 'uploading',
  204. message: '上传中'
  205. })
  206. })
  207. for (let i = 0; i < lists.length; i++) {
  208. const result = await this.uploadFilePromise(lists[i].url)
  209. let item = this[`fileList${event.name}`][fileListLen]
  210. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  211. status: 'success',
  212. message: '',
  213. url: result
  214. }))
  215. fileListLen++
  216. }
  217. },
  218. uploadFilePromise(url) {
  219. uploadImage('image', url, 'appData/',
  220. result => {
  221. // 上传成功回调函数
  222. if (this.formData.coverUrl) {
  223. this.formData.coverUrl = this.formData.coverUrl + ',' + result
  224. } else {
  225. this.formData.coverUrl = result
  226. }
  227. }
  228. )
  229. },
  230. // 新增图片
  231. async afterRead1(event) {
  232. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  233. let lists = [].concat(event.file)
  234. let fileListLen = this[`fileList${event.name}`].length
  235. lists.map((item) => {
  236. this[`fileList${event.name}`].push({
  237. ...item,
  238. status: 'uploading',
  239. message: '上传中'
  240. })
  241. })
  242. for (let i = 0; i < lists.length; i++) {
  243. const result = await this.uploadFilePromise1(lists[i].url)
  244. let item = this[`fileList${event.name}`][fileListLen]
  245. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  246. status: 'success',
  247. message: '',
  248. url: result
  249. }))
  250. fileListLen++
  251. }
  252. },
  253. uploadFilePromise1(url) {
  254. uploadImage('image', url, 'appData/',
  255. result => {
  256. // 上传成功回调函数
  257. if (this.formData.fleetUrl) {
  258. this.formData.fleetUrl = this.formData.fleetUrl + ',' + result
  259. } else {
  260. this.formData.fleetUrl = result
  261. }
  262. }
  263. )
  264. },
  265. submit() {
  266. if (!this.formData.fleetName) {
  267. this.$refs.uToast.show({
  268. type: 'error',
  269. message: "请输入车队名称!",
  270. })
  271. return
  272. }
  273. if (this.formData.fleetName.length < 4) {
  274. this.$refs.uToast.show({
  275. type: 'error',
  276. message: "车队名称需4-15字!",
  277. })
  278. return
  279. }
  280. if (!this.title1) {
  281. this.$refs.uToast.show({
  282. type: 'error',
  283. message: "请选择常驻地址!",
  284. })
  285. return
  286. }
  287. if (!this.formData.invitationPermission) {
  288. this.$refs.uToast.show({
  289. type: 'error',
  290. message: "请设置邀请权限!",
  291. })
  292. return
  293. }
  294. if (!this.formData.fleetProfile) {
  295. this.$refs.uToast.show({
  296. type: 'error',
  297. message: "请填写车队简介!",
  298. })
  299. return
  300. }
  301. if (this.formData.fleetProfile.length < 10) {
  302. this.$refs.uToast.show({
  303. type: 'error',
  304. message: "车队简介需10 - 500个字!",
  305. })
  306. return
  307. }
  308. if (this.fileList1.length == 0) {
  309. this.$refs.uToast.show({
  310. type: 'error',
  311. message: "请上传车队封面!",
  312. })
  313. return
  314. }
  315. if (this.id) { //编辑
  316. this.formData.flag = 2
  317. this.$request.baseRequest('post', '/fleetInfo/api/editFleetInfo', this.formData).then(res => {
  318. if (res.code == 200) {
  319. this.$refs.uToast.show({
  320. type: 'success',
  321. message: "车队修改成功!",
  322. complete() {
  323. // uni.$u.route("pages/riders/fleetSee")
  324. uni.navigateBack({
  325. delta: 1
  326. });
  327. }
  328. })
  329. }
  330. })
  331. .catch(res => {
  332. uni.$u.toast(res.message);
  333. });
  334. } else {
  335. this.formData.commonId = uni.getStorageSync("firstAuthentication").commonId
  336. this.formData.fleetMemberInfo.commonId = uni.getStorageSync("firstAuthentication").commonId
  337. this.formData.fleetMemberInfo.driverNickname = uni.getStorageSync("firstAuthentication").driverCall
  338. this.formData.fleetMemberInfo.driverPortrait = uni.getStorageSync("userInfo").avatarUrl
  339. this.$request.baseRequest('post', '/fleetInfo/api/addFleetInfo', this.formData).then(res => {
  340. if (res.code == 200) {
  341. this.$refs.uToast.show({
  342. type: 'success',
  343. message: "车队添加成功!",
  344. complete() {
  345. uni.$u.route("pages/riders/myTeam")
  346. }
  347. })
  348. }
  349. })
  350. .catch(res => {
  351. uni.$u.toast(res.message);
  352. });
  353. }
  354. }
  355. }
  356. }
  357. </script>
  358. <style lang="scss">
  359. .center1 {
  360. padding: 30rpx;
  361. }
  362. .form_data {
  363. // padding: 30rpx;
  364. }
  365. .form_css {
  366. width: 100%;
  367. display: flex;
  368. margin: 30rpx 0;
  369. height: 80rpx;
  370. border-bottom: 1px solid #eeeeee;
  371. .left-text {
  372. width: 50%;
  373. text-align: left;
  374. }
  375. .right-text {
  376. width: 50%;
  377. justify-content: flex-end;
  378. display: flex;
  379. text-align: right;
  380. .jiantou {
  381. color: #CCCCCC;
  382. width: 23rpx;
  383. height: 23rpx;
  384. display: inline-block;
  385. }
  386. }
  387. }
  388. .textarea {
  389. background: #F9F9FB;
  390. margin: 21rpx 0 80rpx 0;
  391. }
  392. </style>