detail.hbs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <div>
  3. <!-- 增改查弹窗 -->
  4. <el-dialog :title="titles[mode] || '详情'" :visible.sync="formVisible" class="finish-dialog" :class="mode" width="960px" append-to-body :close-on-click-modal="false">
  5. {{!-- <div v-if="mode === 'add'" class="alert-box">说明:xxxx</div> --}}
  6. <el-form v-if="formVisible" ref="detailForm" v-loading="detailLoading" :model="formData" :rules="rules" label-position="right" inline class="detail-dialog" label-width="140px">
  7. <el-form-item label="名称:">
  8. <span>
  9. \{{ formData.name || '--' }}
  10. </span>
  11. </el-form-item>
  12. <el-form-item label="手机号:" prop="phonenum">
  13. <el-input v-if="isEditAdd" v-model.trim="formData.phonenum" placeholder="请输入" type="number" />
  14. <span v-else>
  15. \{{ formData.phonenum || '--' }}
  16. </span>
  17. </el-form-item>
  18. <el-form-item label="开始日期:" prop="startdate">
  19. <el-date-picker v-if="isEditAdd" v-model.trim="formData.startdate" type="date" value-format="yyyy-MM-dd" placeholder="请输入" :disabled="hadConsume" />
  20. <span v-else>
  21. \{{ formData.startdate || '--' }}
  22. </span>
  23. </el-form-item>
  24. <el-form-item label="方案:" prop="consumeway">
  25. <el-checkbox-group v-model.trim="formData.consumeway" :disabled="!isEditAdd || hadConsume" @change="formData.consumeway = $event">
  26. <el-checkbox :label="1">方案1</el-checkbox>
  27. <el-checkbox :label="2">方案2</el-checkbox>
  28. </el-checkbox-group>
  29. </el-form-item>
  30. <el-form-item label="权限开关:" class="fit-width">
  31. <el-switch v-if="isEditAdd" v-model.trim="formData.isgreater" active-value="1" :inactive-value="2" />
  32. <span v-else>
  33. \{{ options.isgreater[formData.isgreater] }}
  34. </span>
  35. </el-form-item>
  36. <el-form-item label="模式:" prop="swapmode" style="width: 100%">
  37. <template v-if="isEditAdd">
  38. <el-radio v-model.trim="formData.swapmode" :label="1">模式1</el-radio>
  39. <el-radio v-model.trim="formData.swapmode" :label="2">模式2</el-radio>
  40. </template>
  41. <span v-else>
  42. \{{ options.swapmode[formData.swapmode] || '--' }}
  43. </span>
  44. </el-form-item>
  45. <el-form-item label="描述:" prop="remark" style="width: 100%">
  46. <el-input
  47. v-if="isEditAdd"
  48. v-model.trim="formData.remark"
  49. placeholder="请输入"
  50. type="textarea"
  51. show-word-limit
  52. :autosize="{ minRows: 3, maxRows: 4 }"
  53. :maxlength="100"
  54. />
  55. <span v-else>
  56. \{{ formData.remark || '--' }}
  57. </span>
  58. </el-form-item>
  59. <!-- <el-row class="mb-20">
  60. <span class="list-title">其他信息</span>
  61. </el-row> -->
  62. </el-form>
  63. <div slot="footer" class="dialog-footer">
  64. <el-button :loading="detailLoading" @click="formVisible = false">关闭</el-button>
  65. <el-button v-if="isEditAdd" type="primary" :loading="detailLoading" @click="submit">确定</el-button>
  66. </div>
  67. </el-dialog>
  68. </div>
  69. </template>
  70. <script>
  71. import dayjs from 'dayjs'
  72. import { deepClone } from '@/utils'
  73. const defaultFormData = { // 表单初始数据
  74. }
  75. export default {
  76. name: '',
  77. inject: ['global', 'refresh'],
  78. data() {
  79. const validateDateRange = (rule, value, callback) => {
  80. if (!this.formData.authorizationstart || !this.formData.authorizationend) {
  81. return callback()
  82. } else if (
  83. dayjs(this.formData.authorizationend).isBefore(this.formData.authorizationstart) &&
  84. this.formData.authorizationend !== this.formData.authorizationstart
  85. ) { // 触发条件:开始在结束后 && 开始不等于结束
  86. return callback(new Error('结束时间不可早于开始时间!'))
  87. } else {
  88. const isStartTimeValid = !(dayjs(this.formData.authorizationstart).isBefore(dayjs()) && !dayjs(this.formData.authorizationstart).isSame(dayjs(), 'date'))
  89. isStartTimeValid && this.$refs.detailForm.clearValidate('authorizationstart')
  90. this.$refs.detailForm.clearValidate('authorizationend')
  91. return callback()
  92. }
  93. }
  94. const validateStartTime = (rule, value, callback) => {
  95. if (this.mode === 'add' && dayjs(value).isBefore(dayjs(), 'date')) {
  96. return callback(new Error('开始时间不能早于当前时间!'))
  97. } else {
  98. return validateDateRange(rule, value, callback)
  99. }
  100. }
  101. const validateEndTime = (rule, value, callback) => {
  102. if (this.mode === 'add' && dayjs(value).isBefore(dayjs(), 'date')) {
  103. return callback(new Error('结束时间不能早于当前时间!'))
  104. } else {
  105. return validateDateRange(rule, value, callback)
  106. }
  107. }
  108. return {
  109. detailLoading: false,
  110. mode: 'see', // 查看see / 编辑edit / 添加add
  111. titles: { // 弹窗标题(动态)
  112. see: '查看',
  113. add: '新增',
  114. edit: '编辑'
  115. },
  116. formVisible: false, // 弹窗显示
  117. formConfig: {}, // 表单配置
  118. formData: {}, // 表单数据
  119. rules: {
  120. // TODO: 校验规则
  121. // userid: [
  122. // { required: true, message: '用户不能为空', trigger: 'change' }
  123. // ],
  124. // starttime: [
  125. // { required: true, message: '开始时间不能为空', trigger: 'change' },
  126. // { validator: validateStartTime, trigger: 'change' }
  127. // ],
  128. // endtime: [
  129. // { required: true, message: '结束时间不能为空', trigger: 'change' },
  130. // { validator: validateEndTime, trigger: 'change' }
  131. // ]
  132. }
  133. }
  134. },
  135. computed: {
  136. isEditAdd() {
  137. return this.mode === 'edit' || this.mode === 'add'
  138. }
  139. },
  140. methods: {
  141. showDialog({ mode, formConfig, formData, formTitle }) {
  142. this.mode = mode || (this.formData.id ? 'edit' : 'add')
  143. if (this.mode === 'add') {
  144. this.formData = { ...defaultFormData }
  145. } else {
  146. this.formData = { ...formData }
  147. }
  148. this.initFormData()
  149. this.formVisible = true
  150. },
  151. initFormData() { // 表单数据初始化
  152. // TODO: init formData
  153. // const {} = this.formData
  154. // this.$set(this.formData, 'authorizationtype', authorizationtype || 1)
  155. },
  156. filterFormData(formData) { // 提交数据过滤
  157. const data = deepClone(formData)
  158. // TODO: 自定义数据过滤
  159. return data
  160. },
  161. submit() {
  162. console.log('output->formData', this.formData)
  163. this.$refs.detailForm.validate(async(valid) => {
  164. if (valid) {
  165. const formData = this.filterFormData(this.formData)
  166. console.log('FORM', formData)
  167. this.detailLoading = true
  168. try {
  169. let res = {}
  170. if (this.mode === 'add') {
  171. // TODO: 提交接口
  172. // res = await addInvitation(formData)
  173. } else {
  174. // TODO: 修改接口
  175. // res = await updateInvitation(formData)
  176. }
  177. if (res.success) {
  178. this.formVisible = false
  179. this.refresh()
  180. }
  181. } finally {
  182. this.detailLoading = false
  183. }
  184. } else {
  185. this.$message.warning('校验失败')
  186. }
  187. })
  188. }
  189. }
  190. }
  191. </script>
  192. <style scoped lang="scss">
  193. .width-clear {
  194. width: auto
  195. }
  196. .finish-dialog {
  197. /deep/ .el-form-item {
  198. &__content {
  199. width: calc(100% - 180px); // 减去label宽
  200. max-width: none;
  201. .el-checkbox-group {
  202. line-height: normal;
  203. }
  204. }
  205. &__label {
  206. padding-right: 12px !important;
  207. }
  208. &.fit-width {
  209. .el-form-item__content {
  210. width: fit-content;
  211. }
  212. }
  213. }
  214. &.edit, &.add {
  215. /deep/ .el-form-item {
  216. margin-bottom: 22px;
  217. }
  218. }
  219. &.see {
  220. .detail-dialog {
  221. // background-color: #f8f8f8;
  222. padding: 20px;
  223. }
  224. /deep/ .el-form-item {
  225. &__label, &__content { // 统一行高
  226. line-height: 2;
  227. }
  228. margin-bottom: 10px;
  229. }
  230. }
  231. }
  232. /* 穿梭框 */
  233. /deep/ .el-transfer {
  234. &__buttons {
  235. display: inline-flex;
  236. flex-direction: column;
  237. .el-button + .el-button {
  238. margin-left: 0;
  239. }
  240. }
  241. }
  242. </style>