publish.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <template>
  2. <view class="pages">
  3. <form @submit="formSubmit" @reset="formReset">
  4. <view class="form-item-type nomal-top">
  5. <view class="form-item">
  6. <view class="form-item-til">类目</view>
  7. <view class="form-item-con">
  8. <input type="text" disabled placeholder="商品类目" v-model="params.type" value="" />
  9. </view>
  10. </view>
  11. <!-- <view class="form-item arrow">
  12. <view class="form-item-til">地理位置</view>
  13. <view class="form-item-con" @click="chooseaddr">
  14. <input type="text" placeholder="请选择地理位置" v-model="params.myposition" value="" />
  15. </view>
  16. </view> -->
  17. </view>
  18. <view class="form-item-type">
  19. <view class="form-item">
  20. <view class="form-item-til">标题</view>
  21. <view class="form-item-con">
  22. <input type="text" placeholder="请输入发布产品标题" v-model="params.title" value="" />
  23. </view>
  24. </view>
  25. <view class="form-item">
  26. <view class="form-item-til">品牌</view>
  27. <view class="form-item-con">
  28. <input type="text" placeholder="请输入品牌" v-model="params.brand" value="" />
  29. </view>
  30. </view>
  31. <view class="form-item">
  32. <view class="form-item-til">零售价</view>
  33. <view class="form-item-con">
  34. <input type="text" placeholder="请输入零售价" v-model="params.price" value="" />
  35. </view>
  36. </view>
  37. <view class="form-item">
  38. <view class="form-item-til">供应商</view>
  39. <view class="form-item-con">
  40. <input type="text" disabled placeholder="" v-model="params.supplier" value="" />
  41. </view>
  42. </view>
  43. <view class="form-item arrow" @click="openplaceoforigin">
  44. <view class="form-item-til">生产地</view>
  45. <view class="form-item-con">
  46. <input type="text" disabled="disabled" placeholder="" v-model="params.placeoforigin" value="" />
  47. </view>
  48. </view>
  49. <view class="form-item arrow" @click="openspecifications">
  50. <view class="form-item-til">规格</view>
  51. <view class="form-item-con">
  52. <text v-for="(item,index) in params.specifications">{{item}},</text>
  53. <!-- <input type="text" placeholder="" v-model="params.specifications" value="" /> -->
  54. </view>
  55. </view>
  56. <view class="form-item">
  57. <view class="form-item-til">保质期</view>
  58. <view class="form-item-con">
  59. <input type="text" placeholder="请输入保质期" v-model="params.shelflife" value="" />
  60. </view>
  61. </view>
  62. <view class="form-item">
  63. <view class="form-item-til">生产日期</view>
  64. <view class="form-item-con">
  65. <picker mode="date" :value="params.date" :start="startDate" :end="endDate" @change="bindDateChange">
  66. <view class="uni-input">{{params.date}}</view>
  67. </picker>
  68. <!-- <input type="text" placeholder="请输入生产日期" v-model="params.productiondate" value="" /> -->
  69. </view>
  70. </view>
  71. <view class="form-item">
  72. <view class="form-item-til">包装</view>
  73. <view class="form-item-con">
  74. <input type="text" placeholder="请输入包装" v-model="params.packaging" value="" />
  75. </view>
  76. </view>
  77. <view class="form-item">
  78. <view class="form-item-til">标签</view>
  79. <view class="form-item-con">
  80. <input type="text" placeholder="请输入标签,用逗号隔开" v-model="params.productlabel" value="" />
  81. </view>
  82. </view>
  83. </view>
  84. <view class="form-item upfile">
  85. <view class="form-item-til">图片视频</view>
  86. <view class="form-item-con">
  87. <view class="form-item-chooseIMGs-wrap">
  88. <image v-for="(item,index) in params.media" :key="index" :src="item" class="choosedIMG" ></image>
  89. </view>
  90. <view class="chooseIMG-btn">
  91. <image class="chooseIMG-btn-img" @click="chooseimg" src="/static/img/icon-upload.png"></image>
  92. </view>
  93. </view>
  94. </view>
  95. </form>
  96. <view class="bottom-btn-wrap">
  97. <button class="bottom-btn" @click="publish" type="primary">发布</button>
  98. </view>
  99. <!-- 页面显示结束 下面是隐藏内容 -->
  100. <!-- 供应商开始 -->
  101. <!-- <view class="supplier-page fix-content translate" :class="{ 'open': supplieropen }" >
  102. <view class="search-wrap search-left-color">
  103. <view class="search">
  104. <view class="searchTxt">
  105. <uni-search-bar placeholder="搜索供应商关键词" @confirm="searchsupplier" @input="searchsupplier" ></uni-search-bar>
  106. </view>
  107. </view>
  108. </view>
  109. <view class="simplepage-wrap">
  110. <mescroll-body ref="mescrollRef0" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  111. <view>
  112. <view v-for="(item,index) in supplierlist" :key="index" @click="supplierclick(item)" class="simplepage-item">{{item}}</view>
  113. </view>
  114. </mescroll-body>
  115. </view>
  116. </view> -->
  117. <!-- 供应商结束 -->
  118. <!-- 产地开始 -->
  119. <view class="placeoforigin-page fix-content translate" :class="{ 'open': placeoforiginopen }" >
  120. <view class="search-wrap search-left-color">
  121. <view class="search">
  122. <view class="searchTxt">
  123. <uni-search-bar placeholder="搜索产地关键词" @confirm="searchplace" @input="searchplace" ></uni-search-bar>
  124. </view>
  125. </view>
  126. </view>
  127. <!-- 搜索 结束 -->
  128. <scroll-view class="simplepage-wrap" scroll-y="true">
  129. <view v-for="(item,index) in placeoforiginlist" :key="index" @click="placeoforiginclick(item.detailAddress)" class="simplepage-item">{{item.detailAddress}}</view>
  130. </scroll-view>
  131. </view>
  132. <!-- 产地结束 -->
  133. <!-- 规格开始 -->
  134. <view class="specifications-page fix-content translate" :class="{ 'open': specificationsopen }" >
  135. <view class="specifications-wrap wrap">
  136. <checkbox-group @change="checkboxChange">
  137. <label v-for="(item,index) in specificationslist" :key="index" class="checkbox-style" >
  138. <checkbox :value="item.value" :checked="item.checked" />{{item.name}}
  139. </label>
  140. </checkbox-group>
  141. <view class="pecifications-btn-wrap">
  142. <button type="default" class="big-btn big-btn-hollow" @click="resetcheckbox">重置</button>
  143. <button type="default" class="big-btn primary" @click="specificationsclick">确定</button>
  144. </view>
  145. </view>
  146. </view>
  147. <!-- 规格结束 -->
  148. </view>
  149. </template>
  150. <script>
  151. // 引入mescroll-mixins.js
  152. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  153. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  154. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  155. import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue';
  156. import { bus } from '../../utils/bus.js';
  157. export default {
  158. mixins: [MescrollMixin], // 使用mixin
  159. components: {
  160. MescrollBody,
  161. uniSearchBar,
  162. },
  163. data() {
  164. const currentDate = this.getDate({
  165. format: true
  166. })
  167. return {
  168. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  169. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  170. downOption: {
  171. // ...
  172. },
  173. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  174. upOption: {
  175. page: {
  176. size: 10 // 每页数据的数量,默认10
  177. },
  178. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  179. empty: {
  180. tip: '暂无相关数据'
  181. }
  182. },
  183. params: {
  184. token: '',
  185. type:'',
  186. myposition:'',
  187. title:'',
  188. brand:'',
  189. price:'',
  190. supplier:'默认的供应商',//供应商
  191. placeoforigin:'',//产地
  192. specifications:[],//规格
  193. shelflife:'',//保质期
  194. date: currentDate,//生产日期 // productiondate:'',//生产日期
  195. packaging:'',//包装
  196. productlabel:'',//标签
  197. media:[],//图片视频
  198. },
  199. //表单检查结果
  200. checkStatus:false,
  201. //供应商
  202. supplieropen:false,
  203. supplierlist:[],
  204. // 产地
  205. placeoforiginopen:false,
  206. placeoforiginlist:[],
  207. places:[],//临时暂存
  208. // 规格
  209. specificationsopen:false,
  210. specificationslist:[
  211. {value: '500g/提(250g/盒*2)',name: '500g/提(250g/盒*2)',checked: false},
  212. {value: '10g/罐',name: '10g/罐',checked: false},
  213. {value: '30g/盒',name: '30g/盒',checked: false},
  214. {value: '150g/盒',name: '150g/盒',checked: false},
  215. {value: '30g/盒(1.5g*20瓶)',name: '30g/盒(1.5g*20瓶)',checked: false},
  216. ],
  217. backtyep:1,
  218. }
  219. },
  220. onShow() {
  221. uni.hideTabBar();
  222. let serf = this;
  223. //检查登录,获取token
  224. // let loginRes = this.checkLogin('/pages/publish/publish', '2');
  225. // if (!loginRes) {
  226. // return false;
  227. // }
  228. // serf.params.token = loginRes[0];
  229. },
  230. onHide() {
  231. uni.showTabBar()
  232. },
  233. onLoad(option) {
  234. let self = this;
  235. if(Object.keys(bus.data).length>0){
  236. console.log('bus.data',bus.data)
  237. this.params.type = bus.data.name;
  238. // console.log(this.params.type);
  239. };
  240. // console.log(option);
  241. // this.params.type = option.type;
  242. uni.getStorage({
  243. key:'token',
  244. success: function (res) {
  245. self.params.token = res.data;
  246. // console.log(res.data);
  247. }
  248. });
  249. uni.getStorage({
  250. key:'tokenhead',
  251. success: function (res) {
  252. self.params.tokenhead = res.data;
  253. // console.log(res.data);
  254. }
  255. });
  256. //供应商详情
  257. let thetoken = this.params.tokenhead+this.params.token;
  258. this.$api.http.get(this.config.apiBaseurl+'/company/cp/detail',{header: {Authorization:thetoken},params:{compId:72}}).then(res =>{
  259. console.log('res',JSON.parse(JSON.stringify(res)));
  260. this.placeoforiginlist = res.data.data.origines;
  261. this.places = res.data.data.origines;
  262. this.params.supplier= res.data.data.compName;
  263. }).catch( err => {
  264. console.log(err)
  265. });
  266. },
  267. computed: {
  268. startDate() {
  269. return this.getDate('start');
  270. },
  271. endDate() {
  272. return this.getDate('end');
  273. }
  274. },
  275. methods: {
  276. getDate(type) {
  277. const date = new Date();
  278. let year = date.getFullYear();
  279. let month = date.getMonth() + 1;
  280. let day = date.getDate();
  281. if (type === 'start') {
  282. year = year - 60;
  283. } else if (type === 'end') {
  284. year = year + 2;
  285. }
  286. month = month > 9 ? month : '0' + month;;
  287. day = day > 9 ? day : '0' + day;
  288. return `${year}-${month}-${day}`;
  289. },
  290. bindDateChange: function(e) {
  291. this.params.date = e.target.value
  292. // console.log(this.params.date);
  293. },
  294. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  295. mescrollInit(mescroll) {
  296. this.mescroll = mescroll;
  297. },
  298. downCallback(){
  299. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  300. },
  301. /*上拉加载的回调*/
  302. upCallback(page) {
  303. let pageNum = page.num; // 页码, 默认从1开始
  304. let pageSize = page.size; // 页长, 默认每页10条
  305. this.params = Object.assign(this.params,{page:pageNum,rows:pageSize});
  306. this.$api.http.post(this.config.apiBaseurl+'hotel/reserve/data',this.params,{
  307. header: {
  308. Accept:'application/json',
  309. Authorization: 'Bearer '+ this.params.token, //注意Bearer后面有一空格
  310. }
  311. }).then(data => {
  312. if(data.data.code=='1001'){
  313. // uni.redirectTo({
  314. // url:'/pages/login/login?backpage=/pages/index/index'+'&backtype='+2,
  315. // });
  316. };
  317. console.log(data);
  318. // 接口返回的当前页数据列表 (数组)
  319. let curPageData = data.data.rows;
  320. console.log('curPageData',curPageData);
  321. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  322. let curPageLen = curPageData.length;
  323. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  324. // let totalPage = data.xxx;
  325. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  326. let totalSize = data.data.total;
  327. // 接口返回的是否有下一页 (true/false)
  328. // let hasNext = data.xxx;
  329. //设置列表数据
  330. if(page.num == 1) this.dataList = []; //如果是第一页需手动置空列表
  331. this.dataList = this.dataList.concat(curPageData); //追加新数据
  332. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  333. this.mescroll.endBySize(curPageLen, totalSize);
  334. // setTimeout(()=>{
  335. // this.mescroll.endSuccess(curPageLen)
  336. // },20)
  337. }).catch(err => {
  338. this.mescroll.endErr()
  339. console.log(err)
  340. });
  341. },
  342. //选择图片
  343. chooseimg() {
  344. let _self = this;
  345. uni.chooseImage({
  346. count: 3,
  347. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  348. sourceType: ['album', 'camera'], //从相册选择
  349. success: function(res) {
  350. const tempFilePaths = res.tempFilePaths;
  351. _self.image = tempFilePaths[0];
  352. console.log("tempFilePaths[0]", tempFilePaths[0]) //能够打印出选中的图片
  353. _self.iconcheck = 1; //点击后图片更改状态由0变成1
  354. console.log('111', JSON.stringify(res.tempFilePaths));
  355. _self.params.media = res.tempFilePaths;
  356. console.log(_self.params.media);
  357. // 预览图片
  358. // uni.previewImage({
  359. // urls: res.tempFilePaths,
  360. // longPressActions: {
  361. // // itemList: [],
  362. // success: function(data) {
  363. // console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
  364. // },
  365. // fail: function(err) {
  366. // console.log(err.errMsg);
  367. // }
  368. // }
  369. // });
  370. },
  371. error: function(e) {
  372. console.log(e);
  373. }
  374. });
  375. },
  376. //发布
  377. publish() {
  378. this.checkStatus = this.check_form();
  379. if(this.checkStatus){
  380. let _self = this;
  381. //上传图片
  382. // uni.uploadFile({
  383. // url: _self.httpUrl + '', // 后端api接口
  384. // filePath: _self.image, // uni.chooseImage函数调用后获取的本地文件路劲
  385. // name: 'EmployeeImage', //后端通过'file'获取上传的文件对象(字段)
  386. // formData: {
  387. // // openid:_self.openid, //剩下的字段
  388. // },
  389. // header: {
  390. // "Content-Type": "multipart/form-data"
  391. // },
  392. // success: (res) => {
  393. // console.log(res)
  394. // if (res.statusCode == 200) {
  395. // uni.showToast({
  396. // icon: 'success',
  397. // title: "添加成功...",
  398. // })
  399. // }
  400. // setTimeout(() => {
  401. // uni.navigateTo({
  402. // url: ''
  403. // })
  404. // }, 2000)
  405. // },
  406. // error(error) {
  407. // uni.showToast({
  408. // title: "添加失败...",
  409. // })
  410. // }
  411. // });
  412. uni.showLoading({
  413. title: '请稍等'
  414. });
  415. setTimeout(function () {
  416. uni.hideLoading();
  417. }, 2000);
  418. // setTimeout(()=>{
  419. // uni.showToast({
  420. // icon:'success',
  421. // title:`发布成功,请等待审核!`,
  422. // duration: 2000
  423. // });
  424. // },2000);
  425. setTimeout(() => {
  426. uni.redirectTo({
  427. url:'/pages/publish/publishsuccess/publishsuccess'
  428. })
  429. }, 2000);
  430. }
  431. },
  432. //表单验证
  433. check_form() {
  434. console.log('this.params',this.params);
  435. if(this.params.type.length <= 0) {
  436. uni.showToast({icon:'none',title:`请填写类别!`,duration: 2000});
  437. return false;
  438. }
  439. // if(this.params.myposition.length <= 0) {
  440. // console.log(this.params.myposition);
  441. // uni.showToast({icon:'none',title:`请填写地理位置!`,duration: 2000});
  442. // return false;
  443. // }
  444. if(this.params.title.length <= 0) {
  445. uni.showToast({icon:'none',title:`请填写标题!`,duration: 2000});
  446. return false;
  447. }
  448. if(this.params.brand.length <= 0) {
  449. uni.showToast({icon:'none',title:`请填写品牌!`,duration: 2000});
  450. return false;
  451. }
  452. if(this.params.price.length <= 0) {
  453. uni.showToast({icon:'none',title:`请填写零售价!`,duration: 2000});
  454. return false;
  455. }
  456. if(this.params.supplier.length <= 0) {
  457. uni.showToast({icon:'none',title:`请填写供应商!`,duration: 2000});
  458. return false;
  459. }
  460. if(this.params.placeoforigin.length <= 0) {
  461. uni.showToast({icon:'none',title:`请填写生产地!`,duration: 2000});
  462. return false;
  463. }
  464. if(this.params.specifications.length <= 0) {
  465. uni.showToast({icon:'none',title:`请填写规格!`,duration: 2000});
  466. return false;
  467. }
  468. if(this.params.shelflife.length <= 0) {
  469. uni.showToast({icon:'none',title:`请填写保质期!`,duration: 2000});
  470. return false;
  471. }
  472. if(this.params.date.length <= 0) {
  473. uni.showToast({icon:'none',title:`请填写生产日期!`,duration: 2000});
  474. return false;
  475. }
  476. if(this.params.packaging.length <= 0) {
  477. uni.showToast({icon:'none',title:`请填写包装!`,duration: 2000});
  478. return false;
  479. }
  480. if(this.params.productlabel.length <= 0) {
  481. uni.showToast({icon:'none',title:`请填写标签!`,duration: 2000});
  482. return false;
  483. }
  484. if(this.params.media.length <= 0) {
  485. uni.showToast({icon:'none',title:`请上传图片!`,duration: 2000});
  486. return false;
  487. }
  488. return true;
  489. },
  490. //选择供应商
  491. // supplierclick(name){
  492. // this.params.supplier = name;
  493. // this.supplieropen = false;
  494. // this.showback();
  495. // },
  496. //打开供应商弹出框
  497. // opensupplier(){
  498. // this.supplieropen = true;
  499. // this.hideback();
  500. // },
  501. // 搜索供应商
  502. // searchsupplier(e){
  503. // console.log(e);
  504. // },
  505. //选择生产地
  506. placeoforiginclick(name){
  507. this.params.placeoforigin = name;
  508. this.placeoforiginopen = false;
  509. this.showback();
  510. },
  511. //打开生产地弹出框
  512. openplaceoforigin(){
  513. this.placeoforiginopen = true;
  514. this.hideback();
  515. },
  516. //选择规格
  517. specificationsclick(e){
  518. // this.params.specifications = name;
  519. this.specificationsopen = false;
  520. this.showback();
  521. },
  522. //打开规格弹出框
  523. openspecifications(){
  524. this.specificationsopen = true;
  525. this.hideback();
  526. },
  527. // 规格checkbox
  528. checkboxChange: function (e) {
  529. var items = this.specificationslist,
  530. values = e.detail.value;
  531. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  532. const item = items[i]
  533. if(values.includes(item.value)){
  534. this.$set(item,'checked',true)
  535. }else{
  536. this.$set(item,'checked',false)
  537. }
  538. }
  539. this.params.specifications = e.detail.value;
  540. console.log(this.params.specifications);
  541. },
  542. resetcheckbox(){
  543. var items = this.specificationslist;
  544. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  545. const item = items[i];
  546. this.$set(item,'checked',false)
  547. }
  548. this.params.specifications = [];
  549. // console.log(this.params.specifications);
  550. },
  551. //隐藏返回按钮
  552. hideback(){
  553. // let backbtn = document.getElementsByClassName('uni-page-head-hd')[0];
  554. // backbtn.style.display = 'none';
  555. this.backtyep = 2;
  556. console.log(this.backtyep)
  557. },
  558. // 显示返回按钮
  559. showback(){
  560. // let backbtn = document.getElementsByClassName('uni-page-head-hd')[0];
  561. // backbtn.style.display = 'block';
  562. this.backtyep = 1;
  563. console.log(this.backtyep)
  564. },
  565. // 导航返回按钮
  566. onBackPress(e){
  567. console.log(this.backtyep)
  568. if(this.backtyep == 2){
  569. this.placeoforiginopen = false;
  570. this.backtyep = 1;
  571. return true;
  572. };
  573. },
  574. // 选择位置
  575. chooseaddr(){
  576. let self = this;
  577. uni.chooseLocation({
  578. success: function (res) {
  579. self.params.myposition = res.address;
  580. console.log('位置名称:' + res.name);
  581. console.log('详细地址:' + res.address);
  582. console.log('纬度:' + res.latitude);
  583. console.log('经度:' + res.longitude);
  584. }
  585. });
  586. },
  587. // 搜索产地
  588. searchplace(e){
  589. if(e.value){
  590. let place = this.placeoforiginlist.filter(function (value) {
  591. console.log(value.detailAddress);
  592. return value.detailAddress.includes(e.value);
  593. });
  594. console.log('place',place);
  595. this.placeoforiginlist = place;
  596. }else{
  597. this.placeoforiginlist = this.places;
  598. }
  599. }
  600. }
  601. }
  602. </script>
  603. <style >
  604. @import url("./publish.css");
  605. </style>