stockNBComments.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <style lang="scss">
  2. .avatar-uploader .el-upload {
  3. border: 1px dashed #d9d9d9;
  4. border-radius: 6px;
  5. cursor: pointer;
  6. position: relative;
  7. overflow: hidden;
  8. }
  9. .avatar-uploader .el-upload:hover {
  10. border-color: #409eff;
  11. }
  12. .avatar-uploader-icon {
  13. font-size: 28px;
  14. color: #8c939d;
  15. width: 178px;
  16. height: 178px;
  17. line-height: 178px;
  18. text-align: center;
  19. }
  20. .avatar {
  21. width: 178px;
  22. height: 178px;
  23. display: block;
  24. }
  25. </style>
  26. <template>
  27. <section class="content">
  28. <h4>牛人点评</h4>
  29. <el-divider></el-divider>
  30. <el-form label-width="80px" class="filter-form">
  31. <el-row>
  32. <el-col :span="6">
  33. <el-form-item label="股票名称">
  34. <el-input
  35. clearable
  36. @clear="getData()"
  37. v-model="queryParams.stock_name"
  38. placeholder="请输入股票名称/代码"
  39. size="mini"
  40. ></el-input>
  41. </el-form-item>
  42. </el-col>
  43. <el-col :span="6">
  44. <el-form-item label-width="10" style="margin-left: 10px">
  45. <el-button type="primary" @click="getData" size="mini"
  46. >筛选</el-button
  47. >
  48. <el-button
  49. type="primary"
  50. plain
  51. icon="el-icon-plus"
  52. size="mini"
  53. @click="handleAdd"
  54. >新增点评</el-button
  55. >
  56. <!-- <el-button
  57. type="primary"
  58. icon="el-icon-plus"
  59. size="mini"
  60. @click="handleFastAdd"
  61. >新增选手</el-button
  62. > -->
  63. </el-form-item>
  64. </el-col>
  65. </el-row>
  66. </el-form>
  67. <el-table
  68. v-loading="loading"
  69. :data="list"
  70. style="width: 100%; margin-top: 10px"
  71. height="50vh"
  72. >
  73. <el-table-column align="center" prop="stock_name" label="股票名称" />
  74. <el-table-column align="center" prop="stock_code" label="股票代码" />
  75. <el-table-column label="图片">
  76. <template slot-scope="scope">
  77. <el-image
  78. style="width: 80px; height: 60px"
  79. :src="scope.row.img"
  80. :preview-src-list="[scope.row.img]"
  81. >
  82. </el-image>
  83. </template>
  84. </el-table-column>
  85. <el-table-column align="center" prop="content" label="点评内容">
  86. <template slot-scope="scope">
  87. {{ scope.row.content.substring(0, 20) }}...
  88. </template>
  89. </el-table-column>
  90. <el-table-column align="center" prop="ctime" label="创建时间" />
  91. <el-table-column align="center" prop="date" label="操作" width="320">
  92. <template slot-scope="scope">
  93. <el-button @click="edit(scope.row.id)" size="mini" type="warning"
  94. >编辑</el-button
  95. >
  96. <el-button @click="del(scope.row.id)" size="mini" type="danger"
  97. >删除</el-button
  98. >
  99. </template>
  100. </el-table-column>
  101. </el-table>
  102. <Page
  103. ref="pageButton"
  104. :current="form.page"
  105. :page_size="form.page_size"
  106. :total="total"
  107. @pageChange="gopage"
  108. />
  109. <!-- 新增用户 -->
  110. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  111. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  112. <el-form-item label="股票" prop="stock_id">
  113. <el-select
  114. @change="changeStock"
  115. v-model="form.stock_id"
  116. placeholder="请输入股票名称"
  117. filterable
  118. remote
  119. :remote-method="remoteMethod"
  120. >
  121. <el-option
  122. v-for="item in stockList"
  123. :key="item.value"
  124. :label="item.label"
  125. :value="item.id"
  126. >
  127. </el-option>
  128. </el-select>
  129. </el-form-item>
  130. <el-form-item label="图片" prop="">
  131. <el-upload
  132. class="avatar-uploader"
  133. action="/api/admin/uploadfile"
  134. :data="{ watermark: 0 }"
  135. :show-file-list="false"
  136. :on-success="handleAvatarSuccess"
  137. :before-upload="beforeAvatarUpload"
  138. >
  139. <img v-if="form.img" :src="form.img" class="avatar" />
  140. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  141. </el-upload>
  142. </el-form-item>
  143. <el-form-item label="点评内容" prop="content">
  144. <el-input
  145. clearable
  146. v-model="form.content"
  147. placeholder="请输入点评内容"
  148. type="textarea"
  149. rows="10"
  150. ></el-input>
  151. </el-form-item>
  152. </el-form>
  153. <div slot="footer" class="dialog-footer">
  154. <el-button type="primary" @click="submitForm">确 定</el-button>
  155. <el-button @click="open = false">取 消</el-button>
  156. </div>
  157. </el-dialog>
  158. </section>
  159. </template>
  160. <script>
  161. import Page from "../../components/Page";
  162. export default {
  163. components: {
  164. Page,
  165. },
  166. data() {
  167. return {
  168. loading: false,
  169. queryParams: {
  170. page: 1,
  171. },
  172. form: {},
  173. form1: {},
  174. form2: {},
  175. list: [{}, {}],
  176. total: 0,
  177. title: "新增用户",
  178. open: false,
  179. stockList: [],
  180. rules: {
  181. username: [
  182. {
  183. required: true,
  184. message: "请输入用户名",
  185. trigger: "blur",
  186. },
  187. ],
  188. player_type: [
  189. {
  190. required: true,
  191. message: "请选择用户类型",
  192. trigger: "change",
  193. },
  194. ],
  195. phone: [
  196. {
  197. required: true,
  198. message: "请输入用户手机号",
  199. trigger: "blur",
  200. },
  201. ],
  202. avatar: [
  203. {
  204. required: true,
  205. message: "请输入用户手机号",
  206. trigger: "change",
  207. },
  208. ],
  209. },
  210. };
  211. },
  212. methods: {
  213. del(id) {
  214. this.$confirm("删除用户会删除相关数据,确定删除吗?", "提示", {
  215. type: "warning",
  216. }).then(() => {
  217. this.$api
  218. .delStockNBComments({
  219. id: id,
  220. })
  221. .then((res) => {
  222. this.$message({
  223. message: "删除成功",
  224. type: "success",
  225. });
  226. this.getData();
  227. });
  228. });
  229. },
  230. gopage(size) {
  231. if (size) {
  232. this.queryParams.page_size = size;
  233. }
  234. this.queryParams.page = this.$refs.pageButton.page;
  235. this.getData();
  236. },
  237. getData() {
  238. this.loading = true;
  239. this.$api.getStockNBCommentsList(this.queryParams).then((res) => {
  240. this.list = res.data.data.list;
  241. this.total = res.data.data.total;
  242. this.loading = false;
  243. });
  244. },
  245. handleAdd() {
  246. this.open = true;
  247. this.title = "新增牛人点评";
  248. this.form = {};
  249. },
  250. edit(id) {
  251. this.title = "编辑牛人点评";
  252. this.$api
  253. .getStockNBCommentsInfo({
  254. id: id,
  255. })
  256. .then((res) => {
  257. this.form = res.data.data;
  258. this.open = true;
  259. });
  260. },
  261. black(row) {
  262. this.$api
  263. .commentsBlack({
  264. id: row.id,
  265. })
  266. .then((res) => {
  267. this.getData();
  268. });
  269. },
  270. handleAvatarSuccess(res, file) {
  271. this.form.img = res.data.url;
  272. console.log(this.form.img);
  273. },
  274. beforeAvatarUpload(file) {
  275. return;
  276. const isJPG = file.type === "image/jpeg";
  277. const isLt2M = file.size / 1024 / 1024 < 2;
  278. if (!isJPG) {
  279. this.$message.error("上传头像图片只能是 JPG 格式!");
  280. }
  281. if (!isLt2M) {
  282. this.$message.error("上传头像图片大小不能超过 2MB!");
  283. }
  284. return isJPG && isLt2M;
  285. },
  286. /** 提交按钮 */
  287. submitForm() {
  288. this.$refs["form"].validate((valid) => {
  289. if (valid) {
  290. if (this.form.id != null) {
  291. this.$api.editStockNBComments(this.form).then((res) => {
  292. if (res.data.code == 0) {
  293. this.msgSuccess("成功!");
  294. this.open = false;
  295. this.getData();
  296. } else {
  297. this.msgError(res.data.message);
  298. }
  299. });
  300. } else {
  301. this.$api.addStockNBComments(this.form).then((res) => {
  302. if (res.data.code == 0) {
  303. this.msgSuccess("成功!");
  304. this.open = false;
  305. this.getData();
  306. } else {
  307. this.msgError(res.data.message);
  308. }
  309. });
  310. }
  311. }
  312. });
  313. },
  314. remoteMethod(query) {
  315. if (query !== "") {
  316. this.loading = true;
  317. this.$api
  318. .getStockSearchList({
  319. name: query,
  320. })
  321. .then((res) => {
  322. this.stockList = res.data.data;
  323. this.$set(this.stockList, res.data.data);
  324. this.loading = false;
  325. });
  326. } else {
  327. this.stockList = [];
  328. }
  329. }
  330. },
  331. created() {
  332. this.getData();
  333. },
  334. };
  335. </script>