uploadP.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <template>
  2. <view class="content">
  3. <swiper class="swiper-box" :skip-hidden-item-layout='true' :style="{ height: maxheight }" disable-touch
  4. :current="current">
  5. <swiper-item>
  6. <scroll-view scroll-y="true" style="height: 100%;">
  7. <view class="tip">
  8. 最多可以添加5张商品图片
  9. </view>
  10. <view class="banner-box">
  11. <view class="banner" v-for="(item,index) in imageList" :key="index">
  12. <view class="banner-main">
  13. <image :src="item" mode=""></image>
  14. </view>
  15. <image class="cha" @click.stop="delImg(index)" src="../../static/img/cha.png" mode="">
  16. </image>
  17. </view>
  18. <view class="banner" v-if="imageList.length < 5" @click="navCroper(400,400,'banner')">
  19. <image src="../../static/img/addP.png" mode=""></image>
  20. </view>
  21. </view>
  22. <view class="main">
  23. <view class="box-1">
  24. <view class="box-left">
  25. 商品名称
  26. <text class="imp">*</text>
  27. </view>
  28. <input type="text" placeholder="请填写商品名称" value="" class="list-input" v-model="name" />
  29. </view>
  30. <view class="box-1">
  31. <view class="box-left">
  32. 商品编码
  33. <text class="imp">*</text>
  34. </view>
  35. <input type="text" placeholder="请填写商品编码" value="" class="list-input" v-model="bianma" />
  36. </view>
  37. <classify v-if="classify.length != 0" :list="classify" :choose="chooseClass"
  38. @chooseClasswc="chooseClasswc"></classify>
  39. <view class="box-1">
  40. <view class="box-left">运费模板</view>
  41. <picker @change="bindYf" :range="yfarray" range-key="name" class="list-input">
  42. <text>{{ yf.name }}</text>
  43. </picker>
  44. </view>
  45. <view class="box-1">
  46. <view class="box-left">商品规格</view>
  47. <u-radio-group @change="radioGroupChange" v-model="isdanname">
  48. <u-radio v-for="(item, index) in list" :key="index" :name="item">
  49. {{item}}
  50. </u-radio>
  51. </u-radio-group>
  52. </view>
  53. <arrts :value="values" :item="item" @getarrts="getarrts" ref='attr' :baseURL="baseURL"
  54. v-if="isdan === 1"></arrts>
  55. <view class="box-1" v-if="isdan === 0">
  56. <view class="box-left">
  57. 商品规格图片
  58. <text class="imp">*</text>
  59. </view>
  60. <view class="box-image" @click="navCroper(400,400,'guige')">
  61. <image v-if="guige" :src="guige" mode=""></image>
  62. <image v-else src="../../static/img/addP.png" mode=""></image>
  63. </view>
  64. </view>
  65. <view class="box-1" v-if="isdan === 0">
  66. <view class="box-left">
  67. 商品售价
  68. <text class="imp">*</text>
  69. </view>
  70. <input type="text" placeholder="请填写商品售价" value="" class="list-input" v-model="price" />
  71. </view>
  72. <view class="box-1" v-if="isdan === 0">
  73. <view class="box-left">
  74. 商品成本价
  75. <text class="imp">*</text>
  76. </view>
  77. <input type="text" placeholder="请填写商品成本价" value="" class="list-input" v-model="o_price" />
  78. </view>
  79. <view class="box-1" v-if="isdan === 0">
  80. <view class="box-left">
  81. 商品原价
  82. <text class="imp">*</text>
  83. </view>
  84. <input type="text" placeholder="请填写商品原价" value="" class="list-input" v-model="y_price" />
  85. </view>
  86. <view class="box-1" v-if="isdan === 0">
  87. <view class="box-left">
  88. 佣金计算值
  89. <text class="imp">*</text>
  90. </view>
  91. <input type="text" placeholder="请填写佣金计算值" value="" class="list-input"
  92. v-model="breakprice" />
  93. </view>
  94. <view class="box-1" v-if="isdan === 0">
  95. <view class="box-left">
  96. 库存
  97. <text class="imp">*</text>
  98. </view>
  99. <input type="text" placeholder="请填写库存" value="" class="list-input" v-model="stock" />
  100. </view>
  101. <view class="box-1" v-if="isdan === 0">
  102. <view class="box-left">
  103. 编码
  104. <text class="imp">*</text>
  105. </view>
  106. <input type="text" placeholder="请填写编码" value="" class="list-input" v-model="bian" />
  107. </view>
  108. </view>
  109. <view class="btn" @click="next()">
  110. 下一页
  111. </view>
  112. </scroll-view>
  113. </swiper-item>
  114. <swiper-item v-if="showNext">
  115. <scroll-view scroll-y="true" style="height: 100%; padding-bottom: 20rpx;">
  116. <view class="bjq">
  117. <jinEdit v-if="isshow ==1" ref="set" placeholder="请输入文章内容" @editOk="editOk"
  118. uploadFileUrl="/api/upload/image" :header="{'Authori-zation': AuthoriZation}"
  119. :showImgSize="true" :html="content" height="50vh"></jinEdit>
  120. </view>
  121. <view class="btn1" @click="before()">
  122. 上一页
  123. </view>
  124. <view class="btn" @click="save()">
  125. 提交审核
  126. </view>
  127. </scroll-view>
  128. </swiper-item>
  129. </swiper>
  130. </view>
  131. </template>
  132. <script>
  133. import jinEdit from '@/components/jin-edit/jin-edit.vue';
  134. import arrts from './child/arrts.vue'
  135. import classify from './child/classify.vue';
  136. import {
  137. mapState
  138. } from "vuex";
  139. import {
  140. temp_list,
  141. get_product_info,
  142. save,
  143. set_apply
  144. } from '@/api/upload.js'
  145. export default {
  146. components: {
  147. classify,
  148. jinEdit,
  149. arrts
  150. },
  151. onReady() {
  152. // 初始化获取页面宽度
  153. var obj = this;
  154. uni.getSystemInfo({
  155. success: resu => {
  156. const query = uni.createSelectorQuery();
  157. query.select('.swiper-box').boundingClientRect();
  158. query.exec(function(res) {
  159. obj.maxheight = resu.windowHeight - res[0].top + 'px';
  160. console.log(obj.maxheight, 132456);
  161. });
  162. },
  163. fail: res => {}
  164. });
  165. },
  166. data() {
  167. return {
  168. showNext: false, //默认不显示第二页
  169. maxheight: '',
  170. origin_id: 0,
  171. isshow: 0,
  172. product: {},
  173. item: [],
  174. id: 0,
  175. values: [],
  176. current: 0, //当前页数
  177. yfarray: [], //运费列表
  178. yf: {
  179. name: '请选择运费模板'
  180. }, //运费
  181. imageList: [], //轮播图列表
  182. name: '', //商品名称
  183. bianma: '', //商品编码
  184. list: ['单规格', '多规格'],
  185. isdan: '',
  186. isdanname: '',
  187. chooseClass: [],
  188. classify: [], //商品分类
  189. guige: '', //单规格图片
  190. price: '', //单规格售价
  191. o_price: '', //单规格成本价
  192. y_price: '', //单规格原价
  193. breakprice: '', //单规格佣金计算值
  194. stock: '', //单规格库存
  195. bian: '', //单规格编码
  196. content: '', //商品详情
  197. AuthoriZation: '', //请求头
  198. };
  199. },
  200. computed: {
  201. ...mapState(['baseURL']),
  202. },
  203. onLoad(opt) {
  204. if (opt.id) {
  205. this.id = opt.id
  206. }
  207. this.AuthoriZation = 'Bearer ' + uni.getStorageSync('token')
  208. // this.gettemp_list();
  209. this.getclass()
  210. },
  211. onShow() {},
  212. onReachBottom() {},
  213. methods: {
  214. editOk(res) {
  215. // 保存富文本转出的html
  216. this.content = res.html
  217. console.log(this.content);
  218. },
  219. getarrts(res, val) {
  220. this.values = res
  221. this.item = val
  222. },
  223. gettemp_list() {
  224. temp_list().then(({
  225. data
  226. }) => {
  227. console.log(data);
  228. this.yfarray = data.data
  229. })
  230. },
  231. getclass() {
  232. const obj = this
  233. get_product_info({}, obj.id).then(({
  234. data
  235. }) => {
  236. obj.yfarray = data.tempList
  237. obj.classify = data.cateList
  238. console.log(obj.classify, '123456');
  239. obj.product = data.productInfo
  240. let info = data.productInfo
  241. if (obj.id != 0) {
  242. obj.name = info.store_name;
  243. obj.bianma = info.set_code;
  244. obj.isdan = info.spec_type;
  245. obj.isdanname = info.spec_type == 0 ? '单规格' : '多规格'
  246. info.cate_id.forEach(e => {
  247. for (let i = 0; i < data.cateList.length; i++) {
  248. if (data.cateList[i].value == e) {
  249. this.chooseClass.push(data.cateList[i])
  250. }
  251. }
  252. })
  253. data.tempList.forEach(e => {
  254. if (e.id == info.temp_id) {
  255. this.yf = e
  256. }
  257. })
  258. if (info.spec_type == 0) {
  259. obj.guige = info.attr.pic;
  260. obj.price = info.attr.price;
  261. obj.o_price = info.attr.cost;
  262. obj.y_price = info.attr.ot_price;
  263. obj.breakprice = info.attr.brokerage_origin;
  264. obj.stock = info.attr.stock;
  265. obj.bian = info.attr.bar_code;
  266. }
  267. if (info.spec_type == 1) {
  268. obj.values = info.attrs;
  269. obj.item = [...info.items];
  270. console.log(obj.values, '12345');
  271. }
  272. obj.content = info.description;
  273. obj.imageList = info.slider_image;
  274. obj.origin_id = info.origin_id;
  275. }
  276. obj.isshow = 1;
  277. })
  278. },
  279. upLoad(path) {
  280. // #ifdef H5
  281. console.log(path, 'h5');
  282. // #endif
  283. uni.showLoading({
  284. title: '图片上传中',
  285. mask: true
  286. });
  287. return new Promise((resolve, error) => {
  288. uni.uploadFile({
  289. url: this.baseURL + '/api/upload/image', //仅为示例,非真实的接口地址
  290. filePath: path,
  291. name: 'file',
  292. header: {
  293. "Authori-zation": 'Bearer ' + uni.getStorageSync('token')
  294. },
  295. success: (uploadFileRes) => {
  296. console.log(uploadFileRes, '1245');
  297. if ("string" === typeof uploadFileRes.data) {
  298. resolve(JSON.parse(uploadFileRes.data).data)
  299. } else {
  300. resolve(uploadFileRes.data.data)
  301. }
  302. },
  303. complete() {
  304. uni.hideLoading()
  305. }
  306. });
  307. })
  308. },
  309. bindYf: function(e) {
  310. this.yf = this.yfarray[e.target.value];
  311. },
  312. save() {
  313. const obj = this
  314. this.$refs.set.release(true)
  315. let attr = {}
  316. let attrs = []
  317. if (this.isdan == 0) {
  318. attr = {
  319. bar_code: obj.bian,
  320. brokerage: 0,
  321. brokerage_origin: obj.breakprice,
  322. brokerage_two: 0,
  323. cost: obj.o_price,
  324. integral: 0,
  325. ot_price: obj.y_price,
  326. pic: obj.guige,
  327. price: obj.price,
  328. stock: obj.stock,
  329. volume: 0,
  330. weight: 0
  331. }
  332. attrs.push(attr)
  333. }
  334. if (this.isdan == 1) {
  335. attr = obj.values[0]
  336. attrs = obj.values
  337. }
  338. let cate_id = []
  339. obj.chooseClass.forEach(e => {
  340. console.log(e, 'eee');
  341. cate_id.push(e.value + '')
  342. })
  343. console.log(cate_id, '654321');
  344. setTimeout(() => {
  345. save({
  346. activity: ['秒杀', '砍价', '拼团', ],
  347. attr: attr,
  348. attrs: attrs,
  349. cate_id: cate_id,
  350. commission: 0,
  351. description: obj.content,
  352. ficti: 0,
  353. give_integral: 0,
  354. image: obj.imageList[0],
  355. is_benefit: 0,
  356. is_best: 0,
  357. is_good: 0,
  358. is_hot: 0,
  359. is_new: 0,
  360. is_show: 1,
  361. is_sub: 0,
  362. items: obj.item,
  363. keyword: '',
  364. postage: '',
  365. price: '',
  366. set_code: obj.bianma,
  367. slider_image: obj.imageList,
  368. sort: 0,
  369. spec_type: obj.isdan,
  370. store_info: '',
  371. store_name: obj.name,
  372. store_type: 1,
  373. temp_id: obj.yf.id,
  374. unit_name: '',
  375. video_link: '',
  376. origin_id: obj.origin_id ? obj.origin_id : obj.id
  377. }, 0).then(({
  378. data
  379. }) => {
  380. console.log(data, 'success');
  381. set_apply({}, data.id).then(e => {
  382. obj.$api.msg('提交审核成功')
  383. uni.navigateTo({
  384. url: '/pages/upload/commodity'
  385. })
  386. })
  387. }).catch(err => {
  388. console.log(err, '123456');
  389. })
  390. }, 20)
  391. },
  392. navCroper(w, h, type) {
  393. let that = this;
  394. this.onImg().then((url) => {
  395. uni.navigateTo({
  396. url: `/pages/set/cropper?width=${w}&height=${h}`,
  397. events: {
  398. uploadSuccess(res) {
  399. uni.showLoading({
  400. title: '图片上传中',
  401. mask: true
  402. });
  403. that.upLoad(res).then((urldata) => {
  404. if (type == 'banner') {
  405. that.imageList.push(urldata.url)
  406. }
  407. if (type == 'guige') {
  408. that.guige = urldata.url
  409. }
  410. uni.hideLoading()
  411. }).catch(err => {
  412. uni.hideLoading()
  413. })
  414. }
  415. },
  416. success: function(res) {
  417. // 通过eventChannel向被打开页面传送数据
  418. res.eventChannel.emit('urlNext', {
  419. url
  420. })
  421. }
  422. })
  423. })
  424. },
  425. onImg(type) {
  426. const _this = this
  427. return new Promise((ok, erro) => {
  428. // 判断是否需要选择
  429. uni.showActionSheet({
  430. itemList: ['拍照', '选择一张照片'],
  431. success: function(res) {
  432. _this.chooseImage(res.tapIndex).then((url) => {
  433. ok(url)
  434. }).catch((res) => {
  435. erro(res)
  436. })
  437. },
  438. fail: function(res) {
  439. erro(res)
  440. console.log(res.errMsg);
  441. }
  442. });
  443. })
  444. },
  445. chooseImage: function(index) {
  446. const _this = this
  447. return new Promise((ok, error) => {
  448. // 从相册/相机选择
  449. // 如需直接开相机或直接选相册,请只使用一个选项
  450. const sourceType = index === 0 ? ['camera'] : ['album']
  451. uni.chooseImage({
  452. count: 1, //默认9
  453. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  454. sourceType: sourceType,
  455. success: function(res) {
  456. ok(res.tempFilePaths[0])
  457. },
  458. fail(e) {
  459. uni.showModal({
  460. title: '文件打开错误',
  461. content: '请设置授权文件存储权限',
  462. showCancel: false,
  463. });
  464. error(e)
  465. }
  466. });
  467. })
  468. },
  469. radioGroupChange(e) {
  470. if (e == '单规格') {
  471. this.isdan = 0
  472. } else {
  473. this.isdan = 1
  474. }
  475. console.log(this.isdan);
  476. },
  477. chooseClasswc(e) {
  478. this.chooseClass = e;
  479. },
  480. //删除图片
  481. delImg(i) {
  482. uni.showModal({
  483. content: '确定删除这张吗',
  484. success: res => {
  485. if (res.confirm) {
  486. this.imageList.splice(i, 1);
  487. } else if (res.cancel) {}
  488. }
  489. });
  490. },
  491. next() {
  492. this.current += 1
  493. if (this.isdan == 1) {
  494. this.$refs.attr.succ()
  495. }
  496. this.showNext = true;
  497. },
  498. before() {
  499. this.current -= 1
  500. }
  501. }
  502. };
  503. </script>
  504. <style lang="scss">
  505. page,
  506. .content {
  507. min-height: 100%;
  508. height: auto;
  509. background: #f8f8f8;
  510. }
  511. .tip {
  512. font-size: 24rpx;
  513. color: #fd3939;
  514. padding: 10rpx 20rpx;
  515. }
  516. .banner-box {
  517. background: #ffffff;
  518. padding: 20rpx;
  519. display: flex;
  520. align-items: center;
  521. flex-wrap: wrap;
  522. image {
  523. width: 100%;
  524. height: 100%;
  525. }
  526. .banner {
  527. position: relative;
  528. width: 160rpx;
  529. height: 160rpx;
  530. margin-right: 10rpx;
  531. .banner-main {
  532. position: absolute;
  533. top: 0;
  534. left: 0;
  535. right: 0;
  536. width: 160rpx;
  537. height: 160rpx;
  538. border-radius: 20rpx;
  539. image {
  540. border-radius: 20rpx;
  541. }
  542. }
  543. .cha {
  544. position: absolute;
  545. top: 0;
  546. right: 0;
  547. width: 40rpx;
  548. height: 40rpx;
  549. }
  550. }
  551. }
  552. .main {
  553. background: #ffffff;
  554. margin-top: 20rpx;
  555. padding: 0 20rpx 20rpx;
  556. }
  557. .box-1 {
  558. display: flex;
  559. justify-content: space-between;
  560. align-items: center;
  561. width: 100%;
  562. padding-top: 20rpx;
  563. .box-left {
  564. padding-left: 2rpx;
  565. width: 50%;
  566. text-align: left;
  567. color: #000000;
  568. .imp {
  569. color: #e63931;
  570. }
  571. }
  572. input {
  573. height: 66rpx;
  574. line-height: 66rpx;
  575. // height: 88rpx;
  576. }
  577. .list-input {
  578. color: #9598a3;
  579. height: 66rpx;
  580. padding-left: 24rpx;
  581. font-size: 28rpx;
  582. display: flex;
  583. justify-content: flex-end;
  584. align-items: center;
  585. width: 50%;
  586. flex: 1;
  587. text-align: right;
  588. padding-right: 24rpx;
  589. .input-placeholder {
  590. height: 70rpx;
  591. color: #959595;
  592. }
  593. }
  594. .box-image {
  595. height: 66rpx;
  596. width: 66rpx;
  597. image {
  598. width: 100%;
  599. height: 100%;
  600. }
  601. }
  602. }
  603. .btn {
  604. display: flex;
  605. justify-content: center;
  606. align-items: center;
  607. width: 560rpx;
  608. height: 76rpx;
  609. background: #000000;
  610. border-radius: 38rpx;
  611. font-size: 34rpx;
  612. font-weight: 500;
  613. color: #ffffff;
  614. margin: 40rpx auto 20rpx;
  615. }
  616. .btn1 {
  617. display: flex;
  618. justify-content: center;
  619. align-items: center;
  620. width: 560rpx;
  621. height: 76rpx;
  622. background: #ffffff;
  623. border: 1px solid #000000;
  624. border-radius: 38rpx;
  625. font-size: 34rpx;
  626. font-weight: 500;
  627. color: #000000;
  628. margin: 40rpx auto 20rpx;
  629. }
  630. .bjq {
  631. background: #ffffff;
  632. padding: 20rpx;
  633. }
  634. </style>