addFleet.vue 10 KB

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