addFleet.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <view class="center">
  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 itmisterAddressPicker from '@/components/itmister-address-picker/itmister-address-picker.nvue'
  56. export default {
  57. components: {
  58. // Linkage
  59. itmisterAddressPicker
  60. },
  61. data() {
  62. return {
  63. formData: {
  64. fleetMemberInfo: {},
  65. invitationPermission: "1",
  66. },
  67. show: false,
  68. title1: "",
  69. fileList1: [],
  70. fileList2: []
  71. }
  72. },
  73. onShow() {
  74. this.$forceUpdate()
  75. },
  76. onLoad(options) {
  77. this.id = options.id
  78. if (this.id) { //修改
  79. uni.setNavigationBarTitle({
  80. title: '设置'
  81. })
  82. this.getList()
  83. }
  84. },
  85. onNavigationBarButtonTap(e) {
  86. this.submit()
  87. },
  88. methods: {
  89. selectAddress() {
  90. this.$refs.addressElone.show();
  91. },
  92. // 确认选中
  93. confirmChangeOne(address) {
  94. // if(address.province == '全国'){
  95. // uni.$u.toast("发货地不可以是全国")
  96. // // this.$refs.addressElone.show();
  97. // return
  98. // }
  99. this.formData.province = address.province ? address.province : ''
  100. this.formData.city = address.city ? address.city : ''
  101. this.formData.Area = address.area ? address.area : ''
  102. if (address.city == '全省') {
  103. this.title1 = address.province
  104. this.formData.sendCity = ""
  105. this.formData.sendArea = ""
  106. } else if (address.area == '全市') {
  107. this.title1 = address.province + address.city
  108. this.formData.sendArea = ""
  109. } else {
  110. this.title1 = address.province + address.city + address.area;
  111. }
  112. },
  113. getList() {
  114. this.$request.baseRequest('get', '/fleetInfo/getFleetInfo', {
  115. id: this.id
  116. }).then(res => {
  117. this.formData = res.data
  118. if (this.formData.city) {
  119. this.title1 = this.formData.province + this.formData.city
  120. }
  121. if (this.formData.area) {
  122. this.title1 = this.formData.province + this.formData.city + this.formData.area
  123. }
  124. if (this.formData.coverUrl) {
  125. let coverUrlList = this.formData.coverUrl.split(",")
  126. for (let i = 0; i < coverUrlList.length; i++) {
  127. this.fileList1.push({
  128. url: coverUrlList[i]
  129. })
  130. }
  131. }
  132. if (this.formData.fleetUrl) {
  133. let fleetUrlList = this.formData.fleetUrl.split(",")
  134. // this.fileList2 = this.formData.fleetUrl.split(",")
  135. for (let i = 0; i < fleetUrlList.length; i++) {
  136. this.fileList2.push({
  137. url: fleetUrlList[i]
  138. })
  139. }
  140. }
  141. })
  142. .catch(res => {
  143. uni.$u.toast(res.message);
  144. });
  145. },
  146. conceal1(param) {
  147. const {
  148. chooseprovince,
  149. choosecity,
  150. choosearea
  151. } = param
  152. // 获取到传过来的 省 市 区 县数据
  153. this.formData.province = chooseprovince
  154. this.formData.city = choosecity == '全部' ? "" : choosecity
  155. this.formData.area = choosearea == '全部' ? "" : choosearea
  156. this.title1 = chooseprovince + choosecity + choosearea
  157. if (chooseprovince == '全国') {
  158. this.succeed()
  159. }
  160. if (choosecity == '全部') {
  161. this.succeed()
  162. } else if (choosearea != '') {
  163. this.succeed()
  164. }
  165. },
  166. succeed() {
  167. // this.$refs.uDropdown.close();
  168. this.show = false
  169. },
  170. // 删除图片
  171. deletePic(event) {
  172. console.log(this[`fileList${event.name}`])
  173. this[`fileList${event.name}`].splice(event.index, 1)
  174. },
  175. // 新增图片
  176. async afterRead(event) {
  177. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  178. let lists = [].concat(event.file)
  179. console.log(this[`fileList${event.name}`])
  180. let fileListLen = this[`fileList${event.name}`].length
  181. lists.map((item) => {
  182. this[`fileList${event.name}`].push({
  183. ...item,
  184. status: 'uploading',
  185. message: '上传中'
  186. })
  187. })
  188. for (let i = 0; i < lists.length; i++) {
  189. const result = await this.uploadFilePromise(lists[i].url)
  190. let item = this[`fileList${event.name}`][fileListLen]
  191. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  192. status: 'success',
  193. message: '',
  194. url: result
  195. }))
  196. fileListLen++
  197. }
  198. },
  199. uploadFilePromise(url) {
  200. uploadImage('image', url, 'appData/',
  201. result => {
  202. // 上传成功回调函数
  203. if (this.formData.coverUrl) {
  204. this.formData.coverUrl = this.formData.coverUrl + ',' + result
  205. } else {
  206. this.formData.coverUrl = result
  207. }
  208. }
  209. )
  210. },
  211. // 新增图片
  212. async afterRead1(event) {
  213. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  214. let lists = [].concat(event.file)
  215. let fileListLen = this[`fileList${event.name}`].length
  216. lists.map((item) => {
  217. this[`fileList${event.name}`].push({
  218. ...item,
  219. status: 'uploading',
  220. message: '上传中'
  221. })
  222. })
  223. for (let i = 0; i < lists.length; i++) {
  224. const result = await this.uploadFilePromise1(lists[i].url)
  225. let item = this[`fileList${event.name}`][fileListLen]
  226. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  227. status: 'success',
  228. message: '',
  229. url: result
  230. }))
  231. fileListLen++
  232. }
  233. },
  234. uploadFilePromise1(url) {
  235. uploadImage('image', url, 'appData/',
  236. result => {
  237. // 上传成功回调函数
  238. if (this.formData.fleetUrl) {
  239. this.formData.fleetUrl = this.formData.fleetUrl + ',' + result
  240. } else {
  241. this.formData.fleetUrl = result
  242. }
  243. }
  244. )
  245. },
  246. submit() {
  247. if (!this.formData.fleetName) {
  248. this.$refs.uToast.show({
  249. type: 'error',
  250. message: "请输入车队名称!",
  251. })
  252. return
  253. }
  254. if (this.formData.fleetName.length < 4) {
  255. this.$refs.uToast.show({
  256. type: 'error',
  257. message: "车队名称需4-15字!",
  258. })
  259. return
  260. }
  261. if (!this.title1) {
  262. this.$refs.uToast.show({
  263. type: 'error',
  264. message: "请选择常驻地址!",
  265. })
  266. return
  267. }
  268. if (!this.formData.invitationPermission) {
  269. this.$refs.uToast.show({
  270. type: 'error',
  271. message: "请设置邀请权限!",
  272. })
  273. return
  274. }
  275. if (!this.formData.fleetProfile) {
  276. this.$refs.uToast.show({
  277. type: 'error',
  278. message: "请填写车队简介!",
  279. })
  280. return
  281. }
  282. if (this.formData.fleetProfile.length < 10) {
  283. this.$refs.uToast.show({
  284. type: 'error',
  285. message: "车队简介需10 - 500个字!",
  286. })
  287. return
  288. }
  289. if (this.fileList1.length == 0) {
  290. this.$refs.uToast.show({
  291. type: 'error',
  292. message: "请上传车队封面!",
  293. })
  294. return
  295. }
  296. if (this.id) { //编辑
  297. this.formData.flag = 2
  298. this.$request.baseRequest('post', '/fleetInfo/api/editFleetInfo', this.formData).then(res => {
  299. if (res.code == 200) {
  300. this.$refs.uToast.show({
  301. type: 'success',
  302. message: "车队修改成功!",
  303. complete() {
  304. // uni.$u.route("pages/riders/fleetSee")
  305. uni.navigateBack({
  306. delta: 1
  307. });
  308. }
  309. })
  310. }
  311. })
  312. .catch(res => {
  313. uni.$u.toast(res.message);
  314. });
  315. } else {
  316. this.formData.commonId = uni.getStorageSync("firstAuthentication").commonId
  317. this.formData.fleetMemberInfo.commonId = uni.getStorageSync("firstAuthentication").commonId
  318. this.formData.fleetMemberInfo.driverNickname = uni.getStorageSync("firstAuthentication").driverCall
  319. this.formData.fleetMemberInfo.driverPortrait = uni.getStorageSync("userInfo").avatarUrl
  320. this.$request.baseRequest('post', '/fleetInfo/api/addFleetInfo', this.formData).then(res => {
  321. if (res.code == 200) {
  322. this.$refs.uToast.show({
  323. type: 'success',
  324. message: "车队添加成功!",
  325. complete() {
  326. uni.$u.route("pages/riders/myTeam")
  327. }
  328. })
  329. }
  330. })
  331. .catch(res => {
  332. uni.$u.toast(res.message);
  333. });
  334. }
  335. }
  336. }
  337. }
  338. </script>
  339. <style lang="scss">
  340. .center {
  341. padding: 30rpx;
  342. }
  343. .form_data {
  344. // padding: 30rpx;
  345. }
  346. .form_css {
  347. width: 100%;
  348. display: flex;
  349. margin: 30rpx 0;
  350. height: 80rpx;
  351. border-bottom: 1px solid #eeeeee;
  352. .left-text {
  353. width: 50%;
  354. text-align: left;
  355. }
  356. .right-text {
  357. width: 50%;
  358. justify-content: flex-end;
  359. display: flex;
  360. text-align: right;
  361. .jiantou {
  362. color: #CCCCCC;
  363. width: 23rpx;
  364. height: 23rpx;
  365. display: inline-block;
  366. }
  367. }
  368. }
  369. .textarea {
  370. background: #F9F9FB;
  371. margin: 21rpx 0 80rpx 0;
  372. }
  373. </style>