barOptionSection.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <div class="bar-option-wrapper">
  3. <template v-if="dateList.length">
  4. <!-- 排序规则 -->
  5. <div v-if="isBaseBarShow">
  6. <div>
  7. <label style="margin-right: 5px;">排序规则</label>
  8. <el-radio-group v-model="sortObj.sort" @change="() => { sortObj.sortIndex= '';changeSort()}">
  9. <el-radio v-for="item in sortRules" :key="item.key" :label="item.key">{{item.name}}</el-radio>
  10. </el-radio-group>
  11. </div>
  12. <el-select
  13. v-model="sortObj.sortIndex"
  14. v-if="sortObj.sort!==0"
  15. clearable
  16. placeholder="请选择日期"
  17. class="sort-date"
  18. style="width: 100%; margin-top: 20px"
  19. @change="changeSort"
  20. >
  21. <el-option
  22. v-for="(item,index) in dateList"
  23. :key="item.key"
  24. :label="item.RealDate||item.Date"
  25. :value="index"
  26. >
  27. </el-option>
  28. </el-select>
  29. </div>
  30. <el-collapse v-model="activeNames" class="target-list">
  31. <el-collapse-item v-for="(item,index) in dateList" :key="item.EdbInfoId">
  32. <template slot="title">
  33. <span class="text_oneLine"> {{setDynamicTitle(item)}}</span>
  34. <i class="el-icon-edit edit-icon" @click.stop="editDate(item,index)"></i>
  35. <i class="el-icon-delete del-icon" @click.stop="removeDate(index)"></i>
  36. </template>
  37. <ul class="setting-cont">
  38. <li v-if="isBaseBarShow">
  39. <el-input
  40. v-model="item.Name"
  41. style="width: 90%"
  42. placeholder="日期别名"
  43. @change="changeOptions"
  44. />
  45. </li>
  46. <li>
  47. <div style="display: flex">
  48. <span style="margin-right: 3px">颜色:</span>
  49. <el-color-picker
  50. v-model="item.Color"
  51. size="mini"
  52. show-alpha
  53. :predefine="predefineColors"
  54. @change="changeOptions"
  55. ></el-color-picker>
  56. </div>
  57. </li>
  58. </ul>
  59. </el-collapse-item>
  60. </el-collapse>
  61. </template>
  62. <div
  63. class="add-cont"
  64. @click="addDateHandle"
  65. v-if="edblist.length"
  66. >
  67. <img
  68. src="~@/assets/img/set_m/add_ico.png"
  69. alt=""
  70. style="width: 16px; height: 16px; margin-right: 10px"
  71. />
  72. <span>添加日期</span>
  73. </div>
  74. <m-dialog
  75. title="添加日期"
  76. :show.sync="dialogForm.show"
  77. width="650px"
  78. >
  79. <div style="padding-left: 50px">
  80. <el-form
  81. :model="dialogForm"
  82. ref="formRef"
  83. label-position="left"
  84. hide-required-asterisk
  85. label-width="80px">
  86. <el-form-item prop="Type" label="添加方式">
  87. <el-select
  88. v-model="dialogForm.Type"
  89. placeholder="请选择添加方式"
  90. style="width:350px;"
  91. >
  92. <el-option v-for="item in dateOptions" :key="item.key" :label="item.label" :value="item.key"/>
  93. </el-select>
  94. </el-form-item>
  95. <el-form-item label="天数" prop="Value" v-if="dialogForm.Type === 2">
  96. <el-input
  97. type="number"
  98. v-model="dialogForm.Value"
  99. placeholder="请输入数字"
  100. style="width:350px;"
  101. />
  102. </el-form-item>
  103. <el-form-item prop="Type" label="选择日期" v-if="dialogForm.Type === 3">
  104. <el-date-picker
  105. v-model="dialogForm.Date"
  106. value-format="yyyy-MM-dd"
  107. type="date"
  108. placeholder="选择日期"
  109. style="width: 350px"
  110. />
  111. </el-form-item>
  112. </el-form>
  113. </div>
  114. <div slot="footer" style="margin-top: 20px;">
  115. <el-button
  116. @click="cancelDialog"
  117. style="width: 132px; height: 40px"
  118. >取消</el-button>
  119. <el-button
  120. @click="saveDate"
  121. type="primary"
  122. style="width: 132px; height: 40px"
  123. >保存</el-button>
  124. </div>
  125. </m-dialog>
  126. </div>
  127. </template>
  128. <script>
  129. import {
  130. defaultOpts
  131. } from '@/utils/defaultOptions';
  132. import mDialog from '@/components/mDialog.vue'
  133. export default {
  134. components: { mDialog },
  135. props: {
  136. edblist: Array,
  137. datedata: Array,
  138. chartInfo: {
  139. type: Object
  140. },
  141. initData: {
  142. default: null
  143. }
  144. },
  145. watch: {
  146. datedata(newval) {
  147. this.dateList = newval.map((_,index) => ({
  148. ...this.dateList[index],
  149. Color: _.Color,
  150. RealDate: this.dateList[index].Type === 3 ? this.dateList[index].Date : _.Date,
  151. Data: _.Value,
  152. Name: _.Name
  153. }))
  154. }
  155. },
  156. computed: {
  157. /* 判断路由 图库柱状图还是商品价格图 */
  158. isBaseBarShow() {
  159. const show_path = ['/addchart','/editchart']
  160. return show_path.includes(this.$route.path)
  161. }
  162. },
  163. data() {
  164. return {
  165. activeNames: '',
  166. predefineColors: defaultOpts.colors.slice(0, 2), //定义颜色蓝,红 默认颜色
  167. sortObj: {
  168. sort: 0,
  169. sortIndex: ''
  170. },
  171. dateList: [],
  172. sortRules: [
  173. { key:0,name:'默认' },
  174. { key:2,name:'升序' },
  175. { key:1,name:'降序' },
  176. ],
  177. dateMapLabel: {
  178. 1: '最新日期',
  179. 2: 'N天前',
  180. 3: '固定日期'
  181. },
  182. dateOptions: [
  183. { key: 1,label:'最新日期' },
  184. { key: 2,label:'N天前' },
  185. { key: 3,label:'固定日期' },
  186. ],
  187. dialogForm: {
  188. show: false,
  189. Type: 1,
  190. Value: 0,
  191. Date: ''
  192. },
  193. edit_index: 0,
  194. }
  195. },
  196. methods: {
  197. /* 添加日期 */
  198. addDateHandle() {
  199. if(this.$route.path === '/addCommodityChart' && this.$parent.chartInfo.Source===5 && !this.$parent.profitInfo.list.length) return this.$message.warning('请先设置盘面利润配置')
  200. this.dialogForm.show = true;
  201. },
  202. cancelDialog() {
  203. this.edit_index = 0;
  204. this.dialogForm = {
  205. show: false,
  206. Type: 1,
  207. Value: '',
  208. Date: ''
  209. }
  210. },
  211. /* 日期编辑 */
  212. editDate({Type,Date,Value},index) {
  213. this.edit_index = index + 1;
  214. this.dialogForm = {
  215. show: true,
  216. Type,
  217. Value,
  218. Date
  219. }
  220. },
  221. /* 保存日期push日期数组 */
  222. saveDate() {
  223. const { Type,Value,Date } = this.dialogForm;
  224. if( Type === 2 && !Value) return this.$message.warning('天数不能为空')
  225. if( Type === 3 && !Date) return this.$message.warning('日期不能为空')
  226. if(this.edit_index !== 0) {
  227. //修改
  228. this.dateList[this.edit_index-1].Type = Type;
  229. this.dateList[this.edit_index-1].Value = Number(Value);
  230. this.dateList[this.edit_index-1].Date = Date;
  231. } else {
  232. //添加
  233. let date_item = {
  234. Type,
  235. Name: '',
  236. Value: Number(Value),
  237. Date,
  238. Color: ''
  239. }
  240. this.dateList.push(date_item)
  241. let themeOpt = this.chartInfo.ChartThemeStyle ? JSON.parse(this.chartInfo.ChartThemeStyle) : null;
  242. this.dateList.forEach((item,index) => {
  243. item.Color = item.Color || (themeOpt&&themeOpt.colorsOptions[index]||defaultOpts.colors[index]);
  244. })
  245. }
  246. this.cancelDialog()
  247. this.getBarData()
  248. },
  249. /* 改变排序 */
  250. changeSort() {
  251. if(this.sortObj.sort === 0
  252. || (this.sortObj.sort&&this.sortObj.sortIndex!=='')) {
  253. this.getBarData()
  254. }
  255. },
  256. /* 改变配置重绘 不需要请求接口 */
  257. changeOptions(e,index) {
  258. this.getBarData()
  259. },
  260. /* 根据目前配置获取柱形图数据 */
  261. getBarData() {
  262. this.$emit('getData',{
  263. sort: this.sortObj,
  264. dateList: this.dateList
  265. })
  266. },
  267. /* 日期标题 */
  268. setDynamicTitle({Type,RealDate,Date,Value}) {
  269. switch(Type) {
  270. case 1:
  271. return `${RealDate||''}(最新日期)`
  272. case 2:
  273. return this.isBaseBarShow ? `${RealDate||''}(${Value}天前)` : `${Value}天前`
  274. case 3:
  275. return `${Date}(固定日期)`
  276. }
  277. },
  278. /* 移除日期 */
  279. removeDate(index) {
  280. this.dateList.splice(index,1)
  281. this.getBarData();
  282. },
  283. },
  284. mounted () {
  285. if(this.initData) {
  286. const { DateList,Sort } = this.initData;
  287. this.dateList = this.datedata.map((_,index) => ({
  288. ...DateList[index],
  289. Color: _.Color,
  290. RealDate: DateList[index].Type === 3 ? DateList[index].Date : _.Date,
  291. Data: _.Value,
  292. Name: _.Name
  293. }));
  294. this.sortObj = {
  295. sort: Sort.Sort,
  296. sortIndex: Sort.DateIndex
  297. }
  298. }
  299. }
  300. }
  301. </script>
  302. <style lang="scss" scoped>
  303. .bar-option-wrapper {
  304. color: #606266;
  305. .add-cont {
  306. align-items: center;
  307. margin-top: 20px;
  308. display: flex;
  309. color: #409eff;
  310. font-size: 16px;
  311. cursor: pointer;
  312. }
  313. .target-list {
  314. margin-top: 20px;
  315. }
  316. .edit-icon {
  317. position: absolute;
  318. right: 35px;
  319. font-size: 16px;
  320. color: #409eff;
  321. cursor: pointer;
  322. }
  323. }
  324. </style>
  325. <style lang="scss">
  326. .bar-option-wrapper {
  327. .sort-date .el-input__inner {
  328. padding: 0 15px !important;
  329. height: 40px !important;
  330. }
  331. }
  332. </style>