customer.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <div id="app" v-cloak>
  2. <div class="container">
  3. <el-card shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  4. <div slot="header">
  5. <div class="flex flex-x-between flex-y-center">
  6. <span>客服设置</span>
  7. </div>
  8. </div>
  9. </el-card>
  10. <div class="content_form">
  11. <el-form :model="formData" ref="elForm" label-width="180px" style="position: relative;">
  12. <el-alert title="警告:如果开启客服必须填写外部客服链接" type="warning" :closable="false"></el-alert>
  13. <el-form-item label="是否开启客服:" style="margin-top: 10px;">
  14. <el-checkbox v-model="formData.is_customer" label="是否开启" :true-label="1"
  15. :false-label="0"></el-checkbox>
  16. </el-form-item>
  17. <el-form-item :label="item.label" v-for="(item,index) in formData.customer_types">
  18. <div class="el_customer_group">
  19. <el-input :placeholder="getCustomerTypesPlaceholder(item)" v-model="item.url" clearable style="width: 30%;">
  20. </el-input>
  21. </div>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" @click="onSubmitCustomer" size="small">保存数据</el-button>
  25. </el-form-item>
  26. </el-form>
  27. </div>
  28. </div>
  29. </div>
  30. <script>
  31. const app = new Vue({
  32. el: '#app',
  33. data: {
  34. customers: [],
  35. formData: {
  36. is_customer: 0,// 是否开启客服
  37. customer_types: [
  38. {
  39. value: 'official',
  40. url: '',
  41. label: '公众号外部客服链接:'
  42. }
  43. ],// 客服显示类型
  44. },
  45. },
  46. methods: {
  47. getCustomers: function () {
  48. request({
  49. params: {
  50. r: 'store/client/setting/customer',
  51. },
  52. method: 'get',
  53. }).then(e => {
  54. const sourceValues = e.data.data.setting.customer_types.map(obj => obj.value);
  55. const formValues = this.formData.customer_types.map(obj => obj.value);
  56. if (sourceValues.length > formValues.length) {// 当数据库数据长度大于formData长度
  57. let newValues = sourceValues.filter(x => !formValues.includes(x));
  58. if (newValues.length > 0) {
  59. e.data.data.setting.customer_types = e.data.data.setting.customer_types.filter(function (item) {
  60. return !newValues.includes(item.value);
  61. })
  62. }
  63. }
  64. this.formData.customer_types.forEach(item => {
  65. if (!sourceValues.includes(item.value)) {
  66. e.data.data.setting.customer_types.push(item);
  67. }
  68. e.data.data.setting.customer_types.find(obj => obj.value === item.value).label = item.label;
  69. })
  70. this.formData = e.data.data.setting;
  71. }).catch(e => {
  72. })
  73. },
  74. onSubmitCustomer: function () {
  75. request({
  76. params: {
  77. r: 'store/client/setting/customer',
  78. },
  79. method: 'post',
  80. data: this.formData,
  81. }).then(e => {
  82. if (e.data.code === 0) {
  83. this.$message({
  84. message: e.data.msg,
  85. type: 'success',
  86. duration: 2000,
  87. onClose: () => {
  88. this.getCustomers();
  89. }
  90. })
  91. } else {
  92. this.$message.error(e.data.msg);
  93. }
  94. }).catch(e => {
  95. this.$message.error(e.data.msg);
  96. })
  97. },
  98. getCustomerTypesPlaceholder(val) {// 获取客服类型placeholder
  99. return val.value === 'web_view' ? '请填写webview外部客服:例如 group_id=xxx&score=xxx' : '请填写外部客服链接';
  100. }
  101. },
  102. mounted: function () {
  103. this.getCustomers();
  104. }
  105. });
  106. </script>
  107. <style>
  108. .content_form {
  109. padding: 20px;
  110. background: #FFFFFF;
  111. }
  112. .el_customer_group {
  113. display: flex;
  114. justify-content: left;
  115. }
  116. .el-checkbox-group {
  117. margin-left: 20px;
  118. }
  119. </style>