set-welcome.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <div class="page">
  3. <div class="list-item" v-for="(item, index) of welcome" :key="index">
  4. <div class="con">
  5. <div class="l-con">
  6. <div class="index">第{{ index + 1 }}条:</div>
  7. <div class="type">{{ item.type | welcomeType }}</div>
  8. </div>
  9. <div class="r-con">
  10. <block v-if="item.type === 1">
  11. <div @click="viewImg(item.content)">
  12. <my-image
  13. class="main-img"
  14. :src="item.content"
  15. ></my-image>
  16. </div>
  17. </block>
  18. <block v-else>{{ item.content }}</block>
  19. </div>
  20. </div>
  21. <div class="tool" @click="menu(item, index)">
  22. <my-image class="menu" src="/static/icon/menu.png"></my-image>
  23. </div>
  24. </div>
  25. <div class="btns">
  26. <button type="button" class="btn" @click="add">
  27. 添加群欢迎消息
  28. </button>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. import MyImage from "../../components/image/index";
  34. let welcomeType = {
  35. 0: "文字",
  36. 1: "图片",
  37. 2: "视频",
  38. 3: "网页链接",
  39. 4: "小程序",
  40. 5: "产品",
  41. 6: "优惠券",
  42. 7: "产品列表",
  43. 8: "首页",
  44. 9: "会员码",
  45. 10: "今日推荐",
  46. 11: "京东首页",
  47. 12: "京东秒杀",
  48. 13: "微信名片",
  49. 14: "平台店铺首页",
  50. 15: "平台产品页",
  51. 16: "平台优惠券",
  52. 17: "平台会员码",
  53. 18: "平台今日推荐",
  54. 19: "平台产品分类页",
  55. 999: "登录码",
  56. };
  57. export default {
  58. name: "",
  59. components: { MyImage },
  60. // 数据
  61. data() {
  62. return {
  63. groupData: {},
  64. welcome: [],
  65. };
  66. },
  67. filters: {
  68. welcomeType(v) {
  69. return welcomeType[v] || "";
  70. },
  71. },
  72. onLoad(opts) {},
  73. async onShow() {
  74. this.getList();
  75. },
  76. // 函数
  77. methods: {
  78. getList() {
  79. let gid = this.$store.state.common.groupData._id;
  80. this.api
  81. .get("/Group/GetGroup", { gid }, { pass: true })
  82. .then((res) => {
  83. this.groupData = res.data;
  84. this.welcome = this.groupData.welcome || [];
  85. });
  86. },
  87. menu(item, index) {
  88. // "上移", "下移"
  89. let arr = ["编辑", "删除"];
  90. if (index !== 0) {
  91. arr.push("上移");
  92. }
  93. if (index !== this.welcome.length - 1) {
  94. arr.push("下移");
  95. }
  96. uni.showActionSheet({
  97. itemList: arr,
  98. success: (res) => {
  99. let tapIndex = res.tapIndex;
  100. switch (arr[tapIndex]) {
  101. case "编辑":
  102. this.edit(item, index);
  103. break;
  104. case "删除":
  105. this.remove(item, index);
  106. break;
  107. case "上移":
  108. this.up(item, index);
  109. break;
  110. case "下移":
  111. this.down(item, index);
  112. break;
  113. }
  114. console.log(res, item);
  115. },
  116. });
  117. },
  118. edit(v, index) {
  119. this.$store.commit("common/update", {
  120. welcomeData: this.welcome,
  121. welcomeItemData: v,
  122. });
  123. this.router.push({
  124. path: "/pages/assistant/welcome-item",
  125. query: {
  126. type: index,
  127. gid: this.groupData._id,
  128. index
  129. },
  130. });
  131. },
  132. up(v, index) {
  133. let arr = [...this.welcome];
  134. arr.splice(index, 1);
  135. arr.splice(index - 1, 0, v);
  136. let data = {
  137. id: this.groupData._id,
  138. welcome: [...arr],
  139. };
  140. this.api
  141. .post("/Group/SetWelcome", data, { pass: true })
  142. .then((res) => {
  143. this.submitLoading = false;
  144. if (res.success) {
  145. this.fn.showToast("移动成功");
  146. this.welcome = arr;
  147. } else {
  148. this.fn.showModal({
  149. title: "移动失败",
  150. content: "错误信息:" + res.message,
  151. showCancel: false,
  152. });
  153. }
  154. });
  155. },
  156. down(v, index) {
  157. let arr = [...this.welcome];
  158. arr.splice(index, 1);
  159. arr.splice(index + 1, 0, v);
  160. let data = {
  161. id: this.groupData._id,
  162. welcome: [...arr],
  163. };
  164. this.api
  165. .post("/Group/SetWelcome", data, { pass: true })
  166. .then((res) => {
  167. this.submitLoading = false;
  168. if (res.success) {
  169. this.fn.showToast("移动成功");
  170. this.welcome = arr;
  171. } else {
  172. this.fn.showModal({
  173. title: "移动失败",
  174. content: "错误信息:" + res.message,
  175. showCancel: false,
  176. });
  177. }
  178. });
  179. },
  180. remove(v, index) {
  181. this.welcome.splice(index, 1);
  182. console.log(this.welcome, index);
  183. let data = {
  184. id: this.groupData._id,
  185. welcome: this.welcome,
  186. };
  187. this.api
  188. .post("/Group/SetWelcome", data, { pass: true })
  189. .then((res) => {
  190. this.submitLoading = false;
  191. uni.hideLoading();
  192. if (res.success) {
  193. this.fn.showToast("删除成功");
  194. } else {
  195. this.fn.showModal({
  196. title: "删除失败",
  197. content: "错误信息:" + res.message,
  198. showCancel: false,
  199. });
  200. }
  201. });
  202. },
  203. add() {
  204. uni.showActionSheet({
  205. //, , "小程序消息"
  206. itemList: ["文字消息", "图片消息"],
  207. success: (res) => {
  208. let index = res.tapIndex;
  209. this.$store.commit("common/update", {
  210. welcomeData: this.welcome,
  211. });
  212. this.router.push({
  213. path: "/pages/assistant/welcome-item",
  214. query: {
  215. type: index,
  216. gid: this.groupData._id,
  217. },
  218. });
  219. },
  220. });
  221. },
  222. viewImg(url) {
  223. uni.previewImage({
  224. urls: [url],
  225. });
  226. },
  227. },
  228. // 数据计算
  229. computed: {
  230. user() {
  231. return this.$store.state.user.user;
  232. },
  233. },
  234. // 数据监听
  235. watch: {},
  236. };
  237. </script>
  238. <style lang="scss" scoped>
  239. .page {
  240. padding-bottom: 4em;
  241. }
  242. .list-item {
  243. padding: px(40);
  244. display: flex;
  245. justify-content: space-between;
  246. align-items: flex-start;
  247. background-color: #fff;
  248. border-bottom: 1px solid #f1f1f1;
  249. .menu {
  250. width: px(60);
  251. height: px(60);
  252. flex-shrink: 0;
  253. margin-left: px(40);
  254. /deep/ img {
  255. width: px(60);
  256. height: px(60);
  257. }
  258. }
  259. .con {
  260. width: 100%;
  261. display: flex;
  262. align-items: flex-start;
  263. justify-content: space-between;
  264. }
  265. .l-con {
  266. width: px(220);
  267. flex-shrink: 0;
  268. margin-right: px(10);
  269. .index {
  270. font-size: px(44);
  271. }
  272. .type {
  273. font-size: px(42);
  274. margin-top: px(10);
  275. color: #666;
  276. }
  277. }
  278. .r-con {
  279. width: 100%;
  280. font-size: px(44);
  281. line-height: 1.5;
  282. }
  283. }
  284. .btns {
  285. display: flex;
  286. justify-content: space-between;
  287. align-items: center;
  288. position: fixed;
  289. bottom: 0;
  290. left: 0;
  291. right: 0;
  292. z-index: 100;
  293. .btn {
  294. background-color: rgb(0, 188, 38);
  295. color: #fff;
  296. border-radius: 0;
  297. font-size: px(50);
  298. border: none;
  299. width: 100%;
  300. & ~ .btn {
  301. border-left: 1px solid #999;
  302. }
  303. }
  304. }
  305. .main-img {
  306. width: px(200);
  307. height: px(200);
  308. /deep/ img {
  309. width: px(200);
  310. height: px(200);
  311. }
  312. }
  313. </style>