detail.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div id="detail">
  3. <el-row>
  4. <el-col :span="24" class="main" v-loading="loadings" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading">
  5. <el-col :span="24" style="margin: 0 0 10px 0">
  6. <el-col :span="2"><el-button type="primary" size="mini" @click="toBack()">返回</el-button></el-col>
  7. </el-col>
  8. <el-col :span="24">
  9. <data-form :fields="infoFields" :rules="rules" v-model="form" labelWidth="150px" @save="toSave">
  10. <template #customer>
  11. <el-select
  12. v-model="form.customer"
  13. filterable
  14. multiple
  15. remote
  16. placeholder="请选择用户"
  17. :remote-method="querySearch"
  18. :loading="loading"
  19. style="width: 100%"
  20. >
  21. <el-option v-for="item in customerList" :key="item._id" :label="item.name" :value="item._id"> </el-option>
  22. </el-select>
  23. </template>
  24. <template #status>
  25. <el-option v-for="i in statusList" :key="i.label" :label="i.label" :value="i.value"></el-option>
  26. </template>
  27. </data-form>
  28. </el-col>
  29. </el-col>
  30. </el-row>
  31. </div>
  32. </template>
  33. <script>
  34. import { mapState, createNamespacedHelpers } from 'vuex';
  35. const { mapActions: users } = createNamespacedHelpers('users');
  36. const { mapActions: dictData } = createNamespacedHelpers('dictData'); // 字典
  37. const { mapActions: notice } = createNamespacedHelpers('notice'); // 消息
  38. export default {
  39. name: 'detail',
  40. props: { id: { type: String } },
  41. components: {},
  42. data: function () {
  43. return {
  44. loadings: true,
  45. // info部分
  46. infoFields: [
  47. { label: '用户', model: 'customer', custom: true },
  48. { label: '发送时间', model: 'time', type: 'datetime' },
  49. { label: '内容', model: 'content', type: 'textarea' },
  50. { label: '状态', model: 'status', type: 'select' },
  51. ],
  52. rules: {
  53. goods: [{ required: true, message: '商品名称', trigger: 'change' }],
  54. spec: [{ required: true, message: '商品规格', trigger: 'change' }],
  55. leader_price: [{ required: true, message: '团长价', trigger: 'blur' }],
  56. price: [{ required: true, message: '团购价', trigger: 'blur' }],
  57. leader_get: [{ required: true, message: '团长提成金额', trigger: 'blur' }],
  58. freight: [{ required: true, message: '运费', trigger: 'blur' }],
  59. },
  60. form: {},
  61. // 加载
  62. loading: false,
  63. // 远程搜索团长列表
  64. customerList: [],
  65. // 规格列表
  66. statusList: [],
  67. };
  68. },
  69. created() {
  70. this.searchOthers();
  71. this.search();
  72. },
  73. methods: {
  74. ...users({ usersQuery: 'query', usersFetch: 'fetch' }),
  75. ...dictData({ dictQuery: 'query' }),
  76. ...notice(['query', 'delete', 'fetch', 'update', 'create']),
  77. // 查询
  78. async search() {
  79. if (this.id) {
  80. const res = await this.fetch(this.id);
  81. if (this.$checkRes(res)) {
  82. let list = [];
  83. list.push(res.data.customer);
  84. res.data.customer = list;
  85. this.$set(this, `form`, res.data);
  86. }
  87. }
  88. this.loadings = false;
  89. },
  90. // 远程查询
  91. async querySearch(value) {
  92. this.loading = true;
  93. let res = await this.usersQuery({ name: value, is_leader: '0' });
  94. if (this.$checkRes(res)) this.$set(this, 'customerList', res.data);
  95. this.loading = false;
  96. },
  97. // 保存
  98. async toSave({ data }) {
  99. let res;
  100. if (data._id) res = await this.update(data);
  101. else res = await this.create(data);
  102. if (this.$checkRes(res)) {
  103. this.$message({ type: `success`, message: `维护信息成功` });
  104. this.toBack();
  105. }
  106. },
  107. // 返回
  108. toBack() {
  109. this.$emit('toBack');
  110. },
  111. // 查询其他信息
  112. async searchOthers() {
  113. let res;
  114. res = await this.dictQuery({ code: 'notice_status' });
  115. if (this.$checkRes(res)) this.$set(this, `statusList`, res.data);
  116. // 团长列表
  117. res = await this.usersQuery({ is_leader: '0' });
  118. if (this.$checkRes(res)) {
  119. // for (const p1 of res.data) {
  120. // p1.name = '团长' + '---' + p1.phone + '---' + p1.name;
  121. // }
  122. this.$set(this, `customerList`, res.data);
  123. }
  124. },
  125. },
  126. computed: {
  127. ...mapState(['user']),
  128. },
  129. metaInfo() {
  130. return { title: this.$route.meta.title };
  131. },
  132. watch: {
  133. test: {
  134. deep: true,
  135. immediate: true,
  136. handler(val) {},
  137. },
  138. },
  139. };
  140. </script>
  141. <style lang="less" scoped></style>