settingProduct.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <template>
  2. <div class="product-content panel">
  3. <div class="panel-header">
  4. <h3 class="header-title">{{ content.name }}设置</h3>
  5. <a class="el-icon-close close-btn" @click="closeRightTemplateHandle"></a>
  6. </div>
  7. <div class="tab">
  8. <span v-for="(item, index) in 3" :key="index" @click="changeLayoutNum(index)"
  9. :class="{ active: index + 1 == content.value.layoutNum }"><i class="el-icon-s-data"></i> {{ index + 1
  10. }}</span>
  11. </div>
  12. <p class="tit">商品列表</p>
  13. <el-button class="add-btn" type="primary" @click="toggleSearchPopup"><i class="el-icon-plus"></i> 添加商品
  14. </el-button>
  15. <template v-if="content.value.productList && content.value.productList.length > 0">
  16. <ul class="list" v-if="content.value.productList && content.value.productList.length > 0">
  17. <div v-for="(item, index) in content.value.productList" :key="index" style="display: flex;">
  18. <li class="item" style="margin-right: 10px !important;">
  19. <img :src="item.pic">
  20. <i class="el-icon-error" @click="deleteItem(index)"></i>
  21. </li>
  22. <div style="flex: 1;min-width: 0;">
  23. <div style="flex: 1;" class="tover">{{ item.title }}</div>
  24. <div style="display: flex;margin-top: 10px;">
  25. <div style="margin-right: 10px;">是否悬浮</div>
  26. <el-switch v-model="item.isFixedNode" @change="fixedNodeChange($event,item)" :active-value="true" :inactive-value="false">
  27. </el-switch>
  28. </div>
  29. </div>
  30. </div>
  31. </ul>
  32. </template>
  33. <div class="options">
  34. <el-form label-width="100px">
  35. <el-form-item label="划线价">
  36. <el-switch v-model="content.value.showOriginalPrice" :active-value="true" :inactive-value="false"
  37. @change="handleDate">
  38. </el-switch>
  39. </el-form-item>
  40. </el-form>
  41. </div>
  42. <el-dialog title="添加商品" :visible.sync="show" @close="close">
  43. <el-form label-width="100px">
  44. <el-form-item label="选择商品">
  45. <el-select v-model="selectProduct" filterable remote reserve-keyword placeholder="请输入商品名称"
  46. :remote-method="searchProductList" @change="addProduct" :loading="loading">
  47. <el-option v-for="item in productList" :key="item.productId" :label="item.productName"
  48. :value-key="item.productName" :value="item">
  49. </el-option>
  50. </el-select>
  51. </el-form-item>
  52. <el-form-item>
  53. <el-button type="primary" @click="confirm">确定</el-button>
  54. </el-form-item>
  55. </el-form>
  56. </el-dialog>
  57. <!-- 商品导入组件 -->
  58. <productManage v-if="productVisible" :on-success="chooseProductHandle">
  59. </productManage>
  60. </div>
  61. </template>
  62. <script>
  63. import productManage from '@/components/productManage.vue'
  64. export default {
  65. name: 'settingProduct',
  66. components: {
  67. productManage
  68. },
  69. props: ['data'],
  70. data() {
  71. return {
  72. content: JSON.parse(JSON.stringify(this.data)),
  73. list: {},
  74. productList: [],
  75. loading: false,
  76. show: false,
  77. selectItem: null,
  78. selectProduct: '',
  79. options: {
  80. originalPrice: '划线价',
  81. goodRatio: '好评率',
  82. volumeStr: '销量数'
  83. },
  84. loadingOption: false,
  85. productVisible: false
  86. }
  87. },
  88. mounted() {
  89. },
  90. // watch: {
  91. // data: {
  92. // deep: true,
  93. // handler(val) {
  94. // this.content = val;
  95. // },
  96. // },
  97. // },
  98. created() {
  99. this.content.value.isFixedNode = this.getFixedState()
  100. },
  101. methods: {
  102. handleDate() {
  103. this.$emit('updataContent', this.content)
  104. },
  105. closeRightTemplateHandle() {
  106. this.$emit('closeRightTemplateHandle', false)
  107. },
  108. // 改变商品排列数量
  109. changeLayoutNum(index) {
  110. this.content.value.layoutNum = index + 1
  111. this.handleDate()
  112. },
  113. deleteItem(index) {
  114. if(this.content.value.productList[index].isFixedNode)
  115. this.$parent.setFixedNodeContent(this.content,this.content.key,true)
  116. this.content.value.productList.splice(index, 1)
  117. this.handleDate()
  118. },
  119. // 搜索商品
  120. searchProductList(productName) {
  121. this.productList = productList
  122. },
  123. confirm() {
  124. this.content.value.productList.push(this.selectItem)
  125. this.close()
  126. this.handleDate()
  127. },
  128. // 打开商品添加弹框
  129. toggleSearchPopup() {
  130. this.productVisible = true
  131. // this.show = true
  132. },
  133. // 关闭商品添加弹框
  134. close() {
  135. this.show = false
  136. this.selectItem = null
  137. this.selectProduct = ''
  138. },
  139. addProduct(data) {
  140. this.selectItem = data
  141. },
  142. // 选择商品后的回调
  143. chooseProductHandle(val){
  144. this.productVisible = false
  145. val.forEach(item => {
  146. this.content.value.productList.push(item)
  147. });
  148. let map = new Map()
  149. this.content.value.productList = this.content.value.productList.filter((item) => !map.has(item.id.toString()) && map.set(item.id.toString()))
  150. this.handleDate()
  151. },
  152. // 悬浮节点切换判断
  153. fixedNodeChange(val,pitem){
  154. console.log(val,pitem)
  155. let fixedNode = this.$parent.view.filter(item=> item.key=='fixedNode')
  156. if(fixedNode.length>0){
  157. console.log('已存在悬浮节点')
  158. if(val){
  159. console.log('切换悬浮节点')
  160. this.$confirm('当前已存在悬浮组件, 是否替换?', '提示', {
  161. confirmButtonText: '确定',
  162. cancelButtonText: '取消',
  163. type: 'warning'
  164. }).then(() => {
  165. this.content.value.productList.map(item=>{item.isFixedNode = false})
  166. pitem.isFixedNode = true
  167. this.$parent.setFixedNodeContent(this.content,this.content.key)
  168. this.content.value.isFixedNode = this.getFixedState()
  169. this.handleDate()
  170. }).catch(() => {
  171. this.content.value.isFixedNode = this.getFixedState()
  172. });
  173. }else{
  174. this.content.value.productList.map(item=>{item.isFixedNode = false})
  175. this.$parent.setFixedNodeContent(this.content,this.content.key,true)
  176. this.content.value.isFixedNode = this.getFixedState()
  177. this.handleDate()
  178. }
  179. }else{
  180. console.log('未存在悬浮节点')
  181. this.$parent.clickType(this.$parent.typeList.filter(item=> item.key=='fixedNode')[0])
  182. this.content.value.productList.map(item=>{item.isFixedNode = false})
  183. pitem.isFixedNode = true
  184. this.$parent.setFixedNodeContent(this.content,this.content.key)
  185. this.content.value.isFixedNode = this.getFixedState()
  186. this.handleDate()
  187. }
  188. },
  189. getFixedState(){
  190. let fixedNode = this.$parent.view.filter(item=> item.key=='fixedNode'&&item.value.type==this.content.key)
  191. if(fixedNode.length>0){
  192. for(var i=0;i<fixedNode.length;i++){
  193. let item = fixedNode[i]
  194. if(this.content.id==item.value.contentObj.id) {
  195. this.content.value.productList.map(citem=>{
  196. item.value.contentObj.value.productList.map(it=>{
  197. if(it.id==citem.id) citem.isFixedNode = it.isFixedNode
  198. })
  199. })
  200. return true
  201. }
  202. }
  203. }else{
  204. this.content.value.productList.map(citem=>{
  205. citem.isFixedNode = false
  206. })
  207. this.content = JSON.parse(JSON.stringify(this.content))
  208. return false
  209. }
  210. },
  211. }
  212. }
  213. </script>
  214. <style lang="scss" scoped>
  215. .panel {
  216. padding: 0 10px;
  217. }
  218. .panel .panel-header {
  219. position: relative;
  220. height: 40px;
  221. line-height: 40px;
  222. margin-left: 8px;
  223. margin-right: 8px;
  224. vertical-align: middle;
  225. border-bottom: 1px solid #dcdcdc;
  226. box-sizing: border-box;
  227. z-index: 10;
  228. }
  229. .panel .panel-header .header-title {
  230. padding-left: 5px;
  231. font-size: 14px;
  232. color: #29304e;
  233. position: relative;
  234. }
  235. .panel .panel-header .header-title:before {
  236. content: "";
  237. position: absolute;
  238. top: 50%;
  239. left: 0;
  240. transform: translateY(-50%);
  241. width: 3px;
  242. height: 18px;
  243. background: #1890ff;
  244. opacity: 1;
  245. border-radius: 2px;
  246. }
  247. .panel .panel-header .close-btn {
  248. position: absolute;
  249. top: 12px;
  250. right: 0;
  251. border: none;
  252. outline: none;
  253. cursor: pointer;
  254. color: #999;
  255. font-weight: 700;
  256. }
  257. .product-content {
  258. padding: 0 15px;
  259. }
  260. .product-content h2 {
  261. font-size: 16px;
  262. color: #333;
  263. }
  264. .product-content .tab {
  265. display: flex;
  266. justify-content: space-around;
  267. border: 1px solid #ddd;
  268. border-radius: 6px;
  269. margin-top: 10px;
  270. }
  271. .product-content .tab span {
  272. width: 33.33%;
  273. text-align: center;
  274. font-size: 14px;
  275. color: #666;
  276. display: block;
  277. height: 36px;
  278. line-height: 36px;
  279. cursor: pointer;
  280. }
  281. .product-content .tab span.active {
  282. color: #fff;
  283. background: #409eff;
  284. border-radius: 2px;
  285. }
  286. .product-content .tab span:nth-of-type(2) {
  287. border-left: 1px solid #ddd;
  288. border-right: 1px solid #ddd;
  289. }
  290. .product-content .tit {
  291. text-align: center;
  292. font-size: 12px;
  293. color: #666;
  294. margin: 18px 0;
  295. padding-bottom: 10px;
  296. border-bottom: 1px dashed #ddd;
  297. }
  298. .product-content .add-btn {
  299. width: calc(100% - 30px);
  300. height: 34px;
  301. line-height: 34px;
  302. padding: 0;
  303. font-size: 12px;
  304. margin-left: 15px;
  305. margin-top: 5px;
  306. }
  307. .product-content .list {
  308. // display: flex;
  309. // flex-wrap: wrap;
  310. padding: 12px;
  311. margin: 0;
  312. }
  313. .product-content .list .item {
  314. width: 70px;
  315. height: 70px;
  316. border-radius: 6px;
  317. margin: 4px;
  318. position: relative;
  319. transition: all .3s;
  320. list-style: none;
  321. }
  322. .product-content .list .item img {
  323. width: 100%;
  324. height: 100%;
  325. border-radius: 4px;
  326. }
  327. .product-content .list .item i {
  328. position: absolute;
  329. top: -6px;
  330. right: -6px;
  331. cursor: pointer;
  332. opacity: 0;
  333. transition: all .3s;
  334. color: red;
  335. }
  336. .product-content .list .item::before {
  337. content: '';
  338. height: 100%;
  339. width: 100%;
  340. position: absolute;
  341. top: 0;
  342. right: 0;
  343. background: rgba(0, 0, 0, 0.4);
  344. border-radius: 4px;
  345. opacity: 0;
  346. transition: all .3s;
  347. }
  348. .product-content .list .item:hover {
  349. cursor: grab;
  350. }
  351. .product-content .list .item:hover::before,
  352. .product-content .list .item:hover i {
  353. opacity: 1;
  354. }
  355. .product-content .options {
  356. padding: 15px;
  357. border-radius: 6px;
  358. }
  359. .product-content .options .el-form {
  360. background: #f7f8f9;
  361. overflow: hidden;
  362. padding: 10px 0;
  363. }
  364. .product-content .options .el-form .el-form-item {
  365. margin: 0;
  366. }
  367. .product-content .options .el-form .el-form-item label {
  368. font-size: 12px;
  369. }
  370. .tover{text-overflow: ellipsis;white-space: nowrap;overflow: hidden;}
  371. </style>