RoomPrice.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <div>
  3. <el-drawer
  4. :show-close="false"
  5. :title="type === 'edit' ? '编辑一房一价' : '新增一房一价'"
  6. :wrapper-closable="false"
  7. :close-on-press-escape="false"
  8. :visible.sync="isShow"
  9. size="1100px"
  10. custom-class="xl-drawer"
  11. direction="rtl"
  12. >
  13. <div v-if="this.type === 'add'" class="scoped-top">
  14. <base-form slot="content" ref="ruleForm" :data="searchData" :noLabel="false" labelWidth="100px">
  15. <div slot="footer">
  16. <el-button icon="el-icon-Plus" class="xl-form-btn bgc2" @click="batchAdd">批量添加</el-button>
  17. </div>
  18. </base-form>
  19. </div>
  20. <table-list
  21. :listLoading="false"
  22. listLoadStr="createdClose"
  23. :data="tableData2"
  24. :columns="listConfig"
  25. :current-page="currentPage"
  26. :page-size="-1"
  27. :operationsDefaultLength="4"
  28. />
  29. <div class="xl-form">
  30. <div class="xl-form-footer fixed" style="width:960px;padding-top: 20px;border-top: 1px solid #dcdcdc;right:0;">
  31. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  32. <el-button v-if="this.type === 'add'" class="xl-form-btn t1" @click="close('confirm')">保存</el-button>
  33. </div>
  34. </div>
  35. </el-drawer>
  36. <rpt-edit
  37. :isShow="isREShow"
  38. :curObj="reObj"
  39. :roomAreaList="roomAreaList"
  40. @close="closeREPopup"
  41. />
  42. </div>
  43. </template>
  44. <script>
  45. import { arrToObj } from '@/utils'
  46. import baseTable from '_m/baseTable.js'
  47. import RptEdit from './RoomPriceTypeEdit.vue'
  48. export default {
  49. components: {
  50. RptEdit
  51. },
  52. mixins: [...mixins, baseTable],
  53. props: {
  54. isShow: Boolean,
  55. curObj: Object,
  56. type: String,
  57. },
  58. inject: ['parentData'],
  59. data() {
  60. return {
  61. apiStr: 'house.admpricelist',
  62. searchForm: {},
  63. noCreated: true,
  64. isLEShow: false,
  65. cObj: {},
  66. searchData: [],
  67. roomAreaList: [],
  68. isREShow: false,
  69. reObj: {},
  70. }
  71. },
  72. computed: {
  73. tableData2() {
  74. const arr = [...this.tableData]
  75. arr.map(item => {
  76. if (this.type === 'add') item.noCan = true
  77. })
  78. return arr
  79. }
  80. },
  81. mounted() {
  82. this.getDef()
  83. this.listConfig = {
  84. rows: [
  85. { label: '楼栋', prop: 'building_num', type: 'input', width: '100px'},
  86. { label: '层高', prop: 'floor_height', type: 'input', width: '60px'},
  87. { label: '楼层', prop: 'storey', type: 'input', width: '60px'},
  88. { label: '房号', prop: 'room', type: 'input', width: '60px'},
  89. { label: '建筑面积(㎡)', prop: 'built', type: 'input', width: '80px'},
  90. { label: '套内面积(㎡)', prop: 'space', type: 'input', width: '80px'},
  91. { label: '毛坯单价(元/㎡)', prop: 'blank', type: 'input', width: '90px'},
  92. { label: '装修单价(元/㎡)', prop: 'decoration', type: 'input', width: '90px'},
  93. { label: '户型名', prop: 'house_type', width: '100px'},
  94. { label: '户型图', prop: 'houseImg', type: 'img'},
  95. { label: '操作', width: 200, type: 'handle2', operations:
  96. [
  97. { label: '保存', func: this.saveHandle, btnType: 'primary', hide: 'noCan' },
  98. { label: '修改户型', func: this.openREPopup, btnType: 'success', hide: 'noCan' },
  99. { label: '删除', func: this.delHandle, btnType: 'danger' },
  100. ]
  101. }
  102. ]
  103. }
  104. },
  105. watch: {
  106. isShow: function(val) {
  107. if (val) {
  108. if (this.type === 'edit') {
  109. this.getData()
  110. }
  111. this.getDef()
  112. this.$api.house.admestatehousearealist({estate_id: this.curObj.estate_id}).then(res => {
  113. const list = res.list || []
  114. const htObj = arrToObj(this.$dictData.house_type)
  115. const ptObj = arrToObj(this.$dictData.product_type)
  116. list.map(item => {
  117. item.key = `${htObj[item.house_type]}${item.area}㎡-${ptObj[item.product_type]}`
  118. item.key2 = `${htObj[item.house_type]}`
  119. item.val = item.id
  120. })
  121. this.roomAreaList = [...list]
  122. })
  123. }
  124. },
  125. },
  126. methods: {
  127. openREPopup(row) {
  128. console.log(row)
  129. this.reObj = row
  130. this.isREShow = true
  131. },
  132. closeREPopup(obj) {
  133. this.isREShow = false
  134. if (obj) {
  135. this.getData()
  136. }
  137. },
  138. getData () {
  139. this.$api.house.admestatelotterypricelist({estate_id: this.curObj.estate_id}).then(res => {
  140. let list = res.list || []
  141. list.map(item => {
  142. item.houseImg = item.house_img + '_adm0'
  143. })
  144. this.tableData = [...list]
  145. })
  146. },
  147. saveHandle (row) {
  148. this.$api.house.admestatelotterypriceedit(row).then(res => {
  149. this.getData()
  150. this.$msgs('更新成功~')
  151. })
  152. },
  153. getDef (str) {
  154. if (str === 'col') {
  155. let params = {...this.$refs.ruleForm.baseForm}
  156. let addArr = []
  157. const colArr = new Array(Number(params.batchCol)).fill({i: "add"})
  158. colArr.forEach((item, itemIndex) => {
  159. addArr.push({ label: `${itemIndex + 1}-建筑面积(㎡)`, key: `${itemIndex + 1}-built` })
  160. addArr.push({ label: `${itemIndex + 1}-套内面积(㎡)`, key: `${itemIndex + 1}-space` })
  161. addArr.push({ label: `${itemIndex + 1}-户型`, key: `${itemIndex + 1}-HT`, type: 'select', options: this.roomAreaList})
  162. })
  163. this.searchData = [
  164. { label: '每层户数', key: 'batchCol', changeHandle: this.colChange },
  165. { label: '多少层', key: 'batchRow' },
  166. { label: '楼栋名', key: 'building_num' },
  167. { label: '层高', key: 'floor_height' },
  168. { label: '装修单价', key: 'decoration' },
  169. ...addArr,
  170. ]
  171. this.setDefaultValue(params, 'searchData')
  172. } else {
  173. this.searchData = [
  174. { label: '每层户数', key: 'batchCol', changeHandle: this.colChange },
  175. { label: '多少层', key: 'batchRow' },
  176. { label: '楼栋名', key: 'building_num' },
  177. { label: '层高', key: 'floor_height' },
  178. { label: '装修单价', key: 'decoration' },
  179. ]
  180. }
  181. },
  182. colChange (val) {
  183. this.getDef('col')
  184. },
  185. batchAdd () {
  186. const oldform = this.$refs.ruleForm.baseForm
  187. const newForm = { ...oldform }
  188. let curArr = [...this.tableData]
  189. let newArr = new Array(Number(newForm.batchRow) * Number(newForm.batchCol)).fill({
  190. ...newForm
  191. })
  192. newArr.forEach((n, i) => {
  193. let rowIndex = Math.floor(i / newForm.batchCol) + 1
  194. let colIndex = Math.floor(i % newForm.batchCol) + 1
  195. let built = ''
  196. let space = ''
  197. let house_type = ''
  198. let house_img = ''
  199. let houseImg = ''
  200. for (let f in newForm) {
  201. if (f.indexOf(colIndex + '-built') > -1) {
  202. built = newForm[f]
  203. }
  204. if (f.indexOf(colIndex + '-HT') > -1) {
  205. this.roomAreaList.forEach(ra => {
  206. if (newForm[f] === ra.id) {
  207. house_type = ra.key2
  208. houseImg = ra.pri_image + '_adm0'
  209. house_img = ra.pri_image
  210. }
  211. })
  212. }
  213. if (f.indexOf(colIndex + '-space') > -1) {
  214. space = newForm[f]
  215. }
  216. }
  217. curArr.push({
  218. ...n,
  219. storey: rowIndex,
  220. room: `${rowIndex}0${colIndex}`,
  221. built,
  222. space,
  223. house_type,
  224. house_img,
  225. houseImg,
  226. blank: 1,
  227. })
  228. })
  229. this.tableData = [...curArr]
  230. this.setDefaultValue({}, 'searchData')
  231. },
  232. delHandle(row) {
  233. this.$msg(`您确定要删除该楼盘吗?`, 'confirm', () => {
  234. if (this.type === 'add') {
  235. let arr = [...this.tableData]
  236. let cIndex = ''
  237. arr.map((item, index) => {
  238. if (item.randomId === row.randomId) {
  239. cIndex = index
  240. }
  241. })
  242. arr.splice(cIndex, 1)
  243. this.tableData = [...arr]
  244. } else {
  245. this.$api.house.admestatelotterypricedel({id: row.id}).then(res => {
  246. this.$msgs('删除成功~')
  247. this.getData()
  248. })
  249. }
  250. }, null, true)
  251. },
  252. close(str) {
  253. if (str === 'confirm') {
  254. let curArr = [...this.tableData]
  255. let newArr = []
  256. curArr.map(item => {
  257. newArr.push({
  258. blank: item.blank,
  259. building_num: item.building_num,
  260. built: item.built,
  261. decoration: item.decoration,
  262. floor_height: item.floor_height,
  263. house_type: item.house_type,
  264. room: item.room,
  265. space: item.space,
  266. storey: item.storey,
  267. house_img: item.house_img,
  268. })
  269. })
  270. let params = {
  271. estate_id: this.curObj.estate_id,
  272. lottery_id: this.curObj.id,
  273. data: JSON.stringify(newArr)
  274. }
  275. let apiStr = 'admestatelotterypriceadd'
  276. this.$api.house[apiStr](params).then(data => {
  277. this.$msgs(params.lottery_id ? '编辑成功' : '新增成功')
  278. this.tableData = []
  279. this.$emit('close', newForm)
  280. })
  281. } else {
  282. this.$emit('close')
  283. this.tableData = []
  284. this.setDefaultValue()
  285. }
  286. }
  287. }
  288. }
  289. </script>
  290. <style lang="scss" scoped>
  291. ::v-deep .xl-table-box {
  292. padding-bottom: 50px;
  293. }
  294. ::v-deep .el-form-item {
  295. &:nth-child(5) {
  296. margin-right: 300px;
  297. }
  298. }
  299. </style>