promotionUp-add-or-update.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <el-dialog
  3. :title="!dataForm.id ? this.$i18n.t('crud.addTitle') : this.$i18n.t('temp.modify')"
  4. :close-on-click-modal="false"
  5. :visible.sync="visible">
  6. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
  7. <el-row>
  8. <el-col :span="10">
  9. <el-form-item label="推广人" prop="tgUserName" :rules="{required: true, message: '推广人必填', trigger: 'blur'}" size="small">
  10. <el-input v-model="dataForm.tgUserName"></el-input>
  11. </el-form-item>
  12. </el-col>
  13. <el-col :span="10" :offset="1">
  14. <el-form-item label="推广店铺" prop="shopId" :rules="{required: true, message: '推广店铺必填', trigger: 'blur'}" size="small">
  15. <el-select v-model="dataForm.shopId" placeholder="推广店铺" style="width: 330px" @change="shopChange"
  16. controls-position="right" :clearable="true">
  17. <el-option v-for="(item,index) in shopList" :key="index" :label="item.shopName" :value="item.shopId">
  18. </el-option>
  19. </el-select>
  20. </el-form-item>
  21. </el-col>
  22. </el-row>
  23. <el-row>
  24. <el-col :span="10">
  25. <el-form-item label="博主ID" prop="upId" size="small">
  26. <el-input v-model="dataForm.upId"></el-input>
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="10" :offset="1">
  30. <el-form-item label="博主名称" prop="upName" :rules="{required: true, message: '博主昵称必填', trigger: 'blur'}" size="small">
  31. <el-input v-model="dataForm.upName"></el-input>
  32. </el-form-item>
  33. </el-col>
  34. </el-row>
  35. <el-row>
  36. <el-col :span="10">
  37. <el-form-item label="视频平台" prop="publishPlatform" size="small">
  38. <el-autocomplete
  39. class="inline-input"
  40. v-model="dataForm.publishPlatform"
  41. :fetch-suggestions="querySearch"
  42. placeholder="请输入内容"
  43. style="width :330px;">
  44. <template slot-scope="{ item }">
  45. <div class="name">{{ item.label }}</div>
  46. </template>
  47. </el-autocomplete>
  48. </el-form-item>
  49. </el-col>
  50. <el-col :span="10" :offset="1">
  51. <el-form-item label="粉丝数" prop="fansNum" size="small">
  52. <el-input v-model="dataForm.fansNum" type="number"></el-input>
  53. </el-form-item>
  54. </el-col>
  55. </el-row>
  56. </el-form>
  57. <span slot="footer" class="dialog-footer">
  58. <el-button class="default-btn" @click="visible = false">{{$t("crud.filter.cancelBtn")}}</el-button>
  59. <el-button class="default-btn primary-btn" type="primary" @click="dataFormSubmit()">{{$t("crud.filter.submitBtn")}}</el-button>
  60. </span>
  61. </el-dialog>
  62. </template>
  63. <script>
  64. export default {
  65. data () {
  66. return {
  67. visible: false,
  68. dataForm: {
  69. id: null,
  70. upId: null,
  71. upName: null,
  72. publishPlatform: null,
  73. fansNum: null,
  74. tgUserName: null,
  75. shopId: this.$store.state.user.shopId,
  76. shopName: null
  77. },
  78. dataRule: {
  79. },
  80. shopList:[],
  81. videoPlatformList: [
  82. {value: '抖音', label: '抖音'},
  83. {value: '小红书', label: '小红书'},
  84. {value: '视频号', label: '视频号'},
  85. {value: '快手', label: '快手'},
  86. {value: 'B站', label: 'B站'},
  87. ],
  88. }
  89. },
  90. mounted() {
  91. this.getShopList()
  92. },
  93. methods: {
  94. init (id) {
  95. this.dataForm.id = id || 0
  96. this.visible = true
  97. this.$nextTick(() => {
  98. this.$refs['dataForm'].resetFields()
  99. if (this.dataForm.id) {
  100. this.$http({
  101. url: this.$http.adornUrl('/promotion/promotionUp/info/' + this.dataForm.id),
  102. method: 'get',
  103. params: this.$http.adornParams()
  104. }).then(({data}) => {
  105. this.dataForm = data
  106. })
  107. }
  108. })
  109. },
  110. shopChange (index) {
  111. this.dataForm.shopName = this.shopList[index].shopName
  112. },
  113. getShopList() {
  114. this.$http({
  115. url: this.$http.adornUrl('/platform/shopDetail/getShopList'),
  116. method: 'get',
  117. params: this.$http.adornParams({})
  118. }).then(({ data }) => {
  119. if (data) {
  120. this.shopList = data
  121. }
  122. })
  123. },
  124. querySearch (queryString, cb) {
  125. var restaurants = this.videoPlatformList
  126. var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants
  127. // 调用 callback 返回建议列表的数据
  128. cb(results)
  129. },
  130. createFilter (queryString) {
  131. return (restaurant) => {
  132. return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0)
  133. }
  134. },
  135. // 表单提交
  136. dataFormSubmit () {
  137. this.$refs['dataForm'].validate((valid) => {
  138. if (valid) {
  139. this.dataForm.shopName = this.shopList.find(item => item.shopId === this.dataForm.shopId).shopName
  140. this.$http({
  141. url: this.$http.adornUrl('/promotion/promotionUp'),
  142. method: this.dataForm.id ? 'put' : 'post',
  143. data: this.$http.adornData(this.dataForm)
  144. }).then(({data}) => {
  145. this.$message({
  146. message: this.$i18n.t('publics.operation'),
  147. type: 'success',
  148. duration: 200,
  149. onClose: () => {
  150. this.visible = false
  151. this.$emit('refreshDataList')
  152. }
  153. })
  154. })
  155. }
  156. })
  157. }
  158. }
  159. }
  160. </script>