VoucherForm.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <seller-base :show="false">
  3. <view class="div container seller-voucher-form">
  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="(mode=='edit'?'编辑':'新增')+'代金券'" class="common-header" left-icon="back" @clickLeft="goBack()">
  10. </uni-nav-bar>
  11. </view>
  12. </view>
  13. <view class="div main-content">
  14. <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="vouchertemplate.vouchertemplate_title" /></view></flex-line>
  15. <view class="div" v-if="!seller.is_platform_store" @click="showPopup('storeClassVisible')">
  16. <flex-line :is-link="true" :show-border="true"><text class="span line-name">店铺分类</text><text class="span" slot="right">{{store_class_name}}</text></flex-line>
  17. </view>
  18. <view class="div">
  19. <flex-line class="menu-item" :is-link="true" :show-border="true">
  20. <text class="span line-name">有效期</text>
  21. <view class="span" slot="right">
  22. <uni-datetime-picker class="common-datetime-picker" type="date" v-model="endtime"
  23. start="1970-1-1" :end="quotainfo.voucherquota_endtime"></uni-datetime-picker>
  24. </view>
  25. </flex-line>
  26. </view>
  27. <view class="div" @click="showPopup('priceVisible')">
  28. <flex-line :is-link="true" :show-border="true"><text class="span line-name">面额</text><text class="span" slot="right">{{price}}</text></flex-line>
  29. </view>
  30. <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" type="number" v-model="vouchertemplate.vouchertemplate_total" /></view></flex-line>
  31. <view class="div" @click="showPopup('limitVisible')">
  32. <flex-line :is-link="true" :show-border="true"><text class="span line-name">每人限领</text><text class="span" slot="right">{{limit_name}}</text></flex-line>
  33. </view>
  34. <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" type="number" v-model="vouchertemplate.vouchertemplate_limit" /></view></flex-line>
  35. <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="vouchertemplate.vouchertemplate_desc" /></view></flex-line>
  36. <flex-line :show-border="true">
  37. <text class="span">有效</text>
  38. <view class="div" slot="right">
  39. <radio-group @change="radioChange(1,$event)" class="radio-wrapper">
  40. <label v-for="(item, index) in state_options" :key="index">
  41. <radio :value="item.value" :checked="vouchertemplate.vouchertemplate_state==item.value" />
  42. <text>{{item.label}}</text>
  43. </label>
  44. </radio-group>
  45. </view>
  46. </flex-line>
  47. <flex-line :show-border="true">
  48. <text class="span">是否私密</text>
  49. <view class="div" slot="right">
  50. <radio-group @change="radioChange(5,$event)" class="radio-wrapper">
  51. <label v-for="(item, index) in state_options1" :key="index">
  52. <radio :value="item.value" :checked="vouchertemplate.vouchertemplate_if_private==item.value" />
  53. <text>{{item.label}}</text>
  54. </label>
  55. </radio-group>
  56. </view>
  57. </flex-line>
  58. <view class="div pt-10 pb-10"><view class="div common-btn ds-button-large" @click="submit">保存</view></view>
  59. </view>
  60. <!--店铺分类-->
  61. <uni-popup background-color="#fff" ref="storeClassVisible" type="right" >
  62. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  63. <view class="div common-header-wrap">
  64. <view :style="'height:'+navHeight+'px'"></view>
  65. <view class="common-header-holder"></view>
  66. <view class="common-header-fixed">
  67. <title-header />
  68. <uni-nav-bar title="店铺分类" class="common-header" left-icon="back" @clickLeft="hidePopup('storeClassVisible')">
  69. </uni-nav-bar>
  70. </view>
  71. </view>
  72. <view class="div common-popup-content">
  73. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" scroll-y="true">
  74. <radio-group @change="radioChange(2,$event)" class="radio-wrapper">
  75. <view v-for="(item, index) in store_class_options" :key="index" class="radio-item">
  76. <radio :value="item.value" :checked="store_class_id==item.value" />
  77. <text>{{item.label}}</text>
  78. </view>
  79. </radio-group>
  80. </scroll-view>
  81. </view>
  82. </view>
  83. </uni-popup>
  84. <!--面额-->
  85. <uni-popup background-color="#fff" ref="priceVisible" type="right" >
  86. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  87. <view class="div common-header-wrap">
  88. <view :style="'height:'+navHeight+'px'"></view>
  89. <view class="common-header-holder"></view>
  90. <view class="common-header-fixed">
  91. <title-header />
  92. <uni-nav-bar title="面额" class="common-header" left-icon="back" @clickLeft="hidePopup('priceVisible')">
  93. </uni-nav-bar>
  94. </view>
  95. </view>
  96. <view class="div common-popup-content">
  97. <radio-group @change="radioChange(3,$event)" class="radio-wrapper">
  98. <view v-for="(item, index) in price_options" :key="index" class="radio-item">
  99. <radio :value="item.value" :checked="price==item.value" />
  100. <text>{{item.label}}</text>
  101. </view>
  102. </radio-group>
  103. </view>
  104. </view>
  105. </uni-popup>
  106. <!--限领-->
  107. <uni-popup background-color="#fff" ref="limitVisible" type="right" >
  108. <view :style="'width:'+screenWidth+'px'" class="common-popup-wrapper">
  109. <view class="div common-header-wrap">
  110. <view :style="'height:'+navHeight+'px'"></view>
  111. <view class="common-header-holder"></view>
  112. <view class="common-header-fixed">
  113. <title-header />
  114. <uni-nav-bar title="每人限领" class="common-header" left-icon="back" @clickLeft="hidePopup('limitVisible')">
  115. </uni-nav-bar>
  116. </view>
  117. </view>
  118. <view class="div common-popup-content">
  119. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" scroll-y="true">
  120. <radio-group @change="radioChange(4,$event)" class="radio-wrapper">
  121. <view v-for="(item, index) in limit_options" :key="index" class="radio-item">
  122. <radio :value="item.value" :checked="limit==item.value" />
  123. <text>{{item.label}}</text>
  124. </view>
  125. </radio-group>
  126. </scroll-view>
  127. </view>
  128. </view>
  129. </uni-popup>
  130. </view>
  131. </seller-base>
  132. </template>
  133. <script>
  134. import {getFontSize} from '@/util/common'
  135. import TitleHeader from '../../TitleHeader'
  136. import SellerBase from '../SellerBase'
  137. import { getVoucherList, getCommonData, addVoucher, editVoucher, getVoucherInfo } from '../../../api/sellerVoucher'
  138. import { getStoreClass } from '../../../api/seller'
  139. import { mapState, mapMutations } from 'vuex'
  140. import flexLine from '../../flexLine'
  141. export default {
  142. name: 'SellerVoucherForm',
  143. components:{
  144. TitleHeader,
  145. SellerBase,
  146. flexLine,
  147. },
  148. data(){
  149. return {
  150. navHeight: 0,
  151. screenWidth:0,
  152. mode: '',
  153. tid: 0,
  154. store_class_options: [{
  155. label: '所有分类',
  156. value: '0'
  157. }],
  158. vouchertemplate: {},
  159. store_class_id: '0',
  160. store_class_list: { '0': '所有分类' },
  161. store_class_name: '所有分类',
  162. price_options: [],
  163. quotainfo:[],
  164. price: '',
  165. limit_options: [{
  166. label: '不限',
  167. value: '0'
  168. }],
  169. limit: '',
  170. limit_name: '不限',
  171. state_options: [{
  172. label: '是',
  173. value: '1'
  174. },
  175. {
  176. label: '否',
  177. value: '2'
  178. }],
  179. state_options1: [{
  180. label: '是',
  181. value: '1'
  182. },
  183. {
  184. label: '否',
  185. value: '0'
  186. }],
  187. endtime: ''
  188. }
  189. },
  190. onLoad: function (option) {
  191. this.mode = option.mode
  192. this.tid = option.tid
  193. getCommonData().then(res => {
  194. for (var i = 1; i <= res.result.voucher_buyertimes_limit; i++) {
  195. this.limit_options.push({
  196. label: i + '张',
  197. value: i + ''
  198. })
  199. }
  200. let price_options = res.result.pricelist
  201. this.quotainfo = res.result.quotainfo
  202. if (this.mode != 'edit') {
  203. this.price = price_options[0].voucherprice
  204. this.limit = '0'
  205. this.vouchertemplate.vouchertemplate_state = '1'
  206. this.vouchertemplate.vouchertemplate_if_private = '0'
  207. } else {
  208. getVoucherInfo(this.tid).then(res => {
  209. this.vouchertemplate = res.result.t_info
  210. this.vouchertemplate.vouchertemplate_enddate = this.$moment.unix(this.vouchertemplate.vouchertemplate_enddate).format('YYYY-MM-DD')
  211. this.endtime = this.vouchertemplate.vouchertemplate_enddate
  212. this.price = this.vouchertemplate.vouchertemplate_price + ''
  213. this.limit = this.vouchertemplate.vouchertemplate_eachlimit + ''
  214. this.store_class_id = this.vouchertemplate.vouchertemplate_sc_id + ''
  215. if (this.store_class_list) {
  216. this.store_class_name = this.store_class_list[this.store_class_id]
  217. }
  218. this.vouchertemplate.vouchertemplate_state = this.vouchertemplate.vouchertemplate_state + ''
  219. }).catch(function (error) {
  220. uni.showToast({icon:'none',title: error.message})
  221. })
  222. }
  223. for (var i in price_options) {
  224. this.price_options.push({
  225. label: price_options[i].voucherprice,
  226. value: price_options[i].voucherprice
  227. })
  228. }
  229. }).catch(function (error) {
  230. uni.showToast({icon:'none',title: error.message})
  231. uni.navigateBack({delta:1})
  232. })
  233. if (this.seller.is_platform_store) {
  234. this.vouchertemplate.vouchertemplate_sc_id = this.seller.storeclass_id
  235. }
  236. getStoreClass().then(res => {
  237. let store_class_options = res.result.store_class
  238. for (var i in store_class_options) {
  239. this.store_class_list[store_class_options[i].storeclass_id] = store_class_options[i].storeclass_name
  240. this.store_class_options.push({
  241. label: store_class_options[i].storeclass_name,
  242. value: store_class_options[i].storeclass_id + ''
  243. })
  244. }
  245. if (this.mode == 'edit') {
  246. if (this.vouchertemplate) {
  247. this.store_class_id = this.vouchertemplate.vouchertemplate_sc_id + ''
  248. this.store_class_name = this.store_class_list[this.store_class_id]
  249. }
  250. }
  251. }).catch(function (error) {
  252. uni.showToast({icon:'none',title: res.message})
  253. })
  254. },
  255. watch: {
  256. store_class_id: function (store_class_id) {
  257. this.vouchertemplate.vouchertemplate_sc_id = store_class_id
  258. this.store_class_name = this.store_class_list[store_class_id]
  259. this.hidePopup('storeClassVisible')
  260. },
  261. price: function (price) {
  262. this.vouchertemplate.vouchertemplate_price = price
  263. this.price = price + ''
  264. this.hidePopup('priceVisible')
  265. },
  266. limit: function (limit) {
  267. this.vouchertemplate.vouchertemplate_eachlimit = limit
  268. this.limit_name = (limit != '0') ? (limit + '张') : '不限'
  269. this.hidePopup('limitVisible')
  270. }
  271. },
  272. computed:{
  273. fontSize(){
  274. return getFontSize()
  275. },
  276. ...mapState({
  277. seller: state => state.seller.info
  278. })
  279. },
  280. mounted(){
  281. // #ifdef MP-WEIXIN
  282. this.navHeight = uni.getMenuButtonBoundingClientRect().height
  283. // #endif
  284. this.screenWidth=uni.getSystemInfoSync().screenWidth
  285. },
  286. methods:{
  287. radioChange(i,e){
  288. switch(i){
  289. case 1:
  290. this.vouchertemplate.vouchertemplate_state=e.detail.value
  291. break
  292. case 2:
  293. this.store_class_id=e.detail.value
  294. break
  295. case 3:
  296. this.price=e.detail.value
  297. break
  298. case 4:
  299. this.limit=e.detail.value
  300. break
  301. }
  302. },
  303. showPopup(id){
  304. this.$refs[id].open()
  305. },
  306. hidePopup(id){
  307. this.$refs[id].close()
  308. },
  309. goBack(){uni.navigateBack({delta:1})},
  310. submit () {
  311. this.vouchertemplate.vouchertemplate_enddate = this.endtime
  312. if (this.mode == 'edit') {
  313. editVoucher(this.tid, this.vouchertemplate.vouchertemplate_title, this.vouchertemplate.vouchertemplate_total, this.vouchertemplate.vouchertemplate_price, this.vouchertemplate.vouchertemplate_limit, this.vouchertemplate.vouchertemplate_desc, this.vouchertemplate.vouchertemplate_enddate, this.vouchertemplate.vouchertemplate_sc_id, this.vouchertemplate.vouchertemplate_eachlimit, this.vouchertemplate.vouchertemplate_state).then(res => {
  314. uni.showToast({icon:'none',title: res.message})
  315. uni.navigateTo({url:'/pages/seller/voucher/VoucherList'})
  316. }).catch(function (error) {
  317. uni.showToast({icon:'none',title: error.message})
  318. })
  319. } else {
  320. addVoucher(this.vouchertemplate.vouchertemplate_title, this.vouchertemplate.vouchertemplate_total, this.vouchertemplate.vouchertemplate_price, this.vouchertemplate.vouchertemplate_limit, this.vouchertemplate.vouchertemplate_desc, this.vouchertemplate.vouchertemplate_enddate, this.vouchertemplate.vouchertemplate_sc_id, this.vouchertemplate.vouchertemplate_eachlimit).then(res => {
  321. uni.showToast({icon:'none',title: res.message})
  322. uni.navigateTo({url:'/pages/seller/voucher/VoucherList'})
  323. }).catch(function (error) {
  324. uni.showToast({icon:'none',title: error.message})
  325. })
  326. }
  327. }
  328. }
  329. }
  330. </script>
  331. <style lang="scss">
  332. .seller-voucher-form{
  333. .mint-radiolist {
  334. display: flex;
  335. .mint-cell {
  336. flex: 1;
  337. .mint-radio-input:checked + .mint-radio-core {
  338. background-color: $primaryColor !important;
  339. border-color: $primaryColor !important;
  340. }
  341. &:after{display: none}
  342. }
  343. }
  344. }
  345. </style>
  346. <style scoped lang="scss">
  347. .main-content{background: #fff;padding:0 $pageSpace}
  348. .container {
  349. height: 100%;
  350. display: flex;
  351. position: relative;
  352. flex-direction: column;
  353. justify-content: flex-start;
  354. align-items: stretch;
  355. }
  356. .common-voucher{margin:0.5rem auto}
  357. .radio-wrapper{
  358. display: block;
  359. padding: 0 $pageSpace;
  360. .radio-item{
  361. padding:.5rem 0;
  362. border-bottom: 1px dashed #f5f5f5;
  363. }
  364. }
  365. </style>