add.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div>
  3. <el-button size="mini" type="primary" @click="show">
  4. {{ title_btn ? $t(title_btn) : $t('新 建') }}
  5. </el-button>
  6. <el-dialog
  7. :title="title_drawer ? $t(title_drawer) : $t(`新建工单模板`)"
  8. append-to-body
  9. :visible.sync="dialogFormVisible"
  10. width="30%"
  11. >
  12. <el-row :gutter="20">
  13. <el-form
  14. :model="form"
  15. :rules="rules"
  16. ref="form"
  17. :label-width="tool.onlyZh('120px')"
  18. label-position="right"
  19. size="mini"
  20. >
  21. <el-col :span="24">
  22. <el-form-item :label="$t('模板名称:')" prop="name">
  23. <el-input v-model="form.name" :placeholder="$t('请填写')"></el-input>
  24. </el-form-item>
  25. </el-col>
  26. <el-col :span="24">
  27. <el-form-item :label="$t('工单类型:')" prop="type">
  28. <el-cascader
  29. v-model="form.type"
  30. :options="typeOptions"
  31. :props="typeProps"
  32. clearable
  33. :placeholder="$t('请选择')"
  34. style="width: 100%"
  35. />
  36. </el-form-item>
  37. </el-col>
  38. <el-col :span="24">
  39. <el-form-item>
  40. <el-checkbox v-model="form.isworkorder" :true-label="1" :false-label="0">
  41. {{ $t('是否有后续工单') }}
  42. </el-checkbox>
  43. <el-checkbox v-model="form.ispoints" :true-label="1" :false-label="0">
  44. {{ $t('是否积分计算') }}
  45. </el-checkbox>
  46. </el-form-item>
  47. </el-col>
  48. </el-form>
  49. </el-row>
  50. <div class="dialog-footer">
  51. <el-button size="small" @click="onCancel" class="normal-btn-width">{{ $t('取 消') }}</el-button>
  52. <el-button
  53. :loading="loading"
  54. class="normal-btn-width"
  55. size="small"
  56. :type="title_btn == '编辑' ? 'warning' : 'primary'"
  57. @click="onSubmit"
  58. >{{ title_btn == '编辑' ? $t('保 存') : $t('确 定') }}
  59. </el-button>
  60. </div>
  61. </el-dialog>
  62. </div>
  63. </template>
  64. <script>
  65. export default {
  66. name: 'add',
  67. props: { title_btn: String, title_drawer: String, data: Object },
  68. data() {
  69. return {
  70. typeOptions: [], //工单类型
  71. typeProps: {
  72. value: 'value',
  73. label: 'label',
  74. children: 'children',
  75. checkStrictly: true, //允许只选一级
  76. },
  77. loading: false,
  78. dialogFormVisible: false,
  79. currentData: {},
  80. form: {
  81. sc_workorder_templateid: 0,
  82. name: '', //模板名称
  83. type: '', //工单类型
  84. isused: 0, //是否启用
  85. isworkorder: 0, //是否有后续工单 否0,是1 默认否
  86. ispoints: 0, //是否积分计算 否0,是1 默认否
  87. },
  88. rules: {
  89. name: [{ required: true, message: this.$t('请填写模板名称'), trigger: 'blur' }],
  90. type: [{ required: true, message: this.$t('请选择工单类型'), trigger: 'change' }],
  91. },
  92. };
  93. },
  94. methods: {
  95. async getWorktype() {
  96. const res = await this.$store.dispatch('optiontypeselect', 'endcustomerserviceworktype');
  97. console.log('工单类型', res.data);
  98. this.typeOptions = res.data.map((item) => {
  99. return {
  100. value: item.value,
  101. label: item.value,
  102. children:
  103. item.subvalues && item.subvalues.length
  104. ? item.subvalues.map((sub) => ({
  105. value: sub,
  106. label: sub,
  107. }))
  108. : undefined,
  109. };
  110. });
  111. },
  112. //初始化
  113. show() {
  114. this.getWorktype();
  115. this.dialogFormVisible = true;
  116. if (this.title_btn == '编辑') {
  117. this.form = Object.assign({}, this.form, this.data);
  118. this.form.type = this.data.type ? this.data.type.split('/') : [];
  119. }
  120. },
  121. onSubmit() {
  122. console.log(this.form);
  123. this.$refs['form'].validate(async (valid) => {
  124. if (!valid) return false;
  125. this.loading = true;
  126. this.form.type = this.form.type.join('/');
  127. const res = await this.$api.requested({
  128. id: '2026051511251702',
  129. content: this.form,
  130. });
  131. this.tool.showMessage(res, () => {
  132. this.$emit('onSuccess');
  133. this.loading = false;
  134. this.$refs['form'].resetFields();
  135. this.dialogFormVisible = false;
  136. });
  137. });
  138. },
  139. onCancel() {
  140. this.dialogFormVisible = false;
  141. this.$refs['form'].resetFields();
  142. },
  143. async queryType(type) {
  144. if (this.options[type].length == 0) {
  145. const res = await this.$store.dispatch('optiontypeselect', type);
  146. this.options[type] = res.data;
  147. }
  148. },
  149. },
  150. };
  151. </script>