tool-select-link.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <div class="module-box link-select" :class="styleType && 'style'+styleType">
  3. <div class="link-select__warp">
  4. <div class="module-box__title">
  5. <label class="module-box__label">{{title}}</label>
  6. </div>
  7. <el-select class="link-select__select" :popper-append-to-body="false" v-model="selsectValue" placeholder="请选择跳转到的页面" @change="selectChanged">
  8. <el-option
  9. v-for="item in options"
  10. :key="item.value"
  11. :label="item.label"
  12. :value="item.value">
  13. </el-option>
  14. </el-select>
  15. </div>
  16. <div class="link-select__confirm" v-show="confirmBtnVisible">
  17. <div class="btn" v-if="!selectName" @click="openDialog">
  18. <span class="iconfont">&#xe685;</span> 添加{{typeText}}
  19. </div>
  20. <div class="info" v-else>
  21. <span class="text">{{typeText}}</span>
  22. <span class="name">{{selectName}}</span>
  23. <span class="iconfont" @click="openDialog">&#xe66c;</span>
  24. <span class="iconfont" @click="delSelect">&#xe651;</span>
  25. </div>
  26. </div>
  27. <el-dialog width="600px" title="选择类别" :visible.sync="categoryVisible">
  28. <category-select ref="categorySelect"></category-select>
  29. <span slot="footer" class="dialog-footer">
  30. <el-button @click="categoryVisible = false">取 消</el-button>
  31. <el-button type="primary" @click="categoryChanged">确 定</el-button>
  32. </span>
  33. </el-dialog>
  34. <el-dialog title="选择商品" :visible.sync="productVisible">
  35. <product-select ref="productSelect"></product-select>
  36. <span slot="footer" class="dialog-footer">
  37. <el-button @click="productVisible = false">取 消</el-button>
  38. <el-button type="primary" @click="productChanged">确 定</el-button>
  39. </span>
  40. </el-dialog>
  41. <el-dialog title="选择店辅" :visible.sync="shopVisible">
  42. <shop-select ref="shopSelect"></shop-select>
  43. <span slot="footer" class="dialog-footer">
  44. <el-button @click="shopVisible = false">取 消</el-button>
  45. <el-button type="primary" @click="shopChanged">确 定</el-button>
  46. </span>
  47. </el-dialog>
  48. <el-dialog title="选择自定义页面" :visible.sync="customVisible">
  49. <custom-page-select ref="customPageSelect"></custom-page-select>
  50. <span slot="footer" class="dialog-footer">
  51. <el-button @click="customVisible = false">取 消</el-button>
  52. <el-button type="primary" @click="customChanged">确 定</el-button>
  53. </span>
  54. </el-dialog>
  55. <el-dialog title="选择公告" :visible.sync="noticeVisible">
  56. <notice-select ref="noticeSelect"></notice-select>
  57. <span slot="footer" class="dialog-footer">
  58. <el-button @click="noticeVisible = false">取 消</el-button>
  59. <el-button type="primary" @click="noticeChanged">确 定</el-button>
  60. </span>
  61. </el-dialog>
  62. </div>
  63. </template>
  64. <script>
  65. import ProductSelect from './product-select'
  66. import ShopSelect from './shop-select'
  67. import CategorySelect from './category-select'
  68. import CustomPageSelect from './custom-page-select'
  69. import NoticeSelect from "./notice-select";
  70. export default {
  71. name: 'tool-select-link',
  72. components: {NoticeSelect, CustomPageSelect, CategorySelect, ShopSelect, ProductSelect },
  73. data () {
  74. return {
  75. selsectValue: '',
  76. confirmBtnVisible: false,
  77. selectName: '',
  78. typeText: '',
  79. productVisible: false,
  80. shopVisible: false,
  81. categoryVisible: false,
  82. customVisible: false,
  83. noticeVisible: false
  84. }
  85. },
  86. props: {
  87. title: {
  88. type: String,
  89. default: '链接'
  90. },
  91. styleType: {
  92. type: String,
  93. default: ''
  94. },
  95. linkObj: {
  96. type: Object,
  97. default: () => ({
  98. selsectValue: '',
  99. selectName: '',
  100. typeText: '',
  101. url: ''
  102. })
  103. },
  104. options: {
  105. type: Array,
  106. default: () => [
  107. // {
  108. // value: '/index',
  109. // label: '首页'
  110. // },
  111. {
  112. value: '/category',
  113. label: '分类页面'
  114. },
  115. {
  116. value: '/shop',
  117. label: '店辅主页'
  118. },
  119. {
  120. value: '/detail',
  121. label: '商品详情'
  122. },
  123. {
  124. value: '/notice',
  125. label: '公告'
  126. },
  127. // {
  128. // value: '/custom',
  129. // label: '自定义页面'
  130. // }
  131. ]
  132. }
  133. },
  134. mounted () {
  135. this.selsectValue = this.linkObj.selsectValue
  136. this.selectName = this.linkObj.selectName
  137. this.typeText = this.linkObj.typeText
  138. this.confirmBtnVisible = this.selsectValue !== '/index' && this.selsectValue
  139. },
  140. methods: {
  141. // 链接选择
  142. selectChanged (value) {
  143. this.categoryVisible = false
  144. this.shopVisible = false
  145. this.productVisible = false
  146. this.confirmBtnVisible = true
  147. this.selectName = ''
  148. this.typeText = ''
  149. switch (value) {
  150. case '/category':
  151. this.typeText = '类别'
  152. break
  153. case '/shop':
  154. this.typeText = '店辅'
  155. break
  156. case '/detail':
  157. this.typeText = '商品'
  158. break
  159. case '/custom':
  160. this.typeText = '自定义'
  161. case '/notice':
  162. this.typeText = '公告'
  163. break
  164. default:
  165. this.confirmBtnVisible = false
  166. let linkObj = {
  167. selsectValue: this.selsectValue,
  168. selectName: '',
  169. typeText: '',
  170. url: '/'
  171. }
  172. this.$emit('update:linkObj', linkObj)
  173. }
  174. },
  175. // 打开添加弹窗
  176. openDialog () {
  177. switch (this.typeText) {
  178. case '类别':
  179. this.categoryVisible = true
  180. break
  181. case '店辅':
  182. this.shopVisible = true
  183. break
  184. case '商品':
  185. this.productVisible = true
  186. break
  187. case '自定义':
  188. this.customVisible = true
  189. case '公告':
  190. this.noticeVisible = true
  191. break
  192. }
  193. },
  194. // 类别选择
  195. categoryChanged () {
  196. let nodesObj = this.$refs.categorySelect.$refs['cascader'].getCheckedNodes()
  197. if (nodesObj) {
  198. var data = nodesObj[0].data
  199. this.selectName = nodesObj[0].label
  200. this.categoryVisible = false
  201. let linkObj = {
  202. selsectValue: this.selsectValue,
  203. selectName: this.selectName,
  204. typeText: this.typeText,
  205. data: data
  206. }
  207. this.$emit('update:linkObj', linkObj)
  208. }
  209. },
  210. // 商品选择
  211. productChanged () {
  212. console.log(this.$refs.productSelect)
  213. var data = this.$refs.productSelect.tableRadio
  214. this.productVisible = false
  215. this.selectName = this.$refs.productSelect.tableRadio.productName
  216. let linkObj = {
  217. selsectValue: this.selsectValue,
  218. selectName: this.selectName,
  219. typeText: this.typeText,
  220. data: data
  221. }
  222. this.$emit('update:linkObj', linkObj)
  223. },
  224. // 店辅选择
  225. shopChanged () {
  226. var data = this.$refs.shopSelect.tableRadio
  227. this.shopVisible = false
  228. this.selectName = this.$refs.shopSelect.tableRadio.shopName
  229. let linkObj = {
  230. selsectValue: this.selsectValue,
  231. selectName: this.selectName,
  232. typeText: this.typeText,
  233. data: data
  234. }
  235. this.$emit('update:linkObj', linkObj)
  236. },
  237. // 自定义页面选择
  238. customChanged () {
  239. var data = this.$refs.customPageSelect.tableRadio
  240. this.customVisible = false
  241. this.selectName = this.$refs.customPageSelect.tableRadio.name
  242. let linkObj = {
  243. selsectValue: this.selsectValue,
  244. selectName: this.selectName,
  245. typeText: this.typeText,
  246. data: data
  247. }
  248. this.$emit('update:linkObj', linkObj)
  249. },
  250. // 公告选择
  251. noticeChanged () {
  252. var data = this.$refs.noticeSelect.tableRadio
  253. this.noticeVisible = false
  254. this.selectName = this.$refs.noticeSelect.tableRadio.noticeTitle
  255. let linkObj = {
  256. selsectValue: this.selsectValue,
  257. selectName: this.selectName,
  258. typeText: this.typeText,
  259. data: data
  260. }
  261. this.$emit('update:linkObj', linkObj)
  262. },
  263. // 删除选择
  264. delSelect () {
  265. let linkObj = {
  266. selsectValue: '',
  267. selectName: '',
  268. typeText: '',
  269. data: {}
  270. }
  271. this.$emit('update:linkObj', linkObj)
  272. }
  273. },
  274. watch: {
  275. linkObj: {
  276. handler (newVal, oldVal) {
  277. this.selsectValue = newVal.selsectValue
  278. this.selectName = newVal.selectName
  279. this.typeText = newVal.typeText
  280. this.confirmBtnVisible = this.selsectValue !== '/index' && this.selsectValue
  281. },
  282. deep: true
  283. }
  284. }
  285. }
  286. </script>
  287. <style lang="scss" scoped>
  288. .link-select{
  289. &__select{
  290. width: 100%;
  291. }
  292. &__confirm{
  293. margin-top: 10px;
  294. .btn{
  295. text-align: center;
  296. background-color: $mainColor;
  297. color: #fff;
  298. height: 36px;
  299. line-height: 36px;
  300. border-radius: 4px;
  301. cursor: pointer;
  302. }
  303. .info{
  304. height: 36px;
  305. line-height: 36px;
  306. border-radius: 4px;
  307. padding: 0 10px;
  308. border:1px solid $mainColor;
  309. display: flex;
  310. .text{
  311. color: $mainColor;
  312. }
  313. .name{
  314. flex: 1;
  315. margin-left: 10px;
  316. overflow: hidden;
  317. text-overflow:ellipsis;
  318. white-space: nowrap;
  319. }
  320. .iconfont{
  321. margin-left: 10px;
  322. cursor: pointer;
  323. color: #666;
  324. }
  325. }
  326. }
  327. &.style1{
  328. .link-select__warp{
  329. display: flex;
  330. justify-content: space-between;
  331. width: 100%;
  332. align-items: center;
  333. }
  334. width: 100%;
  335. margin-bottom: 0;
  336. .module-box__title{
  337. margin-bottom: 0;
  338. }
  339. .link-select__select{
  340. width: auto;
  341. }
  342. }
  343. }
  344. </style>