index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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:0,
  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.active = 1
  197. }else{
  198. uni.showToast({
  199. title: res.msg,
  200. duration: 500
  201. });
  202. }
  203. })
  204. },
  205. onChange(e){
  206. },
  207. deleteRYXXZP(event) {
  208. this.fileList.splice(event.detail.index, 1);
  209. this.$forceUpdate();
  210. },
  211. uploadRYXXZP(event) {
  212. console.log(event)
  213. let that = this;
  214. const { file } = event.detail;
  215. uni.uploadFile({
  216. url: that.$constant.BASE_URI + "/wx/fileController/upload",
  217. filePath: file.url,
  218. name: "file",
  219. formData: { user: "test" },
  220. success(res) {
  221. // 上传完成需要更新 fileList
  222. let data = JSON.parse(res.data);
  223. console.log('data',data)
  224. that.fileList.push({
  225. imgUrl: "/FileController/download/" + data.data[0],
  226. id: data.data[0],
  227. url:
  228. that.$constant.BASE_URI +
  229. "/FileController/download/" +
  230. data.data[0],
  231. isImage: true,
  232. });
  233. },
  234. fail(res) {},
  235. });
  236. },
  237. }
  238. }
  239. </script>
  240. <style lang="scss">
  241. .surrounding{
  242. .newRelease_com{
  243. .predetermineUl{
  244. margin: 24rpx 0;
  245. background: white;
  246. box-sizing: border-box;
  247. padding: 0 32rpx;
  248. .predetermineLi{
  249. padding: 32rpx 0;
  250. border-bottom: 1px solid rgba(230, 230, 230, 1);
  251. display: flex;
  252. justify-content: space-between;
  253. }
  254. .predetermineLi2{
  255. padding: 32rpx 0;
  256. border-bottom: 1px solid rgba(230, 230, 230, 1);
  257. display: flex;
  258. flex-direction: column;
  259. }
  260. .van-cell {
  261. background: #F5F7FA !important;
  262. border-radius: 8rpx;
  263. font-size: 28rpx;
  264. margin-top: 16rpx;
  265. }
  266. .liName{
  267. color: rgba(51, 51, 51, 1);
  268. font-size: 32rpx;
  269. }
  270. .liIpt{
  271. color: rgba(102, 102, 102, 1);
  272. font-size: 32rpx;
  273. text-align: right;
  274. }
  275. .detailLi{
  276. display: flex;
  277. justify-content: space-between;
  278. align-items: center;
  279. padding: 32rpx 0;
  280. border-bottom: 2rpx solid #E6E6E6;
  281. .liInfo{
  282. display: inline-block;
  283. text-align: right;
  284. min-width: 528rpx;
  285. max-width: 528rpx;
  286. color: rgba(102, 102, 102, 1);
  287. font-size: 32rpx;
  288. line-height: 38rpx;
  289. .radio{
  290. margin-left: 64rpx;
  291. }
  292. }
  293. }
  294. .detailLi2{
  295. display: flex;
  296. flex-direction: column;
  297. padding: 32rpx 0;
  298. border-bottom: 2rpx solid #E6E6E6;
  299. .detailLi2BoxTop{
  300. display: flex;
  301. flex-wrap: wrap;
  302. justify-content: space-between;
  303. margin: 12rpx 0;
  304. .checkItem{
  305. width: 128rpx;
  306. height: 64rpx;
  307. font-size: 28rpx;
  308. color: #666666;
  309. display: flex;
  310. align-items: center;
  311. justify-content: center;
  312. background: #F5F7FA;
  313. border-radius: 8rpx;
  314. margin: 12rpx 0;
  315. }
  316. .checked{
  317. background: #0365F9;
  318. color: white;
  319. }
  320. }
  321. }
  322. }
  323. .titleBox{
  324. display: flex;
  325. align-items: center;
  326. .titleName{
  327. color: rgba(24, 23, 42, 1);
  328. font-size: 32rpx;
  329. font-weight: 600;
  330. margin-right: 16rpx;
  331. }
  332. .tips{
  333. font-size: 28rpx;
  334. color: rgba(179, 179, 179, 1);
  335. }
  336. }
  337. .buttonBox{
  338. display: flex;
  339. justify-content: center;
  340. .btn{
  341. width: 240rpx;
  342. height: 80rpx;
  343. display: flex;
  344. border-radius: 8rpx;
  345. align-items: center;
  346. justify-content: center;
  347. margin: 48rpx 16rpx 150rpx 16rpx;
  348. color: white;
  349. letter-spacing: 2rpx;
  350. text-indent: 2rpx;
  351. }
  352. .zcBtn{
  353. background: #FE8643;
  354. }
  355. .tjBtn{
  356. background: #0365F9;
  357. }
  358. }
  359. }
  360. }
  361. </style>