GoodsForm3.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <seller-base :show="false">
  3. <view class="div container">
  4. <view class="div common-header-wrap">
  5. <view :style="'height:'+navHeight+'px'"></view>
  6. <view class="common-header-holder"></view>
  7. <view class="common-header-fixed">
  8. <title-header />
  9. <uni-nav-bar title="商品发布" class="common-header" left-icon="back" @clickLeft="goBack()">
  10. </uni-nav-bar>
  11. </view>
  12. </view>
  13. <step :options="options" :active="2"></step>
  14. <view class="div" v-if="value_array.length">
  15. <view class="div image-wrapper" v-for="(item,index) in value_array" :key="index">
  16. <view class="div label">{{(spec_value && spec_value[1] && spec_value[1][item.spvalue_id])?spec_value[1][item.spvalue_id]:item.spvalue_name}}</view>
  17. <view class="div user-avatar-wrapper">
  18. <view class="div user-avatar">
  19. <uni-file-picker v-model="imageValue[item.spvalue_id]" fileMediatype="image" mode="grid" :limit="5" :auto-upload="false"
  20. @select="uploadInformPic(item.spvalue_id,$event)" @delete="dropImage(item.spvalue_id,$event)"></uni-file-picker>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="div pt-10 pb-10"><view class="div common-btn ds-button-large" @click="nextStep">保存</view></view>
  25. </view>
  26. <uni-popup background-color="#fff" ref="isshow" class="popup" >
  27. <image mode="aspectFit" class="img" :src="showimage" :style="getBannerStyle" @click="hidePopup('isshow')">
  28. </uni-popup>
  29. <tui-picture-cropper v-if="cropperOption.imgUrl" :width="cropperOption.autoCropWidth" :height="cropperOption.autoCropHeight" :imageUrl="cropperOption.img" @ready="cropReady" @cropper="useCrop" @back="cropBack"></tui-picture-cropper>
  30. </view>
  31. </seller-base>
  32. </template>
  33. <script>
  34. import {getFontSize} from '@/util/common'
  35. import TitleHeader from '../../TitleHeader'
  36. import SellerBase from '../SellerBase'
  37. import tuiPictureCropper from "@/components/thorui/tui-picture-cropper/tui-picture-cropper"
  38. import { mapState, mapActions } from 'vuex'
  39. import Step from '../../Step'
  40. import { imageEdit, imageSave, uploadInfoFile } from '../../../api/sellerGoods'
  41. export default {
  42. data(){
  43. return {
  44. navHeight: 0,
  45. imageValue:{},
  46. screenWidth:0,
  47. cropType: '',
  48. cropperOption: {
  49. img: '',
  50. canMove: false,
  51. autoCrop: true,
  52. autoCropWidth: 100,
  53. autoCropHeight: 100,
  54. maxImgSize: 500,
  55. outputType: 'png'
  56. },
  57. crop: {},
  58. controller: 'Sellergoodsonline',
  59. options: [{ title: '选择商品分类' }, { title: '填写商品详情' }, { title: '上传商品图片' }],
  60. commonid: 0,
  61. showimage: '',
  62. value_array: false,
  63. spec_value: false,
  64. }
  65. },
  66. computed:{
  67. fontSize(){
  68. return getFontSize()
  69. },
  70. getBannerStyle: function () {
  71. const res = uni.getSystemInfoSync()
  72. var width = res.windowWidth
  73. var height = res.windowHeight
  74. let itemWidth = width
  75. let itemHeight = height
  76. return "max-width:"+itemWidth +"px;max-height:"+itemHeight +"px"
  77. }
  78. },
  79. onLoad: function (option) {
  80. this.commonid = option.commonid
  81. var action = option.action
  82. if (action == 'add') {
  83. this.controller = 'Sellergoodsadd'
  84. }
  85. imageEdit(this.controller, this.commonid).then(res => {
  86. this.value_array = res.result.value_array
  87. this.spec_value = res.result.spec_value
  88. let img = res.result.img
  89. for (var i in this.value_array) {
  90. this.imageValue[this.value_array[i].spvalue_id] = []
  91. if(img[this.value_array[i].spvalue_id]){
  92. for(var j in img[this.value_array[i].spvalue_id]){
  93. if(img[this.value_array[i].spvalue_id][j].goodsimage_url){
  94. this.imageValue[this.value_array[i].spvalue_id].push(Object.assign({
  95. name:i+'_'+j,
  96. extname:'jpg',
  97. url:img[this.value_array[i].spvalue_id][j].goodsimage_full_url
  98. },img[this.value_array[i].spvalue_id][j]))
  99. }
  100. }
  101. }
  102. }
  103. }).catch(error => {
  104. uni.showToast({icon:'none',title: error.message})
  105. })
  106. },
  107. components:{
  108. TitleHeader,
  109. SellerBase,
  110. tuiPictureCropper,
  111. Step
  112. },
  113. mounted(){
  114. // #ifdef MP-WEIXIN
  115. this.navHeight = uni.getMenuButtonBoundingClientRect().height
  116. // #endif
  117. this.screenWidth=uni.getSystemInfoSync().screenWidth
  118. },
  119. methods:{
  120. showPopup(id){
  121. this.$refs[id].open()
  122. },
  123. hidePopup(id){
  124. this.$refs[id].close()
  125. },
  126. goBack(){uni.navigateBack({delta:1})},
  127. openImage (src) {
  128. this.showimage = src
  129. this.showPopup('isshow')
  130. },
  131. dropImage (index, event) {
  132. for(var i in this.imageValue[index]){
  133. if(this.imageValue[index][i].name==event.tempFile.name){
  134. this.imageValue[index].splice(i,1)
  135. break
  136. }
  137. }
  138. this.$forceUpdate()
  139. },
  140. useCrop (res) {
  141. let index = this.cropType
  142. var formdata={
  143. filePath:res.url,
  144. name:'file',
  145. }
  146. uni.showLoading({ title: '加载中' })
  147. uploadInfoFile(this.controller, formdata).then(res => {
  148. this.imageValue[index].push({
  149. name:index,
  150. extname:'jpg',
  151. url:res.result.url,
  152. goodsimage_full_url:res.result.url,
  153. goodsimage_isdefault: 0,
  154. goodsimage_url:res.result.path
  155. })
  156. this.cropperOption.imgUrl=''
  157. this.$forceUpdate()
  158. uni.hideLoading()
  159. }).catch(error => {
  160. uni.showToast({icon:'none',title: error.message})
  161. uni.hideLoading()
  162. this.cropperOption.imgUrl=''
  163. this.$forceUpdate()
  164. })
  165. },
  166. cropReady(){
  167. this.cropperOption.img = this.cropperOption.imgUrl
  168. },
  169. cropBack(){
  170. this.cropperOption.imgUrl=''
  171. this.$forceUpdate()
  172. },
  173. uploadInformPic (index, event) {
  174. let that = this
  175. this.cropType = index
  176. let file = event.tempFiles[0]
  177. that.cropperOption.imgUrl = file.path
  178. that.cropperOption.autoCropWidth = uni.getSystemInfoSync().windowWidth
  179. that.cropperOption.autoCropHeight = uni.getSystemInfoSync().windowWidth
  180. that.cropperOption.maxImgSize = uni.getSystemInfoSync().windowHeight - 40
  181. that.$forceUpdate()
  182. },
  183. nextStep () {
  184. imageSave(this.controller, this.commonid, this.imageValue).then(res => {
  185. uni.showToast({icon:'none',title: res.message})
  186. uni.redirectTo({url:'/pages/seller/goods/Goodsonline'})
  187. }).catch(error => {
  188. uni.showToast({icon:'none',title: error.message})
  189. })
  190. }
  191. }
  192. }
  193. </script>
  194. <style scoped lang="scss">
  195. .common-header{
  196. .btn{background: #000;color: #fff;box-shadow: 0px 2px 4px #d2d2d2;}
  197. }
  198. .user-avatar-wrapper{padding:0 $pageSpace}
  199. .ds-button-large{margin:0 $pageSpace}
  200. .container{background: #fff}
  201. .image-wrapper{width: 100%;position: relative;}
  202. .label{
  203. padding:.5rem $pageSpace;
  204. font-size:$subFontSize;
  205. background: #eee;
  206. margin-bottom: .5rem;
  207. }
  208. </style>