tool-select-link.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. </div>
  56. </template>
  57. <script>
  58. import ProductSelect from './product-select'
  59. import ShopSelect from './shop-select'
  60. import CategorySelect from './category-select'
  61. import CustomPageSelect from './custom-page-select'
  62. export default {
  63. name: 'tool-select-link',
  64. components: { CustomPageSelect, CategorySelect, ShopSelect, ProductSelect },
  65. data () {
  66. return {
  67. selsectValue: '',
  68. confirmBtnVisible: false,
  69. selectName: '',
  70. typeText: '',
  71. productVisible: false,
  72. shopVisible: false,
  73. categoryVisible: false,
  74. customVisible: false
  75. }
  76. },
  77. props: {
  78. title: {
  79. type: String,
  80. default: '链接'
  81. },
  82. styleType: {
  83. type: String,
  84. default: ''
  85. },
  86. linkObj: {
  87. type: Object,
  88. default: () => ({
  89. selsectValue: '',
  90. selectName: '',
  91. typeText: '',
  92. url: ''
  93. })
  94. },
  95. options: {
  96. type: Array,
  97. default: () => [
  98. // {
  99. // value: '/index',
  100. // label: '首页'
  101. // },
  102. {
  103. value: '/category',
  104. label: '分类页面'
  105. },
  106. {
  107. value: '/shop',
  108. label: '店辅主页'
  109. },
  110. {
  111. value: '/detail',
  112. label: '商品详情'
  113. },
  114. // {
  115. // value: '/custom',
  116. // label: '自定义页面'
  117. // }
  118. ]
  119. }
  120. },
  121. mounted () {
  122. this.selsectValue = this.linkObj.selsectValue
  123. this.selectName = this.linkObj.selectName
  124. this.typeText = this.linkObj.typeText
  125. this.confirmBtnVisible = this.selsectValue !== '/index' && this.selsectValue
  126. },
  127. methods: {
  128. // 链接选择
  129. selectChanged (value) {
  130. this.categoryVisible = false
  131. this.shopVisible = false
  132. this.productVisible = false
  133. this.confirmBtnVisible = true
  134. this.selectName = ''
  135. this.typeText = ''
  136. switch (value) {
  137. case '/category':
  138. this.typeText = '类别'
  139. break
  140. case '/shop':
  141. this.typeText = '店辅'
  142. break
  143. case '/detail':
  144. this.typeText = '商品'
  145. break
  146. case '/custom':
  147. this.typeText = '自定义'
  148. break
  149. default:
  150. this.confirmBtnVisible = false
  151. let linkObj = {
  152. selsectValue: this.selsectValue,
  153. selectName: '',
  154. typeText: '',
  155. url: '/'
  156. }
  157. this.$emit('update:linkObj', linkObj)
  158. }
  159. },
  160. // 打开添加弹窗
  161. openDialog () {
  162. switch (this.typeText) {
  163. case '类别':
  164. this.categoryVisible = true
  165. break
  166. case '店辅':
  167. this.shopVisible = true
  168. break
  169. case '商品':
  170. this.productVisible = true
  171. break
  172. case '自定义':
  173. this.customVisible = true
  174. break
  175. }
  176. },
  177. // 类别选择
  178. categoryChanged () {
  179. let nodesObj = this.$refs.categorySelect.$refs['cascader'].getCheckedNodes()
  180. if (nodesObj) {
  181. var data = nodesObj[0].data
  182. this.selectName = nodesObj[0].label
  183. this.categoryVisible = false
  184. let linkObj = {
  185. selsectValue: this.selsectValue,
  186. selectName: this.selectName,
  187. typeText: this.typeText,
  188. data: data
  189. }
  190. this.$emit('update:linkObj', linkObj)
  191. }
  192. },
  193. // 商品选择
  194. productChanged () {
  195. console.log(this.$refs.productSelect)
  196. var data = this.$refs.productSelect.tableRadio
  197. this.productVisible = false
  198. this.selectName = this.$refs.productSelect.tableRadio.productName
  199. let linkObj = {
  200. selsectValue: this.selsectValue,
  201. selectName: this.selectName,
  202. typeText: this.typeText,
  203. data: data
  204. }
  205. this.$emit('update:linkObj', linkObj)
  206. },
  207. // 店辅选择
  208. shopChanged () {
  209. var data = this.$refs.shopSelect.tableRadio
  210. this.shopVisible = false
  211. this.selectName = this.$refs.shopSelect.tableRadio.shopName
  212. let linkObj = {
  213. selsectValue: this.selsectValue,
  214. selectName: this.selectName,
  215. typeText: this.typeText,
  216. data: data
  217. }
  218. this.$emit('update:linkObj', linkObj)
  219. },
  220. // 自定义页面选择
  221. customChanged () {
  222. var data = this.$refs.customPageSelect.tableRadio
  223. this.customVisible = false
  224. this.selectName = this.$refs.customPageSelect.tableRadio.name
  225. let linkObj = {
  226. selsectValue: this.selsectValue,
  227. selectName: this.selectName,
  228. typeText: this.typeText,
  229. data: data
  230. }
  231. this.$emit('update:linkObj', linkObj)
  232. },
  233. // 删除选择
  234. delSelect () {
  235. let linkObj = {
  236. selsectValue: '',
  237. selectName: '',
  238. typeText: '',
  239. data: {}
  240. }
  241. this.$emit('update:linkObj', linkObj)
  242. }
  243. },
  244. watch: {
  245. linkObj: {
  246. handler (newVal, oldVal) {
  247. this.selsectValue = newVal.selsectValue
  248. this.selectName = newVal.selectName
  249. this.typeText = newVal.typeText
  250. this.confirmBtnVisible = this.selsectValue !== '/index' && this.selsectValue
  251. },
  252. deep: true
  253. }
  254. }
  255. }
  256. </script>
  257. <style lang="scss" scoped>
  258. .link-select{
  259. &__select{
  260. width: 100%;
  261. }
  262. &__confirm{
  263. margin-top: 10px;
  264. .btn{
  265. text-align: center;
  266. background-color: $mainColor;
  267. color: #fff;
  268. height: 36px;
  269. line-height: 36px;
  270. border-radius: 4px;
  271. cursor: pointer;
  272. }
  273. .info{
  274. height: 36px;
  275. line-height: 36px;
  276. border-radius: 4px;
  277. padding: 0 10px;
  278. border:1px solid $mainColor;
  279. display: flex;
  280. .text{
  281. color: $mainColor;
  282. }
  283. .name{
  284. flex: 1;
  285. margin-left: 10px;
  286. overflow: hidden;
  287. text-overflow:ellipsis;
  288. white-space: nowrap;
  289. }
  290. .iconfont{
  291. margin-left: 10px;
  292. cursor: pointer;
  293. color: #666;
  294. }
  295. }
  296. }
  297. &.style1{
  298. .link-select__warp{
  299. display: flex;
  300. justify-content: space-between;
  301. width: 100%;
  302. align-items: center;
  303. }
  304. width: 100%;
  305. margin-bottom: 0;
  306. .module-box__title{
  307. margin-bottom: 0;
  308. }
  309. .link-select__select{
  310. width: auto;
  311. }
  312. }
  313. }
  314. </style>