GoodsForm.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <seller-base :show="false" class="scroll-view-wrapper">
  3. <view class="scroll-view-wrapper scroll-view 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="getTitle" class="common-header" left-icon="back" @clickLeft="goBack()">
  10. <view class="div common-btn btn" slot="right" @click="onDelete" v-if="!isAddMode">删除</view>
  11. </uni-nav-bar>
  12. </view>
  13. </view>
  14. <view class="div main-content">
  15. <view class="div" v-if="isAddMode">
  16. <view class="div" @click="showPopup('popupSelect')">
  17. <flex-line :is-link="true" :show-border="true"><text class="span line-name">{{getSelecedTitle}}</text></flex-line>
  18. </view>
  19. <uni-popup background-color="#fff" ref="popupSelect" type="right">
  20. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  21. <view class="div common-header-wrap">
  22. <view :style="'height:'+navHeight+'px'"></view>
  23. <view class="common-header-holder"></view>
  24. <view class="common-header-fixed">
  25. <title-header />
  26. <uni-nav-bar title="选择商品" class="common-header" left-icon="back" @clickLeft="hidePopup('popupSelect')">
  27. </uni-nav-bar>
  28. </view>
  29. </view>
  30. <view class="scroll-view-wrapper scroll-view div common-popup-content">
  31. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view div" @scrolltolower="loadMore" scroll-y="true">
  32. <view class="div select-goods" v-if="selectGoodsList">
  33. <view class="ul" v-if="selectGoodsList.length">
  34. <view class="li" v-for="item in selectGoodsList" v-bind:key="item.goods_commonid" @click="selectedGoods(item)">
  35. <view class="div p-img">
  36. <image mode="aspectFit" class="img" :src="item.goods_image"/>
  37. </view>
  38. <view class="div p-info">
  39. <view class="p name">{{item.goods_name}}</view>
  40. <view class="p price">{{item.goods_price}}</view>
  41. </view>
  42. </view>
  43. </view>
  44. <empty-record v-else></empty-record>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. </view>
  49. </uni-popup>
  50. </view>
  51. <view class="div" v-else>
  52. <flex-line :show-border="true"><text class="span line-name">{{getSelecedTitle}}</text></flex-line>
  53. </view>
  54. <flex-line class="field-line" :show-border="true"><text class="span field-name">佣金比例</text><view class="div field-line-right" slot="right"><input class="field-input" v-model="goods.inviter_ratio" /></view></flex-line>
  55. <view class="div pt-10 pb-10"><view class="div common-btn ds-button-large" @click="submit">提交</view></view>
  56. </view>
  57. </view>
  58. <uni-popup background-color="#fff" ref="confirm" type="dialog">
  59. <uni-popup-dialog :mode="dialog.mode" :title="dialog.title" :content="dialog.content" :placeholder="dialog.content" @confirm="confirmDialog" @close="closeDialog"></uni-popup-dialog>
  60. </uni-popup>
  61. </seller-base>
  62. </template>
  63. <script>
  64. import {getFontSize} from '@/util/common'
  65. import TitleHeader from '../../TitleHeader'
  66. import SellerBase from '../SellerBase'
  67. import { searchGoodsList, addInviterGoods, editInviterGoods, getInviterGoodsInfo, delInviterGoods } from '../../../api/sellerInviter'
  68. import EmptyRecord from '../../EmptyRecord'
  69. import flexLine from '../../flexLine'
  70. export default {
  71. name: 'GoodsForm',
  72. data(){
  73. return {
  74. navHeight: 0,
  75. dialog:{},
  76. screenWidth:0,
  77. action:'',
  78. params: { 'page': 0, 'per_page': 10 },
  79. loading: false, // 是否加载更多
  80. isMore: true, // 是否有更多
  81. // 商品列表用于选择商品设置分拥比例
  82. selectGoodsList: false,
  83. // 关键词
  84. selectGoodsName: '',
  85. goods: {
  86. 'goods_commonid': 0,
  87. 'goods_name': '',
  88. 'inviter_ratio': '',
  89. }
  90. }
  91. },
  92. onLoad: function (option) {
  93. this.action = option.action
  94. if (!this.isAddMode) {
  95. this.goods.goods_commonid = option.goods_commonid
  96. getInviterGoodsInfo(this.goods.goods_commonid).then(res => {
  97. this.goods = res.result.info
  98. }).catch(function (error) {
  99. uni.showToast({icon:'none',title: error.message})
  100. })
  101. }
  102. this.loadMore()
  103. },
  104. components:{
  105. TitleHeader,
  106. SellerBase,
  107. flexLine,
  108. EmptyRecord
  109. },
  110. computed:{
  111. fontSize(){
  112. return getFontSize()
  113. },
  114. isAddMode () {
  115. let mode = this.action
  116. if (mode === 'add') {
  117. return true
  118. } else {
  119. return false
  120. }
  121. },
  122. getTitle () {
  123. if (this.isAddMode) {
  124. return '新增分销商品'
  125. } else {
  126. return '修改分销商品'
  127. }
  128. },
  129. getSelecedTitle () {
  130. if (this.goods.goods_commonid) {
  131. return this.goods.goods_name
  132. } else {
  133. return '选择商品'
  134. }
  135. }
  136. },
  137. mounted(){
  138. // #ifdef MP-WEIXIN
  139. this.navHeight = uni.getMenuButtonBoundingClientRect().height
  140. // #endif
  141. this.screenWidth=uni.getSystemInfoSync().screenWidth
  142. },
  143. methods:{
  144. closeDialog(){
  145. },
  146. confirmDialog(value){
  147. delInviterGoods(this.goods.goods_commonid).then(
  148. (response) => {
  149. uni.navigateTo({url:'/pages/seller/inviter/GoodsList'})
  150. }, (error) => {
  151. uni.showToast({icon:'none',title: error.message})
  152. })
  153. },
  154. showPopup(id){
  155. this.$refs[id].open()
  156. },
  157. hidePopup(id){
  158. this.$refs[id].close()
  159. },
  160. goBack(){uni.navigateBack({delta:1})},
  161. onDelete () {
  162. this.dialog={content:'确定要取消该商品佣金设置吗?'}
  163. this.$refs.confirm.open()
  164. },
  165. loadMore () {
  166. this.loading = true
  167. this.params.page = ++this.params.page
  168. if (this.isMore) {
  169. this.loading = false
  170. this.getSelectGoodsList(true)
  171. }
  172. },
  173. reload () {
  174. // 重新加载数据
  175. this.params.page = 0
  176. this.isMore = true
  177. this.selectGoodsList = []
  178. this.loadMore()
  179. },
  180. submit () {
  181. if (this.isAddMode) {
  182. uni.showLoading({ title: '加载中' })
  183. addInviterGoods(this.goods).then(
  184. (response) => {
  185. uni.hideLoading()
  186. uni.showToast({icon:'none',title: response.message})
  187. uni.navigateTo({url:'/pages/seller/inviter/GoodsList'})
  188. }, (error) => {
  189. uni.hideLoading()
  190. uni.showToast({icon:'none',title: error.message})
  191. })
  192. } else {
  193. uni.showLoading({ title: '加载中' })
  194. editInviterGoods(this.goods).then(
  195. (response) => {
  196. uni.hideLoading()
  197. uni.showToast({icon:'none',title: response.message})
  198. uni.navigateTo({url:'/pages/seller/inviter/GoodsList'})
  199. }, (error) => {
  200. uni.hideLoading()
  201. uni.showToast({icon:'none',title: error.message})
  202. })
  203. }
  204. },
  205. // 获取商品列表 用于设置产品分佣
  206. getSelectGoodsList () {
  207. searchGoodsList(this.selectGoodsName,this.params).then(res => {
  208. if (this.selectGoodsList) {
  209. this.selectGoodsList = this.selectGoodsList.concat(res.result.goods_list)
  210. } else {
  211. this.selectGoodsList = res.result.goods_list
  212. }
  213. if (res.result.hasmore) {
  214. this.isMore = true
  215. } else {
  216. this.isMore = false
  217. }
  218. }).catch(function (error) {
  219. uni.showToast({icon:'none',title: error.message})
  220. })
  221. },
  222. // 选择商品
  223. selectedGoods (item) {
  224. this.goods.goods_name = item.goods_name
  225. this.goods.goods_commonid = item.goods_commonid
  226. // Close
  227. this.hidePopup('popupSelect')
  228. }
  229. }
  230. }
  231. </script>
  232. <style scoped lang="scss">
  233. .scroll-view-wrapper{display: flex;flex-direction: column;}
  234. .scroll-view{flex:1}
  235. .common-header{
  236. .btn{background: #000;color: #fff;box-shadow: 0px 2px 4px #d2d2d2;}
  237. }
  238. .main-content{background: #fff;padding:0 $pageSpace}
  239. .select-goods .li{height:3rem;padding:.6rem;display:flex;}
  240. .select-goods .li .p-img{}
  241. .select-goods .li .p-img .img{width:3rem;height: 3rem;}
  242. .select-goods .li .p-info{margin-left:1rem;}
  243. .select-goods .li .p-info .p{line-height:1rem;}
  244. .select-goods .li .p-info .price{font-size:$fontSize;color:$primaryColor;height:2rem;overflow: hidden}
  245. .select-goods .li .p-info .name{font-size:$subFontSize;}
  246. </style>