LotteryEdit.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-loading="loading"
  5. :show-close="false"
  6. :close-on-click-modal="false"
  7. :visible.sync="isShow"
  8. :title="curObj.estate_id ? '编辑摇号信息' : '新增摇号信息'"
  9. :fullscreen="false"
  10. width="700px"
  11. custom-class="xl-dialog"
  12. center
  13. >
  14. <base-form ref="ruleForm" class="lib-edit" :data="formData" :is-inline="false" label-width="110px" :insertSlotArr="[0, 1]">
  15. <div slot="OI0" class="scoped-other-form">
  16. <div class="scoped-img-area">
  17. <div class="sia-title">项目图</div>
  18. <div class="sia-op" v-for="(imgsrc,index) in infoImg" :key="index">
  19. <img class="img" :src="imgsrc" alt="img">
  20. <span class="close" @click="infoImgDel(index)"></span>
  21. </div>
  22. <el-upload
  23. class="sia-img"
  24. :action="`${domainUrl}/adm/upload/cloudpub`"
  25. :data="{logic_type: 'estate', token}"
  26. name="upload"
  27. :show-file-list="false"
  28. :on-success="infoImgSuccess"
  29. :before-upload="imgUploadBefore"
  30. >
  31. <i class="el-icon-plus icon" />
  32. </el-upload>
  33. </div>
  34. </div>
  35. <div slot="OI1" class="scoped-other-form">
  36. <div class="scoped-img-area">
  37. <div class="sia-title">一房一价图</div>
  38. <div class="sia-op" v-for="(imgsrc,index) in houseImg" :key="index">
  39. <img class="img" :src="imgsrc" alt="img">
  40. <span class="close" @click="houseImgDel(index)"></span>
  41. </div>
  42. <el-upload
  43. class="sia-img"
  44. :action="`${domainUrl}/adm/upload/cloudpub`"
  45. :data="{logic_type: 'estate', token}"
  46. name="upload"
  47. :show-file-list="false"
  48. :on-success="houseImgSuccess"
  49. :before-upload="imgUploadBefore"
  50. >
  51. <i class="el-icon-plus icon" />
  52. </el-upload>
  53. </div>
  54. </div>
  55. <div slot="otherItem" class="scoped-other-form">
  56. <div class="scoped-img-area">
  57. <div class="sia-title">摇号结果图</div>
  58. <div class="sia-op" v-for="(imgsrc,index) in lotteryImg" :key="index">
  59. <img class="img" :src="imgsrc" alt="img">
  60. <span class="close" @click="lotteryImgDel(index)"></span>
  61. </div>
  62. <el-upload
  63. class="sia-img"
  64. :action="`${domainUrl}/adm/upload/cloudpub`"
  65. :data="{logic_type: 'estate', token}"
  66. name="upload"
  67. :show-file-list="false"
  68. :on-success="lotteryImgSuccess"
  69. :before-upload="imgUploadBefore"
  70. >
  71. <i class="el-icon-plus icon" />
  72. </el-upload>
  73. </div>
  74. </div>
  75. <div slot="footer" style="padding-top: 20px;">
  76. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  77. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  78. </div>
  79. </base-form>
  80. </el-dialog>
  81. </div>
  82. </template>
  83. <script>
  84. export default {
  85. components: { },
  86. mixins,
  87. props: {
  88. isShow: Boolean,
  89. curObj: Object
  90. },
  91. inject: ['parentData'],
  92. data() {
  93. let domainUrl = process.env.VUE_APP_BASE_API
  94. const token = window.sessionStorage.getItem('fp_token')
  95. return {
  96. domainUrl,
  97. token,
  98. formData: [],
  99. loading: true,
  100. cObj: {},
  101. infoImg: [],
  102. houseImg: [],
  103. lotteryImg: [],
  104. }
  105. },
  106. watch: {
  107. isShow: function(val) {
  108. if (val) {
  109. this.infoImg = []
  110. this.houseImg = []
  111. this.lotteryImg = []
  112. this.$api.house.admestatelotterydetail({estate_id: this.curObj.estate_id}).then(res => {
  113. this.cObj = res || {}
  114. if (res.info_img) this.infoImg = res.info_img.split(',')
  115. if (res.house_img) this.houseImg = res.house_img.split(',')
  116. if (res.lottery_img) this.lotteryImg = res.lottery_img.split(',')
  117. this.getDef()
  118. })
  119. }
  120. },
  121. },
  122. methods: {
  123. comImgDel (str, index) {
  124. let cImg = this[str]
  125. cImg.splice(index, 1)
  126. this[str] = [...cImg]
  127. },
  128. comImgSuccess(str, res) {
  129. const data = res.data || {}
  130. let cImg = [...this[str]]
  131. cImg.push(`${data.url}`)
  132. this[str] = [...cImg]
  133. },
  134. lotteryImgDel (index) {
  135. this.comImgDel('lotteryImg', index)
  136. },
  137. lotteryImgSuccess(res, file) {
  138. this.comImgSuccess('lotteryImg', res)
  139. },
  140. houseImgDel (index) {
  141. this.houseImg.splice(index, 1)
  142. this.houseImg = [...this.houseImg]
  143. },
  144. houseImgSuccess(res, file) {
  145. this.comImgSuccess('houseImg', res)
  146. },
  147. infoImgDel (index) {
  148. this.infoImg.splice(index, 1)
  149. this.infoImg = [...this.infoImg]
  150. },
  151. infoImgSuccess(res, file) {
  152. this.comImgSuccess('infoImg', res)
  153. },
  154. imgUploadBefore(file) {
  155. const isJPGPNG = file.type === 'image/jpeg' || file.type === 'image/png'
  156. const isLt2M = file.size / 1024 / 1024 < 5
  157. if (!isJPGPNG) {
  158. this.$message.error('上传图片只能是 JPG PNG 格式!')
  159. }
  160. if (!isLt2M) {
  161. this.$message.error('上传图片大小不能超过 5M!')
  162. }
  163. return isJPGPNG && isLt2M
  164. },
  165. getDef() {
  166. const params = { ...this.cObj }
  167. this.formData = [
  168. { label: '摇号中标题', key: 'under_way' },
  169. { label: '摇号结果标题', key: 'result' },
  170. ]
  171. this.setDefaultValue(params)
  172. },
  173. close(str) {
  174. if (str === 'confirm') {
  175. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  176. if (valid) {
  177. const oldform = this.$refs.ruleForm.baseForm
  178. const newForm = { ...oldform }
  179. if (this.curObj.estate_id) {
  180. newForm.estate_id = this.curObj.estate_id
  181. }
  182. if (this.infoImg && this.infoImg.length > 0) {
  183. newForm.info_img = this.infoImg.join(',')
  184. }
  185. if (this.houseImg && this.houseImg.length > 0) {
  186. newForm.house_img = this.houseImg.join(',')
  187. }
  188. if (this.lotteryImg && this.lotteryImg.length > 0) {
  189. newForm.lottery_img = this.lotteryImg.join(',')
  190. }
  191. let apiStr = 'admestatelotterychange'
  192. this.$api.house[apiStr](newForm).then(data => {
  193. this.$msgs(newForm.id ? '编辑成功' : '新增成功')
  194. this.$emit('close', newForm)
  195. })
  196. }
  197. })
  198. } else {
  199. this.$emit('close')
  200. this.setDefaultValue()
  201. }
  202. }
  203. }
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. @import '../../../../styles/libEdit.scss';
  208. .lib-edit {
  209. padding-top: 0;
  210. ::v-deep .el-form-item {
  211. margin-bottom: 10px;
  212. }
  213. ::v-deep .el-date-editor.el-input {
  214. width: 100%;
  215. }
  216. }
  217. .scoped-img-area {
  218. padding-left: 20px;
  219. margin-bottom: 20px;
  220. .sia-title {
  221. font-size: 12px;
  222. padding-bottom: 10px;
  223. color: #666;
  224. font-weight: bold;
  225. }
  226. .sia-op {
  227. display: inline-block;
  228. vertical-align: middle;
  229. margin-right: 10px;
  230. margin-bottom: 10px;
  231. border: 1px solid #f2f2f2;
  232. width: 80px;
  233. height: 80px;
  234. position: relative;
  235. &:hover {
  236. .img-big {
  237. display: block;
  238. }
  239. }
  240. .img {
  241. width: 80px;
  242. height: 80px;
  243. }
  244. .close {
  245. position: absolute;
  246. width: 20px;
  247. height: 20px;
  248. top: -10px;
  249. right: -10px;
  250. background: url(../../../../assets/icon_g_close.png) no-repeat;
  251. background-size: 20px;
  252. cursor: pointer;
  253. }
  254. .img-big {
  255. position: absolute;
  256. bottom: 0;
  257. left: 0;
  258. width: 400px;
  259. height: auto;
  260. display: none;
  261. box-shadow: 10px 10px 10px #ccc;
  262. z-index: 99;
  263. }
  264. }
  265. .sia-img {
  266. display: inline-block;
  267. vertical-align: middle;
  268. width: 80px;
  269. height: 80px;
  270. overflow: hidden;
  271. border: 1px dashed #999;
  272. margin-bottom: 10px;
  273. .el-icon-plus {
  274. color: #999;
  275. padding: 30px;
  276. }
  277. }
  278. }
  279. </style>