index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <view>
  3. <u-modal :show="showModal" ref="uModal" :title="(editOrAdd === 'add' || editOrAdd === 'receptFormAdd') ? '新增' : '编辑'" :asyncClose="false" showCancelButton @cancel="closeDialog" cancelColor="#909399" :confirmText="'确定'" confirmColor="#2979ff" @confirm="confirm" @close="closeDialog" :closeOnClickOverlay="false">
  4. <view class="modal_wrap">
  5. <text @click="handleBrandClick" class="item" :class="info.dictLabel ? 'brand' : 'brand placeholder'">{{ info.dictLabel || '品牌' }}</text>
  6. <text class="divider">|</text>
  7. <u--input placeholder="型号" class="item" border="none" v-model="info.model" clearable @blur="handleModelBlur"></u--input>
  8. <text class="divider">|</text>
  9. <u--input class="code-input item" placeholder="编码" border="none" v-model="info.code" clearable></u--input>
  10. </view>
  11. <view class="img_wrap">
  12. <imgs-row-scroll v-if="info.imgsUrl.length > 0" :isShowDeleteIcon="true" @deleteImgInfo="getDeleteImgInfo" imgMode="aspectFill" :totalWidth="400" :images="info.imgsUrl" :previewEnabled="true" :imageWidth="150" :imageHeight="150"></imgs-row-scroll>
  13. <u-upload
  14. @afterRead="afterRead"
  15. name="3"
  16. multiple
  17. :maxCount="10"
  18. ></u-upload>
  19. </view>
  20. <u--input v-if="editOrAdd === 'edit'" class="price" placeholder="价格" border="bottom" v-model="info.price" clearable></u--input>
  21. <view class="charts_box" v-show="chartShow">
  22. <qiun-data-charts type="line" :chartData="chartData" canvasId="trendChart" :opts="opts" :ontouch="true"
  23. width="700rpx" height="200rpx" backgroundColor="#ffffff" />
  24. </view>
  25. </u-modal>
  26. <brandList ref="brandListRef" @selectedBrand="handleSelectedBrand"></brandList>
  27. </view>
  28. </template>
  29. <script>
  30. import imgsRowScroll from '@/components/imgs-row-scroll/index.vue'
  31. import brandList from '@/components/brand-list/index.vue'
  32. export default {
  33. name: 'AddInquiryDialog',
  34. components: {
  35. imgsRowScroll,
  36. brandList
  37. },
  38. props: {
  39. clueId: {
  40. type: String,
  41. default: ''
  42. },
  43. show: {
  44. type: Boolean,
  45. default: false
  46. },
  47. editOrAdd: {
  48. type: String,
  49. default: ''// edit 编辑(有价格), editForm 编辑询价单(无价格), add 新增询价单, receptFormAdd 新增接收询价单 线索页面:第一次点击是新增(不需要回显),status传1,第二次点击是无价格编辑status传1;接单中心:第一次点击是新增(需要回显)status传1,第二次点击是无价格编辑status传1;只有edit是有价格编辑status传2
  50. },
  51. editInfo: {
  52. type: Object,
  53. default: () => {}
  54. },
  55. type: {
  56. type: Number,
  57. default: 1
  58. },
  59. },
  60. emits: ['submitSuccess'],
  61. data() {
  62. return {
  63. showModal: false,
  64. info: {
  65. model:'',
  66. code:'',
  67. id:'',
  68. price:'',
  69. dictLabel:'',
  70. dictValue:'',
  71. imgsUrl:[]
  72. },
  73. rules: {
  74. brand: [
  75. { required: true, message: '请输入品牌', trigger: 'blur' }
  76. ]
  77. },
  78. chartData:{},
  79. opts: {
  80. color: ["#f9ae3d"],
  81. padding: [10, 10, 0, 0],
  82. dataLabel: false,
  83. dataPointShape: false,
  84. enableScroll: true,
  85. legend: {
  86. show: false
  87. },
  88. xAxis: {
  89. disableGrid: true,
  90. scrollShow: true,
  91. itemCount: 10,
  92. rotateLabel: true,
  93. rotateAngle: 45,
  94. },
  95. yAxis: {
  96. gridType: "dash",
  97. dashLength: 7,
  98. },
  99. extra: {
  100. line: {
  101. type: "curve",
  102. width: 3,
  103. activeType: "hollow",
  104. linearType: "custom",
  105. onShadow: true,
  106. animation: "horizontal"
  107. }
  108. }
  109. },
  110. chartShow: false
  111. }
  112. },
  113. watch: {
  114. show: {
  115. handler(newVal) {
  116. this.showModal = newVal;
  117. },
  118. immediate: true
  119. }
  120. },
  121. methods: {
  122. // 编辑回显
  123. initData() {
  124. this.$nextTick(()=>{
  125. this.info = JSON.parse(JSON.stringify(this.editInfo))
  126. this.showModal = true;
  127. if(this.info.model && this.info.dictValue){
  128. this.getChartData()
  129. }
  130. })
  131. },
  132. // 获取删除图片信息
  133. getDeleteImgInfo(info) {
  134. this.info.imgsUrl = info.newImages
  135. },
  136. handleBrandClick() {
  137. this.$refs.brandListRef.showBrandList();
  138. },
  139. handleSelectedBrand(info) {
  140. this.info.dictLabel = info.dictLabel
  141. this.info.dictValue = info.dictValue
  142. },
  143. // 上传图片
  144. afterRead(info) {
  145. info.file.forEach(item=>{
  146. uni.$u.api.uploadFile(item.url).then((res) => {
  147. this.info.imgsUrl.push(res.data.url);
  148. uni.$u.toast("文件上传成功");
  149. }).catch(() => {
  150. uni.$u.toast("上传文件失败");
  151. })
  152. })
  153. },
  154. // 确认添加
  155. confirm() {
  156. if (!this.info.dictLabel || !this.info.dictValue) {
  157. uni.showToast({
  158. title: '请选择品牌',
  159. icon: 'none'
  160. })
  161. return
  162. }
  163. if (!this.info.model) {
  164. uni.showToast({
  165. title: '请输入型号',
  166. icon: 'none'
  167. })
  168. return
  169. }
  170. if (!this.info.code) {
  171. uni.showToast({
  172. title: '请输入编码',
  173. icon: 'none'
  174. })
  175. return
  176. }
  177. if(this.info.imgsUrl.length == 0){
  178. uni.showToast({
  179. title: '请上传图片',
  180. icon: 'none'
  181. })
  182. return
  183. }
  184. if(this.editOrAdd === 'edit' && !this.info.price){
  185. uni.showToast({
  186. title: '请输入价格',
  187. icon: 'none'
  188. })
  189. return
  190. }
  191. const data = {
  192. clueId: this.clueId,
  193. dictValue: this.info.dictValue,
  194. dictLabel: this.info.dictLabel,
  195. model: this.info.model,
  196. code: this.info.code,
  197. id: (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm') ? this.info.id : '',
  198. price: this.editOrAdd === 'edit' ? this.info.price : '',
  199. imgsUrl:this.info.imgsUrl,
  200. status: this.editOrAdd === 'edit' ? '2' : '1',
  201. type: this.type
  202. }
  203. uni.$u.api.addInquiry(data).then(res => {
  204. if (res.code == 200) {
  205. uni.showToast({
  206. title: '添加成功',
  207. icon: 'success'
  208. })
  209. this.closeDialog()
  210. this.$emit('submitSuccess')
  211. }
  212. })
  213. },
  214. showDialog() {
  215. if (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm' || this.editOrAdd === 'receptFormAdd') {
  216. this.initData();
  217. }else if(this.editOrAdd === 'add'){
  218. this.clearForm()
  219. this.showModal = true;
  220. }
  221. },
  222. clearForm() {
  223. this.info = {
  224. dictLabel:'',
  225. dictValue:'',
  226. model:'',
  227. code:'',
  228. id:'',
  229. price:'',
  230. imgsUrl:[]
  231. }
  232. },
  233. closeDialog() {
  234. this.showModal = false;
  235. this.chartShow = false
  236. this.chartData = {}
  237. },
  238. handleModelBlur() {
  239. if (this.info.model !== ''){
  240. this.getChartData()
  241. }
  242. },
  243. getChartData() {
  244. uni.$u.api.inquiryChart({
  245. model: this.info.model,
  246. }).then(res => {
  247. if (res.code == 200) {
  248. const reverseData = res.data.reverse()
  249. let data = {
  250. categories: reverseData.map(item=>item.recycleTime),
  251. series: [
  252. {
  253. name: this.info.model+'价格',
  254. data: reverseData.map(item=>item.price),
  255. setShadow: [
  256. 3,
  257. 8,
  258. 15,
  259. "#f9ae3d"
  260. ],
  261. }
  262. ]
  263. }
  264. this.chartData = JSON.parse(JSON.stringify(data))
  265. this.chartShow = true
  266. }
  267. })
  268. },
  269. }
  270. };
  271. </script>
  272. <style lang="scss" scoped>
  273. @import './index.scss'
  274. </style>