PriceCalendar.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <el-dialog
  3. :visible.sync="visible"
  4. title="价格方案"
  5. width="780px"
  6. append-to-body
  7. @close="handleCancel"
  8. >
  9. <div
  10. class="wrap"
  11. v-loading="loading">
  12. <div>
  13. <div class="block-title">
  14. 基础价格
  15. </div>
  16. <el-input
  17. placeholder="请输入内容"
  18. v-model="basic_price"
  19. style="width: 160px">
  20. </el-input>
  21. </div>
  22. <div>
  23. <div class="block-title">
  24. 周价格
  25. </div>
  26. <div
  27. class="weekWrap"
  28. style="margin-bottom:30px"
  29. >
  30. <div
  31. class="weekItem"
  32. v-for="(item,index) in weekDayPriceList"
  33. :key="index"
  34. >
  35. <label>{{ item.label }}</label>
  36. <el-input
  37. oninput="value=value.replace(/[^\d.]/g,'')"
  38. class="priceInput"
  39. v-model="item.value"
  40. />
  41. </div>
  42. </div>
  43. </div>
  44. <div>
  45. <div class="block-title">
  46. 日期段价格(时间不可重叠)
  47. <el-button
  48. class="addBtn"
  49. type="primary"
  50. icon="el-icon-plus"
  51. @click="handleAdd"
  52. size="small"
  53. >
  54. 新增
  55. </el-button>
  56. </div>
  57. <div
  58. class="noData"
  59. v-if="priceList.length===0"
  60. >
  61. 暂无
  62. </div>
  63. <ul class="priceList">
  64. <li
  65. v-for="(item,index) in priceList"
  66. :key="index"
  67. >
  68. <el-date-picker
  69. class="calendarPicker"
  70. type="daterange"
  71. v-model="item.dateRange"
  72. @change="handleChange($event,item)"
  73. />
  74. <el-input-number
  75. class="priceInput"
  76. :controls="false"
  77. v-model="item.price"
  78. />
  79. <el-button
  80. type="danger"
  81. icon="el-icon-close"
  82. size="small"
  83. @click="handleDelete(index)"
  84. ></el-button>
  85. </li>
  86. </ul>
  87. </div>
  88. <div
  89. class="btn-wrap"
  90. slot="footer">
  91. <el-button
  92. size="small"
  93. @click="visible=false">
  94. 取 消
  95. </el-button>
  96. <el-button
  97. :loading="confirmLoading"
  98. size="small"
  99. type="primary"
  100. @click="handleOk">
  101. 保 存
  102. </el-button>
  103. </div>
  104. </div>
  105. </el-dialog>
  106. </template>
  107. <script>
  108. import moment from 'moment'
  109. import { getPricePlan, setPricePlan } from '@/api/otaTicketSale'
  110. const week = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  111. const stragegiesMap = {
  112. PERIOD: '日期段价格',
  113. WEEKDAY: '周价格',
  114. BASIC: '日常价格'
  115. }
  116. export default {
  117. data () {
  118. return {
  119. week,
  120. stragegiesMap,
  121. pricecode: '',
  122. loading: false,
  123. visible: false,
  124. confirmLoading: false,
  125. basic_price: '',
  126. priceList: [],
  127. weekDayPriceList: [],
  128. form: {
  129. period_price: {
  130. price: []
  131. },
  132. weekday_price: {
  133. price: {}
  134. },
  135. pricecode: 0
  136. }
  137. }
  138. },
  139. methods: {
  140. moment,
  141. show (id) {
  142. Object.assign(this.$data, this.$options.data())
  143. this.visible = true
  144. this.pricecode = id
  145. this.weekDayPriceList = week.map((val, index) => {
  146. return {
  147. label: val,
  148. value: null
  149. }
  150. })
  151. this.getPricePlan()
  152. },
  153. getPricePlan (e) {
  154. let params = { 'pricecode': this.pricecode }
  155. this.loading = true
  156. getPricePlan(params).then(res => {
  157. try {
  158. let basicPrice = res.find(v => v.type === 'basic')
  159. basicPrice && (this.basic_price = basicPrice.price_content)
  160. let priceList = res.find(v => v.type === 'period')
  161. priceList && (priceList = JSON.parse(priceList.price_content))
  162. priceList && priceList.forEach(item => {
  163. item.dateRange = [new Date(item.start), new Date(item.end)]
  164. })
  165. this.priceList = priceList || []
  166. let weekPrice = res.find(v => v.type === 'weekday')
  167. weekPrice && (weekPrice = JSON.parse(weekPrice.price_content).price)
  168. this.weekDayPriceList = week.map((val, index) => {
  169. return {
  170. label: val,
  171. value: (weekPrice && weekPrice[index]) || null
  172. }
  173. })
  174. } catch (e) {
  175. console.log(e)
  176. }
  177. }).finally(() => {
  178. this.loading = false
  179. })
  180. },
  181. handleCancel () {
  182. this.visible = false
  183. },
  184. handleChange (event, item) {
  185. this.$set(item, 'start', moment(event[0]).format('YYYY-MM-DD'))
  186. this.$set(item, 'end', moment(event[1]).format('YYYY-MM-DD'))
  187. },
  188. handleDelete (index) {
  189. this.$confirm('确定删除吗', '提示', {
  190. confirmButtonText: '确定',
  191. cancelButtonText: '取消',
  192. type: 'warning'
  193. }).then(() => {
  194. this.priceList.splice(index, 1)
  195. }).catch(() => {})
  196. },
  197. handleAdd () {
  198. let lastPrice
  199. if (this.priceList.length > 0) {
  200. lastPrice = JSON.parse(JSON.stringify(this.priceList[this.priceList.length - 1]))
  201. } else {
  202. lastPrice = { start: new Date(), end: new Date(), price: '' }
  203. }
  204. lastPrice.dateRange = [moment(lastPrice.start), moment(lastPrice.end)]
  205. this.priceList.push({
  206. ...lastPrice,
  207. isEdit: true
  208. })
  209. },
  210. handleOk () {
  211. this.confirmLoading = true
  212. let weekPrice = this.weekDayPriceList.map(i => i.value)
  213. weekPrice = Object.assign({}, weekPrice)
  214. let params = {}
  215. params = JSON.parse(JSON.stringify(this.form))
  216. params.period_price.price = this.priceList
  217. params.weekday_price.price = JSON.parse(JSON.stringify(weekPrice))
  218. params.pricecode = this.pricecode
  219. params.basic_price = this.basic_price
  220. setPricePlan(params).then(res => {
  221. this.$message.success('设置成功')
  222. this.handleCancel()
  223. }).finally(() => {
  224. this.confirmLoading = false
  225. })
  226. }
  227. }
  228. }
  229. </script>
  230. <style lang="scss" scoped>
  231. .wrap{
  232. padding: 20px;
  233. }
  234. .btn-wrap{
  235. text-align: right; margin-top: 20px;
  236. }
  237. .priceList {
  238. font-variant: tabular-nums;
  239. li {
  240. margin-bottom: 15px;
  241. }
  242. .calendarTxt {
  243. display: inline-block; width: 332px; box-sizing: border-box; padding-right: 30px;margin-right: 20px;text-align: center;
  244. span {
  245. display: inline-block; width: 135px;
  246. }
  247. }
  248. .priceTxt {
  249. display: inline-block; width: 200px; box-sizing: border-box; padding-left: 10px;margin-right: 20px;
  250. span {
  251. margin-right: 5px;
  252. }
  253. }
  254. .calendarPicker {
  255. margin-right: 20px;
  256. }
  257. .priceInput {
  258. display: inline-block; width: 200px; margin-right: 20px;
  259. }
  260. }
  261. .weekWrap {
  262. display: flex; justify-content: space-between;
  263. .weekItem{
  264. label{
  265. display: block; text-align: center; margin-bottom: 5px; font-weight: bold;
  266. }
  267. }
  268. .weekItem + .weekItem {
  269. margin-left: 10px;
  270. }
  271. .priceTxt{
  272. width: 88px; padding: 0 11px; display: inline-block;
  273. i{
  274. font-style: normal;
  275. }
  276. }
  277. }
  278. .addBtn {
  279. float: right; margin-bottom: 5px;
  280. }
  281. .noData {padding: 10px;
  282. text-align: center; border: 1px dashed #ddd;
  283. }
  284. </style>