index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <div class="surrounding">
  3. <van-tabs :active="active" @change="onChange">
  4. <van-tab title="新增发布" :name="0">
  5. <div class="newRelease_com">
  6. <ul class="predetermineUl">
  7. <li class="predetermineLi2" style="border-bottom: none">
  8. <div class="liName">标题</div>
  9. <van-field
  10. :value="postData.businessName"
  11. autosize
  12. type="textarea"
  13. placeholder="请输入"
  14. class="myField"
  15. maxlength="50"
  16. show-word-limit
  17. @change="changeTitle"
  18. />
  19. </li>
  20. </ul>
  21. <ul class="predetermineUl">
  22. <li class="detailLi2" style="border-bottom: none">
  23. <span class="liName">
  24. 快捷选择
  25. </span>
  26. <div class="detailLi2Box">
  27. <div class="detailLi2BoxTop">
  28. <div class="checkItem" :class="checkedName===item.label?'checked':''" v-for="item in checkList" :key="item.id" @click="clickCheck(item)">{{item.label}}</div>
  29. </div>
  30. </div>
  31. </li>
  32. <li class="detailLi">
  33. <span class="liName">地址</span>
  34. <span >
  35. <input class="liInfo" placeholder="选择地址" v-model="postData.businessAddress" disabled @tap="showMap">
  36. <van-icon name="location" style="color: rgba(51, 51, 51, 0.90)"/>
  37. </span>
  38. </li>
  39. <li class="detailLi" style="border-bottom: none">
  40. <span class="liName">电话</span>
  41. <span >
  42. <input class="liInfo" placeholder="请填写" v-model="postData.businessPhone">
  43. </span>
  44. </li>
  45. </ul>
  46. <ul class="predetermineUl">
  47. <li class="detailLi2">
  48. <div class="titleBox" style="margin-bottom: 24rpx">
  49. <span class="liName">简介</span>
  50. <span class="tips">(支持图片上传限20M内,最多1张)</span>
  51. </div>
  52. <van-uploader
  53. :max-count="1"
  54. @delete="deleteRYXXZP"
  55. :file-list="fileList"
  56. @after-read="uploadRYXXZP"
  57. :show-upload="true"
  58. />
  59. <van-field
  60. :value="postData.introduction"
  61. autosize
  62. type="textarea"
  63. placeholder="请输入"
  64. class="myField"
  65. maxlength="2000"
  66. show-word-limit
  67. @change="changeIntro"
  68. />
  69. </li>
  70. </ul>
  71. <div class="buttonBox">
  72. <button class="btn zcBtn" @tap="addSurr('unpublished')">暂存</button>
  73. <button class="btn tjBtn" @tap="addSurr('published')">发布</button>
  74. </div>
  75. </div>
  76. </van-tab>
  77. <van-tab title="发布记录" :name="1">
  78. <releaseRecord_com ref="releaseRecord"/>
  79. </van-tab>
  80. </van-tabs>
  81. </div>
  82. </template>
  83. <script>
  84. import releaseRecord_com from "./components/releaseRecord_com.vue";
  85. import { getByCodes,peripheryAdd,getUserLocalStorageInfo } from "@/js_sdk/http";
  86. import dayjs from "dayjs";
  87. export default {
  88. name: "index",
  89. components:{
  90. releaseRecord_com
  91. },
  92. data(){
  93. return{
  94. active:1,
  95. dc_key: ['periphery_type'],
  96. fileList:[],
  97. checkList:[],
  98. postData:{
  99. createdBy:getUserLocalStorageInfo().userId,
  100. status:'',
  101. businessName:'',
  102. type:'',
  103. businessAddress:'',
  104. longitude:'',
  105. latitude:'',
  106. businessPhone:'',
  107. fileUrl:'',
  108. introduction:'',
  109. releaseType:'periphery'
  110. },
  111. checkedName:'干洗',
  112. }
  113. },
  114. onPullDownRefresh() {
  115. this.$refs.releaseRecord.getByCodes()
  116. setTimeout(function () {
  117. uni.stopPullDownRefresh();
  118. }, 1000);
  119. },
  120. created(){
  121. this.getByCodes()
  122. },
  123. methods:{
  124. changeTitle(e){
  125. this.postData.businessName = e.detail
  126. },
  127. changeIntro(e){
  128. this.postData.introduction = e.detail
  129. },
  130. async getByCodes() {
  131. let data = await getByCodes(JSON.stringify(this.dc_key));
  132. this.dic_SelectList = this.$common.handleDicList(data);
  133. this.checkList = this.dic_SelectList.periphery_type
  134. console.log('checkList',this.checkList)
  135. },
  136. clickCheck(item){
  137. // console.log(item)
  138. this.checkedName = item.label
  139. this.postData.type = item.value
  140. },
  141. showMap(){
  142. const _this = this
  143. uni.chooseLocation({
  144. success: function (res) {
  145. console.log('选择的位置:', res.name);
  146. _this.postData.businessAddress = res.name
  147. console.log('纬度:' + res.latitude + ',经度:' + res.longitude);
  148. _this.postData.latitude = res.latitude
  149. _this.postData.longitude = res.longitude
  150. // 其他业务逻辑
  151. },
  152. fail: function (error) {
  153. console.error('Choose location failed: ' + JSON.stringify(error));
  154. },
  155. complete: function () {
  156. console.log('chooseLocation operation is complete');
  157. }
  158. });
  159. },
  160. addSurr(e){
  161. const dayjs = require('dayjs')
  162. const fileArr = []
  163. this.fileList.forEach(file=>{
  164. fileArr.push(file.id)
  165. })
  166. this.postData.fileUrl = fileArr.toString()
  167. this.postData.status = e
  168. let toastMsg = ''
  169. if (e==='published'){
  170. this.postData.publisherUserId = getUserLocalStorageInfo().userId
  171. this.postData.releaseTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
  172. toastMsg = '发布成功'
  173. }else{
  174. toastMsg = '暂存成功'
  175. }
  176. // console.log(this.postData)
  177. peripheryAdd(this.postData).then(res=>{
  178. if (res.code=='200'){
  179. uni.showToast({
  180. title: toastMsg,
  181. duration: 500
  182. });
  183. this.postData = {
  184. createdBy:getUserLocalStorageInfo().userId,
  185. status:'',
  186. businessName:'',
  187. type:'',
  188. businessAddress:'',
  189. longitude:'',
  190. latitude:'',
  191. businessPhone:'',
  192. fileUrl:'',
  193. introduction:'',
  194. releaseType:'periphery'
  195. }
  196. this.fileList = []
  197. this.active = 1
  198. this.$refs.releaseRecord.getByCodes()
  199. }else{
  200. uni.showToast({
  201. title: res.msg,
  202. duration: 500
  203. });
  204. }
  205. })
  206. },
  207. onChange(e){
  208. // console.log(e)
  209. this.active = e.detail.name
  210. },
  211. deleteRYXXZP(event) {
  212. this.fileList.splice(event.detail.index, 1);
  213. this.$forceUpdate();
  214. },
  215. uploadRYXXZP(event) {
  216. console.log(event)
  217. let that = this;
  218. const { file } = event.detail;
  219. uni.uploadFile({
  220. url: that.$constant.BASE_URI + "/wx/fileController/upload",
  221. filePath: file.url,
  222. name: "file",
  223. formData: { user: "test" },
  224. success(res) {
  225. // 上传完成需要更新 fileList
  226. let data = JSON.parse(res.data);
  227. console.log('data',data)
  228. that.fileList.push({
  229. imgUrl: "/FileController/download/" + data.data[0],
  230. id: data.data[0],
  231. url:
  232. that.$constant.BASE_URI +
  233. "/FileController/download/" +
  234. data.data[0],
  235. isImage: true,
  236. });
  237. },
  238. fail(res) {},
  239. });
  240. },
  241. }
  242. }
  243. </script>
  244. <style lang="scss">
  245. .surrounding{
  246. .newRelease_com{
  247. .predetermineUl{
  248. margin: 24rpx 0;
  249. background: white;
  250. box-sizing: border-box;
  251. padding: 0 32rpx;
  252. .predetermineLi{
  253. padding: 32rpx 0;
  254. border-bottom: 1px solid rgba(230, 230, 230, 1);
  255. display: flex;
  256. justify-content: space-between;
  257. }
  258. .predetermineLi2{
  259. padding: 32rpx 0;
  260. border-bottom: 1px solid rgba(230, 230, 230, 1);
  261. display: flex;
  262. flex-direction: column;
  263. }
  264. .van-cell {
  265. background: #F5F7FA !important;
  266. border-radius: 8rpx;
  267. font-size: 28rpx;
  268. margin-top: 16rpx;
  269. }
  270. .liName{
  271. color: rgba(51, 51, 51, 1);
  272. font-size: 32rpx;
  273. }
  274. .liIpt{
  275. color: rgba(102, 102, 102, 1);
  276. font-size: 32rpx;
  277. text-align: right;
  278. }
  279. .detailLi{
  280. display: flex;
  281. justify-content: space-between;
  282. align-items: center;
  283. padding: 32rpx 0;
  284. border-bottom: 2rpx solid #E6E6E6;
  285. .liInfo{
  286. display: inline-block;
  287. text-align: right;
  288. min-width: 528rpx;
  289. max-width: 528rpx;
  290. color: rgba(102, 102, 102, 1);
  291. font-size: 32rpx;
  292. line-height: 38rpx;
  293. .radio{
  294. margin-left: 64rpx;
  295. }
  296. }
  297. }
  298. .detailLi2{
  299. display: flex;
  300. flex-direction: column;
  301. padding: 32rpx 0;
  302. border-bottom: 2rpx solid #E6E6E6;
  303. .detailLi2BoxTop{
  304. display: flex;
  305. flex-wrap: wrap;
  306. justify-content: space-between;
  307. margin: 12rpx 0;
  308. .checkItem{
  309. width: 128rpx;
  310. height: 64rpx;
  311. font-size: 28rpx;
  312. color: #666666;
  313. display: flex;
  314. align-items: center;
  315. justify-content: center;
  316. background: #F5F7FA;
  317. border-radius: 8rpx;
  318. margin: 12rpx 0;
  319. }
  320. .checked{
  321. background: #0365F9;
  322. color: white;
  323. }
  324. }
  325. }
  326. }
  327. .titleBox{
  328. display: flex;
  329. align-items: center;
  330. .titleName{
  331. color: rgba(24, 23, 42, 1);
  332. font-size: 32rpx;
  333. font-weight: 600;
  334. margin-right: 16rpx;
  335. }
  336. .tips{
  337. font-size: 28rpx;
  338. color: rgba(179, 179, 179, 1);
  339. }
  340. }
  341. .buttonBox{
  342. display: flex;
  343. justify-content: center;
  344. .btn{
  345. width: 240rpx;
  346. height: 80rpx;
  347. display: flex;
  348. border-radius: 8rpx;
  349. align-items: center;
  350. justify-content: center;
  351. margin: 48rpx 16rpx 150rpx 16rpx;
  352. color: white;
  353. letter-spacing: 2rpx;
  354. text-indent: 2rpx;
  355. }
  356. .zcBtn{
  357. background: #FE8643;
  358. }
  359. .tjBtn{
  360. background: #0365F9;
  361. }
  362. }
  363. }
  364. }
  365. </style>