EnergyRateForm.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <template>
  2. <a-spin :spinning="confirmLoading">
  3. <j-form-container :disabled="formDisabled">
  4. <!-- 主表单区域 -->
  5. <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
  6. <div class="cmms-dialog-item-title">基本信息</div>
  7. <a-row>
  8. <a-col :xs="24" :sm="12">
  9. <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
  10. <a-input v-model="model.name" placeholder="请输入名称" ></a-input>
  11. </a-form-model-item>
  12. </a-col>
  13. <a-col :xs="24" :sm="12">
  14. <a-form-model-item label="能源分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="energytypeid">
  15. <j-search-select-tag v-model="model.energytypeid" placeholder="请选择设备" dict="base_energy_type,name,id" />
  16. </a-form-model-item>
  17. </a-col>
  18. <a-col :xs="24" :sm="12">
  19. <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ratetype">
  20. <span slot="label">
  21. 费率类型&nbsp;
  22. <a-tooltip title="切换类型后,价格信息表将重置">
  23. <a-icon type="exclamation-circle" />
  24. </a-tooltip>
  25. </span>
  26. <j-dict-select-tag type="list" v-model="model.ratetype" dictCode="energy_rate_type" placeholder="请选择费率类型" @change="handleChangeType"/>
  27. </a-form-model-item>
  28. </a-col>
  29. <a-col :xs="24" :sm="12">
  30. <a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rateunit">
  31. <a-input v-model="model.rateunit" placeholder="请输入单位" ></a-input>
  32. </a-form-model-item>
  33. </a-col>
  34. <a-col :xs="24" :sm="12">
  35. <a-form-model-item label="费率有效期开始" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="begintime">
  36. <j-date placeholder="请选择费率有效期开始" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" v-model="model.begintime" style="width: 100%" />
  37. </a-form-model-item>
  38. </a-col>
  39. <a-col :xs="24" :sm="12">
  40. <a-form-model-item label="费率有效期结束" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endtime">
  41. <j-date placeholder="请选择费率有效期结束" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" v-model="model.endtime" style="width: 100%" />
  42. </a-form-model-item>
  43. </a-col>
  44. <a-col :xs="24" :sm="24">
  45. <a-form-model-item label="备注" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="remark">
  46. <a-textarea v-model="model.remark" placeholder="请输入备注" rows="3" ></a-textarea>
  47. </a-form-model-item>
  48. </a-col>
  49. </a-row>
  50. <!-- </a-form-model>
  51. </j-form-container> -->
  52. <!-- 子表单区域 -->
  53. <div class="cmms-dialog-item-title">价格信息表详情</div>
  54. <a-button type="primary" style="margin-bottom:10px;" @click="newMember">新增</a-button>
  55. <a-table
  56. size="small"
  57. :columns="model.columns1"
  58. :dataSource="model.data"
  59. :pagination="false"
  60. :rowKey="(record, index) => { return index }"
  61. bordered
  62. class="j-table-force-nowrap"
  63. >
  64. <template slot="begintime" slot-scope="text, record,index">
  65. <a-form-model-item :prop="'data.'+index+'.begintime'" :rules="validatorRules.begintime2" style="margin-bottom: 0px;">
  66. <a-time-picker format="HH:mm:ss" placeholder="请选择分时开始时间" v-model="record.begintime" style="width: 100%" />
  67. </a-form-model-item>
  68. </template>
  69. <template slot="endtime" slot-scope="text, record,index">
  70. <a-form-model-item :prop="'data.'+index+'.endtime'" :rules="validatorRules.endtime2" style="margin-bottom: 0px;">
  71. <a-time-picker format="HH:mm:ss" placeholder="请选择分时结束时间" v-model="record.endtime" style="width: 100%" />
  72. </a-form-model-item>
  73. </template>
  74. <template slot="pandv" slot-scope="text, record,index">
  75. <a-form-model-item :prop="'data.'+index+'.pandv'" :rules="validatorRules.pandv" style="margin-bottom: 0px;">
  76. <!-- <j-dict-select-tag type="list" v-model="record.pandv" dictCode="ems_pandv" placeholder="请选择峰平谷" style="width: 100%" /> -->
  77. <a-select
  78. v-model="record.pandv"
  79. placeholder="请选择峰平谷"
  80. showSearch
  81. :filterOption="filterOption"
  82. :options="typeOptions">
  83. </a-select>
  84. </a-form-model-item>
  85. </template>
  86. <template slot="price" slot-scope="text, record,index">
  87. <a-form-model-item :prop="'data.'+index+'.price'" :rules="validatorRules.price" style="margin-bottom: 0px;">
  88. <a-input v-model="record.price" placeholder="请输入价格" ></a-input>
  89. </a-form-model-item>
  90. </template>
  91. <template slot="beginamount" slot-scope="text, record,index">
  92. <a-form-model-item :prop="'data.'+index+'.beginamount'" :rules="validatorRules.beginamount" style="margin-bottom: 0px;">
  93. <a-input v-model="record.beginamount" placeholder="请输入起始量" ></a-input>
  94. </a-form-model-item>
  95. </template>
  96. <template slot="endamount" slot-scope="text, record,index">
  97. <a-form-model-item :prop="'data.'+index+'.endamount'" :rules="validatorRules.endamount" style="margin-bottom: 0px;">
  98. <a-input v-model="record.endamount" placeholder="请输入结束量" ></a-input>
  99. </a-form-model-item>
  100. </template>
  101. <template slot="operation" slot-scope="text, record">
  102. <span>
  103. <a-popconfirm title="是否要删除此行?" @confirm="remove(record.key)">
  104. <a>删除</a>
  105. </a-popconfirm>
  106. </span>
  107. </template>
  108. </a-table>
  109. </a-form-model>
  110. </j-form-container>
  111. <!-- <a-tabs v-model="activeKey" @change="handleChangeTabs">
  112. <a-tab-pane tab="详情" :key="refKeys[0]" :forceRender="true">
  113. <j-editable-table
  114. :ref="refKeys[0]"
  115. :loading="model.loading"
  116. :columns="model.columns"
  117. :dataSource="model.data"
  118. :maxHeight="300"
  119. :disabled="formDisabled"
  120. :rowNumber="true"
  121. :rowSelection="true"
  122. :actionButton="true"/>
  123. </a-tab-pane>
  124. </a-tabs> -->
  125. </a-spin>
  126. </template>
  127. <script>
  128. import { FormTypes,getRefPromise,VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
  129. import { JEditableTableModelMixin } from '@/mixins/JEditableTableModelMixin'
  130. import { validateDuplicateValue } from '@/utils/util'
  131. import {ajaxGetDictItems,getDictItemsFromCache} from '@/api/api'
  132. export default {
  133. name: 'EnergyRateForm',
  134. mixins: [JEditableTableModelMixin],
  135. components: {
  136. },
  137. data() {
  138. return {
  139. // typeOptions: [
  140. // {label: '尖', value: 0},
  141. // {label: '峰', value: 1},
  142. // {label: '平', value: 2},
  143. // {label: '谷', value: 3},
  144. // ],
  145. labelCol: {
  146. xs: { span: 24 },
  147. sm: { span: 6 },
  148. },
  149. wrapperCol: {
  150. xs: { span: 24 },
  151. sm: { span: 16 },
  152. },
  153. labelCol2: {
  154. xs: { span: 24 },
  155. sm: { span: 3 },
  156. },
  157. wrapperCol2: {
  158. xs: { span: 24 },
  159. sm: { span: 20 },
  160. },
  161. model:{
  162. loading: false,
  163. data: [],
  164. columns1: []
  165. },
  166. validatorRules: {
  167. energyrateid: [
  168. { required: true, message: '请输入能源费率ID!'},
  169. ],
  170. name: [
  171. { required: true, message: '请输入名称!'},
  172. ],
  173. energytypeid: [
  174. { required: true, message: '请输入能源分类ID!'},
  175. ],
  176. ratetype: [
  177. { required: true, message: '请输入费率类型:分时费率、阶梯费率!'},
  178. ],
  179. // rateunit: [
  180. // { required: true, message: '请输入单位!'},
  181. // ],
  182. begintime: [
  183. { required: true, message: '请输入费率有效期开始!'},
  184. ],
  185. endtime: [
  186. { required: true, message: '请输入费率有效期结束!'},
  187. ],
  188. begintime2: [
  189. { required: true, message: '请选择分时开始时间!'},
  190. ],
  191. endtime2: [
  192. { required: true, message: '请选择分时结束时间!'},
  193. ],
  194. pandv: [
  195. { required: true, message: '请选择峰平谷!'},
  196. ],
  197. price: [
  198. { required: true, message: '请输入价格!'},
  199. ],
  200. beginamount: [
  201. { required: true, message: '请输入起始量!'},
  202. ],
  203. endamount: [
  204. { required: true, message: '请输入结束量!'},
  205. ],
  206. },
  207. // validatorListRules: {
  208. // begintime: [
  209. // { required: true, message: '请选择分时开始时间!'},
  210. // ],
  211. // endtime: [
  212. // { required: true, message: '请选择分时结束时间!'},
  213. // ],
  214. // pandv: [
  215. // { required: true, message: '请选择峰平谷!'},
  216. // ],
  217. // price: [
  218. // { required: true, message: '请输入价格!'},
  219. // ],
  220. // beginamount: [
  221. // { required: true, message: '请输入起始量!'},
  222. // ],
  223. // endamount: [
  224. // { required: true, message: '请输入结束量!'},
  225. // ],
  226. // },
  227. // 新增时子表默认添加几行空数据
  228. addDefaultRowNum: 1,
  229. refKeys: ['baseEnergyRateDetail', ],
  230. tableKeys:['baseEnergyRateDetail', ],
  231. activeKey: 'baseEnergyRateDetail',
  232. // base_energy_rate_detail
  233. // baseEnergyRateDetailTable: {
  234. // loading: false,
  235. // data: [],
  236. // columns1: []
  237. // },
  238. url: {
  239. add: "/energyRate/energyRate/add",
  240. edit: "/energyRate/energyRate/edit",
  241. baseEnergyRateDetail: {
  242. list: '/energyRate/energyRate/queryDetailByMainId'
  243. },
  244. },
  245. count: 1,
  246. ratetype: '',
  247. dictCode: 'ems_pandv'
  248. }
  249. },
  250. props: {
  251. //表单禁用
  252. disabled: {
  253. type: Boolean,
  254. default: false,
  255. required: false
  256. }
  257. },
  258. computed: {
  259. formDisabled(){
  260. return this.disabled
  261. },
  262. },
  263. created () {
  264. this.initDictData()
  265. },
  266. methods: {
  267. initDictData() {
  268. //优先从缓存中读取字典配置
  269. if(getDictItemsFromCache(this.dictCode)){
  270. this.typeOptions = getDictItemsFromCache(this.dictCode);
  271. return
  272. }
  273. //根据字典Code, 初始化字典数组
  274. ajaxGetDictItems(this.dictCode, null).then((res) => {
  275. if (res.success) {
  276. // console.log(res.result);
  277. this.typeOptions = res.result;
  278. }
  279. })
  280. },
  281. filterOption (value, option) {
  282. return option.componentOptions.children[0].text.indexOf(value) >= 0
  283. },
  284. addBefore(){
  285. this.model.data=[]
  286. },
  287. getAllTable() {
  288. let values = this.tableKeys.map(key => getRefPromise(this, key))
  289. return Promise.all(values)
  290. },
  291. /** 调用完edit()方法之后会自动调用此方法 */
  292. editAfter() {
  293. this.$nextTick(() => {
  294. })
  295. // 加载子表数据
  296. if (this.model.id) {
  297. let params = { id: this.model.id }
  298. this.requestSubTableData(this.url.baseEnergyRateDetail.list, params, this.model)
  299. }
  300. },
  301. //校验所有一对一子表表单
  302. validateSubForm(allValues){
  303. return new Promise((resolve,reject)=>{
  304. Promise.all([
  305. ]).then(() => {
  306. resolve(allValues)
  307. }).catch(e => {
  308. if (e.error === VALIDATE_NO_PASSED) {
  309. // 如果有未通过表单验证的子表,就自动跳转到它所在的tab
  310. this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
  311. } else {
  312. console.error(e)
  313. }
  314. })
  315. })
  316. },
  317. /** 整理成formData */
  318. classifyIntoFormData(allValues) {
  319. let main = Object.assign(this.model, allValues.formValue)
  320. return {
  321. ...main, // 展开
  322. baseEnergyRateDetailList: allValues.tablesValue[0].values,
  323. }
  324. },
  325. validateError(msg){
  326. this.$message.error(msg)
  327. },
  328. close() {
  329. this.visible = false
  330. this.$emit('close')
  331. this.$refs.form.clearValidate();
  332. },
  333. // 获取选中的费率类型
  334. handleChangeType(value){
  335. console.log(99,value)
  336. if (value == '') {
  337. // this.model.columns1 = []
  338. this.model.data = []
  339. this.count = 1
  340. this.ratetype = ''
  341. }
  342. if (value != this.ratetype) {
  343. this.model.data = []
  344. this.count = 1
  345. }
  346. if (value == 1) {
  347. this.ratetype = value
  348. this.model.columns1 = [
  349. {
  350. title: '分时开始时间',
  351. dataIndex: 'begintime',
  352. key: 'begintime',
  353. width:"200px",
  354. align: 'center',
  355. scopedSlots: { customRender: 'begintime' },
  356. },
  357. {
  358. title: '分时结束时间',
  359. dataIndex: 'endtime',
  360. key: 'endtime',
  361. width:"200px",
  362. align: 'center',
  363. scopedSlots: { customRender: 'endtime' },
  364. },
  365. {
  366. title: '峰平谷',
  367. dataIndex: 'pandv',
  368. key: 'pandv',
  369. width:"200px",
  370. align: 'center',
  371. scopedSlots: { customRender: 'pandv' },
  372. },
  373. {
  374. title: '价格',
  375. dataIndex: 'price',
  376. key: 'price',
  377. width:"200px",
  378. align: 'center',
  379. scopedSlots: { customRender: 'price' },
  380. },
  381. {
  382. title: '操作',
  383. key: 'operation',
  384. align: 'center',
  385. width:"100px",
  386. scopedSlots: { customRender: 'operation' }
  387. }
  388. ]
  389. this.model.data.push({
  390. key: this.count + '',
  391. begintime: '',
  392. endtime: '',
  393. pandv: '',
  394. price: '',
  395. beginamount: '',
  396. endamount: ''
  397. })
  398. this.count++
  399. console.log(this.model.data)
  400. }
  401. if (value == 2) {
  402. this.ratetype = value
  403. this.model.columns1 = [
  404. {
  405. title: '起始量',
  406. dataIndex: 'beginamount',
  407. key: 'beginamount',
  408. width:"200px",
  409. align: 'center',
  410. scopedSlots: { customRender: 'beginamount' },
  411. },
  412. {
  413. title: '结束量',
  414. dataIndex: 'endamount',
  415. key: 'endamount',
  416. width:"200px",
  417. align: 'center',
  418. scopedSlots: { customRender: 'endamount' },
  419. },
  420. {
  421. title: '价格',
  422. dataIndex: 'price',
  423. key: 'price',
  424. width:"200px",
  425. align: 'center',
  426. scopedSlots: { customRender: 'price' },
  427. },
  428. {
  429. title: '操作',
  430. key: 'operation',
  431. align: 'center',
  432. width:"100px",
  433. scopedSlots: { customRender: 'operation' }
  434. }
  435. ]
  436. this.model.data.push({
  437. key: this.count + '',
  438. begintime: '',
  439. endtime: '',
  440. pandv: '',
  441. price: '',
  442. beginamount: '',
  443. endamount: ''
  444. })
  445. this.count++
  446. console.log(this.model.data)
  447. }
  448. },
  449. // 创建一条新数据
  450. newMember() {
  451. console.log(this.model.ratetype)
  452. if (this.model.ratetype == undefined) {
  453. this.$message.warning('请先选择费率类型');
  454. } else {
  455. this.model.data.push({
  456. key: this.count + '',
  457. begintime: '',
  458. endtime: '',
  459. pandv: '',
  460. price: '',
  461. beginamount: '',
  462. endamount: ''
  463. })
  464. this.count++
  465. console.log(this.model.data)
  466. }
  467. },
  468. remove(key) {
  469. console.log(key)
  470. const newData = this.model.data.filter(item => item.key !== key)
  471. this.model.data = newData
  472. },
  473. submitForm () {
  474. console.log(1111)
  475. const that = this;
  476. // 触发表单验证
  477. this.$refs.form.validate(valid => {
  478. if (valid) {
  479. console.log(22222)
  480. // that.confirmLoading = true;
  481. // let httpurl = '';
  482. // let method = '';
  483. // if(!this.model.id){
  484. // httpurl+=this.url.add;
  485. // method = 'post';
  486. // }else{
  487. // httpurl+=this.url.edit;
  488. // method = 'put';
  489. // }
  490. // httpAction(httpurl,this.model,method).then((res)=>{
  491. // if(res.success){
  492. // that.$message.success(res.message);
  493. // that.$emit('ok');
  494. // }else{
  495. // that.$message.warning(res.message);
  496. // }
  497. // }).finally(() => {
  498. // that.confirmLoading = false;
  499. // })
  500. }
  501. })
  502. },
  503. }
  504. }
  505. </script>
  506. <style scoped>
  507. @import "~@/assets/less/uStyle.less";
  508. </style>