hot_add_edit.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="container add_edit">
  3. <el-form :model="form" :rules="rules" ref="ruleForm" label-width="100px">
  4. <el-form-item label="关键字" prop="keyword" ref="keyword"><el-input v-model="form.keyword"></el-input></el-form-item>
  5. <el-form-item label="排序"><el-input type="number" v-model.number="form.sort" min="0" placeholder="请输入排序"></el-input></el-form-item>
  6. <el-form-item>
  7. <el-button class="confirm_btn" @click="submitForm('ruleForm')">确 定</el-button>
  8. <el-button @click="returnPage">返回列表</el-button>
  9. </el-form-item>
  10. </el-form>
  11. </div>
  12. </template>
  13. <script>
  14. import bus from '@/common/bus';
  15. const __name = 'usemall-search-hot';
  16. export default {
  17. data() {
  18. return {
  19. dataId: '',
  20. form: {
  21. search_cnt: 0,
  22. keyword: '',
  23. sort: 0,
  24. },
  25. rules: {
  26. keyword: [
  27. {
  28. required: true,
  29. message: '关键字不能为空',
  30. trigger: 'change'
  31. }
  32. ]
  33. },
  34. now_date:'',
  35. };
  36. },
  37. methods: {
  38. loadData() {
  39. if (!this.dataId) {
  40. return;
  41. }
  42. // this.$db[__name].tofirst(this.dataId).then(res => {
  43. // if (res.code == 200) {
  44. // for (let item in this.form) {
  45. // this.form[item] = res.datas[item];
  46. // }
  47. // this.imageValue = {};
  48. // this.imageValue.url = this.form.img;
  49. // }
  50. // });
  51. },
  52. submitForm(formName) {
  53. this.getNowDate()
  54. this.$refs[formName].validate((valid, obj) => {
  55. // 默认获取第一个未验证 form 属性名
  56. this.$api.set_unvalidated_form_focus(this, obj);
  57. if (valid) {
  58. if (!this.dataId) {//新增
  59. var _self=this
  60. //新增热门搜索
  61. _self.$axios.post("/searchHot/admin/add",
  62. {
  63. "createBy": uni.getStorageSync("nickName"),
  64. "createTime": _self.now_date,
  65. "keyword": _self.form.keyword,
  66. "searchCnt": _self.form.search_cnt,
  67. "sort": _self.form.sort
  68. },
  69. {
  70. headers:{
  71. 'Mall-Token': uni.getStorageSync("token")
  72. }
  73. }
  74. ).then(response => {
  75. let res = response
  76. if (res.success) {
  77. _self.getOpenerEventChannel().emit('loadData');
  78. _self.returnPage();
  79. } else {
  80. }
  81. }).catch(res =>{
  82. });
  83. // this.$db[__name].add(this.form).then(res => {
  84. // if (res.code == 200) {
  85. // this.getOpenerEventChannel().emit('loadData');
  86. // this.returnPage();
  87. // }
  88. // });
  89. } else {
  90. this.$db[__name].update(this.dataId, this.form).then(res => {
  91. if (res.code == 200) {
  92. this.getOpenerEventChannel().emit('loadData');
  93. this.returnPage();
  94. }
  95. });
  96. }
  97. }
  98. });
  99. },
  100. //获取当前时间
  101. getNowDate() {
  102. var _this = this;
  103. // this.timer = setInterval(function() {
  104. var aData = new Date();
  105. var month = aData.getMonth() < 9 ? "0" + (aData.getMonth() + 1) : aData.getMonth() + 1;
  106. var date = aData.getDate() <= 9 ? "0" + aData.getDate() : aData.getDate();
  107. var date2 = aData.getDate() <= 9 ? "0" + (aData.getDate()-1) : (aData.getDate()-1);
  108. var Hour = aData.getHours() <= 9 ? "0" + (aData.getHours()) : aData.getHours();
  109. var Miunte = aData.getMinutes() <= 9 ? "0" + (aData.getMinutes()) : aData.getMinutes();
  110. var Seconds = aData.getSeconds() <= 9 ? "0" + (aData.getSeconds()) : aData.getSeconds();
  111. // console.log(aData.getTime())
  112. _this.now_date = aData.getFullYear() + "-" + month + "-" + date + ' '+ Hour +":"+ Miunte +":"+ Seconds;
  113. // console.log(aData.getFullYear() + "-" + month + "-" + date2)昨天
  114. // }, 86400000);
  115. },
  116. returnPage() {
  117. bus.$emit('tab-close');
  118. this.$router.push('/pages/shop/search/page');
  119. }
  120. },
  121. created() {
  122. this.dataId = this.$route.query.id || '';
  123. this.loadData();
  124. }
  125. };
  126. </script>
  127. <style ></style>